1. Victim 为含有漏洞的智能合约,在 Rinkeby 测试网络的合约地址为:
    2. 0x68D28fE315E6A344029D42915Fbc7af4261AB833
    3. 接口为:
    4. contract Victim {
    5. function withdraw() public returns (string memory ){
    6. return "ISCC{xxxxx}";
    7. }
    8. }
    9. 请编写攻击合约,实现对 Victim 的攻击,获取 flag

    也是给了个合约地址,继续访问https://rinkeby.etherscan.io/,搜索
    image.png
    在contract中点击decompile bytecode,反编译出来代码,拿到flag

    1. #
    2. # Panoramix v4 Oct 2019
    3. # Decompiled source of rinkeby:0x68D28fE315E6A344029D42915Fbc7af4261AB833
    4. #
    5. # Let's make the world open source
    6. #
    7. #
    8. # I failed with these:
    9. # - getBalance()
    10. # All the rest is below.
    11. #
    12. def storage:
    13. balances is mapping of uint256 at storage 0
    14. unknown0568e65e is mapping of uint256 at storage 1
    15. success is uint256 at storage 2
    16. stor3 is uint256 at storage 3
    17. stor4 is uint256 at storage 4
    18. def unknown0568e65e(addr _param1) payable:
    19. require calldata.size - 4 >= 32
    20. return unknown0568e65e[_param1]
    21. def success() payable:
    22. return success
    23. def balances(address _param1) payable:
    24. require calldata.size - 4 >= 32
    25. return balances[_param1]
    26. def getBalanceOf(address _address) payable:
    27. require calldata.size - 4 >= 32
    28. return balances[addr(_address)]
    29. #
    30. # Regular functions
    31. #
    32. def _fallback() payable: # default function
    33. revert
    34. def withdraw() payable:
    35. if balances[caller]:
    36. revert with 0, 'you have executed the withdrawal'
    37. if success > 10:
    38. if success >= 100:
    39. stor4 = 2
    40. else:
    41. stor4 = 3
    42. if unknown0568e65e[caller] == stor4:
    43. success++
    44. if unknown0568e65e[caller] < stor4:
    45. unknown0568e65e[caller]++
    46. call caller with:
    47. value stor3 wei
    48. gas gas_remaining wei
    49. log 0xae0e6674: caller, stor3, bool(ext_call.success)
    50. balances[caller] = stor3 * unknown0568e65e[caller]
    51. if balances[caller] <= stor3:
    52. revert with 0, 'failed to withdraw'
    53. return 'ISCC{h@ve_fun~Re-EntRan(y}'

    yysy,这两道区块链题目真的是这么做的吗