Skip to content

Instantly share code, notes, and snippets.

@InsiderPhD
Created January 24, 2020 23:28
Show Gist options
  • Save InsiderPhD/69cf3acf91c84123e0a9fbb18e83493e to your computer and use it in GitHub Desktop.
Save InsiderPhD/69cf3acf91c84123e0a9fbb18e83493e to your computer and use it in GitHub Desktop.
RCE PHP Demo for YT
<h1>Katie's Maths</h1>
<p>Type in an equation and let me do the hard work!</p>
<form method="post" action="code.php">
<input type="text" name="code" value="1+1">
<button type="submit" name="submit">Submit</button>
</form>
<hr>
<h1>Results</h1>
<?php
if(isset($_POST["code"]))
{
// eval allows any PHP code to be executed
// the intended output is $math = 1+1;
// echo $math
eval("\$maths = " . $_POST["code"] . ";");
echo $_POST["code"] . "=" .$maths;
}
<h1>Test</h1>
<p>Connection problems? Use this tool to ping our servers!</p>
<form action="command.php" method="post">
<select name="cmd">
<option value="ping 8.8.8.8">US West</option>
<option value="ping 8.8.4.4">US East</option>
<option value="ping 1.1.1.1">Europe</option>
</select>
<button name="submit" type="submit">Submit</button>
</form>
<hr>
<h1>Results</h1>
<?php
// this is an example of command injection
// Some styling
echo "<div style='background-color: black; color: lawngreen; font-family: monospace; padding: 5px;'>";
if(isset($_POST["cmd"])){
$exec = [];
// exec allows us to run a command and then save the output to $exec
exec($_POST["cmd"], $exec);
// $exec is an array with each line as an option
foreach ($exec as $line)
{
echo "<p>" . $line . "</p>";
}
}
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment