- 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');
$zzfile = "flag.\x0a\xe2x08php";
$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);
if (strrpos($filename, '.') !== false) //zwraca od pierwszej kropki od prawej do konca + end
$ext = substr($filename, strrpos($filename, '.'));
else
$ext = '';
$newfile = "flag$ext";
print $newfile;
echo "Reading <strong>$newfile</strong>...";
// Hint: the flag is in flag.php
echo '<pre>';
readfile($newfile);
echo '</pre>';
?>