抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

Fallout

1.题目要求

获得以下合约的所有权来完成这一关

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

import 'openzeppelin-contracts-06/math/SafeMath.sol';

contract Fallout {

using SafeMath for uint256;
mapping (address => uint) allocations;
address payable public owner;


/* constructor */
function Fal1out() public payable {
owner = msg.sender;
allocations[owner] = msg.value;
}

modifier onlyOwner {
require(
msg.sender == owner,
"caller is not the owner"
);
_;
}

function allocate() public payable {
allocations[msg.sender] = allocations[msg.sender].add(msg.value);
}

function sendAllocation(address payable allocator) public {
require(allocations[allocator] > 0);
allocator.transfer(allocations[allocator]);
}

function collectAllocations() public onlyOwner {
msg.sender.transfer(address(this).balance);
}

function allocatorBalance(address allocator) public view returns (uint) {
return allocations[allocator];
}
}

2. 分析

  • import 'openzeppelin-contracts-06/math/SafeMath.sol';
    
  • 2.1 由于没有SafeMath.sol文件在remix中,所以可以在remix中建相同路径的文件夹

  • image-20230223192113696

  • 2.2 阅读代码可知,在fal1out() 函数中可以修改合约的所有权,即成功调用fal1out()函数即可

3. 解题

  • 3.1 获取关卡实例地址: 0x578d3Fca5950E9CB155B91002FAe154796D05217

  • 3.2 调用关卡合约

  • image-20230224131300803

  • 3.3 image-20230224131436398

  • 3.4 查看原合约拥有者

  • image-20230224131533437

  • 3.5 调用Fal1out() 函数之后,再次查看合约的owner

  • image-20230224131723503

  • 3.6 提交实例并查看结果

  • image-20230224131818350

  • 成功!!!!

评论



政策 · 统计 | 本站使用 Volantis 主题设计