# 智能合约黑客攻击 Ethernaut:    6. Delegate

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

---

[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 - ….
    

题目
--

将 Delegation 合约中的owner改为自己。

Hack思路
------

Delegation 可以委托调用 Delegate， 其中owner变量在同一个slot， 只要改 Delegate.owner , Delegation.owner 也会修改，调用时利用 fallback 这个方法不存在的默认hook来触发。

**使用时要用 Delegate 的ABI来包装下 Delegation 的地址。**

代码参考：

    Delegate(address(Delegation(payable(levelAddress)))).pwn();
    

Hack案例
------

…

防范思路
----

….

参考资料
----

*   [The Parity Wallet Hack Explained](https://blog.openzeppelin.com/on-the-parity-wallet-multisig-hack-405a8c12e8f7)
    
*

---

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