# 智能合约黑客攻击 Ethernaut: 2. Fallout **Published by:** [Leek DEV](https://paragraph.com/@leekdev/) **Published on:** 2023-09-26 **URL:** https://paragraph.com/@leekdev/ethernaut-2-fallout ## Content Ethernaut 是一个基于 Web3/Solidity 的对抗游戏,受 overthewire.org 启发, 运行于以太坊虚拟机. 每个关卡是一个需要被 ‘hacked’ 的智能合约。题目攻击合约,将合约里的owner设置为自己。Hack思路在 solidity 0.6版本是 合约方法名与合约名相同的方法就创建时会调用,和现在的 constructor() 一样。但是这个合约 名称是 Fallout ,里面的构造方法错误的写成了 Fal1out,所以创建后也可以执行Fal1out 方法来获取权限。// 1. 检查当前合约owner await contract.owner(); // 2.直接调用错误的初始化方法来获取 owner await contract.Fal1out(); // 3. 再次检查当前合约owner await contract.owner(); 如果是用 Remix IDE 的话,需要把合约的 SafeMath 库替换为老版本。// 将合约的 SafeMath 替换为老版本 // import 'openzeppelin-contracts-06/math/SafeMath.sol'; import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v3.4.2/contracts/math/SafeMath.sol"; Hack案例Rubixi防范思路…参考资料… ## Publication Information - [Leek DEV](https://paragraph.com/@leekdev/): Publication homepage - [All Posts](https://paragraph.com/@leekdev/): More posts from this publication - [RSS Feed](https://api.paragraph.com/blogs/rss/@leekdev): Subscribe to updates - [Twitter](https://twitter.com/LeekDEV): Follow on Twitter