baby toctou -- Race Condition
WebShell [Version 1.0.00000.001]
WebShell:/ $ help
only "ls", "cat api.php", "cat index.php" allowed
WebShell:/ $ ls
api.php
flag.php
index.php
user
WebShell:/ $ cat api.php
<?php
// system($_GET['q']);
if (!preg_match('/^[a-f0-9]+$/', $_COOKIE["baby_toctou"])) {
$newCookie = uniqid() . rand(1, 999999999);
setcookie("baby_toctou", $newCookie);
$_COOKIE["baby_toctou"] = $newCookie;
}
$cmd = $_GET["q"];
($myfile = fopen("user/{$_COOKIE["baby_toctou"]}.sh", "w")) or die("Unable to open file!");
fwrite($myfile, $cmd);
fclose($myfile);
if ($cmd === "ls" || $cmd === "cat api.php" || $cmd === "cat index.php") {
// valid check
sleep(1); // my server is small and weak
system("sh ./user/{$_COOKIE["baby_toctou"]}.sh");
} else {
echo <<<HELP
only "ls", "cat api.php", "cat index.php" allowed
HELP;
}
?>
WebShell:/ $Last updated