- substr: documentation ( source)
- var_dump: documentation ( source)
- readfile: documentation ( source)
- preg_match: documentation ( source)
- strrpos: documentation ( source)
- in_array: documentation ( source)
<?php
$allowed = array('txt', 'docx');
print "\n\$_REQUEST:"; var_dump($_REQUEST);
//o$a="txt.$php";
//echo "test${a}test\n";
$zzfile = $_REQUEST['zzfile'];
//$filename = basename($zzfile);
$filename = $zzfile;
print "\nfilename:\n";
var_dump($filename);
if (preg_match('#\.(.+)$#', $filename, $matches) && isset($matches[1]) && !in_array($matches[1], $allowed))
die("Extension ${matches[1]} is not allowed!");
echo "\nmatches:"; var_dump($matches);
preg_match('#.#', $filename, $met);
print("\nmet:\n");
var_dump($met);
if (strrpos($filename, '.') !== false) //zwraca od pierwszej kropki od prawej do konca + end
$ext = substr($filename, strrpos($filename, '.'));
else
$ext = '';
$newfile = "flag$ext";
echo "Reading <strong>$newfile</strong>...";
// Hint: the flag is in flag.php
echo '<pre>';
readfile($newfile);
echo '</pre>';
?>