Pwnstar

Ethernaut Level 0(Hello Ethernaut) 본문

Wargame/Ethernaut

Ethernaut Level 0(Hello Ethernaut)

포너블처돌이 2023. 1. 27. 21:42

혼자 힘으로 풀어 뿌듯하긴 한데 첫 문제의 도움말은 꼭 보고 풀길 바란다.

그런걸 원체 안보는 성격이라 환경설정하는 부분만 보고 처음 문제 접근하는 부분을 안봤더니 혼자 개같이 고생하다 도움말 보고 수월하게 풀었다.


설정 부분을 제외하고, 도움말의 2번부터 보면

2. Open the browser’s console

개발자 도구를 열어 콘솔에 player 를 입력하면 사용자의 주소를 볼 수 있다.

3. Use the console helpers

getBalance(player)

현재 나의 Ether balance를 볼 수 있다.

balance가 뭔지 알 수가 없었다. 하지만 명령어를 입력해보면

이렇게 나오고, Promise를 눌러보면

PromiseResult현재 나의 잔고 ether를 보여준다.

나머지 Prototype에 대한 정보와 PromiseState의 fulfilled가 무엇을 의미하는 지는 아직 파악하지 못했다. 추후 공부해서 알게 된다면 추가할 예정

help()

이 명령어로 입력할 수 있는 함수의 종류들을 보여준다.

4. The ethernaut contract

ethernaut

입력하면 게임의 main smart contract를 확인할 수 있다.

5. Interact with the ABI

ethernaut은 블록체인에 배포된 Ethernaut.sol 계약을 래핑하는 TrauffleContract 객체이다.

contract의 ABI는 Ethernaut.sol의 모든 public method를 노출시킨다.

💡
ABI : 컨트랙트 내의 함수를 호출하거나 컨트랙트로부터 데이터를 얻는 방법. 컨트랙트 내의 어떤 함수를 호출할 지를 지정하는 데 필요

6. Get test ether

game을 하기 위해서는 test ether가 필요하다. faucet을 통해 선택한 네트워크의 테스트넷 이더를 얻을 수 있다. 필자는 Goerli 테스트 네트워크를 선택했다.

7. Getting a level instance

level을 실행할때, ethernaut contract와 직접적으로 상호작용하는 것이 아니고, 나를 위한 level instance를 생성해달라고 요청하는 것이다. 이렇게 하기 위해 “Get New Instance” 버튼을 누르면 된다.

MetaMask에서 트랜잭션을 승인하라는 메시지가 표시되어야 한다. 블록체인에 새 계약을 배포하는 과정이고 시간이 좀 걸릴수도 있다.

8. Inspecting the contract

계약 변수를 사용해서 콘솔을 통해 이 계약의 ABI를 실행할 수 있다.

9. Interact with the contract to complete the level

contract.info()await contract.info() 를 이용해 레벨의 정보를 볼 수 있다.

레벨을 클리어하면 submit 버튼을 눌러서 내가 레벨을 완료했는 지 알 수 있는 instance를 ethernaut에 보낸다.

도움말을 간단하게 번역해서 정리했는데 이제 문제풀이를 해보자.


도움말대로 contract.info() 혹은 크롬 v62이면 await contract.info() 를 입력하여 문제에 접근하라고 나와있다.

입력해보면

‘info1()에서 원하는 것을 찾을 수 있을거란다.’

그러면 info1()함수도 호출해보자

‘hello’를 매개변수로 info2()를 호출하면

infoNum이라는 property가 다음 호출할 메서드의 넘버를 가지고 있다고 한다.

words에 42라는 값이 들어있다. 그런데 메서드의 넘버가 42라는 것만 알고 메서드 이름이 method42인지, 뭔지 몇 개 입력하다 보니

info42()라는 메서드가 존재하는 것을 발견.

theMethodName이 다음 메서드의 이름이라고 한다.

method7123949를 호출해보자

이제 비밀번호를 안다면 authenticate()를 호출해서 submit하라는데, 여기서 좀 오래 걸렸다.

비밀번호가 뭔지 위에 메서드 번호인가해서 7123949를 입력해봤는데 아니라하고, 그래서 위의 도움말에 help()를 입력해서 나오는 명령어 중, contract를 입력하면 현재 생성된 instance를 볼 수 있기에 입력해보았더니,

password라는 메서드가 존재한다.

password는 ethernaut0

await contract.authenticate('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;
  }
}


첫 번째 문제 후기

이더리움에 대해 조금 공부를 하고 풀어봤는데, 아직 이해도가 많이 낮은 상태이고, 이 문제가 첫 번째 문제라 그런지, 약간 가벼운 misc 문제 푸는 느낌을 많이 받았다.


Uploaded by N2T

'Wargame > Ethernaut' 카테고리의 다른 글

Ethernaut Level 4(Telephone)  (0) 2023.03.12
Ethernaut Level 3(Coin Flip)  (1) 2023.03.09
Ethernaut Level 2(Fal1out)  (0) 2023.02.21
Ethernaut Level 1(Fallback)  (0) 2023.01.31
Ethernaut 문제풀이를 위한 환경설정  (0) 2023.01.27
Comments