How to get a Reverse Shell from any Wordpress ?
An attacker who already has WordPress admin credentials can edit a theme's 404 template to insert a PHP reverse shell, then trigger it by visiting the theme's 404 page. This gives a remote shell on the server.
We are pentesting a wordpress site & eventually got admin credentials. After logging in, we get an admin dashboard from where we can edit themes or plugins.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the WordPress admin theme editor allows editing PHP template files, so anyone with admin access can run arbitrary PHP code on the server.
Impact
An attacker with admin credentials could gain a remote shell on the web server, but this requires already having admin access.
What the attacker needed
WordPress admin credentials; Theme editor enabled; Ability to edit theme files
The fix
The theme editor should be disabled or restricted so that admin users cannot edit PHP files directly, or file editing should be disallowed in production.
How it was found
- Log in to the WordPress admin dashboard.
- Go to Appearance > Editor > 404 Template.
- Replace the PHP code in the box with a PHP reverse shell and set the IP and port.
- Click Update File to save the changes.
- Start a netcat listener on the attacker machine.
- Visit the theme's 404.php page to trigger the shell.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A reverse shell is a way to make the victim server connect back to the attacker's computer, giving the attacker a command prompt on that server. The article assumes the attacker already has WordPress admin login, which normally lets you edit theme files. By replacing the 404 error page's code with a malicious script, the attacker gets a shell when that page is loaded.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.