0

Since I have a testing contract with the reentrancy vulnerability, I want to reproduce it. However, only when the deployer is a reentrancy attack contract can this vulnerability be reproduced. Its codes are as following:

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);
  }
}

So the first step is using a contract that can exploit the vulnerability to deploy this vulnerable contract, how can I use a smart contract to deploy another one, especially through Remix?

1 Answer 1

1

You can do something like this:

pragma solidity ^0.6.0;
import './Forwarder.sol';

contract SelfDeploy{
        
    event Addr(address);
    
    function getnewaddress() public returns (uint){
       emit Addr(address(new Forwarder()));
    }
}

After the successful transaction, you can check on etherscan or you can put a listener to get the Forwarder's address.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.