Damn vulnerable defi Challenge2 naive receiver
overview
There’s a pool with 1000 ETH in balance, offering flash loans. It has a fixed fee of 1 ETH.
A user has deployed a contract with 10 ETH in balance. It’s capable of interacting with the pool and receiving flash loans of ETH.
Take all ETH out of the user’s contract. If possible, in a single transaction.
how to get it started
- git clone github repo
- yarn install
- fill your code in *.challenge.js
- run your script via hardhat tools
Let’s jump into the naive receiver case solidity code:
[source code] consist of 2 solidity files:
- FlashLoanReceiver.sol
- NaiveReceiverLenderPool.sol
code bug
The issue here is that the user contract does not authenticate the user to be the owner, so anyone can just take any flash loan on behalf of that contract.
We can interact with pool contract directly to drain user’s contract like this:
1 | const ETH = await pool.ETH(); |
Or we can delpoy an attack contract to invoking pool contract:
1 | interface INaiveReceiverLenderPool{ |
After we deployed the attack contract,invoke it using javascript
1 | const AttackFactory = await ethers.getContractFactory("AttackContract", player); |