transferFrom
function is used to transfer tokens from one address to another. However, in this case, the from
address is set to listing.buyer
, which is an arbitrary address that can be controlled by an attacker.Swan.purchase
function in the Swan
contract uses an arbitrary from
address in the transferFrom
function, allowing an attacker to manipulate the from
address and potentially drain the funds of an unsuspecting victim.What is the issue?
The issue is that the transferFrom
function is called with an arbitrary from
address, which is set to listing.buyer
. This allows an attacker to manipulate the from
address and transfer tokens from an unintended address.
How can an attacker exploit this vulnerability?
How can an attacker exploit this vulnerability?
An attacker can exploit this vulnerability by:
Creating a malicious listing: An attacker can create a malicious listing with a buyer
address that is under their control.
Calling the purchase function: The attacker can call the purchase
function, passing in the malicious listing.
Manipulating the from address: The attacker can manipulate the from
address to transfer tokens from an unintended address.
Draining the funds of the victim: The attacker can drain the funds of the victim by transferring tokens from the unintended address.
Example Attack Scenario:
An attacker creates a malicious listing with a buyer
address that is under their control.
The attacker calls the purchase
function, passing in the malicious listing.
The transferFrom
function is called with the arbitrary from
address set to the attacker's controlled address.
The attacker manipulates the from
address to transfer tokens from an unintended address, potentially draining the funds of an unsuspecting victim.
Prevention:
What are the consequences of this vulnerability?
The consequences of this vulnerability are severe, as an attacker can potentially drain the funds of an unsuspecting victim. This can result in significant financial losses for the victim and damage to the reputation of the Swan
contract.
Swan
contract.The Swan.purchase function in the Swan contract uses an arbitrary from address in the transferFrom function, allowing an attacker to manipulate the from address and potentially drain the funds of an unsuspecting victim.
In this example, the Attacker
contract creates a malicious listing and calls the purchase
function on the Swan
contract. The Swan
contract then transfers tokens from the msg.sender
address to the maliciousListing
address. The Attacker
contract then manipulates the from
address to transfer tokens from the Swan
contract to the Attacker
contract.
This proof of concept code demonstrates the vulnerability and shows how an attacker can exploit it to drain the funds of an unsuspecting victim.
Use a trusted address: Use a trusted address, such as msg.sender
, as the from
address in the transferFrom
function.
Implement input validation: Implement input validation to ensure that the buyer
address is valid and not under the control of an attacker.
Implement access control: Implement access control to ensure that only authorized addresses can call the purchase
function.
To fix this vulnerability, the from
address in the transferFrom
function should be set to a trusted address, such as the msg.sender
address. This ensures that the tokens are transferred from the intended address and prevents an attacker from manipulating the from
address.
Code Fix:
By setting the from
address to msg.sender
, we ensure that the tokens are transferred from the intended address and prevent an attacker from manipulating the from
address.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.