Arbitrary contract call allows attackers to steal ERC20 from users’ wallets
The contract's fillZrxQuote function makes an arbitrary external call with user-supplied calldata, allowing an attacker to invoke transferFrom on any token contract and steal tokens that users have approved to the Swap contract.
Submitted by WatchPug
function fillZrxQuote(
IERC20 zrxBuyTokenAddress,
address payable zrxTo,
bytes calldata zrxData,
uint256 ethAmount
) internal returns (uint256, uint256) {
uint256 originalERC20Balance = 0;
if(!signifiesETHOrZero(address(zrxBuyTokenAddress))) {
originalERC20Balance = zrxBuyTokenAddress.balanceOf(address(this));
}
uint256 originalETHBalance = address(this).balance;
(bool success,) = zrxTo.call{value: ethAmount}(zrxData);
A call to an arbitrary contract with custom calldata is made in fillZrxQuote(), which means the contract can be an ERC20 token, and the calldata can be transferFrom a previously approved user.
Impact
The wallet balances (for the amount up to the allowance limit) of the tokens that users approved to the contract can be stolen.
PoC
Given:
- Alice has approved 1000 WETH to
Swap.sol;
The attacker can:
TallySwap.swapByQuote(
address(WETH),
0,
address(WETH),
0,
address(0),
address(WETH),
abi.encodeWithSignature(
"transferFrom(address,address,uint256)",
address(Alice),
address(this),
1000 ether
)
)
As a result, 1000 WETH will be stolen from Alice and sent to the attacker.
This PoC has been tested on a forking network.
Recommendation
Consider adding a whitelist for zrxTo addresses.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
The contract performs an arbitrary external call to a user-controlled address with user-controlled calldata without validating the target or the function being called.
Impact
The wallet balances (for the amount up to the allowance limit) of the tokens that users approved to the contract can be stolen.
What the attacker needed
Victim has approved tokens to the contract; attacker can call swapByQuote
The fix
The contract should add a whitelist for the addresses that can be called in fillZrxQuote.
How it was found
- Alice approves the Swap contract to spend 1000 WETH.
- The attacker calls swapByQuote with parameters that set the target contract to the WETH token and the calldata to a transferFrom call moving Alice's WETH to the attacker.
- The Swap contract executes the call, transferring 1000 WETH from Alice to the attacker.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
The smart contract lets users swap tokens and, as part of that, it calls another contract address that the user provides. Because the contract does not check who is being called, an attacker can tell it to call a token contract and use a function that moves tokens from someone who had given the swap contract permission to spend their tokens. This lets the attacker take those tokens.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.