-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎉 Added README.md till challenge #10
- Loading branch information
1 parent
6f20c4c
commit 1f32514
Showing
68 changed files
with
191 additions
and
84 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
File renamed without changes.
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
File renamed without changes.
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
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
File renamed without changes.
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,17 @@ | ||
## Ethernaut Challenge 10 | ||
|
||
In this challenge the user is provided with a contract called [`Reentrance.sol`](./Reentrance.sol). The goal of this challenge to drain the contract. | ||
|
||
This challenge requires user to be familiar with the following concepts. | ||
- Checks-effects-interaction pattern | ||
|
||
### Solution | ||
- Create a contract [`Atatck.sol`](./Atatck.sol) that has a function to call the fallback of [`Reentrance.sol`](./Reentrance.sol) using `drain()`. | ||
- When the ether are received in `Attack` contract it invoke its fallback function where it gives us the control over the execution. | ||
- We call the `withdraw()` in the fallback to re-enter the contract to drain it. | ||
|
||
1. Run Exploit! | ||
|
||
```sh | ||
cd .. && forge test -vv -m test_challenge_10 | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.6.0; | ||
|
||
contract FakeERC20 { | ||
function approve(address addr, uint256 amount) public pure returns (bool) { | ||
// Silence compiler | ||
{ | ||
addr; | ||
amount; | ||
} | ||
return true; | ||
} | ||
|
||
function balanceOf(address account) public pure returns (uint256) { | ||
// Silence compiler | ||
{ | ||
account; | ||
} | ||
return 1; | ||
} | ||
|
||
function transferFrom( | ||
address spender, | ||
address receiver, | ||
uint256 amount | ||
) public pure returns (bool) { | ||
// Silence compiler | ||
{ | ||
spender; | ||
receiver; | ||
amount; | ||
} | ||
return true; | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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,18 @@ | ||
## Ethernaut Challenge 4 | ||
|
||
In this challenge the user is provided with a contract called [`Telephone.sol`](./Telephone.sol). The goal of this challenge claim the ownership of the contract. | ||
|
||
This challenge requires user to be familiar with the following concepts.. | ||
|
||
- Difference between `tx.origin` & `msg.sender` | ||
|
||
### Solution | ||
|
||
- The [`Telephone contract`](./Telephone.sol) has a `changeOwner()` that takes in an address value. | ||
- The function which can be called from a custom contract that will change the `tx.origin` value from the `msg.sender` allowing us to set whatever address we want the onwer to be. | ||
|
||
1. Run Exploit! | ||
|
||
```sh | ||
cd .. && forge test -vv -m test_challenge_4 | ||
``` |
File renamed without changes.
File renamed without changes.
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
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,15 @@ | ||
## Ethernaut Challenge 5 | ||
|
||
In this challenge the user is provided with a contract called [`Token.sol`](./Token.sol). The goal of this challenge is to hack the the token contract. | ||
|
||
### Solution | ||
|
||
- The [`Token contract`](./Token.sol) has a `transfer()` functions that takes in an address & value. | ||
- It has a check that should be checking for interger overflow but the condition `require(balances[msg.sender] - _value >= 0);` will always returns `0`. | ||
- Here we also need to make sure that `msg.sender` has some tokens otherwise `balances[msg.sender] -= _value;` will be overflowed. | ||
|
||
1. Run Exploit! | ||
|
||
```sh | ||
cd .. && forge test -vv -m test_challenge_5 | ||
``` |
File renamed without changes.
File renamed without changes.
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
File renamed without changes.
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,19 @@ | ||
## Ethernaut Challenge 6 | ||
|
||
In this challenge the user is provided with a contract called [`Delegate.sol`](./Delegate.sol). The goal of this challenge claim the ownership of the contract. | ||
|
||
This challenge requires user to be familiar with the following concepts.. | ||
- Solidity `delegtecall` function & storage layout. | ||
- Fallback functions. | ||
|
||
### Solution | ||
|
||
- We can simply invoke fallback of [Delegation](./Delegate.sol) which has the exact same storage variable layout as [Delegate](./Delegate.sol). It will make a `delegatecall` to [Delegate contract](./Delegate.sol) which will set the owner to out address i.e `msg.sender`. | ||
- This storage layout is important because whenever a `delegatecall` is made to another contract `msg.sender` & `msg.value` are preserved but the storage changes will be made to the contract from which th `delegatecall` started. | ||
- In other word, whenever a `delegatecall` is made from `A` to function in another contract `B` that function behaves as it was the the part of the contract `A`. If any state changes are made, they are made in contract `A` storage. | ||
|
||
1. Run Exploit! | ||
|
||
```sh | ||
cd .. && forge test -vv -m test_challenge_6 | ||
``` |
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
File renamed without changes.
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,16 @@ | ||
## Ethernaut Challenge 7 | ||
|
||
In this challenge the user is provided with a contract called [`Force.sol`](./Force.sol). The goal of this challenge to send ether to the contract that has no ability to receive ether. | ||
|
||
This challenge requires user to be familiar with the following concepts.. | ||
- Solidity `selfdestruct()` function | ||
|
||
### Solution | ||
- We create a contract [`ForceSend`](./Force.sol) & use selfdestruct to forcefully send the ether to the contract. | ||
- Since the contract addresses can be predicted, it is possible to send ether to an address & later deploy a contract at it. | ||
|
||
1. Run Exploit! | ||
|
||
```sh | ||
cd .. && forge test -vv -m test_challenge_7 | ||
``` |
File renamed without changes.
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,29 @@ | ||
## Ethernaut Challenge 8 | ||
|
||
In this challenge the user is provided with a contract called [`Vault.sol`](./Vault.sol). The goal of this challenge to unlock the vault. | ||
|
||
This challenge requires user to be familiar with the following concepts. | ||
|
||
- Storage or slot packing technique while contract creation. | ||
|
||
### Solution | ||
|
||
- Private variables of a contract cannot be accessed from another smart contract unless it is inherting the contract. But contract storage slots can be accessed off-chain through an ethereum RPC endpoint using. | ||
|
||
```js | ||
const provider = new providers.JsonRpcProvider( | ||
{ url: YOUR_ETHEREUM_RPC_URL }, | ||
1 | ||
); | ||
let pass = await provider.getStorageAt("YOU_INSTANCE_ADDRESS", 1); | ||
console.log("The password is :", pass); | ||
``` | ||
|
||
### Alternative solution | ||
- For demostrative pruposes, I have created a function call `getValueAtSlot()` in [`Vault.sol`](./Vault.sol) to get the storage at slot `1` as it is where the value of the `password` in bytes32 is stored. | ||
|
||
1. Run Exploit! | ||
|
||
```sh | ||
cd .. && forge test -vv -m test_challenge_8 | ||
``` |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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,17 @@ | ||
## Ethernaut Challenge 9 | ||
|
||
In this challenge the user is provided with a contract called [`King.sol`](./King.sol). The goal of this challenge to become the king in such a way that no one should be able to overpay & become the king. | ||
|
||
This challenge requires user to be familiar with the following concepts. | ||
- Solidity `fallback()` funtion. | ||
|
||
### Solution | ||
- Create a contract [`AttackKing.sol`](./AttackKing.sol) that has a function to call the fallback of [`King.sol`](./King.sol). | ||
- We also include a `fallback()` function in out contract for handling event when receiving Eth. And force the transaction to fail is anyone send ether to it by `require(false, "Can't overthrow me!");` to never be overthrown. | ||
- We call the [`AttackKing.sol`](./AttackKing.sol) with amount of eth that is greater than `prize` which makes our contract the king. | ||
|
||
1. Run Exploit! | ||
|
||
```sh | ||
cd .. && forge test -vv -m test_challenge_9 | ||
``` |
File renamed without changes.