因为我有一个带有重入漏洞的测试合同,所以我想复制它。但是,只有当部署人员是重入攻击契约时,才能再现此漏洞。其守则如下:
contract Forwarder {
// Address to which any funds sent to this contract will be forwarded
address public parentAddress;
event ForwarderDeposited(address from, uint value, bytes data);
event TokensFlushed(
address tokenContractAddress, // The contract address of the token
uint value // Amount of token sent
);
/**
* Create the contract, and set the destination address to that of the creator
*/
function Forwarder() {
parentAddress = msg.sender;
}
/**
* Modifier that will execute internal code block only if the sender is a parent of the forwarder contract
*/
modifier onlyParent {
if (msg.sender != parentAddress) {
throw;
}
_;
}
/**
* Default function; Gets called when Ether is deposited and forwards it to the destination address
*/
function() payable {
if (**!parentAddress.call.value(msg.value**)(msg.data))
throw;
// Fire off the deposited event if we can forward it
ForwarderDeposited(msg.sender, msg.value, msg.data);
}
}因此,第一步是使用可以利用漏洞部署此易受攻击契约的契约,我如何使用智能契约来部署另一个契约,特别是通过Remix?
发布于 2021-04-07 11:02:26
你可以这样做:
pragma solidity ^0.6.0;
import './Forwarder.sol';
contract SelfDeploy{
event Addr(address);
function getnewaddress() public returns (uint){
emit Addr(address(new Forwarder()));
}
}在成功的事务处理之后,您可以检查以太扫描,也可以让侦听器获取转发器的地址。
https://ethereum.stackexchange.com/questions/96826
复制相似问题