I'm trying to reproduce the Null Byte Injection attack on an upload form. I have this code:
<?php
if(substr($_FILES['file']['name'], -3) != "php") {
if(move_uploaded_file($_FILES['file']['tmp_name'], $_FILES['file']['name']))
echo '<b>File uploaded</b>';
else
echo '<b>Can not upload</b>';
}
else
echo '<b>This is not a valid file/b>';
?>
I'm trying to upload a file named like this : file.php%00jpg so it will bypass the substr() and will be uploaded as file.php since move_uploaded_file() should stop at the null byte (%00).
The problem is that the uploaded file is not named file.php on the server but file.php%00jpg (which can be accessed by typing /file.php%2500jpg in the url bar).
It seems that move_uploaded_file() does not care about the null byte, so how does this works? Is it possible to upload a file with .php extension with my piece of code?
Thanks :).