Back to Blog
|7 min read

The foothold was the debt: chaining PMB and php2shell to a shell

Five boring bugs and a patched CVE: an unauthenticated RCE on EOL PHP

php2shellappsecinfosecphp

The CVE was the last mile: chaining an unauthenticated RCE out of application debt

An authorized penetration test against a library portal running an end-of-life PHP runtime — and why the patched CVE was the least interesting part.


Everyone is patching php2shell this week. CVE-2026-109618 and CVE-2026-109619 are nasty: unauthenticated remote code execution in PHP itself, triggerable before application code even runs. If you run PHP, you have probably already been told to patch to 8.2.35, 8.3.36, 8.4.27 or 8.5.12.

On a recent authorized engagement, the CVE was the last mile, not the entry point.

The foothold was five pieces of application debt that had been sitting there for years. Each one is boring on its own. Chained, they handed us a shell.

This is the full story.


Scope and authorization

The target was a library management portal (PMB) on a university-adjacent domain, tested under written authorization. We were allowed read-only access plus non-destructive writes, and we cleaned up after ourselves. Hostnames here are sanitized to example.com; paths, versions and behaviour are real.

The runtime was PHP 7.4.33 on Apache mod_php, Ubuntu 22.04.

That last sentence is the whole ballgame. mod_php is the SAPI the PHP project rates highest risk for php2shell — an unauthenticated request can trigger exploitation before your framework, your router, or your auth layer ever runs. And 7.4 is end-of-life: there is no fixed release at all, only a source backport nobody deploys.

But to reach the CVE, we first had to get a request in front of PHP with enough control to matter. That meant going through the application.


Stage 1: the boring entry

PMB's OPAC exposes an AJAX endpoint that takes an id parameter:

GET /ajax.php?categ=storage&datetime=undefined&id=<ID>&module=ajax&sub=save&token=undefined

id is interpolated straight into a query. A time-based oracle confirms it in two requests:

id=1 AND IF(1=1,SLEEP(3),0)   → 3.0 s
id=1 AND IF(1=2,SLEEP(3),0)   → 0.1 s

One gotcha worth recording: literal quotes break this endpoint. Every string literal in a payload has to be hex-encoded (0x...). That is the kind of detail that eats an afternoon if you find it the hard way.

A blind boolean oracle is enough to build a full integer reader, and from there a file reader.

Stage 2: fingerprinting through the database

The MySQL user could call LOAD_FILE. That turns an injection into an arbitrary file-read oracle, which is a far bigger deal than it sounds.

We read:

| Path | What it told us | |------|-----------------| | /etc/apache2/mods-enabled/php7.4.load | mod_php 7.4 module is loaded | | /etc/apache2/mods-enabled/ | mpm_prefork on, no php8.*.load, no proxy_fcgi | | /usr/bin/php7.4 | contains 7.4.33 | | /etc/os-release | Ubuntu 22.04 | | /var/lib/dpkg/status | Version: 7.4.33 |

No php8 module, no FPM, no proxy. The served SAPI is mod_php on an EOL branch. That is the worst-case configuration for php2shell, and the version is frozen.

At this point we knew the box was vulnerable. We still needed a way to land a request that could exploit it.

Stage 3: sessions and the human layer

PMB keeps a sessions table with SESSID and LastOn. SESSIDs are ten-digit integers, and the injection can binary-search one out of the table.

That works, but the freshest row churns every few seconds, so a two-minute binary search drifts off target. The reliable path is to stop stealing sessions and mint one.

Stage 4: weak credentials

The admin panel at /pmb/index.php posts to /pmb/main.php with user, password, database. The install used a guessable pair.

One login later we had a real admin session: PhpMyBibli-SESSID, PhpMyBibli-LOGIN, and the PHP session cookie. That is the difference between "a row exists in a table" and "the application believes you are logged in."

Stage 5: the upload primitive

camera_upload.php is the PMB camera-upload handler. Reading its source through the file-read oracle showed the shape:

  • the filename comes straight from $_POST['upload_filename']
  • the payload arrives base64-encoded in imgBase64
  • it is decoded and fwrite()-ed under $base_path

