The smart contract contains two critical issues: lack of owner validation and improper access control in the changeOwner function. An attacker can leverage these vulnerabilities to gain unauthorized ownership and steal all funds from the contract using the withdrawFunds function.
Affected Functions:
changeOwner(address _newOwner)
withdrawFunds()
Issue 1: Lack of Owner Validation The changeOwner function lacks proper access control, allowing anyone to change the owner of the contract. This creates a serious security risk because an unauthorized entity can become the owner without restriction.
Code:
Issue 2: Access Control Vulnerability The withdrawFunds function allows only the owner to withdraw the contract’s balance. However, because of the lack of validation in changeOwner, an attacker can first become the owner, then call withdrawFunds to steal all funds.
Code:
Potential Consequences:
An attacker can call the changeOwner function to become the contract's owner.
After gaining ownership, the attacker can invoke the withdrawFunds function to transfer all contract funds to their own wallet or their owned Exploit contract.
Loss of contract funds, leading to financial damage and potential project collapse.
Step 1: Attacker calls the changeOwner function, passing their own address as the new owner.
Step 2: Now as the new owner, the attacker calls withdrawFunds to drain the contract balance.
To fix the vulnerabilities, add proper access control to the changeOwner function and ensure only the current owner can transfer ownership.
Code Fix Example: Add an onlyOwner modifier to restrict access to the changeOwner function.
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.