Policy bypass (verifyFCrDNS) via multiple PTR records
Description
It is possible to bypass any policy that makes use of the verifyFCrDNS function as it's main method of validation. One example is /data/crawlers/yandexbot.yaml which is allowed by default (via /data/crawlers/_allow-good.yaml).
The main cause of the vulnerability is due to how decoupled the reverse DNS check is from the forward check. The logic appears to only prove that, in a given set of multiple PTR records under a specific IP address;
- at least one PTR record in the set matches the domain name pattern being tested
- at least one of the domains in the set forward resolves to the correct IP address
However, the logic does not appear to validate that both records are the same record. It is possible to satisfy both conditions separately (across at least 2 PTR records), without needing any individual PTR record to satisfy both forward and reverse conditions.
Details
Under /internal/dns/dns.go, VerifyFCrDNS performs the reverse DNS request on the IP address, returning a list of names. If a pattern has been supplied, the code iterates through each name in names, checking for a match against the pattern. If any PTR value matches the pattern, anyNameMatched is set to true, and the code does not distinguish which name matched. verifyFCrDNSInternal is then called, which performs the forward lookup on all names until any domain resolves to the IP address.
Proof of concept
First perform a network request to a webpage protected by Anubis (e.g: curl -L https://developer.valvesoftware.com/wiki/Main_Page). The site should respond with the 'Making sure you're not a bot!' page.
Using a provider that supports setting multiple PTR records (e.g: some VPS offerings), create two PTR records:
- one that passes the forward confirmation (e.g: my-real-website.com, which represents a domain you have ownership over in this hypothetical)
- one that passes the pattern check (e.g: fake.yandex.com)
Then ensure the domain we do have ownership over is indeed pointing to the IP address that's performing the network request to Anubis.
After the records are set, propagated, and all relevant DNS caches have expired/been cleared, perform the same network request as before (e.g: curl -L https://developer.valvesoftware.com/wiki/Main_Page). The network request should succeed in bypassing the intended policy for yandexbot.yaml. The same should apply to any other policy that relies on the verifyFCrDNS function to do the heavy lifting.
Alternatively, if you are not able to find a provider that supports users setting multiple PTR records (I myself wasn't having great luck finding any free solutions without a lot of manual hurdles), you can hardcode your own hypothetical PTR records in the go function yourself and find it succeeds the check.
Impact
Policy bypass.
Affects anyone that hosts Anubis with the current default allow-list, or with custom policies that have allow-rules that make use of verifyFCrDNS as their main method of validation.