ctf-agent 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/AGENTS.md +131 -0
  2. package/Dockerfile +192 -0
  3. package/README.md +522 -0
  4. package/agents/ctf-analyzer.md +58 -0
  5. package/agents/ctf-controller.md +151 -0
  6. package/agents/ctf-speedrun.md +74 -0
  7. package/bin/ctf-agent.js +119 -0
  8. package/docker-compose.yml +13 -0
  9. package/mcp_config.json +19 -0
  10. package/package.json +44 -0
  11. package/references/ctf-triage-ladder.md +68 -0
  12. package/references/exploit-databases.md +575 -0
  13. package/references/llm-safety-and-policy-compliance.md +173 -0
  14. package/references/multi-agent-orchestration-and-policy-routing.md +278 -0
  15. package/references/security-events-and-intelligence.md +566 -0
  16. package/references/version-matrix.md +59 -0
  17. package/rules/ctf-execution-rules.md +44 -0
  18. package/rules/ctf-safety-framing-rules.md +140 -0
  19. package/rules/flag-validation-rules.md +25 -0
  20. package/scripts/__init__.py +1 -0
  21. package/scripts/ctf-tools.lock +205 -0
  22. package/scripts/ctf_init.py +1026 -0
  23. package/scripts/ctf_update.py +583 -0
  24. package/scripts/ctfd_client.py +81 -0
  25. package/scripts/cve_lookup.py +453 -0
  26. package/scripts/extract_flags.py +155 -0
  27. package/scripts/install_as_agent.py +278 -0
  28. package/scripts/install_ctf_tools.sh +603 -0
  29. package/scripts/parallel_triage.py +395 -0
  30. package/scripts/prompt_policy_sanitizer.py +283 -0
  31. package/scripts/scope_guard.py +444 -0
  32. package/scripts/skill_validator.py +504 -0
  33. package/scripts/workspace_cleaner.py +141 -0
  34. package/skills/ctf-ai-ml/SKILL.md +120 -0
  35. package/skills/ctf-ai-ml/adversarial-ml.md +623 -0
  36. package/skills/ctf-ai-ml/llm-attacks.md +487 -0
  37. package/skills/ctf-ai-ml/model-attacks.md +422 -0
  38. package/skills/ctf-crypto/SKILL.md +320 -0
  39. package/skills/ctf-crypto/advanced-math.md +798 -0
  40. package/skills/ctf-crypto/classic-ciphers.md +651 -0
  41. package/skills/ctf-crypto/ecc-attacks.md +347 -0
  42. package/skills/ctf-crypto/exotic-crypto-2.md +380 -0
  43. package/skills/ctf-crypto/exotic-crypto.md +528 -0
  44. package/skills/ctf-crypto/historical.md +113 -0
  45. package/skills/ctf-crypto/lattice-and-lwe.md +524 -0
  46. package/skills/ctf-crypto/modern-ciphers-2.md +563 -0
  47. package/skills/ctf-crypto/modern-ciphers-3.md +453 -0
  48. package/skills/ctf-crypto/modern-ciphers.md +649 -0
  49. package/skills/ctf-crypto/prng-attacks.md +257 -0
  50. package/skills/ctf-crypto/prng.md +664 -0
  51. package/skills/ctf-crypto/rsa-attacks-2.md +792 -0
  52. package/skills/ctf-crypto/rsa-attacks.md +487 -0
  53. package/skills/ctf-crypto/stream-ciphers.md +390 -0
  54. package/skills/ctf-crypto/zkp-and-advanced.md +456 -0
  55. package/skills/ctf-forensics/3d-printing.md +121 -0
  56. package/skills/ctf-forensics/SKILL.md +379 -0
  57. package/skills/ctf-forensics/disk-advanced.md +497 -0
  58. package/skills/ctf-forensics/disk-and-memory.md +491 -0
  59. package/skills/ctf-forensics/disk-recovery.md +699 -0
  60. package/skills/ctf-forensics/linux-forensics.md +511 -0
  61. package/skills/ctf-forensics/network-advanced.md +583 -0
  62. package/skills/ctf-forensics/network.md +645 -0
  63. package/skills/ctf-forensics/peripheral-capture.md +287 -0
  64. package/skills/ctf-forensics/signals-and-hardware.md +713 -0
  65. package/skills/ctf-forensics/steganography.md +694 -0
  66. package/skills/ctf-forensics/stego-advanced-2.md +475 -0
  67. package/skills/ctf-forensics/stego-advanced.md +481 -0
  68. package/skills/ctf-forensics/stego-image.md +691 -0
  69. package/skills/ctf-forensics/windows.md +625 -0
  70. package/skills/ctf-malware/SKILL.md +181 -0
  71. package/skills/ctf-malware/c2-and-protocols.md +274 -0
  72. package/skills/ctf-malware/pe-and-dotnet.md +108 -0
  73. package/skills/ctf-malware/scripts-and-obfuscation.md +449 -0
  74. package/skills/ctf-misc/SKILL.md +498 -0
  75. package/skills/ctf-misc/bashjails.md +323 -0
  76. package/skills/ctf-misc/ctfd-navigation.md +465 -0
  77. package/skills/ctf-misc/dns.md +255 -0
  78. package/skills/ctf-misc/encodings-advanced.md +504 -0
  79. package/skills/ctf-misc/encodings.md +431 -0
  80. package/skills/ctf-misc/games-and-vms-2.md +254 -0
  81. package/skills/ctf-misc/games-and-vms-3.md +690 -0
  82. package/skills/ctf-misc/games-and-vms-4.md +229 -0
  83. package/skills/ctf-misc/games-and-vms.md +529 -0
  84. package/skills/ctf-misc/linux-privesc.md +333 -0
  85. package/skills/ctf-misc/pyjails.md +671 -0
  86. package/skills/ctf-misc/rf-sdr.md +91 -0
  87. package/skills/ctf-osint/SKILL.md +198 -0
  88. package/skills/ctf-osint/geolocation-and-media.md +464 -0
  89. package/skills/ctf-osint/social-media.md +312 -0
  90. package/skills/ctf-osint/web-and-dns.md +341 -0
  91. package/skills/ctf-pwn/SKILL.md +214 -0
  92. package/skills/ctf-pwn/advanced-exploits-2.md +579 -0
  93. package/skills/ctf-pwn/advanced-exploits-3.md +598 -0
  94. package/skills/ctf-pwn/advanced-exploits-4.md +590 -0
  95. package/skills/ctf-pwn/advanced-exploits-5.md +119 -0
  96. package/skills/ctf-pwn/advanced-exploits.md +773 -0
  97. package/skills/ctf-pwn/advanced.md +326 -0
  98. package/skills/ctf-pwn/field-notes.md +245 -0
  99. package/skills/ctf-pwn/format-string.md +694 -0
  100. package/skills/ctf-pwn/heap-fsop.md +285 -0
  101. package/skills/ctf-pwn/heap-techniques-2.md +333 -0
  102. package/skills/ctf-pwn/heap-techniques.md +513 -0
  103. package/skills/ctf-pwn/kernel-bypass.md +421 -0
  104. package/skills/ctf-pwn/kernel-techniques.md +366 -0
  105. package/skills/ctf-pwn/kernel.md +636 -0
  106. package/skills/ctf-pwn/overflow-basics.md +611 -0
  107. package/skills/ctf-pwn/rop-advanced.md +725 -0
  108. package/skills/ctf-pwn/rop-and-shellcode.md +659 -0
  109. package/skills/ctf-pwn/sandbox-escape.md +313 -0
  110. package/skills/ctf-reverse/SKILL.md +163 -0
  111. package/skills/ctf-reverse/anti-analysis-ctf.md +204 -0
  112. package/skills/ctf-reverse/anti-analysis.md +693 -0
  113. package/skills/ctf-reverse/field-notes.md +376 -0
  114. package/skills/ctf-reverse/languages-compiled.md +666 -0
  115. package/skills/ctf-reverse/languages-platforms.md +592 -0
  116. package/skills/ctf-reverse/languages.md +553 -0
  117. package/skills/ctf-reverse/patterns-ctf-2.md +397 -0
  118. package/skills/ctf-reverse/patterns-ctf-3.md +797 -0
  119. package/skills/ctf-reverse/patterns-ctf.md +670 -0
  120. package/skills/ctf-reverse/patterns-runtime.md +274 -0
  121. package/skills/ctf-reverse/patterns.md +572 -0
  122. package/skills/ctf-reverse/platforms-hardware.md +387 -0
  123. package/skills/ctf-reverse/platforms.md +664 -0
  124. package/skills/ctf-reverse/tools-advanced-2.md +421 -0
  125. package/skills/ctf-reverse/tools-advanced.md +407 -0
  126. package/skills/ctf-reverse/tools-dynamic.md +679 -0
  127. package/skills/ctf-reverse/tools-emulation.md +319 -0
  128. package/skills/ctf-reverse/tools.md +573 -0
  129. package/skills/ctf-web/SKILL.md +153 -0
  130. package/skills/ctf-web/auth-and-access-2.md +82 -0
  131. package/skills/ctf-web/auth-and-access.md +783 -0
  132. package/skills/ctf-web/auth-infra.md +321 -0
  133. package/skills/ctf-web/auth-jwt.md +186 -0
  134. package/skills/ctf-web/client-side-advanced.md +739 -0
  135. package/skills/ctf-web/client-side.md +529 -0
  136. package/skills/ctf-web/cves.md +373 -0
  137. package/skills/ctf-web/field-notes.md +482 -0
  138. package/skills/ctf-web/node-and-prototype.md +200 -0
  139. package/skills/ctf-web/server-side-2.md +337 -0
  140. package/skills/ctf-web/server-side-advanced-2.md +559 -0
  141. package/skills/ctf-web/server-side-advanced-3.md +125 -0
  142. package/skills/ctf-web/server-side-advanced-4.md +480 -0
  143. package/skills/ctf-web/server-side-advanced.md +378 -0
  144. package/skills/ctf-web/server-side-deser.md +443 -0
  145. package/skills/ctf-web/server-side-exec-2.md +799 -0
  146. package/skills/ctf-web/server-side-exec.md +457 -0
  147. package/skills/ctf-web/server-side.md +629 -0
  148. package/skills/ctf-web/sql-injection.md +790 -0
  149. package/skills/ctf-web/web3.md +374 -0
  150. package/skills/ctf-writeup/SKILL.md +90 -0
  151. package/skills/solve-challenge/SKILL.md +269 -0
  152. package/skills.json +16 -0
