2023 | Hard | Solidity Security
Slot Puzzle
Objective of CTF¶
Your purpose is just to call the deploy() function to recover the 3 ether.
QuillCTF Challenges - Slot Puzzle
Vulnerability Description¶
- Only the instance of SlotPuzzle deployed from SlotPuzzleFactory can call the
payout()
function to transfer ether and we need to pass the check inascertainSlot()
to let SlotPuzzle callpayout()
- Calculate the slot iteratively according to
keccak256(key, slot + (is ghostStore ? 1 : 0))
pattern - We need three recipients, all pointing to hacker, to recover 3 ether since each
payout()
can only transfer 1 ether -
The difficult part is to decide
offset
> <params.slotKey
is copy from calldata to memory.bytes memory slotKey
stores the slotKey offset in memory, here is 0x80- The offset of slot is calculated using
add(slotKey, calldataload(offset))
. So, the value ofoffset
should be the offset of target value (i.e. slot.offset - slotKey) in the calldata. We can make use ofParameters.slotKey
to pass that value
Offset(Hex) Calldata Layout 04 offset of struct Parameters 24 totalRecipients, 3 44 offset 64 offset of the Recipients array (relative to struct offset) 84 offset of slotKey (relative to struct offset) a4 size of the Recipients array c4 recipients[0].account ... ... 184 size of slotKey 1a4 slot.offset - 0x80 1c4 slot
Proof of Concept¶
最后更新:
2023年6月9日 11:11:10
Contributors: