LOCAL FILE INCLUSION X REMOTE FILE INCLUSION#3
LOCAL FILE INCLUSION X REMOTE FILE INCLUSION#3
ก่อนหน้านี้เราพูดถึง PHP wrapper php://input ซึ่งทำให้เปลี่ยนจาก Local File Inclusion ให้กลายเป็น Remote Code Execution ได้ แต่ก็มี PHP Wrapper อีกหนึ่งอันที่เป็นที่นิยมในการใช้งานร่วมกับ LFI คือ php://filter ซึ่งเป็นการ encode file ที่ถูก include เข้ามา โดยการใช้งานนี้มักถูกใช้เมื่อกรณีที่เราต้องการเห็นเนื้อหาภายในไฟล์นั้นๆ เพราะโดยปกติแล้วเมื่อมีการ include file เข้ามาโดยตรง หากภายในไฟล์นั้นมี php code อยู่จะกลายเป็นว่า php code นั้นจะถูกนำมาใช้งานทันที ซึ่งทำให้เราไม่สามารถเห็นเนื้อหาของไฟล์นั้นๆได้ ดังนั้นสิ่งที่เราทำคือเปลี่ยนรูปลักษณะของไฟล์นั้นๆให้เป็น base64 ก่อนที่จะถูกนำไป include เข้าไฟล์
โดยตัวอย่าง request เป็นดังนี้
โดยตัวอย่าง request เป็นดังนี้
GET /index.php?page=php://filter/convert.base64-encode/resource=index.php HTTP/1.1
Host: target.com
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Cookie: __cfduid=dd8465cb7b2c28a4cb6dee2d7096b65fd1546792095
Connection: close
Upgrade-Insecure-Requests: 1
Content-Length: 41
จากภาพจะเห็นว่า URL เป็น page=php://filter/convert.base64-encode/resource=index.php ดังนั้นผลที่เกิดขึ้นคือเนื้อหาภายในไฟล์ index.php จะถูก encode ในรูปแบบ base64 ก่อนถูกนำไป include() เข้าไปใน index.php ดังนั้นสิ่งที่ต้องทำต่อคือการนำ content นั้นๆไป decode base64 อีกทีก็จะได้เนื้อหาของไฟล์ index.php
โดยหากเป็น Linux จะสามารถใช้ได้เป็น
echo "<content base64>" | base64 -d
ก็จะได้เป็น source code ของ index.php

Comments
Post a Comment