Web3/Ethernaut
1. Hello Ethernaut
kevin3709
2024. 11. 11. 19:47
워게임을 진행할 때 개발자 도구의 콘솔을 사용한다. Get new Instance 버튼을 눌러 풀이를 시작할 수 있다.
문제 설명대로 contract.info() method를 실행시키면
info1() method 를 사용할 수 있다고 한다.
문제를 계속 따라가보자.
infoNum() method의 결과가 42인 것을 보니 다음에 호출해야 할 method는 info42() 임을 알 수 있다.
authenticate() 메소드에 특정 password 를 입력해야 하지만 알 수 없다. contract 코드에 어떤 값이 들어있는지 password() 로 확인해볼 수 있다.
password는 ethernaut0 라는 것을 알 수 있다.
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;
}
}
풀이 이후 공개된 코드를 보면 string public password; 처럼 password 변수가 public으로 설정되어 있음을 알 수 있다.