Practice library / Web attacks
Lab · Hard · 2.5 hoursFree account
White-Box Web Exploitation: Auth Bypass to RCE
Code review-driven auth bypass chained with a shell command-injection sink to prove RCE in a PHP web application.
On this page 16 sections
- ·Why this lab is different
- ·Prerequisites
- ·Lab setup
- ·Build the target
- 1Map the codebase before touching the app
- 2Find the authentication backdoor in the login check
- Locked: Confirm the bypass reaches an admin-only route
- Locked: Hunt for a command-execution sink
- Locked: Trace the taint from the request to the sink
- Locked: Chain both bugs and prove command execution blindly
- Locked: Assess the blast radius from the deployment config
- Locked: Check whether PHP hardening would have stopped this
- Locked: Detection and defence
- Locked: Check
- Locked: Clean-up
- Locked: Command reference
White-box review reads the real code, not guesses from the outside. A hardcoded authentication bypass and a shell-injection sink are each small bugs; chained, they give an attacker full command execution on the server. Public breach reports describe this pattern on vendor appliances, backup consoles and internal admin panels. The reader audits a PHP codebase, confirms the bypass and the sink, and proves RCE end to end.
Lab Objectives
- Navigate an unfamiliar PHP codebase to find the real authentication entry point
- Identify a hardcoded authentication bypass by reading the login check, not by guessing
- Find a command-execution sink by grepping for dangerous function calls
- Trace user input from the request to the sink to prove it is reachable
- Chain the bypass and the sink into a working command-execution proof
- Assess the blast radius of a code-execution bug by reading deployment and hardening config
Why this lab is different
SQL Injection Deep Dive and Advanced SQL Injection found injection points by reading source first. This lab uses the same workflow on a different bug class: an authentication bypass, chained with an OS command-injection sink, into remote code execution (RCE).
You will read two small PHP files from one application. The first file hides a leftover debug backdoor in the login check — a common real finding in code review, not a cryptographic trick. The second file passes a request value into a shell command without escaping it. Neither bug alone gives you code execution on its own: the sink sits behind the login check the first bug lets you skip. You prove the chain with a safe, non-destructive command, then read the deployment config to judge how far that command execution actually reaches.
Prerequisites
- Finish Attacking Authentication Mechanisms. You need to already know how login checks, sessions, and roles normally work, so a broken one stands out when you read it.
- Finish Modern Web Exploitation if you have not chained two separate bugs into one exploit before.
- Read basic PHP. You read two short files and one Dockerfile. You do not write any PHP.
Lab setup
| Item | Purpose |
|---|---|
curl | Sends the crafted requests and reads the HTTP status and timing |
grep | Searches the source tree for the backdoor and the dangerous sink |
| A text editor | Reads the PHP source and the deployment config for this lab |
Build the target
KaliRange hosts no targets, no virtual machines and no lab files. You run this lab against a small demo application, DocuReview, that you build yourself. The address 10.0.14.40:8080 and the path ~/docureview-src below are the example address and path of this lab. Replace them with your own.
DocuReview is a document-review and PDF-export tool. Build it as a small PHP 8.2 application behind Apache, with a source tree you keep on your Kali machine (for example at ~/docureview-src), and these exact parts, because the later steps read and run them:
- A route table with
POST /admin/reports/exportmapped to a methodexportPdf, andGET /admin/usersmapped to a methodlistUsers, both guarded by a methodrequireAdmin(Step 1). AuthController.php, with arequireAdmin()method that returnssession()->get('role') === 'admin', plus the leftover debug branch printed in full in Step 2: a comment reading "TEMP: lets QA skip SSO while the new identity provider is tested." and "TODO: remove before v2.4 ships.", followed by theX-Debug-Bypass: qa-2026-tempcheck that sets the session role toadmin(Steps 2 and 3).ReportController.php, with anexportPdf()method exactly as printed in Step 5: it callsrequireAdmin(), readstitleandbodyfrom the request, writesbodyto a temporary HTML file, and runswkhtmltopdfthroughsystem()with$titleconcatenated into the command, unescaped (Steps 4, 5 and 6). Installwkhtmltopdfin the container so the command has something real to run.deploy/Dockerfile, startingFROM php:8.2-apache, creating a system group and userappsvc, and endingUSER appsvc(Step 7).deploy/php.ini, with the linesdisable_functions =andopen_basedir =, both left empty (Step 8).- No signed-in session by default, so a plain request to
/admin/usersredirects to login (the302baseline of Step 3).
Build such an application from free, legal parts: write the two PHP files and the two deployment files yourself, since this exact backdoor-plus-sink chain is specific to this lab. Run it in a container or a virtual machine on your own network. Take a snapshot of the virtual machine, or note the state of the container, before Step 1.
Authorised targets only. Run every command in this lab only against a target that you own or have written permission to test. Never point a debug header, a crafted command, or any technique from this lab at a server you do not own or have written permission to test. Unauthorised access and unauthorised command execution are crimes in most countries.
Step 1: Map the codebase before touching the app
Find the entry points before you read any logic
List the controllers and routes first. You need to know where a request enters the app before you can trace what it does.
# List the controllers — this is where request handling lives in most PHP MVC apps
find ~/docureview-src -iname "*Controller.php"
# Find where routes map URLs to controller methods
grep -rn "Route::" ~/docureview-src/routes 2>/dev/nullExample output:
~/docureview-src/app/Http/Controllers/AuthController.php
~/docureview-src/app/Http/Controllers/ReportController.php
~/docureview-src/app/Http/Controllers/DocumentController.php
~/docureview-src/routes/web.php:9:Route::post('/admin/reports/export', [ReportController::class, 'exportPdf']);
~/docureview-src/routes/web.php:14:Route::get('/admin/users', [AuthController::class, 'listUsers']);Two controllers matter for this lab: AuthController, which decides who is an admin, and ReportController, which exports a document to PDF. Read AuthController first — everything else in this lab sits behind it.
Step 2: Find the authentication backdoor in the login check
Read the admin check line by line
Open AuthController.php. Find the method that decides whether the current request is allowed to act as an admin. Read every branch, including the ones that look like leftover debug code.
public function requireAdmin(Request $request)
{
// TEMP: lets QA skip SSO while the new identity provider is tested.
// TODO: remove before v2.4 ships.
if ($request->header('X-Debug-Bypass') === 'qa-2026-temp') {
session()->put('role', 'admin');
return true;
}
return session()->get('role') === 'admin';
}This is a hardcoded debug backdoor, not a cryptographic weakness. The TEMP/TODO comments are the real-world pattern: a developer added a shortcut for testing and it shipped. Code review finds this instantly; black-box testing almost never does, because nothing about the app's behaviour hints that the header exists.
# Confirm the pattern yourself: search the source for debug or bypass headers
grep -rn "X-Debug\|TEMP:\|TODO: remove" ~/docureview-src/appExample output:
~/docureview-src/app/Http/Controllers/AuthController.php:12: // TEMP: lets QA skip SSO while the new identity provider is tested.
~/docureview-src/app/Http/Controllers/AuthController.php:13: // TODO: remove before v2.4 ships.
~/docureview-src/app/Http/Controllers/AuthController.php:14: if ($request->header('X-Debug-Bypass') === 'qa-2026-temp') {Sign in to continue
10 more sections are for signed-in members. It is free: sign in with Google.