[PNM-001] PARENT_CANNOT_CONTROL
can be bypassed by maliciously unwrapping parent node
#173
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
sponsor confirmed
Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity")
Lines of code
https://github.com/code-423n4/2022-07-ens/blob/ff6e59b9415d0ead7daf31c2ed06e86d9061ae22/contracts/wrapper/NameWrapper.sol#L356
https://github.com/code-423n4/2022-07-ens/blob/ff6e59b9415d0ead7daf31c2ed06e86d9061ae22/contracts/wrapper/NameWrapper.sol#L295
https://github.com/code-423n4/2022-07-ens/blob/ff6e59b9415d0ead7daf31c2ed06e86d9061ae22/contracts/registry/ENSRegistry.sol#L74
Vulnerability details
Description
By design, for any subdomain, as long as its
PARENT_CANNOT_CONTROL
fuse is burnt (and does not expire), its parent should not be able to burn its fuses or change its owner.However, this contraint can be bypassed by a parent node maliciously unwrapping itself. As long as the hacker becomes the ENS owner of the parent node, he can leverage
ENSRegistry::setSubnodeOwner
to re-set himself as the ENS owner of the subdomain, and thus re-invokingNameWrapper.wrap
can rewrite the fuses and wrapper owner of the given subdoamin.Considering the following attack scenario:
CANNOT_UNWRAP
PARENT_CANNOT_CONTROL
PARENT_CANNOT_CONTROL
victim.hack.poc.eth
ideallyENSRegistry::setSubnodeOwner(hacker.poc.eth, victim)
on the sub-sub-domainNameWrapper.wrap(victim.hacker.poc.eth)
to over-write the fuses and owner of the sub-sub-domain, i.e., victim.hacker.poc.ethThe root cause here is that, for any node, when one of its subdomains burns
PARENT_CANNOT_CONTROL
, the node itself fails to burnCANNOT_UNWRAP
. Theoretically, this should check to the root, which however is very gas-consuming.Notes
Discussed with the project member, Jeff Lau.
If there is any issue running the attached PoC code, please contact me via
izhuer#0001
discord.Suggested Fix
CANNOT_UNWRAP
which thus letsexpiry
decide whether a node can be unwrapped.PoC / Attack Scenario
There are two attached PoC files,
poc1.js
andpoc2.js
. Thepoc1.js
is for a case where the hacker holds a 2LD, and thepoc2.js
demonstrates the aforementioned scenario.To run the PoC, put then in
2022-07-ens/test/wrapper
and runnpx hardhat test --grep 'PoC'
.poc1.js
poc2.js
The text was updated successfully, but these errors were encountered: