### Challenge Description
Gotham is shrouded in darkness as you receive an urgent message from an anonymous source: A stolen code could threaten the city. You rush to your computer, only to discover that vital files are missing. The only clue is a mysterious note left behind, hinting at a hidden treasure buried within the depths of your system.
As you dig deeper, the flickering lights of your apartment signal an incoming storm—just as your system suddenly crashes, locking you out of everything. In the chaos, whispers of the Dark Knight’s presence linger in the air. Was he protecting you, or is there more to this enigma?
Now, as the clock ticks down, you must piece together the clues scattered throughout your system before Gotham falls into chaos. Can you outsmart the darkness and restore the stolen code?
Note: This challenge doesn't have any questions but the flag itself!
**MD5 Hash:** a180fce0b7d10283617575c3a23cf609 **kn1ghtfl4r3.zip**
> flag format : icc{...}
### Link
> https://drive.google.com/file/d/1DQ0YMRVplbN2t6bw8d6mRjkS--sD5AxC/view?usp=sharing
**Password**
```
MpY6Zzp`8t>3i1c
```
### Solution
##### Bài này cung cấp cho chúng ta 1 file raw (memory dump) có dung lượng ~6.3 GB

##### Sử dụng volatility để phân tích, với pslist để xem danh sách tiến trình
##### Có 1 vài tiến trình đáng chú ý như keepass, notepad, powershell

##### Vì powershell đang chạy nên mình dùng plugin consoles để xem lịch sử powershell trên máy nhưng không có gì
##### Tiếp theo mình truy cập các thư mục thường dùng như Desktop/Documents/Downloads để xem có gì không
> python2 vol.py -f /home/kali/Downloads/test/chall.raw --profile=Win10x64_19041 filescan | grep -E "Downloads|Documents|Desktop"

##### Tại Downloads mình thấy 1 file .hc (file đĩa được mã hóa bằng VeraCrypt)
##### Và 1 vài file bên dưới chỉ để đánh lừa người chơi
##### Tập trung vào file mã hóa (.hc), để giải mã được ta cần mật khẩu giải mã.
##### Ở pslist, ta thấy có 3 process notepad.exe đang chạy ở đó. Mình đoán rằng mật khẩu đã được note ở đây. Để lấy được text đã gõ trong notepad, mình sử dụng kĩ thuật note heap với windbg
https://www.sans.org/blog/the-analysis-of-user-data-in-VADs-extraction-of-precise-data-in-notepad-memory-and-hunting-for-malware-behavior/
##### Tuy nhiên khi import trực tiếp file raw vào nó sẽ báo lỗi không tương thích với định dạng của windbg

##### Cách khắc phục là sử dụng công cụ memprocfs

##### Kết quả là ta thu được file .dmp đúng định dạng

##### Bây giờ mọi thứ đã sẵn sàng, tiến hành debug:
1. Sử dụng WinDBG để tìm địa chỉ notepad `process !process 0 0 notepad.exe`

##### Có 3 tiến trình nên ta sẽ thử từng địa chỉ notepad process một, vì mình thử rồi nên mình biết nó là tiến trình có `PROCESS ffff9c84decee080`
2. Kết nối với quy trình notepad: `.process /r /p ffff9c84decee080`

3. Liệt kê tất cả các vùng bộ nhớ heap và tìm địa chỉ của chunk có cờ "extra"

4. Hiển thị nội dung trong heap

##### Mật khẩu là Y454wE3kh7, ta mount file hc với công cụ VeraCrypt. Ta thu được file project.zip bị nén bởi mật khẩu


##### Dựa vào payload này `strings chall.raw| grep env | grep zip`

##### Các file trong thư mục psreadline đã bị xóa, đồng thời mật khẩu file zip cũng ở đây.
```
$env:zippa4s5wo0rD="MP0Z\CRJws&4e\c':=3k"
```
##### Giải nén ta được 3 file, check file enc.exe trước


##### File exe được pack bằng PyInstaller và đây là mã nguồn của nó
```python=
import os
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import padding
def encrypt_file(file_path, key, iv):
if len(key) != 32 or len(iv) != 16:
raise ValueError('Invalid key or IV length')
cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
encryptor = cipher.encryptor()
padder = padding.PKCS7(128).padder()
with open(file_path, 'rb') as file:
plaintext = file.read()
padded_data = padder.update(plaintext) + padder.finalize()
ciphertext = encryptor.update(padded_data) + encryptor.finalize()
with open(file_path, 'wb') as file:
file.write(ciphertext)
key = b'{REDACTED}'
iv = bytes.fromhex('3038375330a3546850283a2d695b7e23')
original_file = 'Confidential'
encrypt_file(original_file, key, iv)
```
##### Đoạn mã mã háo file Confidential bằng aes, tuy nhiên nó bị ẩn đi. Có thể nó nằm trong file Keylist.kdbx kia
##### Để lấy được key password giải mã file Keylist.kdbx ta sử dụng công cụ [keepass-dump-extractor](https://github.com/JorianWoltjer/keepass-dump-extractor)

##### Đây là tất cả những trường hợp mật khẩu có thể xảy ra, lưu nó vào wordlist rồi dùng john bruteforce

##### Sử dụng keypass 2 để mở thì lấy được main_key ở Recycle bin

##### Bây giờ giải mã bằng cyberchef, ta thu được file pdf

##### Mở ra thì ngoài chữ CONFIDENTIAL thì không có gì, nhưng khi ctrl A để chọn tất cả thì 1 vài điểm bị ẩn sẽ hiện ra

##### Copy và dán vào các trình soạn thảo khác ta thu được flag
```
CONFIDENTIAL
Gotham's fate rests in your hands.
Hidden within your system is a code that holds the city's future.
Your objective: retrieve it before the shadows consume everything.
The code is: icc{15_17_d4rkkn1gh7_0r_4zr34lkn1gh7}
Trust nothing. The clues are buried deeper than you think. Time is running out.
```
> Flag : icc{15_17_d4rkkn1gh7_0r_4zr34lkn1gh7}