@@ -0,0 +1,491 @@
1
+ # CTF Forensics - Disk and Memory Analysis
2
+
3
+ ## Table of Contents
4
+ - [Memory Forensics (Volatility 3)](#memory-forensics-volatility-3)
5
+ - [Disk Image Analysis](#disk-image-analysis)
6
+ - [VM Forensics (OVA/VMDK)](#vm-forensics-ovavmdk)
7
+ - [VMware Snapshot Forensics](#vmware-snapshot-forensics)
8
+ - [GIMP Raw Memory Dump Visual Inspection (INShAck 2018)](#gimp-raw-memory-dump-visual-inspection-inshack-2018)
9
+ - [Coredump Analysis](#coredump-analysis)
10
+ - [Windows KAPE Triage Analysis (UTCTF 2026)](#windows-kape-triage-analysis-utctf-2026)
11
+ - [PowerShell Ransomware Analysis](#powershell-ransomware-analysis)
12
+ - [Android Forensics](#android-forensics)
13
+ - [Container Forensics (Docker)](#container-forensics-docker)
14
+ - [Cloud Storage Forensics (AWS S3 / GCP / Azure)](#cloud-storage-forensics-aws-s3--gcp--azure)
15
+ - [BSON (Binary JSON) Format Reconstruction (IceCTF 2016)](#bson-binary-json-format-reconstruction-icectf-2016)
16
+ - [TrueCrypt / VeraCrypt Volume Mounting (GreHack CTF 2016)](#truecrypt--veracrypt-volume-mounting-grehack-ctf-2016)
17
+ - [Volatility mftparser Offset-Based Deleted File Recovery (BSides Delhi 2018)](#volatility-mftparser-offset-based-deleted-file-recovery-bsides-delhi-2018)
18
+ - [Brotli Blob Detection via ASCII-Art Signature (ASIS Finals 2018)](#brotli-blob-detection-via-ascii-art-signature-asis-finals-2018)
19
+ - [corkami/pocs MD5 PDF Collision Generation (35C3 2018)](#corkamipocs-md5-pdf-collision-generation-35c3-2018)
20
+ - [See Also](#see-also)
21
+
22
+ ---
23
+
24
+ ## Memory Forensics (Volatility 3)
25
+
26
+ ```bash
27
+ vol3 -f memory.dmp windows.info
28
+ vol3 -f memory.dmp windows.pslist
29
+ vol3 -f memory.dmp windows.cmdline
30
+ vol3 -f memory.dmp windows.netscan
31
+ vol3 -f memory.dmp windows.filescan
32
+ vol3 -f memory.dmp windows.dumpfiles --physaddr <addr>
33
+ vol3 -f memory.dmp windows.mftscan | grep flag
34
+ ```
35
+
36
+ **Common plugins:**
37
+ - `windows.pslist` / `windows.pstree` - Process listing
38
+ - `windows.cmdline` - Command line arguments
39
+ - `windows.netscan` - Network connections
40
+ - `windows.filescan` - File objects in memory
41
+ - `windows.dumpfiles` - Extract files by physical address
42
+ - `windows.mftscan` - MFT FILE objects in memory (timestamps, filenames). Note: `mftparser` was Volatility 2 only; Vol3 uses `mftscan`
43
+
44
+ ---
45
+
46
+ ## Disk Image Analysis
47
+
48
+ ```bash
49
+ # Mount read-only
50
+ sudo mount -o loop,ro image.dd /mnt/evidence
51
+
52
+ # Autopsy / Sleuth Kit
53
+ fls -r image.dd # List files recursively
54
+ icat image.dd <inode> # Extract file by inode
55
+
56
+ # Carving deleted files
57
+ photorec image.dd
58
+ foremost -i image.dd
59
+ ```
60
+
61
+ ---
62
+
63
+ ## VM Forensics (OVA/VMDK)
64
+
65
+ ```bash
66
+ # OVA = TAR archive containing VMDK + OVF
67
+ tar -xvf machine.ova
68
+
69
+ # 7z reads VMDK directly (no mount needed)
70
+ 7z l disk.vmdk | head -100
71
+ 7z x disk.vmdk -oextracted "Windows/System32/config/SAM" -r
72
+ ```
73
+
74
+ **Key files to extract from VM images:**
75
+ - `Windows/System32/config/SAM` - Password hashes
76
+ - `Windows/System32/config/SYSTEM` - Boot key
77
+ - `Windows/System32/config/SOFTWARE` - Installed software
78
+ - `Users/*/NTUSER.DAT` - User registry
79
+ - `Users/*/AppData/` - Browser data, credentials
80
+
81
+ ---
82
+
83
+ ## VMware Snapshot Forensics
84
+
85
+ **Converting VMware snapshots to memory dumps:**
86
+ ```bash
87
+ # .vmss (suspended state) + .vmem (memory) → memory.dmp
88
+ vmss2core -W path/to/snapshot.vmss path/to/snapshot.vmem
89
+ # Output: memory.dmp (analyzable with Volatility/MemprocFS)
90
+ ```
91
+
92
+ **Malware hunting in snapshots (Armorless):**
93
+ 1. Check Amcache for executed binaries near encryption timestamp
94
+ 2. Look for deceptive names (Unicode lookalikes: `ṙ` instead of `r`)
95
+ 3. Dump suspicious executables from memory
96
+ 4. If PyInstaller-packed: `pyinstxtractor` → decompile `.pyc`
97
+ 5. If PyArmor-protected: use PyArmor-Unpacker
98
+
99
+ **Ransomware key recovery via MFT:**
100
+ - Even if original files deleted, MFT preserves modification timestamps
101
+ - Seed-based encryption: recover mtime → derive key
102
+ ```bash
103
+ vol3 -f memory.dmp windows.mftscan | grep flag
104
+ # mtime as Unix epoch → seed for PRNG → derive encryption key
105
+ ```
106
+
107
+ ---
108
+
109
+ ## GIMP Raw Memory Dump Visual Inspection (INShAck 2018)
110
+
111
+ **Pattern:** When Volatility fails or profiles don't match, open raw memory dumps directly in GIMP as raw image data. Scroll through memory while adjusting image width to find previously-displayed images rendered as pixel data.
112
+
113
+ **Steps:**
114
+ 1. Open `.dmp` file in GIMP: File > Open, set image type to "Raw image data"
115
+ 2. Set pixel format to RGB, width to ~1920 (monitor resolution)
116
+ 3. Scroll through the file offset while adjusting width with arrow keys
117
+ 4. Previously-displayed images (desktop, browser content) become visible when width matches the original stride
118
+
119
+ ```bash
120
+ # Alternative: use Python + PIL to scan memory as pixel data
121
+ python3 -c "
122
+ from PIL import Image
123
+ import numpy as np
124
+
125
+ with open('memory.dmp', 'rb') as f:
126
+ data = f.read()
127
+
128
+ # Try common display widths: 1920, 1366, 1280, 1024
129
+ for width in [1920, 1366, 1280, 1024]:
130
+ stride = width * 3 # RGB = 3 bytes per pixel
131
+ # Sample at various offsets through the dump
132
+ for offset in range(0, len(data) - stride * 100, stride * 500):
133
+ chunk = data[offset:offset + stride * 100]
134
+ if len(chunk) == stride * 100:
135
+ img = Image.frombytes('RGB', (width, 100), chunk)
136
+ # Check if image has meaningful content (not all zeros/noise)
137
+ arr = np.array(img)
138
+ if 10 < arr.mean() < 245 and arr.std() > 20:
139
+ img.save(f'frame_{width}_{offset}.png')
140
+ print(f'Potential image at offset {offset}, width {width}')
141
+ "
142
+ ```
143
+
144
+ **Key insight:** Raw memory dumps contain framebuffer data that was displayed on screen. GIMP can render arbitrary binary data as pixels. When the image width matches the original display stride, screenshots of the user's desktop become visible without any forensics tools, profiles, or decryption.
145
+
146
+ ---
147
+
148
+ ## Coredump Analysis
149
+
150
+ ```bash
151
+ gdb -c core.dump
152
+ (gdb) info registers
153
+ (gdb) x/100x $rsp
154
+ (gdb) find 0x0, 0xffffffff, "flag"
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Windows KAPE Triage Analysis (UTCTF 2026)
160
+
161
+ **Pattern (Landfall, Sherlockk, Cold Workspace):** KAPE (Kroll Artifact Parser and Extractor) triage collection ZIP containing Windows forensic artifacts. Multiple challenges reference the same triage dataset.
162
+
163
+ **KAPE triage structure:**
164
+ ```text
165
+ Modified_KAPE_Triage_Files/
166
+ ├── C/
167
+ │ ├── Users/<username>/
168
+ │ │ ├── AppData/Local/Microsoft/Windows/PowerShell/PSReadLine/
169
+ │ │ │ └── ConsoleHost_history.txt # PowerShell command history
170
+ │ │ ├── NTUSER.DAT # User registry hive
171
+ │ │ └── AppData/Roaming/Microsoft/Windows/Recent/ # Recent files
172
+ │ ├── Windows/
173
+ │ │ ├── System32/config/
174
+ │ │ │ ├── SAM # Password hashes
175
+ │ │ │ ├── SYSTEM # System config + boot key
176
+ │ │ │ └── SOFTWARE # Installed software
177
+ │ │ └── appcompat/Programs/
178
+ │ │ └── Amcache.hve # Execution history with SHA-1 hashes
179
+ │ └── $MFT # Master File Table
180
+ └── ...
181
+ ```
182
+
183
+ **High-value artifacts:**
184
+
185
+ 1. **PowerShell history** — reveals attacker commands:
186
+ ```bash
187
+ cat "C/Users/*/AppData/Local/Microsoft/Windows/PowerShell/PSReadLine/ConsoleHost_history.txt"
188
+ # Look for: credential access, lateral movement, data staging
189
+ ```
190
+
191
+ 2. **Amcache** — executed programs with timestamps and hashes:
192
+ ```bash
193
+ # Parse with Eric Zimmerman's AmcacheParser or regipy
194
+ python3 -c "
195
+ from regipy.registry import RegistryHive
196
+ reg = RegistryHive('C/Windows/appcompat/Programs/Amcache.hve')
197
+ for entry in reg.recurse_subkeys(as_json=True):
198
+ print(entry)
199
+ " | grep -i "flag\|suspicious\|malware"
200
+ ```
201
+
202
+ 3. **MFT resident data** — small files stored directly in MFT records:
203
+ ```python
204
+ # Parse MFT for resident file data (files < ~700 bytes stored inline)
205
+ # Use analyzeMFT or python-ntfs
206
+ import struct
207
+
208
+ with open('$MFT', 'rb') as f:
209
+ mft_data = f.read()
210
+
211
+ # Search for flag patterns in raw MFT data
212
+ import re
213
+ flags = re.findall(rb'utflag\{[^}]+\}', mft_data)
214
+ for flag in flags:
215
+ print(f"Found: {flag.decode()}")
216
+ ```
217
+
218
+ 4. **Environment variables from memory dumps** (Cold Workspace pattern):
219
+ ```bash
220
+ # Small .dmp files may be minidumps with environment variable blocks
221
+ strings -a cold-workspace.dmp | grep -i "flag\|password\|key\|secret"
222
+ # Environment variables survive in process memory snapshots
223
+ ```
224
+
225
+ **Challenge patterns from UTCTF 2026:**
226
+ - **Landfall:** Flag hidden in PowerShell history or Amcache execution records
227
+ - **Sherlockk:** Correlate Amcache entries with MFT timestamps to identify malicious activity
228
+ - **Cold Workspace:** Flag in environment variables extracted from memory dump
229
+ - **Checkpoint A/B:** Multi-part investigation using combined artifacts
230
+
231
+ **Key insight:** KAPE triage ZIPs contain pre-collected forensic artifacts — no need for full disk imaging. Start with PowerShell history (fastest wins) → Amcache (execution timeline) → MFT (resident data for small files) → registry hives (persistence, credentials).
232
+
233
+ ---
234
+
235
+ ## PowerShell Ransomware Analysis
236
+
237
+ **Pattern (Email From Krampus):** PowerShell memory dump + network capture.
238
+
239
+ **Analysis workflow:**
240
+ 1. Extract script blocks from minidump:
241
+ ```bash
242
+ python power_dump.py powershell.DMP
243
+ # Or: strings powershell.DMP | grep -A5 "function\|Invoke-"
244
+ ```
245
+
246
+ 2. Identify encryption (typically AES-CBC with SHA-256 key derivation)
247
+
248
+ 3. Extract encrypted attachment from PCAP:
249
+ ```bash
250
+ # Filter SMTP traffic in Wireshark
251
+ # Export attachment, base64 decode
252
+ ```
253
+
254
+ 4. Find encryption key in memory dump:
255
+ ```bash
256
+ # Key often generated with Get-Random, regex search:
257
+ strings powershell.DMP | grep -E '^[A-Za-z0-9]{24}$' | sort | head
258
+ ```
259
+
260
+ 5. Find archive password similarly, decrypt layers
261
+
262
+ ---
263
+
264
+ ## Android Forensics
265
+
266
+ ```bash
267
+ # Extract APK from device
268
+ adb pull /data/app/com.target.app/base.apk
269
+
270
+ # Analyze APK contents
271
+ apktool d base.apk -o decompiled/
272
+ # Check: AndroidManifest.xml, res/values/strings.xml, shared_prefs/
273
+
274
+ # Extract data from Android backup
275
+ adb backup -apk -shared -all -f backup.ab
276
+ java -jar abe.jar unpack backup.ab backup.tar
277
+ tar xf backup.tar
278
+
279
+ # SQLite databases (contacts, messages, browser history)
280
+ sqlite3 /data/data/com.android.providers.contacts/databases/contacts2.db ".tables"
281
+ sqlite3 /data/data/com.android.providers.telephony/databases/mmssms.db "SELECT * FROM sms"
282
+
283
+ # Parse Android filesystem image
284
+ mkdir android_mount && mount -o ro android_image.img android_mount/
285
+ # Key locations:
286
+ # /data/data/<app>/databases/ — app SQLite databases
287
+ # /data/data/<app>/shared_prefs/ — app preferences (XML)
288
+ # /data/system/packages.xml — installed packages
289
+ # /data/misc/wifi/wpa_supplicant.conf — saved WiFi passwords
290
+ ```
291
+
292
+ **Key insight:** Android stores app data in `/data/data/<package>/` with SQLite databases and XML shared preferences. `adb backup` captures the full app state. For CTFs, check `shared_prefs/` for hardcoded secrets and `databases/` for flags.
293
+
294
+ ---
295
+
296
+ ## Container Forensics (Docker)
297
+
298
+ ```bash
299
+ # Export Docker image layers
300
+ docker save IMAGE:TAG -o image.tar
301
+ tar xf image.tar
302
+ # Each layer is a directory with layer.tar containing filesystem changes
303
+ # Check: layer.tar files for added/modified files, deleted files (.wh.* whiteout)
304
+
305
+ # Inspect image history for build commands (may contain secrets)
306
+ docker history IMAGE:TAG --no-trunc
307
+ # Shows every Dockerfile instruction including ARGs and ENV values
308
+
309
+ # Extract filesystem without running the container
310
+ docker create --name extract IMAGE:TAG
311
+ docker export extract -o container_fs.tar
312
+ docker rm extract
313
+
314
+ # Analyze with dive (layer-by-layer diff viewer)
315
+ dive IMAGE:TAG
316
+
317
+ # Common forensic targets in container images:
318
+ # /app/.env, /app/config/* — application secrets
319
+ # /root/.bash_history — build-time commands
320
+ # /etc/shadow — leaked credentials
321
+ # Deleted files visible in earlier layers even if removed in later ones
322
+ ```
323
+
324
+ **Key insight:** Docker images are layered — a file deleted in a later layer still exists in the earlier layer's tar. Use `docker history --no-trunc` to see full Dockerfile commands including secrets passed via `ARG` or `ENV`. The `dive` tool visualizes layer diffs interactively.
325
+
326
+ ---
327
+
328
+ ## Cloud Storage Forensics (AWS S3 / GCP / Azure)
329
+
330
+ ```bash
331
+ # Enumerate public S3 buckets
332
+ aws s3 ls s3://target-bucket/ --no-sign-request
333
+ aws s3 cp s3://target-bucket/flag.txt . --no-sign-request
334
+
335
+ # Check bucket versioning (previous versions may contain deleted flags)
336
+ aws s3api list-object-versions --bucket target-bucket --no-sign-request
337
+ aws s3api get-object --bucket target-bucket --key secret.txt --version-id VERSION_ID out.txt
338
+
339
+ # GCP Cloud Storage
340
+ gsutil ls gs://target-bucket/
341
+ gsutil cp gs://target-bucket/flag.txt .
342
+
343
+ # Azure Blob Storage
344
+ az storage blob list --container-name target --account-name storageaccount
345
+ az storage blob download --container-name target --name flag.txt --account-name storageaccount
346
+ ```
347
+
348
+ **Key insight:** Cloud storage versioning preserves deleted objects. Even if a flag file is deleted from the bucket, previous versions may still be accessible via `list-object-versions`. Always check for versioning-enabled buckets.
349
+
350
+ ---
351
+
352
+ ## BSON (Binary JSON) Format Reconstruction (IceCTF 2016)
353
+
354
+ BSON is MongoDB's binary serialization format. Corrupted BSON files need header repair before parsing, and may contain base64-encoded file fragments.
355
+
356
+ ```python
357
+ import bson
358
+
359
+ # BSON header: first 4 bytes = little-endian document size
360
+ # Fix corrupted header by setting correct size
361
+ with open('data.bson', 'rb') as f:
362
+ data = bytearray(f.read())
363
+
364
+ # Fix size header if corrupted (e.g., missing first 3 bytes)
365
+ import struct
366
+ correct_size = len(data) + 3 # account for missing bytes
367
+ data = struct.pack('<I', correct_size)[1:] + data # prepend missing bytes
368
+
369
+ # Parse BSON documents
370
+ docs = bson.decode_all(bytes(data))
371
+ for doc in docs:
372
+ print(doc)
373
+
374
+ # Reconstruct file from BSON chunks (common pattern):
375
+ # Each document has: {index: N, data: "base64_chunk"}
376
+ import base64
377
+ chunks = sorted(docs, key=lambda d: d.get('index', d.get('i', 0)))
378
+ reconstructed = b''
379
+ for chunk in chunks:
380
+ b64_data = chunk.get('data', chunk.get('d', ''))
381
+ reconstructed += base64.b64decode(b64_data)
382
+
383
+ with open('reconstructed.png', 'wb') as f:
384
+ f.write(reconstructed)
385
+ ```
386
+
387
+ **Key insight:** BSON starts with a 4-byte little-endian size field. If the file appears corrupted, check if the first bytes are missing or incorrect. Parse with `bson.decode_all()` (from pymongo), sort chunks by index, and concatenate base64-decoded data to reconstruct embedded files.
388
+
389
+ ---
390
+
391
+ ## TrueCrypt / VeraCrypt Volume Mounting (GreHack CTF 2016)
392
+
393
+ Encrypted volumes in CTF challenges may use TrueCrypt or VeraCrypt. Identify by logo/branding clues, then mount with a recovered keyfile or password.
394
+
395
+ ```bash
396
+ # Identify TrueCrypt volumes:
397
+ # - No file signature/magic bytes (by design)
398
+ # - Exact size is multiple of 512 bytes
399
+ # - High entropy throughout the file
400
+ # - Context clues: TrueCrypt logo in related images
401
+
402
+ # Mount with password:
403
+ truecrypt -t -p "password123" volume.tc /mnt/tc
404
+ veracrypt -t -p "password123" volume.tc /mnt/vc
405
+
406
+ # Mount with keyfile (no password):
407
+ truecrypt -t -p "" -k keyfile.png volume.tc /mnt/tc
408
+ veracrypt -t -p "" -k keyfile.png volume.tc /mnt/vc
409
+
410
+ # Mount hidden volume (different password):
411
+ truecrypt -t -p "hidden_password" volume.tc /mnt/tc
412
+
413
+ # Common keyfile locations in CTFs:
414
+ # - Images extracted from other challenge steps
415
+ # - GPG-encrypted files with keys found in git repos
416
+ # - Files embedded in other forensic artifacts
417
+
418
+ # If TrueCrypt is not available (discontinued):
419
+ # Use VeraCrypt (backwards-compatible with TrueCrypt volumes)
420
+ # Add --truecrypt flag for old TC volumes:
421
+ veracrypt -t --truecrypt -p "password" volume.tc /mnt/vc
422
+ ```
423
+
424
+ **Key insight:** TrueCrypt volumes have no magic bytes or identifiable header -- they look like random data. Identify them from context clues (related images showing TrueCrypt logo, file sizes that are exact multiples of 512, or challenge descriptions mentioning encryption). VeraCrypt with `--truecrypt` flag handles legacy TC volumes.
425
+
426
+ ---
427
+
428
+ ## Volatility mftparser Offset-Based Deleted File Recovery (BSides Delhi 2018)
429
+
430
+ **Pattern:** Standard `dumpfiles` or `filescan` + `dumpfiles --physaddr` fails on a deleted file because its directory entry has been marked free. The MFT record that still holds the file's `$DATA` attribute survives until the record is reused. Volatility 2's `mftparser` can dump the resident `$DATA` directly when given the exact `--offset` of the MFT record found via `filescan`.
431
+
432
+ ```bash
433
+ # 1. Locate the MFT record offset (Volatility 2 example; Vol3 uses windows.mftscan)
434
+ vol.py -f Challenge.raw --profile=Win7SP1x86 mftparser \
435
+ | grep -A2 "target_filename"
436
+
437
+ # 2. Dump every attribute of the matching MFT entry, including $DATA
438
+ vol.py -f Challenge.raw --profile=Win7SP1x86 mftparser \
439
+ --offset=0x7ca3c00 --dump-dir=./out/
440
+
441
+ ls ./out/
442
+ # file.data.$DATA contains the recovered content
443
+ ```
444
+
445
+ **Key insight:** NTFS marks files "deleted" by flipping one bit in the MFT record header (`0x16` byte: `0x01 == in use`). Until the record is reallocated, the entire `$DATA` attribute is still intact and only lazily freed. Use `mftparser --offset=<record>` for resident files (under ~700 bytes — stored inline in the MFT) and `dd`/`icat` with the cluster runs for larger files. Always also grep for the filename in `windows.mftscan` output before giving up: memory-resident MFT fragments are still findable after on-disk deletion.
446
+
447
+ **References:** BSides Delhi CTF 2018 — Never Too Late Mister, writeups 11963, 11970
448
+
449
+ ---
450
+
451
+ ## Brotli Blob Detection via ASCII-Art Signature (ASIS Finals 2018)
452
+
453
+ **Pattern:** Binwalk and `file` miss Brotli-compressed data because the format has no fixed magic. Decompress candidate blobs with `brotli.decompress()`; the Brotli reference implementation embeds its own ASCII-art logo `Brrroootttllliii` as a sanity-check output. If the decompressed bytes contain that or other Brotli-specific telemetry strings, the original blob was Brotli.
454
+
455
+ ```python
456
+ import brotli
457
+ try:
458
+ out = brotli.decompress(blob)
459
+ if b'rrrooottl' in out or b'Brotli' in out:
460
+ print('Brotli-compressed')
461
+ except Exception: pass
462
+ ```
463
+
464
+ **Key insight:** Any compressor without a magic byte is identifiable by trial decompression. For Brotli, `zstd`, `snappy`, `lzma-alone`, spin through each library in order until one succeeds without raising.
465
+
466
+ **References:** ASIS CTF Finals 2018 — Green Cabbage, writeup 12419
467
+
468
+ ---
469
+
470
+ ## corkami/pocs MD5 PDF Collision Generation (35C3 2018)
471
+
472
+ **Pattern:** Challenge demands two valid PDFs with the same MD5 but different content. Use corkami/pocs `pdf.py` combined with `enscript | ps2pdf` to produce a PDF header with collision-friendly padding, then drive the collision via `fastcoll` (or `hashclash` for chosen-prefix). Works because the PDF format tolerates garbage in the `%PDF` trailer region that the MD5 collision block can overwrite.
473
+
474
+ ```bash
475
+ enscript -p out.ps content.txt
476
+ ps2pdf out.ps base.pdf
477
+ python pdf.py base.pdf target1.pdf target2.pdf
478
+ fastcoll -p base.pdf -o target1.pdf target2.pdf
479
+ md5sum target1.pdf target2.pdf # identical
480
+ ```
481
+
482
+ **Key insight:** PDF collision is a one-command pipeline with the right toolchain. The harder variant is chosen-prefix MD5 (different visible content) which requires `hashclash` and 10-20 CPU-hours. Check `pocs/collisions/` for every file format with prebuilt scaffolds.
483
+
484
+ **References:** 35C3 CTF 2018 — collider, writeup 12836
485
+
486
+ ---
487
+
488
+ ## See Also
489
+
490
+ - [disk-advanced.md](disk-advanced.md) - Advanced disk and memory techniques (deleted partition recovery, ZFS forensics, GPT GUID encoding, VMDK sparse parsing, memory dump string carving, ransomware key recovery, WordPerfect macro XOR, minidump ISO 9660 recovery, APFS snapshot recovery, RAID 5 XOR recovery, Kyoto Cabinet hash DB forensics)
491
+ - [disk-recovery.md](disk-recovery.md) - Disk recovery and extraction patterns (LUKS master key recovery, PRNG timestamp seed brute-force, VBA macro binary recovery, FemtoZip decompression, XFS reconstruction, tar duplicate entry extraction, nested matryoshka filesystem extraction, anti-carving via null byte interleaving)