Tx.origin Usage in Group Management Contract Allows Phishing Attack for Unauthorized Actions
The group management contract used tx.origin to check ownership, so a malicious contract could call lock, unlock or membership functions on behalf of the owner. An attacker could therefore perform unauthorised actions and take control of group management.
- Disclosed after under an hour
#37577 [BC-Insight] `tx.origin` Usage in Group Management Contract Allows Phishing Attack for Unauthorized Actions
Submitted on Dec 9th 2024 at 16:37:44 UTC by @cheems for Attackathon | Ethereum Protocol
- Report ID: #37577
- Report Type: Blockchain/DLT
- Report severity: Insight
- Target: https://github.com/hyperledger/besu
- Impacts:
- Direct loss of funds
Description
Brief/Intro
A critical vulnerability exists in the on-chain group management contract, introduced in PR #1288, where tx.origin was used to verify the contract owner. This allows a malicious contract to impersonate the owner and bypass ownership checks, enabling unauthorized users to lock/unlock the contract or modify group membership. The issue arises from the addition of tx.origin as a check for ownership, which was initially introduced as part of removing the enclave key and ensuring only the creator could update the contract.
Vulnerability Details
In this PR (https://github.com/hyperledger/besu/pull/1288), the intention was to ensure that only the creator's account could add/remove members and update the management contract. However, using tx.origin to validate ownership exposes the contract to phishing attacks, where a malicious contract can call the vulnerable contract on behalf of the attacker. Since tx.origin refers to the original transaction sender, the attacker only needs to initiate the call (not execute the exploit directly), allowing them to bypass the ownership checks.
Impact Details
Provide a detailed breakdown of possible losses from an exploit, especially if there are funds at risk. This illustrates the severity of the vulnerability, but it also provides the best possible case for you to be paid the correct amount. Make sure the selected impact is within the program’s list of in-scope impacts and matches the impact you selected.
References
Add any relevant links to documentation or code
Link to Proof of Concept
https://gist.github.com/SamruddhiNavale/100b48157a7101d53bee9056b2a7dbb7
Proof of Concept
Proof of Concept
pragma solidity ^0.8.0;
interface IVulnerableContract {
function lock() external;
function unlock() external;
}
contract MaliciousContract {
IVulnerableContract public vulnerableContract;
constructor(address _vulnerableContract) {
vulnerableContract = IVulnerableContract(_vulnerableContract);
}
function attackLock() public {
vulnerableContract.lock(); // Attack via tx.origin impersonation
}
function attackUnlock() public {
vulnerableContract.unlock(); // Attack via tx.origin impersonation
}
}
Steps to Reproduce:
- Deploy the Vulnerable Contract on a local test network.
- Deploy the Malicious Contract, passing the vulnerable contract address.
- Call
attackLock()orattackUnlock()from the malicious contract. - Verify the contract state is locked/unlocked by the attacker.
Expected Result:
The contract should only allow the actual owner to lock/unlock or modify its state.
Actual Result:
The malicious contract can lock/unlock or modify the contract state due to the tx.origin vulnerability.
Impact:
This vulnerability allows attackers to impersonate the contract owner and perform unauthorized actions, bypassing the intended ownership checks. It can lead to unauthorized updates to the contract and loss of control over group management.
Mitigation Recommendations:
- Avoid Using
tx.originfor ownership checks. - Use
msg.senderfor proper access control. - Implement proper access control mechanisms like
onlyOwner.
Conclusion:
This vulnerability, introduced in PR #1288, exposes the contract to phishing attacks by using tx.origin. The malicious contract only needs to initiate the call, not execute the exploit directly, to bypass ownership checks.
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 used tx.origin instead of msg.sender to verify that the caller was the owner, so any contract called by the owner could act with owner privileges.
Impact
An attacker could impersonate the contract owner and lock or unlock the contract or change group membership, leading to loss of control over group management.
What the attacker needed
Owner interacts with a malicious contract; attacker can deploy a contract
The fix
The contract should stop using tx.origin for ownership checks and use msg.sender with a proper onlyOwner access control modifier instead.
How it was found
- Deploy the vulnerable contract on a local test network.
- Deploy a malicious contract that stores the vulnerable contract's address.
- Call the malicious contract's attack function, which calls lock or unlock on the vulnerable contract.
- Check that the vulnerable contract's state has changed even though the attacker is not the owner.
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.
A smart contract is a program on a blockchain. tx.origin is a special value that tells a contract who started the whole transaction, not who is calling it right now. If a contract trusts tx.origin for permission checks, any other contract that the real owner interacts with can pretend to be the owner and call protected functions.
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.