Exploit Analysis Decoding Transit Finance’s Contract Vulnerability

neptunemutual · November 06, 2024 · 6 hits

Transit Finance, a DEX aggregator lost $21 million after a vulnerability in their code base.

TL;DR

On October 2nd, 2022, Transit Finance lost $21 million after a vulnerability in their code-base allowed a hacker to drain the wallets of users who had approved the protocol's swap contract.

Introduction to Transit Finance

Transit Finance is a multi-chain DEX aggregator that chooses and combines popular DEXs from public chains to improve transaction depth and yields.

Vulnerability Assessment

The vulnerability existed in the project's code, but the attacker specifically targeted users by exploiting a weakness in the transferFrom function. The Transit Swap protocol did not strictly validate the data sent in by the user during token exchange, resulting in an arbitrary external call that the hacker exploited to steal approved tokens from users.

Any tokens approved for trading on Transit Swap could be sent directly from the user's wallet to the address of the exploiter.

Steps

Step 1:

The smart contracts of the project are closed-source contracts. The published byte-code was decompiled to determine that the underlying cause of this vulnerability was a controllable transferFrom external call.

Step 2:

The first attack transaction 0xba75ad7a43e784f51fe777d749fc55ae10f1df2bcb01cde97641613b19acb6ec by the exploiter 0x75f2aba6a44580d7be2c4e42885d4a1917bffd46 lasted around thirty minutes until tokens were exchanged for ETH and BNB on the respective chains. The exploited transaction to drain all the funds can be seen in thorugh this Etherscan details.

Step 3:

When a user initiates a swap through Transit Swap, they initially pass through the routing proxy contract. Different contracts for routing bridges are selected based on the type of exchange.

Step 4:

The routing bridge contract will transmit the claimTokens function of the permissions management contract, which requires user authorization prior to token exchange. The claimTokens function then transfers the tokens to the routing bridge contract to be redeemed by the user.

Step 5:

The claimTokens function transfers funds by running the transferFrom function of the specified token contract. The parameters are unconstrained, except that the caller must be either a routing proxy contract or a routing bridge contract, and passed in by the upper-layer routing bridge contract.

Step 6:

After receiving the tokens to be exchanged by a user, the route bridge contract will then invoke the swap contract for specified swap operations. The address of the swap contract and the call data are all established by the upper-layer route proxy contract; therefore, the route bridge contract does not validate the the parsed swap contract address and call data.

Step 7:

The parameters sent by the route proxy contract to the route bridge contract likewise originate from the user-supplied parameters. The route proxy contract verifies just that the length of each data in the user-supplied calldata meets the expectations and that the called route bridge contract is the address in the whitelist mapping, but does not examine the calldata itself.

Step 8:

The attacker exploited the fact that neither the routing proxy contract, the routing bridge contract, nor the permissions management contract inspects incoming data.

Step 9:

With the constructed data from the routing proxy contract, the callBytes function of the routing bridge contract is invoked. The callBytes function decodes the attacker's exchange contract and redemption data, where the exchange contract is the address of the permissions management contract and the redemption data is a call to the claimTokens function.

Step 10:

The claimTokens function is then used to transmit the tokens of the selected user to the token address of the attacker. This is accomplished by stealing tokens from all authorized users of the permissions management contract.

Aftermath

The hacker has returned over 83% of the stolen assets after the involvement of multiple security firms.

The project team continued to collect specific data from stolen users in order to develop a return plan for those affected by this incident.

How to Prevent Such an Attack Vector

Hiding contract code makes lengthy investigation practically impossible and impedes hackers' ability to find vulnerabilities before they are exploited. Each protocol must take the appropriate procedures to include all validated contracts into its operations.

Hacks, exploits, frauds, and smart contract vulnerabilities are all too common in the blockchain world, and a DeFi team's requirement to keep closed source code raises a lot of suspicion. Is this an insider job involving the use of privileged information against their users for yet another form of business marketing? We will let time decide on everything.

No Reply at the moment.
You need to Sign in before reply, if you don't have an account, please Sign up first.