Skip to content

Instantly share code, notes, and snippets.

@hardword
Forked from PinkDraconian/cli.php
Created March 10, 2022 08:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hardword/d69a2c93c034212446af5f02061688b0 to your computer and use it in GitHub Desktop.
Save hardword/d69a2c93c034212446af5f02061688b0 to your computer and use it in GitHub Desktop.
Can you spot the vulnerability?
<?php
if (!isset($_SERVER['argc']) || $_SERVER['argc'] < 1) {
die("Usage: cli <action> <options>");
}
$argc = $_SERVER['argc'];
$argv = $_SERVER['argv'];
switch ($argv[1]) {
case "ls":
echo "Listing directory";
break;
case "download":
if (($argc) < 4) {
die("Usage: cli download <url> <output-file>");
}
$url = $argv[2];
$outputFile = $argv[3];
echo "Downloading ${url} to ${outputFile}";
file_put_contents($outputFile, file_get_contents($url));
break;
default:
die("Valid command are ls/download");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment