Attackers can drain the `OracleLess` contract by creating an order with a `malicious tokenIn` and executing it with a `malicious target`
The OracleLess contract does not verify that tokenIn is a legitimate ERC20 token and does not validate the target and txData in fillOrder, allowing an attacker to create an order with a malicious token and execute it with a malicious target to drain all USDT from the contract.
In the OracleLess contract, the createOrder() function does not verify whether the tokenIn is a legitimate ERC20 token, allowing attackers to create an order with a malicious token. Additionally, the fillOrder() function does not check if the target and txData are valid, enabling attackers to execute their order with a malicious target and txData.
Root Cause
The OracleLess.createOrder() function does not verify whether tokenIn is a legitimate ERC20 token.
Additionally, the OracleLess.fillOrder() function does not check if target and txData are valid.
Internal pre-conditions
External pre-conditions
Attack Path
Let's consider the following scenario:
Alice, the attacker, creates a malicious token.
Alice creates an order with her malicious token:
tokenIn: Alice's malicious token
tokenOut: WETH
minAmountOut: 0
Alice calls the fillOrder() function to execute her malicious order, setting parameters as follows:
target: address of USDT
txData: transfer all USDT in the OracleLess contract to Alice.
Solidity
function fillOrder(
...
118 (uint256 amountOut, uint256 tokenInRefund) = execute(
target,
txData,
order
);
...
}
At line 118 of the fillOrder() function, execute() is invoked:
At line 237 of the execute() function, tokenIn.safeApprove() is called. Alice made her malicious tokenIn as follows:
Solidity
function approve(address spender, uint256 amount) public virtual override returns (bool) {
WETH.transfer(msg.sender, 1);
return true;
}
This transfers 1 wei of WETH to the OracleLess contract.
At line 240, all USDT are transferred to Alice, as target is USDT and txData is set to transfer to Alice.
At line 251, finalTokenOut - initialTokenOut will be 1, as the contract has already received 1 wei. Thus, the require statement will pass since order.minAmountOut was set 0.
As a result, Alice can drain all USDT from the OracleLess contract.
Impact
Attackers can drain the OracleLess contract by using malicious token, target, and txData.
PoC
Mitigation
It is recommended to implement a whitelist mechanism for token, target, and txData.
The original report as published on Sherlock, by 0xaxaxa. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Impact
Attackers can drain all USDT from the OracleLess contract.
What the attacker needed
Attacker can create a malicious token; Contract holds USDT
The fix
The protocol team fixed this issue in the following PRs/commits: https://github.com/gfx-labs/oku-custom-order-types/pull/1
How it was found
Alice creates a malicious token.
Alice creates an order with her malicious token as tokenIn, WETH as tokenOut, and minAmountOut set to 0.
Alice calls fillOrder() with target set to the USDT address and txData set to transfer all USDT in the OracleLess contract to Alice.
The malicious token's approve function transfers 1 wei of WETH to the OracleLess contract, making the finalTokenOut - initialTokenOut equal to 1, which passes the require statement since minAmountOut is 0.
All USDT is transferred to Alice.
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.
Generating the AI write-up for this report.
This usually takes about a minute. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
A smart contract lets users create orders to swap tokens. The contract failed to check that the token used in an order was real and that the instructions for filling the order were safe. An attacker could use a fake token and a malicious instruction to steal all the USDT held by the contract.
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.
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.