TL;DR

On October 11, 2022, Rabby was the victim of a smart contract exploit in which the hacker stole 114 ETH worth $146,000 and 179 BNB worth $48,500, totaling a loss of ~$200,000.

Introduction to Rabby

Rabby is a browser-based open source Ethereum cryptocurrency wallet. It is built and maintained by the DeBank team and is intended to provide a smooth multi-chain experience for DeFi users.

Vulnerability Assessment

The root cause of the vulnerability is the contract's token exchange function, which was called externally via the functionCallWithValue function in the OpenZeppelin Address library.

Steps

  1. The attacker address can be found here, alongside one of the attack transaction.

  2. The exploitable contract that enables the swap feature had previously been audited, however it appeared that the vulnerability was undetected.

  3. The interface for users to swap tokens in a given DEX router is provided by the RabbyRouter contract. When the source token is address(0), it intends to buy tokens with Ether. It was revealed that there was an existence of a redundant Ether transfer.

  4. In the dexRouter, the _swap() routine is used to complete the token swap from the srcToken to the dstToken.

  1. When the srcToken is Ether (srcToken == address(0)), the Ether value is token in the transaction's msg.value.

  2. However, there was a redundant Ether transfer, which transferred the specified amount of Ether from the current contract to the contract itself.

  1. There were also no validation techniques, require(amount == msg.value) to ensure that the srcToken amount was exactly the same as msg.value.

  2. The _swap function thus calls the dexRouter(token) address using functionCallWithValue function.

  1. A user can pass in the target contract and the call data, however the contract does not validate the user-passed arguments, which causes an arbitrary external call issue. This is what the attacker takes advantage of to steal money from users who have approved the swap contract.

  2. All of the stolen money has been deposited into Tornado Cash by the attacker.

Aftermath

The team has stated that they are currently looking for the stolen assets and that they will provide users with a satisfactory resolution within a week. They advised users to rescind all prior approvals for Rabby Swap contracts on all chains.

How to prevent such an attack vector

This exploit could have been avoided using proper validation techniques to ensure that the any external call to the contracts were restricted.

Protocol, and Platform Security

Our security team at Neptune Mutual can validate your platform for DNS and web-based security, smart contract reviews, as well as frontend and backend security. We can offer you a solution to scan your platform and safeguard your protocol for known and unknown vulnerabilities that have the potential to have catastrophic long-term effects. Contact us on social media if you are serious about security and have the budget, desire, and feeling of responsibility to do so.


About Us

Neptune Mutual project safeguards the Ethereum community from cyber threats. The protocol uses parametric cover as opposed to discretionary insurance. It has an easy and reliable on-chain claim process. This means that when incidents are confirmed by our community, resolution is fast.

Join us in our mission to cover, protect, and secure on-chain digital assets.

Official Website: https://neptunemutual.com
Blog: https://blog.neptunemutual.com/
Twitter: https://twitter.com/neptunemutual
Reddit: https://www.reddit.com/r/NeptuneMutual
Telegram: https://t.me/neptunemutual
Discord: https://discord.gg/2qMGTtJtnW
YouTube: https://www.youtube.com/c/NeptuneMutual
LinkedIn: https://www.linkedin.com/company/neptune-mutual