In this challenge, you need to become the owner of the contract through a delegatecall vulnerability to mint your flag.
The setup involves two contracts:
Challenge7 - The main contract with:
Challenge7Delegate - A contract with:
claimOwnership functionowner variable in the same slot position
delegatecall executes code in the context of the calling contract, using its storage
claimOwnership() on the main contract:
address(challenge7).call(abi.encodeWithSignature("claimOwnership()"));
3. This works because:
- The call gets forwarded via delegatecall
- claimOwnership() sets owner to msg.sender
- Due to delegatecall, it modifies the main contract's storage
- Both contracts have 'owner' in the same storage slot
4. Now we can call mintFlag()
Congratulations! You've exploited a delegatecall vulnerability! 🎉
Remember: delegatecall is a powerful but dangerous feature. Always ensure storage layouts match and consider the security implications of executing external code in your contract’s context!
Delegatecall vulnerabilities have led to some of the most significant hacks:
Common issues arise from: