
SANS Holiday Challenge 2017 Write-up Part 1
Incognito Lab
ช่วงเทศกาล Christmas ของทุกปีทาง SANS และ Counterhack จะมีการจัด CTF ที่เรียกว่า SANS Holiday Hack Challenge เป็นประจำ ซึ่งในปี 2017 สามารถดูรายละเอียดได้ที่ https://www.holidayhackchallenge.com/2017/ ซึ่งในปีนี้เห็นว่ามีคนที่สมัครเล่นประมาณ 10000 accounts
คำถามในปีนี้มีทั้งหมด 9 ข้อ ได้แก่
- Visit the North Pole and Beyond at the Winter Wonder Landing Level to collect the first page of The Great Book using a giant snowball. What is the title of that page?
- Investigate the Letters to Santa application at https://l2s.northpolechristmastown.com. What is the topic of The Great Book page available in the web root of the server? What is Alabaster Snowball’s password?
- The North Pole engineering team uses a Windows SMB server for sharing documentation and correspondence. Using your access to the Letters to Santa server, identify and enumerate the SMB file-sharing server. What is the file server share name?
- Elf Web Access (EWA) is the preferred mailer for North Pole elves, available internally at http://mail.northpolechristmastown.com. What can you learn from The Great Book page found in an e-mail on that server?
- How many infractions are required to be marked as naughty on Santa’s Naughty and Nice List? What are the names of at least six insider threat moles? Who is throwing the snowballs from the top of the North Pole Mountain and what is your proof?
- The North Pole engineering team has introduced an Elf as a Service (EaaS) platform to optimize resource allocation for mission-critical Christmas engineering projects at http://eaas.northpolechristmastown.com. Visit the system and retrieve instructions for accessing The Great Book page from C:\greatbook.txt. Then retrieve The Great Book PDF file by following those directions. What is the title of The Great Book page?
- Like any other complex SCADA systems, the North Pole uses Elf-Machine Interfaces (EMI) to monitor and control critical infrastructure assets. These systems serve many uses, including email access and web browsing. Gain access to the EMI server through the use of a phishing attack with your access to the EWA server. Retrieve The Great Book page from C:\GreatBookPage7.pdf. What does The Great Book page describe?
- Fetch the letter to Santa from the North Pole Elf Database at http://edb.northpolechristmastown.com. Who wrote the letter?
- Which character is ultimately the villain causing the giant snowball problem. What is the villain’s motive?
ซึ่งในเกมจะมีหลาย ๆ ส่วนทั้งที่เป็นการโจมตี Server, การเล่น Minigame ต่าง ๆ โดยถ้าจะเล่นให้ครบทั้งหมดจะมี 3 ส่วนหลักได้แก่
1.Cranberrypi Terminal Challenge -> เป็นแนวการฝึก skill linux command line เพื่อแก้ปัญหา
2.Snowball game -> Mini game ที่ต้องพยายามหาทางพา snowball ไปจุดที่เราต้องการ
3.Collecting 7 pages of the Great Book -> ต้องหาหน้าหนังสือที่กระจายออกไปทั่วเกม เพื่อใช้เอามาตอบคำถามใน CTF ซึ่งแต่ละหน้าก็จะกระจายอยู่ทั้งในส่วนของ snowball game และ server ต่าง ๆ ที่ถูกเตรียมไว้ให้โจมตี
เริ่มจากโจทย์ข้อแรก
- Visit the North Pole and Beyond at the Winter Wonder Landing Level to collect the first page of The Great Book using a giant snowball. What is the title of that page?
ใน snowball game ด่าน Winter Wonder Landing จะมี Page อยู่ สังเกตได้จากรูปด้านล่างทางขวามือ เมื่อกลิ้ง snowball ไปทับก็จะได้ Page ที่ 1 มาโดยมี Title คือ "About This Book"
ถัดไปขอพูดถึงส่วนที่เป็น Cranberrypi challenge ซึ่งจะอยู่ใน snowball mini game ทั้ง 9 ด่าน ซึ่งในแต่ละด่านจะมีรูป Cranberry (ตรงกลางของรูปด้านบน) เมื่อกดเข้าไปจะมี Terminal เด้งขึ้นมาให้เราเล่น
Winconceivable: The Cliffs of Winsanity
โดยเป้าหมายของการผ่านด่านนี้คือต้อง kill process ที่ชื่อว่า "santaslittlehelperd" แต่ว่าเราไม่สามารถใช้คำสั่ง kill ได้เลย เนื่องจากว่ามีการตั้งค่า Alias ในไฟล์ .bashrc โดยให้ kill = ‘true’ พอพิมพ์คำว่า kill ไปก็จะเป็นการพิมพ์ ‘true’ ไม่ใช่การเรียกคำสั่ง kill ทำให้ไม่สามารถ kill process ได้
จากนั้นจึงใช้คำสั่ง find เพื่อหาว่า kill อยู่ที่ไหน
ตอนนี้เจอแล้วว่าอยู่ที่ /bin/kill ดังนั้นจึงเรียกคำสั่งที่ path นี้เพื่อทำการ kill process
Winter Wonder Landing
โจทย์ของด่านนี้คือต้องการให้ execute binary ชื่อว่า elftalkd ซึ่งไม่รู้ว่าไฟล์นี้อยู่ที่ไหน จะใช้คำสั่ง find ก็เกิด error
ดังนั้นจึงลองใช้คำสั่ง whereis เพื่อหาว่ามีคำสั่ง find ที่ไหนบ้าง จะได้เรียกใช้เพื่อหา elftalkd
เจอ find ที่ /usr/bin/find
เจอ elftalkd แล้วก็แค่เรียกไฟล์ตรงๆ
Cryokinetic Magic
ด่านนี้ต้องการให้ execute binary ชื่อ CandyCaneStriper
ซึ่งปัญหาคือเรื่อง permission ของ CandyCaneStriper (เราเป็น elf แต่ไฟล์ owner เป็น root) และ Binary ของ chmod ที่มีค่าเป็น 0 (ไม่มีไส้ใน)
ถ้าเล่นตาม Hint ในเกมจะ reference ถึงการใช้ dynamic linker ในการ execute file -> https://superuser.com/questions/341439/can-i-execute-a-linux-binary-without-the-execute-permission-bit-being-set
แต่ระหว่างเล่นผมใช้อีกวิธีคือ copy file CandyCaneStriper ไปที่ temp และ copy file ที่ elf มี permission ในการ execute ไปที่ temp (ในตัวอย่างนี้คือ chmod นั่นแหละ) แล้วทำการ copy ไส้ในของ CandyCaneStriper ไปยัดไว้ในไฟล์ที่เรามีสิทธิ write และ execute จากนั้นเราก็ execute ไฟล์ที่เรามีสิทธิ
There’s snow place like home
ด่านนี้ต้องการให้ execute binary ชื่อ trainstartup แต่ว่าปัญหาคือไฟล์นี้ไม่ได้ถูก compile มาเพื่อเครื่องที่เราใช้ แต่ถูก compile มาสำหรับ ARM cpu ซึ่งเราสามารถตรวจสอบได้โดยใช้คำสั่ง file จะพบว่าเป็น ARM จากนั้นเราสามารถ execute ได้โดยใช้ qemu ซึ่งเป็น emulator โดยระบุให้ qemu ใช้ arm เพื่อ execute file นี้
Bumble bounce
Note: ด่านนี้มี The Great Book Page 5 อยู่ด้วย
สำหรับด่านนี้ต้องการให้เราตรวจสอบ access.log เพื่อหา user-agent ของ web browser ที่มีการใช้น้อยที่สุด โดย access.log เป็น file web access log ที่เก็บ HTTP request header ไว้
command ที่จะใช้ในการหาคำตอบที่ใช้คือ
- cut ไว้ตัดคำตาม delimiter
- uniq ไว้ดึงค่า string ที่เป็น unique รวมถึงสามารถใช้ในการ count ได้ด้วย (-c)
- sort คำสั่งสำหรับ sorting ทั่วไป
คำตอบคือ Dillo
I don’t think we’re in Kansas anymore
โจทย์สำหรับด่านนี้คือให้หาชื่อเพลงที่ได้รับการกด like มากที่สุด ซึ่งข้อมูลเก็บอยู่ใน file database หลัก ๆ แล้วเป้าหมายคือการให้ฝึกใช้ skill sql แบบ command line โดยเริ่มจากใช้ sqlite3 ดู schema ของ database
ลอง query ดูเนื้อหาของแต่ละ table
จากนั้นก็ใช้คำสั่ง group by, count เพื่อนับข้อมูล แล้วก็ search หาเพลง
คำตอบคือเพลง Stairway to Heaven
Oh wait! May be we are
โจทย์ข้อนี้คือต้องการให้ restore content ของ shadow.bak ไปที่ shadow ซึ่งปัญหาของข้อนี้คือ เราเป็น elf แต่ file shadow นั้น owner:group เป็น root:root ในขณะที่ shadow.bak นั้น owner:group เป็น root:shadow ซึ่ง elf ไม่ควรจะเขียนทับได้ (restore) นอกจากนี้ได้ลองเปิดไฟล์ sudoers ดูพบว่ามีอยู่ 1 บรรทัดที่บอกว่า elf สามารถใช้สิทธิ shadow ในการเรียกคำสั่ง find ได้
ใช้คำสั่ง sudo -g
We’re off to see the …
โจทย์ข้อนี้คือมี binary ชื่อ isit42 ที่จะ random เลขขึ้นมาเรื่อย ๆ เป้าหมายเราคือให้มีการ random เลขให้มีค่า 42 ให้ได้ ซึ่งบางคนเลือกใช้วิธี bruteforce โดยการสร้าง loop เรียก isit42 ไปเรื่อย ๆ
ใน hint มีการพูดถึงเรื่อง LD_Preload https://pen-testing.sans.org/blog/2017/12/06/go-to-the-head-of-the-class-ld-preload-for-the-win ซึ่งคล้าย ๆ กับว่าเป็นการ override บาง function ของ binary นั้น ซึ่งจะต้องมีความเข้าใจถึงโครงสร้างของ function ที่มีการเรียกใช้ รวมไปถึงตอนเรียก binary นั้นจะต้องมีการเรียกคำสั่ง LD_Preload ด้วย
ใน challenge นี้มีตัวอย่าง source code บางส่วนของ isit42 มาให้ด้วย ซึ่งทำให้เราเข้าใจถึง functionที่มีการเรียกใช้
มีการเรียกใช้ function rand() ซึ่งจากการดูข้อมูลพบว่า function ดังกล่าวมีการประกาศคือ
int rand(void)
ดังนั้นจึงเขียน code ขึ้นมาใหม่ ให้ function นี้ return ค่า 42 ทุกครั้ง โดยตอน compile จะมี option เพิ่มคือ -shared -fPIC และตอนเรียก isit42 จะใช้คำสั่ง LD_PRELOAD เรียก file ที่เราเขียน พร้อมทั้ง isit42
จบในส่วนของ Part 1 ที่เน้นที่ Cranberry pi terminal เป็นหลัก
Up Next

ARTICLES
Mar
01
2021
007 Skyfall : the untold story
สวัสดีปีใหม่ สำหรับในปี 2012 ที่ผ่านมาทางทีมงาน Incognito Lab ของเรา ขอขอบคุณทุก ๆ ท่านที่คอยติดตามเรา และ ส่งเมล์เข้ามาให้กำลังใจทีมงานอย่างมากครับ
READ MORE

ARTICLES
Mar
01
2021
Bangkok Governor Election
สิ่งที่อยากจะแชร์ในวันนี้คือ Security ในเขตเลือกตั้งครับ
READ MORE

ARTICLES
Mar
01
2021
Banking Trojan Hunting — g01pack's fundamental analysis
1-2 วันที่ผ่านมาผมคิดว่าหลาย ๆ คนที่เข้าไปดูข่าวออนไลน์บ่อย ๆ อาจจะตกใจเนื่องจาก Google และ Google Chrome มีการแจ้งเตือนภัยคุกคามว่า website ดังกล่าวอาจเป็นอันตรายต่อคอมพิวเตอร์ของผู้ใช้งาน
READ MORE