Skip to content
SSRF Write-up Intermediate

SafeCurl "Capture the Bitcoins" Post-Mortem

SafeCurl, a PHP library meant to prevent SSRF, was bypassed in several ways: using [redacted] to reach localhost, a theoretical DNS rebinding attack, and three URL parsing inconsistencies between PHP's parse_url and curl_exec. An attacker could use these to make the library fetch internal resources it was supposed to block.

Jack Follow

Published on whitton.io

It’s been a week since I launched the SafeCurl “Capture the Bitcoins” contest, which has been a fun, but humbling event.

Jack, on whitton.io

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the library relied on incomplete blacklists and on PHP's URL parser agreeing with cURL's parser, which they do not for crafted URLs.

Impact

An attacker could bypass SafeCurl's SSRF protections to access internal resources, though the DNS rebinding attack was only theoretical and not successfully exploited by the author.

What the attacker needed

SafeCurl library used in an application; Attacker can supply a URL to be fetched

The fix

The fixes included blacklisting all reserved IP ranges, pinning DNS by replacing the hostname with the resolved IP and setting the Host header, disabling credentials in URLs, and URL-encoding the username, password, fragment, path, and query string.

How it was found

  1. Use [redacted] as the host to refer to localhost and bypass the private range blacklist.
  2. Perform a DNS rebinding attack by rapidly switching a domain's A record from a valid IP to an internal IP.
  3. Craft a URL with credentials such that parse_url and curl_exec disagree on the host.
  4. Craft a URL with a fragment such that parse_url and curl_exec disagree on the host.
  5. Craft a URL with an unencoded query string such that parse_url and curl_exec disagree on the host.

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 write-up has not been written yet. The Original tab links to the source.

SafeCurl is a tool that tries to stop a web application from being tricked into fetching internal addresses, a problem called SSRF. The author offered a Bitcoin reward to anyone who could get around its protections, and several people found ways to do so. These bypasses meant the tool could still be made to access internal systems, which is exactly what it was built to prevent.

What is SSRF?

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.

More by Jack

View all

14 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Server-side request forgery (SSRF)

The lesson behind this report.

The server can be made to fetch an address the attacker chooses, reaching internal services, cloud metadata or other customers' data.