区块链安全

文章目录

  • 区块链安全
  • Jump Oriented Programming实战一
  • 实验目的
  • 实验环境
  • 实验工具
  • 实验原理
  • 实验内容
  • Jump Oriented Programming实战一 实验步骤
  • 分析合约源代码漏洞

Jump Oriented Programming实战一

实验目的

学会使用python3的web3模块
学会分析以太坊智能合约中中Jump Oriented Programming(JOP)问题
深刻理解EVM字节码
找到合约漏洞进行分析并形成利用

实验环境

Ubuntu18.04操作机

实验工具

python3

实验原理

JOP 的思想和 ROP 是相似的:串联起一个个小的代码片段(gadget),达成一定的目的。
涉及到 JOP 的是如下三个字节码:0x56 JUMP 0x57 JUMPI 0x5B JUMPDEST,在 EVM 中的无条件跳转 JUMP 和条件跳转 JUMPI 的目的地都必须是 JUMPDEST,这点和 ROP 可以任选返回地址不同。
通常需要用到 JOP 的合约在编写时都夹杂着内联汇编的后门,本实验通过jop控制程序控制流,实现特定目的。

实验内容

合约中内置了简单的JOP问题,找到合约漏洞并形成利用,触发合约的SendFlag(address addr)事件即可
使用python3的web3模块远程利用漏洞并获取flag
实验地址为nc ip 10015

Jump Oriented Programming实战一 实验步骤

获取合约地址和合约源代码
nc ip 10015连接到题目,输入1,获取部署合约的game account及token

打开http://ip,输入上述分配的game account,点击Request获取eth


nc ip 10015连接到题目,输入2,获取部署合约的地址及new token

nc ip 10015连接到题目,输入4,获取合约源代码,或者在题目附件找到合约源代码

分析合约源代码漏洞

pragma solidity ^0.4.23;contract ETH15 { address private owner;bytes4 internal constant SET = bytes4(keccak256('fifth(uint256)'));event SendFlag(address addr);struct Func { function() internal f;}constructor() public payable { owner = msg.sender;}modifier onlyOwner { require(msg.sender == owner);_;}// 0x4b64e492function execute(address _target) public payable{ require(_target.delegatecall(abi.encodeWithSelector(this.execute.selector)) == false, 'unsafe execution');bytes4 sel; uint val;(sel, val) = getRet();require(sel == SET);Func memory func;func.f = gift;assembly {  mstore(