Resolv::getaddresses bug that can be abused to bypass security measures.
The Ruby method Resolv::getaddresses can return an empty list for certain non-standard IP address formats, even though those formats resolve to a real IP. An attacker could use this to bypass SSRF filters that rely on this method to block private IP addresses.
Originally disclosed on HackerOne
- Disclosed after 4 months
Description
Resolv::getaddresses is OS-dependent, therefore by playing around with different IP formats one can return blank values. This bug can be abused to bypass exclusion lists often used to protect against SSRF.
| ๐ป Machine 1 | ๐ป Machine 2 |
|---|---|
| ruby 2.3.3p222 (2016-11-21) [x86_64-linux-gnu] | ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu] |
๐ป Machine 1
irb(main):002:0> Resolv.getaddresses("127.0.0.1")
=> ["127.0.0.1"]
irb(main):003:0> Resolv.getaddresses("localhost")
=> ["127.0.0.1"]
irb(main):004:0> Resolv.getaddresses("127.000.000.1")
=> ["127.0.0.1"]
๐ป Machine 2
irb(main):008:0> Resolv.getaddresses("127.0.0.1")
=> ["127.0.0.1"]
irb(main):009:0> Resolv.getaddresses("localhost")
=> ["127.0.0.1"]
irb(main):010:0> Resolv.getaddresses("127.000.000.1")
=> []
Proof of concept
irb(main):001:0> require 'resolv'
=> true
irb(main):002:0> uri = "0x7f.1"
=> "0x7f.1"
irb(main):003:0> server_ips = Resolv.getaddresses(uri)
=> [] # The bug!
irb(main):004:0> blocked_ips = ["127.0.0.1", "::1", "0.0.0.0"]
=> ["127.0.0.1", "::1", "0.0.0.0"]
irb(main):005:0> (blocked_ips & server_ips).any?
=> false # Bypass
Mitigation
Currently I have been suggesting that the affected vendors stay away from Resolv::getaddresses altogether and use the Socket class.
irb(main):002:0> Resolv.getaddresses("127.1")
=> []
irb(main):003:0> Socket.getaddrinfo("127.1", nil).sample[3]
=> "127.0.0.1"
Affected vendors and gems
By abusing this bug I was able to bypass GitLab, HackerOne and private_address_check's SSRF filters.
The private_address_check gem, for instance, relied on Resolv::getaddresses in lib/private_address_check.rb:
def resolves_to_private_address?(hostname)
ips = Resolv.getaddresses(hostname)
ips.any? do |ip|
private_address?(ip)
end
end
irb(main):001:0> require 'private_address_check'
=> true
irb(main):002:0> PrivateAddressCheck.resolves_to_private_address?("127.1")
=> false # Bypass
The author of this gem has provided a patch for this issue and I can confirm that I am unable to bypass the fix.
GitLab and HackerOne have also been notified and plan on releasing a fix this week.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, Resolv::getaddresses relies on OS-level name resolution that does not consistently parse non-standard IP address formats, returning an empty result instead of the actual address.
What the attacker needed
Application uses Resolv::getaddresses for SSRF checks; attacker can supply a hostname or IP to the application
How it was found
- Call Resolv.getaddresses with a non-standard IP format such as a hexadecimal form.
- Observe that it returns an empty array instead of the real IP address.
- Compare the result against a blocklist of private IPs; the intersection is empty.
- Conclude that the SSRF filter is bypassed.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A server-side request forgery (SSRF) flaw lets an attacker make a server send requests to internal systems. Many defences check the destination address with a Ruby function called Resolv::getaddresses. This report shows that the function sometimes returns nothing for unusual but valid address formats, so the check passes and the request goes through.
What is SSRF?
The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.