Skip to content
RCE Disclosed report Advanced CVE-2022-32212CVE-2018-7160

DNS rebinding in --inspect (insufficient fix of CVE-2022-32212 affecting macOS devices)

The Node.js debugger's DNS rebinding protection allowed the IP address [redacted] in the Host header, and on macOS browsers this address triggers a DNS lookup for the computer's .local hostname. An attacker controlling DNS could resolve that hostname to their own IP, serve a page that later rebinds to [redacted], and access the debugger to achieve remote code execution.

zeyu2001 Follow

Originally disclosed on HackerOne

  • Triaged in 44 hours
  • Fixed in 3 months
  • Disclosed after 3 months

Summary: This is an insufficient fix of CVE-2022-32212, which itself is a fix of CVE-2018-7160. There exists a specific behaviour in browsers on macOS devices when handling the http://0.0.0.0URL that allows an attacker-controlled DNS server to bypass the DNS rebinding protection by resolving hosts in the .local domain.

Description:

In the latest version, only IP addresses and localhost are allowed in the Host header when connecting to the debugger endpoint. IsIPAddress ensures that IPv4 address octets only contain values ranging from 0 to 255, but this allows 0.0.0.0 which indicates an invalid or unroutable target.

In macOS devices, using fetch("http://0.0.0.0")or opening http://0.0.0.0 through a top-level navigation in Chrome and Firefox will cause a DNS request to resolve <Computer Name>.local, where Computer Name is configured in the system preferences (the use of the .local TLD is a known feature of macOS devices). If such a request succeeds, http://0.0.0.0 is routed to the IP address provided in the DNS reply. This would typically be the same as the IP address of the device on the local network, so http://0.0.0.0 will typically route to any application listening on the local interface - working as intended.

An attacker-controlled DNS server can, however, resolve <Computer Name>.local to any arbitrary IP address, and consequently cause the victim's browser to load arbitrary content at http://0.0.0.0. This allows the attacker to bypass the DNS rebinding protection.

Note: On Windows devices, http://0.0.0.0 is treated as an invalid URL and the request is blocked.

Steps To Reproduce:

General Attack Flow

  1. Victim runs node with --inspect option
  2. Victim visits attacker's webpage
  3. The attacker's webpage opens http://0.0.0.0:9229
  4. Victim asks the DNS server for <Computer Name>.local and gets <attacker's-IP>.
  5. Victim loads webpage http://0.0.0.0:9229 from <attacker's-IP>.
  6. The webpage http://0.0.0.0:9229 tries to load http://0.0.0.0:9229/json.
  7. Due to a short TTL, the DNS server will be soon asked again about an entry for <Computer Name>.local. This time, the DNS server responds with "127.0.0.1".
  8. The http://0.0.0.0:9229 website (i.e., the one hosted on <attacker's IP>) will retrieve http://0.0.0.0:9229/json from 127.0.0.1, including webSocketDebuggerUrl.
  9. Now, the attacker knows the webSocketDebuggerUrl and can connect to it using WebSocket. Note that WebSocket is not restricted by same-origin policy. By doing so, they can gain the privileges of the Node.js instance.

Vulnerable code segment: https://github.com/nodejs/node/blob/d9b71f4c241fa31cc2a48331a4fc28c15937875a/src/inspector_socket.cc#L164-L183

DNS Setup

In this example I used dnsmasq as my DNS server. You can use (Attachment on the original report: dnsmasq_setup.zip) for a minimal Docker setup that demonstrates the arbitrary resolution of <Computer Name>.local domains. The hosts file should be changed according to the configured Computer Name of the victim device (through system preferences). For example, my Computer Name is Zeyu’s MacBook Pro, which means I had the Zeyus-Macbook-Pro.local domain.

# Resolve <Computer Name>.local to any IP address
1.1.1.1 Zeyus-Macbook-Pro.local

When connecting to http://0.0.0.0, the page is loaded from 1.1.1.1 instead.

Screenshot_2022-07-11_at_1.22.50_AM.png
Screenshot_2022-07-11_at_1.22.50_AM.png From the original on HackerOne

If you observe the network traffic while connecting to http://0.0.0.0, you should see the relevant DNS requests and replies.

2022-07-10_23.16.44.jpg
2022-07-10_23.16.44.jpg From the original on HackerOne

Subsequently <Computer Name>.local can be rebinded to 127.0.0.1, causing the page to be loaded from 127.0.0.1 where the debugger is listening.

Screenshot_2022-07-11_at_1.33.41_AM.png
Screenshot_2022-07-11_at_1.33.41_AM.png From the original on HackerOne

Suggested Remediation

According to IANA, 0.0.0.0/8 is a reserved address range. To prevent this vulnerability, this address range could be blocked.

A way to check for this address range could simply be accum == 0 in the first octet or host.front() == '0' in IsIPAddress

Supporting Material/References:

Impact

Attacker with access to a compromised DNS server or the ability to spoof its responses can gain access to the Node.js debugger, which can result in remote code execution.

The original report as published on HackerOne, by zeyu2001. Images and videos are our own copies; raw HTML is shown as text. View it on HackerOne.

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 the IsIPAddress check accepted [redacted] as a valid IP address, and macOS browsers resolve [redacted] via a DNS lookup for the computer's .local hostname, which an attacker can control.

Impact

An attacker with access to a compromised DNS server or the ability to spoof its responses can gain access to the Node.js debugger, which can result in remote code execution.

What the attacker needed

Victim runs Node.js with --inspect; Victim uses macOS with Chrome or Firefox; Attacker controls or spoofs DNS responses; Victim visits attacker's webpage

The fix

The [redacted]/8 reserved address range should be blocked in the IsIPAddress check.

How it was found

  1. Victim runs node with --inspect option
  2. Victim visits attacker's webpage
  3. The attacker's webpage opens http://[redacted]:9229
  4. Victim asks the DNS server for <Computer Name>.local and gets <attacker's-IP>.
  5. Victim loads webpage http://[redacted]:9229 from <attacker's-IP>.
  6. The webpage http://[redacted]:9229 tries to load http://[redacted]:9229/json.

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.

When you run Node.js with the --inspect flag, it opens a debugging port that can run code. To stop malicious websites from reaching it, Node.js only accepts connections where the Host header is an IP address or localhost. But the address [redacted] was accepted, and on macOS browsers this address causes a DNS lookup for the computer's local name. An attacker who controls DNS can point that name to their server, then quickly change it to [redacted] so the browser talks to the debugger.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by zeyu2001

View all

8 more disclosed reports, best first.

More from Node.js

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.