Skip to content

Instantly share code, notes, and snippets.

@aeharvlee
Created December 12, 2019 00:06
Show Gist options
  • Save aeharvlee/e3e2295247e181bd31aa468922970b51 to your computer and use it in GitHub Desktop.
Save aeharvlee/e3e2295247e181bd31aa468922970b51 to your computer and use it in GitHub Desktop.
Medium Command Injection Source
<?php
if( isset( $_POST[ 'Submit' ] ) ) {
// Get input
$target = $_REQUEST[ 'ip' ];
// Set blacklist
$substitutions = array(
'&&' => '',
';' => '',
);
// Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target );
// Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
}
// Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment