Flash loan attack + wrong permission configuration, 25 million US dollars wasted | A brief analysis of xToken hacking incident
1. Event overview
secondary title
Although the xToken team issued a statement immediately after the incident and made a positive response to the reasons for the hack and subsequent remedial measures; Chengdu Lianan Security Team believes that the xToken hacking incident is quite typical, involving Hackers such as lightning loan attacks and price manipulation often attack routines, so they immediately intervened in the analysis and sorted out the attack process of the xToken hacking incident, hoping to use this as a lesson to sound the alarm for the majority of DeFi projects.
2. Event analysis
secondary title
In this hacking incident, the attacker used two typical attack routines in the same transaction. First, the hacker used the flash loan to manipulate the price of SNX in DEX, which in turn affected the coinage in xSNX, aiming to achieve the purpose of arbitrage; second, the hacker used the wrong permission configuration in the xBNT contract to pass in unexpected Path address, so as to achieve the purpose of using air coins to complete profit.
Preparation
Next, let's restore how the hacker used "flash loan attack + wrong permission configuration" to complete the entire attack process.
Preparation
1. The attacker first uses flash loans to lend a large amount of funds;
2. Use the lending function of Aave and the DEX function of Sushiswap to obtain a large amount of SNX tokens;
3. Then sell a large number of SNX on Uniswap, thereby disrupting the price of SNX on Uniswap;
attack begins
4. Use a small amount of ETH to obtain a large amount of xSNX;
Principle explanation: The attacker used the xSNX contract to support the mechanism of exchanging ETH and SNX for xSNX. Specifically, when the user transfers ETH, the contract will exchange the user's ETH for equivalent SNX through Uniswap, and then perform xSNX exchange. Due to the attacker's operations in 1~3 in the "preparation work", the price of ETH to SNX in Uniswap is manipulated at this time, which allows a small amount of ETH to be exchanged for a large amount of SNX, and then exchanged for a large amount of xSNX.
attack finish
5. The attacker made a profit by selling in Bancor. Since the price in Bancor was not affected, the price was still normal at that time. At this time, the attacker can arbitrage, and then return the flash loan;
Principle explanation: The attacker used the xBNT contract to support the function of ETH minting xBNT. The contract will convert ETH into BNT in Bancor and then mint xBNT. However, it should be noted that this minting function can specify the exchange path, that is, it does not need Converting to BNT can also be minted, which allows an attacker to arbitrarily specify an address for converting tokens.
3. Event review
secondary title
3. Event review
In the official response of the xToken team, it expressed deep regret for the loss of assets caused by the hacking incident, and mentioned that a security feature will be introduced in the upcoming products to prevent such attacks. Unfortunately, $25 million was lost due to the fact that this safety feature has not yet been introduced across the entire product line.


