[OverTheWire] Natas – Level 13

http://natas13.natas.labs.overthewire.org/

For security reasons, we now only accept image files!
Choose a JPEG to upload (max 1KB)

Task này giống hệt bài 12, chỉ khác là có thêm bước kiểm tra định dạng file sau khi upload:

[php]if(filesize($_FILES[‘uploadedfile’][‘tmp_name’]) > 1000) {
echo “File is too big”;
} else if (! exif_imagetype($_FILES[‘uploadedfile’][‘tmp_name’])) {
echo “File is not an image”;
} else {
if(move_uploaded_file($_FILES[‘uploadedfile’][‘tmp_name’], $target_path)) {
echo “The file $target_path has been uploaded”;
} else{
echo “There was an error uploading the file, please try again!”;
}
}[/php]

Lưu ý rằng exif_imagetype là một hàm có sẵn của PHP, nó kiểm tra một vài byte đầu tiên của file để xác định xem file đó có phải file ảnh hay không. Ta có thể bypass dễ dàng phép kiểm tra này bằng cách chèn nội dung 1 file ảnh vào trước đoạn code php của file 12.php của bài trước, và đổi tên nó thành 13.php emo_popo_big_smile

Thực hiện các bước tương tự như bài 12, kết quả là ta thu được flag nằm sau các byte loạn xạ của file hình:

...¹]j™)â14•j. J›å¿Úi&ûÙmuª[èÿÙ natas14:Lg96M10TdfaPyVBkJdjymbllQ5L6qdl1

→ flag = Lg96M10TdfaPyVBkJdjymbllQ5L6qdl1.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *