FILE NAME VERIFICATION
$blacklist = array(".php", ".phtml", ".php3", ".php4");
foreach ($blacklist as $item)
{
if(preg_match("/$item$/i", $_FILES['userfile']['name']))
{
echo "We do not allow uploading PHP filesn";
exit;
}
}
$uploaddir = 'uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.n";
}
else
{
echo "File uploading failed.n";
}
?>
code di atas, akan cek file yang di upload.
fungsi fregmatch akan cek file yg di upload untuk melihat jika ada file2 yang di blacklist.
sekarang code di atas boleh bypass dengan mengupload gif atau file jpeg yg ade tertanam shell
dalam image tu.
mcm di tunjuk di tutorial part 1..
satu lagi cara untuk bypass guna cara ni ialah
dengan gunakan parameter byte nol
tukarkan nama file ke shell.php.gif
sekarang file boleh di upload.
tapi masa upload ada character (), ia akan abaikan file tu dan simpan file sbg shell.php
korang boleh access file sebagai shell.php
contoh :
http://www.contoh.com/upload/shell.php

0 comments