Skip to content

Commit 4be169e

Browse files
authored
Merge pull request #1874 from HackTricks-wiki/research_update_src_generic-methodologies-and-resources_basic-forensic-methodology_specific-software-file-type-tricks_zips-tricks_20260209_024434
Research Update Enhanced src/generic-methodologies-and-resou...
2 parents 4db7bae + e2616aa commit 4be169e

1 file changed

Lines changed: 61 additions & 1 deletion

File tree

  • src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks

src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ Heuristic: If an APK installs and runs on-device but core entries appear "encryp
6464

6565
Fix by clearing GPBF bit 0 in both Local File Headers (LFH) and Central Directory (CD) entries. Minimal byte-patcher:
6666

67+
<details>
68+
<summary>Minimal GPBF bit-clear patcher</summary>
69+
6770
```python
6871
# gpbf_clear.py – clear encryption bit (bit 0) in ZIP local+central headers
6972
import struct, sys
@@ -95,6 +98,8 @@ if __name__ == '__main__':
9598
print(f'Patched: LFH={p_lfh}, CDH={p_cdh}')
9699
```
97100

101+
</details>
102+
98103
Usage:
99104

100105
```bash
@@ -171,11 +176,66 @@ Blue-team detection ideas:
171176

172177
---
173178

179+
## Other malicious ZIP tricks (2024–2025)
180+
181+
### Concatenated central directories (multi-EOCD evasion)
182+
183+
Recent phishing campaigns ship a single blob that is actually **two ZIP files concatenated**. Each has its own End of Central Directory (EOCD) + central directory. Different extractors parse different directories (7zip reads the first, WinRAR the last), letting attackers hide payloads that only some tools show. This also bypasses basic mail gateway AV that inspects only the first directory.
184+
185+
**Triage commands**
186+
187+
```bash
188+
# Count EOCD signatures
189+
binwalk -R "PK\x05\x06" suspect.zip
190+
# Dump central-directory offsets
191+
zipdetails -v suspect.zip | grep -n "End Central"
192+
```
193+
194+
If more than one EOCD appears or there is "data after payload" warnings, split the blob and inspect each part:
195+
196+
```bash
197+
# recover the second archive (heuristic: start at second EOCD offset)
198+
# adjust OFF based on binwalk output
199+
OFF=123456
200+
dd if=suspect.zip bs=1 skip=$OFF of=tail.zip
201+
7z l tail.zip # list hidden content
202+
```
203+
204+
### Quoted-overlap / overlapping-entry bombs (non-recursive)
205+
206+
Modern "better zip bomb" builds a tiny **kernel** (highly compressed DEFLATE block) and reuses it via overlapping local headers. Every central directory entry points to the same compressed data, achieving >28M:1 ratios without nesting archives. Libraries that trust central directory sizes (Python `zipfile`, Java `java.util.zip`, Info-ZIP prior to hardened builds) can be forced to allocate petabytes.
207+
208+
**Quick detection (duplicate LFH offsets)**
209+
210+
```python
211+
# detect overlapping entries by identical relative offsets
212+
import struct, sys
213+
buf=open(sys.argv[1],'rb').read()
214+
off=0; seen=set()
215+
while True:
216+
i = buf.find(b'PK\x01\x02', off)
217+
if i<0: break
218+
rel = struct.unpack_from('<I', buf, i+42)[0]
219+
if rel in seen:
220+
print('OVERLAP at offset', rel)
221+
break
222+
seen.add(rel); off = i+4
223+
```
224+
225+
**Handling**
226+
- Perform a dry-run walk: `zipdetails -v file.zip | grep -n "Rel Off"` and ensure offsets are strictly increasing and unique.
227+
- Cap accepted total uncompressed size and entry count before extraction (`zipdetails -t` or custom parser).
228+
- When you must extract, do it inside a cgroup/VM with CPU+disk limits (avoid unbounded inflation crashes).
229+
230+
---
231+
174232
## References
175233

176234
- [https://michael-myers.github.io/blog/categories/ctf/](https://michael-myers.github.io/blog/categories/ctf/)
177235
- [GodFather – Part 1 – A multistage dropper (APK ZIP anti-reversing)](https://shindan.io/blog/godfather-part-1-a-multistage-dropper)
178236
- [zipdetails (Archive::Zip script)](https://metacpan.org/pod/distribution/Archive-Zip/scripts/zipdetails)
179237
- [ZIP File Format Specification (PKWARE APPNOTE.TXT)](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT)
238+
- [Hackers bury malware in new ZIP file attack — concatenated ZIP central directories](https://www.tomshardware.com/tech-industry/cyber-security/hackers-bury-malware-in-new-zip-file-attack-combining-multiple-zips-into-one-bypasses-antivirus-protections)
239+
- [Understanding Zip Bombs: overlapping/quoted-overlap kernel construction](https://ubos.tech/news/understanding-zip-bombs-construction-risks-and-mitigation-2/)
180240

181-
{{#include ../../../banners/hacktricks-training.md}}
241+
{{#include ../../../banners/hacktricks-training.md}}

0 commit comments

Comments
 (0)