문제 : https://ethernaut.openzeppelin.com/level/0x7E0f53981657345B31C59aC44e9c21631Ce710c7
https://ethernaut.openzeppelin.com/level/0x7E0f53981657345B31C59aC44e9c21631Ce710c7
ethernaut.openzeppelin.com
Developer tool에 console창에 보면 Ethernaut과 관련된 내용이 떠 있는 것을 볼 수 있다.
중간에 설명에 나와있는것은 건너뛰고 바로 new instance를 실행하겠다.
Ethereum Sepolia Faucet
Get free Sepolia ETH to deploy smart contracts, debug transactions, and experiment on testnet.
cloud.google.com
해당 링크에서 0.05 이더를 받아 가스 비용을 지불했다.
문제를 풀어보자
await contract.info()
를 실행하면 계속 어떤 함수를 실행해야할지 알려준다.
현재 infoNum에 보면 words 배열이 있다.
첫번째 숫자가 42이므로, info42라는 함수를 호출해야함을 추측하였다.
아까와 같은 방식으로 계속 메소드를 호출해나간다.
password를 알고 있다면, 이걸 authenticate의 파라미터로 호출하면 된다.
따라서 password 메소드를 실행시켜 authenticate를 실행한다.
실행하게 되면 이런 식의 트랜젝션 컨펌 요청이 뜨게 되고, 컨펌해준다.
submit하여 다시 트랜젝션을 컨펌해주면 되는 문제이다.
아래는 해당 문제의 코드가 문제풀이 후 주어진 것이다.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Instance {
string public password;
uint8 public infoNum = 42;
string public theMethodName = "The method name is method7123949.";
bool private cleared = false;
// constructor
constructor(string memory _password) {
password = _password;
}
function info() public pure returns (string memory) {
return "You will find what you need in info1().";
}
function info1() public pure returns (string memory) {
return 'Try info2(), but with "hello" as a parameter.';
}
function info2(string memory param) public pure returns (string memory) {
if (keccak256(abi.encodePacked(param)) == keccak256(abi.encodePacked("hello"))) {
return "The property infoNum holds the number of the next info method to call.";
}
return "Wrong parameter.";
}
function info42() public pure returns (string memory) {
return "theMethodName is the name of the next method.";
}
function method7123949() public pure returns (string memory) {
return "If you know the password, submit it to authenticate().";
}
function authenticate(string memory passkey) public {
if (keccak256(abi.encodePacked(passkey)) == keccak256(abi.encodePacked(password))) {
cleared = true;
}
}
function getCleared() public view returns (bool) {
return cleared;
}
}
내가 호출한 메소드가 어떤식으로 구현되어 있는지 확인할 수 있다.
'Hacking > Write Up' 카테고리의 다른 글
[Web3] Fallout (0) | 2025.05.25 |
---|---|
[Web3] Fallback (0) | 2025.05.25 |
[Pwnable] hook (0) | 2025.05.16 |
[Pwnable] oneshot (0) | 2025.05.16 |
[Reversing] Easy Assembly (0) | 2025.05.10 |