Skip to content

Instantly share code, notes, and snippets.

@lirantal
Created December 24, 2024 19:58
Show Gist options
  • Select an option

  • Save lirantal/ed18a4493ca9fe4429957c79454a9df1 to your computer and use it in GitHub Desktop.

Select an option

Save lirantal/ed18a4493ca9fe4429957c79454a9df1 to your computer and use it in GitHub Desktop.
SSRF Bypass in private-ip

SSRF Bypass in private-ip

private-ip is an npm package that serves to check if IP address is private.

Resources:

Exploitation

The private-ip package is vulnerable to an SSRF bypass where an attacker can provide an IP or hostname that resolves to a multicast IP address which is not included as part of the private IP ranges in the package's source code.

The relevant part of the source code is the following allowlist:

const PRIVATE_IP_RANGES = [
  '0.0.0.0/8',
  '10.0.0.0/8',
  '100.64.0.0/10',
  '127.0.0.0/8',
  '169.254.0.0/16',
  '172.16.0.0/12',
  '192.0.0.0/24',
  '192.0.0.0/29',
  '192.0.0.8/32',
  '192.0.0.9/32',
  '192.0.0.10/32',
  '192.0.0.170/32',
  '192.0.0.171/32',
  '192.0.2.0/24',
  '192.31.196.0/24',
  '192.52.193.0/24',
  '192.88.99.0/24',
  '192.168.0.0/16',
  '192.175.48.0/24',
  '198.18.0.0/15',
  '198.51.100.0/24',
  '203.0.113.0/24',
  '240.0.0.0/4',
  '255.255.255.255/32'
]

This array is missing the multicast address space at 224.0.0.0/4

Vulnerable versions

All versions of private-ip are vulnerable to this issue, up to and including to the latest version of 3.0.2.

Exploit Proof of Concept

  1. Install the private-ip package:
npm install private-ip
  1. Define an app.js file with the programmatic API of private-ip as follows:
import is_ip_private from 'private-ip'
import ipaddr from 'ipaddr.js'

// -- private-ip
console.log(is_ip_private('127.0.0.1'))
console.log(is_ip_private('10.0.0.0'))
console.log(is_ip_private('169.254.0.1'))
console.log(is_ip_private('239.255.255.250'))


// -- ipaddr.js
console.log(ipaddr.parse('127.0.0.1').range())
console.log(ipaddr.parse('10.0.0.0').range())
console.log(ipaddr.parse('169.254.0.1').range())
console.log(ipaddr.parse('239.255.255.250').range())
  1. Run the app.js file:
node app.js
  1. Observe that the private-ip package does not detect the multicast IP address 239.255.255.250 as a private IP address and returns true for all 4 checks.

As a case of comparison, the ipaddr.js package correctly identifies the multicast IP address as a non-private IP address.

import ipaddr from 'ipaddr.js'

// -- ipaddr.js
console.log(ipaddr.parse('127.0.0.1').range())
console.log(ipaddr.parse('10.0.0.0').range())
console.log(ipaddr.parse('169.254.0.1').range())
console.log(ipaddr.parse('239.255.255.250').range())

// would result in the following stdout: // loopback // private // linkLocal // multicast


# Author

Liran Tal
@JLLeitschuh

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment