Last active
October 22, 2017 20:11
-
-
Save pich4ya/ee2873f9fd18c1aca008056532d164a3 to your computer and use it in GitHub Desktop.
Thailand CTF 2017 Write-up : Compromised System (400)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
โจทย์ | |
$ xxd Compromised_System.pcap | |
00000000: d4c3 b2a1 0200 0400 0000 0000 0000 0000 ................ | |
00000010: ffff 0000 0100 0000 2927 bf58 90ea 0400 ........)'.X.... | |
00000020: ad01 0000 ad01 0000 1086 8c3b d93f a099 ...........;.?.. | |
00000030: 9b10 66dd 0800 4500 019f 0001 0000 4011 ..f...E.......@. | |
00000040: 6264 0a00 00a3 0c46 0001 0035 0035 018b bd.....F...5.5.. | |
00000050: 5825 0000 00a7 0000 0004 fe9b 2fa7 0000 X%........../... | |
00000060: 0089 0000 0020 cbe6 ebfa cae6 e4f9 fcfd ..... .......... | |
00000070: ecfb d5cb e6eb 8989 8989 8989 8989 8989 ................ | |
00000080: 8989 8989 8989 0000 002f 0000 0040 6c15 ........./...@l. | |
00000090: 736b 404c 5a42 4a41 5b5c 0f4e 414b 0f7c sk@LZBJA[\.NAK.| | |
000000a0: 4a5b 5b46 4148 5c73 6d40 4d73 6b4a 5c44 J[[FAH\sm@MskJ\D | |
000000b0: 5b40 5f73 4641 5c5b 5d5a 4c5b 4640 415c [@_sFA\[]ZL[F@A\ | |
000000c0: 015b 575b 2f2f 2f2f 2f2f 2f2f 2f2f 0000 .[W[//////////.. | |
000000d0: 00e5 0000 00ff b589 8084 9680 c58e 8080 ................ | |
000000e0: 95c5 918d 8c96 c584 c596 8086 9780 91cb ................ | |
000000f0: c5ac c591 8d8c 8b8e c588 9cc5 969c 9691 ................ | |
00000100: 8088 c296 c587 8080 8bc5 868a 8895 978a ................ | |
00000110: 888c 9680 81cb efb1 8d80 c58e 809c c589 ................ | |
00000120: 8c80 96c5 8c8b c591 8d80 c586 8a88 878c ................ | |
00000130: 8b84 918c 8a8b c58a 83c5 84c5 8380 92c5 ................ | |
00000140: 958c 8086 8096 c58a 83c5 8c8b 838a 9788 ................ | |
00000150: 8491 8c8a 8bc5 8a8b 899c c5ac c592 8a90 ................ | |
00000160: 8981 c58e 8b8a 92cb efa6 8a88 878c 8b8c ................ | |
00000170: 8b82 c588 9cc5 8b84 8880 c592 8c91 8dc5 ................ | |
00000180: 889c c595 8496 9692 8a97 81c9 c5c2 a784 ................ | |
00000190: 81b5 8496 9692 d597 81c2 c9c5 848b 81c5 ................ | |
000001a0: 9589 8486 8c8b 82c5 8c91 c58c 8bc5 9584 ................ | |
000001b0: 9780 8b91 8d80 968c 96c5 8c96 c591 8d80 ................ | |
000001c0: c58e 809c cbef e5e5 e5e5 e5e5 e5e5 e5e5 ................ | |
000001d0: e5e5 e5e5 e5 ..... | |
วิธีแก้ | |
ไอเดียคือ แฮกเกอร์ฝังมัลแวร์ลงเครื่องเหยื่อได้ แล้วมัลแวร์ตัวนี้ส่ง payload เป็น DNS packet กับค่าที่เข้ารหัส | |
เราต้องหาทางถอดรหัส packet นี้เพื่ออ่านข้อมูลข้างใน หนึ่งในวิธีที่มัลแวร์นิยมใช้เข้ารหัสแบบง่าย ๆ คือการ XOR | |
แต่เราไม่มี key เลยเดาว่า key อาจจะถูกส่งไปกับ packet นี้ด้วยเลยสุ่มเอาทุก byte มาเป็น key ลองถอด | |
แล้วมาวิเคราะห์ผลทั้งหมดจากการลองถอดหาดูว่าอันไหนได้ output ที่น่าจะเป็นผลที่ถูกต้อง | |
โดยข้อนี้คนออกโจทย์แอบ hint โดยการใส่ 0xe5 ไว้ตรงท้ายเยอะ ๆ ให้ลองเอาไปใช้เป็น XOR key | |
พอถอดออกได้ flag ส่วนหลังแล้วจึงต้องหาชื่อ hacker โดยใช้ byte อื่น ๆ | |
from scapy.all import rdpcap | |
def xor_packet(buf, key): | |
buf = bytearray(buf) | |
for i, bufbyte in enumerate(buf): | |
buf[i] = bufbyte ^ key | |
return str(buf) | |
pkt = rdpcap('Compromised_System.pcap')[0] | |
payload = str(pkt.payload) | |
for x in xrange(0, len(payload)): | |
try_key = int(hex(ord(payload[x])),16) | |
print "[+] key = "+str(try_key) | |
print xor_packet(str(payload), try_key) | |
# [+] key = 47 | |
# /.//o>MK%// | |
# #i/./ | |
# ///+ | |
# ///oC:\Documents and Settings\Bob\Desktop\instructions.txt | |
# [+] key = 137 | |
# BobsComputer\Bob | |
# [+] key = 229 | |
# llllllllllllllll | |
# Please keep this a secret. I think my system's been compromised. | |
# The key lies in the combination of a few pieces of information only I would know. | |
# Combining my name with my password, 'BadPassw0rd', and placing it in parenthesis is the key. | |
flag: (BobBadPassw0rd) | |
แถมท้ายตัวอย่างมัลแวร์ที่ใช้ 0xe5 มา XOR payload เหมือนกัน | |
https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/windows/backdoor/energizer_duo_payload.rb | |
https://blog.rapid7.com/2010/03/08/locate-and-exploit-the-energizer-trojan/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment