Saya akan membahas tentang cara simple mempatch PHP Arbitrary File Upload.
Kebanyakan website yang vuln diupload memiliki garis besar seperti ini:
Contoh simple upload.php file upload.
123456789 <span style="color: #0000ff;"><?php$uploaddir = 'uploads/'; // Relative path under webroot$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";}?></span>
Contoh form yang dipake dalam file index untuk upload:
1234 <span style="color: #0000ff;"><form name="upload" action="upload.php" method="POST" ENCTYPE="multipart/formdata">Select the file to upload: <input type="file" name="userfile"><input type="submit" name="upload" value="upload"></form></span>
Disini tidak ada code yang memfilter upload filetype.
Jadi kita bisa langsung saja upload: shell.php
Jadi kita bisa langsung saja upload: shell.php
Patching yg bisa dilakukan adalah menambahkan filter filetype dalam script upload.php
Contohnya:
Contohnya:
12345678910111213 <span style="color: #0000ff;"><?phpif($_FILES['userfile']['type'] != "image/gif") {echo "Sorry, we only allow uploading GIF images";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";}?></span>
Untuk “images/gif” bisa diganti dengan “images/jpg” dll…
Kita liat backgound request uploadnya
123456789101112131415161718 <span style="color: #0000ff;">POST /upload.php HTTP/1.1TE: deflate,gzip;q=0.3Connection: TE, closeHost: localhostUser-Agent: libwww-perl/5.803Content-Type: multipart/form-data;Content-Length: 156Content-Disposition: form-data; name="userfile"; filename="shell.php"......-HTTP/1.1 200 OKDate: Thu, 31 May 2007 13:54:01 GMTServer: ApacheX-Powered-By: PHP/5.2.2-pl6-gentooConnection: closeContent-Type: text/htmlSorry, we only allow uploading GIF images</span>
Hehehe..
Happy Patching..
Happy Patching..
Tidak ada komentar:
Posting Komentar