From 4bc8a8ada0269bb7eca009f14ab980858c4787ad Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Fri, 29 Aug 2025 18:34:18 +0000 Subject: [PATCH] Add content from: GodFather - Part 1 - A multistage dropper - Remove searchindex.js (auto-generated file) --- .../zips-tricks.md | 165 +++++++++++++++++- 1 file changed, 161 insertions(+), 4 deletions(-) diff --git a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md index 0dacaa3c0..c510af153 100644 --- a/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md +++ b/src/generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md @@ -14,11 +14,168 @@ The [Zip file format specification](https://pkware.cachefly.net/webdocs/casestud It's crucial to note that password-protected zip files **do not encrypt filenames or file sizes** within, a security flaw not shared with RAR or 7z files which encrypt this information. Furthermore, zip files encrypted with the older ZipCrypto method are vulnerable to a **plaintext attack** if an unencrypted copy of a compressed file is available. This attack leverages the known content to crack the zip's password, a vulnerability detailed in [HackThis's article](https://www.hackthis.co.uk/articles/known-plaintext-attack-cracking-zip-files) and further explained in [this academic paper](https://www.cs.auckland.ac.nz/~mike/zipattacks.pdf). However, zip files secured with **AES-256** encryption are immune to this plaintext attack, showcasing the importance of choosing secure encryption methods for sensitive data. +--- + +## Anti-reversing tricks in APKs using manipulated ZIP headers + +Modern Android malware droppers use malformed ZIP metadata to break static tools (jadx/apktool/unzip) while keeping the APK installable on-device. The most common tricks are: + +- Fake encryption by setting the ZIP General Purpose Bit Flag (GPBF) bit 0 +- Abusing large/custom Extra fields to confuse parsers +- File/directory name collisions to hide real artifacts (e.g., a directory named `classes.dex/` next to the real `classes.dex`) + +### 1) Fake encryption (GPBF bit 0 set) without real crypto + +Symptoms: +- `jadx-gui` fails with errors like: + + ``` + java.util.zip.ZipException: invalid CEN header (encrypted entry) + ``` +- `unzip` prompts for a password for core APK files even though a valid APK cannot have encrypted `classes*.dex`, `resources.arsc`, or `AndroidManifest.xml`: + + ```bash + unzip sample.apk + [sample.apk] classes3.dex password: + skipping: classes3.dex incorrect password + skipping: AndroidManifest.xml/res/vhpng-xhdpi/mxirm.png incorrect password + skipping: resources.arsc/res/domeo/eqmvo.xml incorrect password + skipping: classes2.dex incorrect password + ``` + +Detection with zipdetails: + +```bash +zipdetails -v sample.apk | less +``` + +Look at the General Purpose Bit Flag for local and central headers. A telltale value is bit 0 set (Encryption) even for core entries: + +``` +Extract Zip Spec 2D '4.5' +General Purpose Flag 0A09 + [Bit 0] 1 'Encryption' + [Bits 1-2] 1 'Maximum Compression' + [Bit 3] 1 'Streamed' + [Bit 11] 1 'Language Encoding' +``` + +Heuristic: If an APK installs and runs on-device but core entries appear "encrypted" to tools, the GPBF was tampered with. + +Fix by clearing GPBF bit 0 in both Local File Headers (LFH) and Central Directory (CD) entries. Minimal byte-patcher: + +```python +# gpbf_clear.py – clear encryption bit (bit 0) in ZIP local+central headers +import struct, sys + +SIG_LFH = b"\x50\x4b\x03\x04" # Local File Header +SIG_CDH = b"\x50\x4b\x01\x02" # Central Directory Header + +def patch_flags(buf: bytes, sig: bytes, flag_off: int): + out = bytearray(buf) + i = 0 + patched = 0 + while True: + i = out.find(sig, i) + if i == -1: + break + flags, = struct.unpack_from(' 1: + print('COLLISION', base, '->', variants) +``` + +Blue-team detection ideas: +- Flag APKs whose local headers mark encryption (GPBF bit 0 = 1) yet install/run. +- Flag large/unknown Extra fields on core entries (look for markers like `JADXBLOCK`). +- Flag path-collisions (`X` and `X/`) specifically for `AndroidManifest.xml`, `resources.arsc`, `classes*.dex`. + +--- + ## References - [https://michael-myers.github.io/blog/categories/ctf/](https://michael-myers.github.io/blog/categories/ctf/) +- [GodFather – Part 1 – A multistage dropper (APK ZIP anti-reversing)](https://shindan.io/blog/godfather-part-1-a-multistage-dropper) +- [zipdetails (Archive::Zip script)](https://metacpan.org/pod/distribution/Archive-Zip/scripts/zipdetails) +- [ZIP File Format Specification (PKWARE APPNOTE.TXT)](https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT) -{{#include ../../../banners/hacktricks-training.md}} - - - +{{#include ../../../banners/hacktricks-training.md}} \ No newline at end of file