blockchain | 区块链安全靶场 The Ethernaut

发布时间 2023-04-06 11:55:00作者: Mz1

blockchain | 区块链安全靶场 The Ethernaut

最近在学这一块,找个靶场玩玩:https://ethernaut.openzeppelin.com/
可以参考:https://blog.csdn.net/rfrder/article/details/115572137

需要提前安装好MetaMask和自己的链子(用测试链也行,主要自己的链子有用不完的ether)

然后先部署,通过contract查看合约。
然后在控制台进行交互操作:
image

然后通过以后点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;
  }
}

image