Two gates stood between us and a file in the web root:

  1. Session. Without a logged-in session the page returns Pas de session ouverte, vous devez vous connecter.
  2. Image check. A non-image payload returns {"status":0,"message":"not an image"}.

The first gate is the session we already had. The second is where it gets fun.

The check only asks whether the payload looks like an image. So we made it look like one: a valid 1×1 GIF, with PHP appended after the GIF trailer. The validator sees a GIF. PHP sees code.

The delivery detail matters too. The endpoint wants the base64 behind a data URI — data:image/gif;base64,.... Raw base64 is rejected. With the prefix, the same payload sails through:

{"status":1,"message":"remote_app.php"}

Stage 6: a live endpoint in the web root

The file landed at /var/www/html/pmb/remote_app.php and was served at /pmb/remote_app.php. It is a fifteen-line polyglot: the GIF, a CachedData class, and an unserialize($_POST['cook']) sink.

Proof that PHP executes is a single POST — the response is the GIF header followed by the re-serialized input:

POST /pmb/remote_app.php   cook=a:1:{i:0;s:11:"HELLO_World";}

→ GIF89a...;a:1:{i:0;s:11:"HELLO_World";}

We now had an attacker-controlled unserialize() endpoint inside the document root. That is the landing pad the php2shell unserialize chain needs.

Stage 7: the chain

The unserialize UAF gadget is small and precise. A CachedData object hands an inner stdClass with eight properties to unserialize(). The eighth property insert trips an 8→16 resize, freeing the backing arData while eight property zvals still point into it. Thirty-two spray strings in the same payload reclaim the freed chunk.

From there the chain walks forward:

| Stage | Action | |-------|--------| | R-1 | heap leak via ZVAL_MAKE_REF over the freed arData | | R-2 | ELF scan for libphp.so | | R-3 | .gnu_hash → executor_globals + GOT | | R-4 | GOT dump → libc → system() | | R-5 | EG.class_table → stdClass class entry | | R-6 | spray slot discovery | | R-7 | type confusion → system() |

R-7 forges an object whose handler is system() and whose GC header is the shell command. The command budget is fourteen bytes, so longer payloads are assembled with repeated echo -n ...>>w triggers.

The proof is one line, read back off the target:

uid=33(www-data)

Stage 8: leaving it clean

Every planted file was overwritten with a one-pixel GIF at the end. The files remain, but they are inert. The target was left as we found it.


Why this matters more than the CVE

It would be easy to file this as "patch PHP." But look at what actually got us in:

  • an unparameterised query
  • a guessable admin password
  • an upload endpoint that trusts the filename
  • an image check that only sniffs the header
  • an EOL runtime nobody owned

Not one of those is exotic. Every one of them is years old. The CVE was the last mile; the foothold was the debt.

And the debt is what makes the CVE reachable. A hardened app on the same runtime might never expose an unserialize() sink or an upload path. A soft one hands you both.

Remediation, in order

  1. Patch PHP to 8.2.35 / 8.3.36 / 8.4.27 / 8.5.12, or a distro backport. 7.4 has no fixed release.
  2. Parameterise the ajax.php query. It is unauthenticated and gives LOAD_FILE.
  3. Strong admin passwords, ideally 2FA on the backend.
  4. Harden the upload: allow-list extensions, validate with getimagesize() and re-encode, or store outside the web root.
  5. Detect: alert on new .php files in the web root and on imgBase64 payloads with a non-image tail.

The takeaway

If you run PMB, Moodle, WordPress or any PHP application on 7.4, the runtime is frozen and the clock is running. But patching alone does not close the chain — the application layer is what decides whether an attacker can even reach the bug.

Patch the runtime. Then go fix the boring things, because the boring things are the foothold.


Full writeup and PoC — SQLi oracle, session theft, upload bypass, UAF chain, cleanup — are on GitHub: github.com/Latifox/php2shell-pmb-poc.

Tested under authorization. Sanitized hostnames. Use only on systems you own or have permission to test.

The foothold was the debt: chaining PMB and php2shell to a shell | Latif Abderrahmane