Skip to content

Commit 8c5460a

Browse files
authored
Merge branch 'master' into update_DLL_ForwardSideLoading_20250824_182553
2 parents 20b0687 + 7b609ae commit 8c5460a

19 files changed

Lines changed: 1379 additions & 139 deletions

File tree

src/SUMMARY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
- [Anti-Forensic Techniques](generic-methodologies-and-resources/basic-forensic-methodology/anti-forensic-techniques.md)
4242
- [Docker Forensics](generic-methodologies-and-resources/basic-forensic-methodology/docker-forensics.md)
4343
- [Image Acquisition & Mount](generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md)
44+
- [Ios Backup Forensics](generic-methodologies-and-resources/basic-forensic-methodology/ios-backup-forensics.md)
4445
- [Linux Forensics](generic-methodologies-and-resources/basic-forensic-methodology/linux-forensics.md)
4546
- [Malware Analysis](generic-methodologies-and-resources/basic-forensic-methodology/malware-analysis.md)
4647
- [Memory dump analysis](generic-methodologies-and-resources/basic-forensic-methodology/memory-dump-analysis/README.md)
@@ -61,6 +62,7 @@
6162
- [Office file analysis](generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/office-file-analysis.md)
6263
- [PDF File analysis](generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/pdf-file-analysis.md)
6364
- [PNG tricks](generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/png-tricks.md)
65+
- [Structural File Format Exploit Detection](generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/structural-file-format-exploit-detection.md)
6466
- [Video and Audio file analysis](generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/video-and-audio-file-analysis.md)
6567
- [ZIPs tricks](generic-methodologies-and-resources/basic-forensic-methodology/specific-software-file-type-tricks/zips-tricks.md)
6668
- [Windows Artifacts](generic-methodologies-and-resources/basic-forensic-methodology/windows-forensics/README.md)

src/binary-exploitation/stack-overflow/ret2win/ret2win-arm64.md

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,21 @@ int main() {
3333
Compile without pie and canary:
3434

3535
```bash
36-
clang -o ret2win ret2win.c -fno-stack-protector -Wno-format-security -no-pie
36+
clang -o ret2win ret2win.c -fno-stack-protector -Wno-format-security -no-pie -mbranch-protection=none
3737
```
3838

39+
- The extra flag `-mbranch-protection=none` disables AArch64 Branch Protection (PAC/BTI). If your toolchain defaults to enabling PAC or BTI, this keeps the lab reproducible. To check whether a compiled binary uses PAC/BTI you can:
40+
- Look for AArch64 GNU properties:
41+
- `readelf --notes -W ret2win | grep -E 'AARCH64_FEATURE_1_(BTI|PAC)'`
42+
- Inspect prologues/epilogues for `paciasp`/`autiasp` (PAC) or for `bti c` landing pads (BTI):
43+
- `objdump -d ret2win | head -n 40`
44+
45+
### AArch64 calling convention quick facts
46+
47+
- The link register is `x30` (a.k.a. `lr`), and functions typically save `x29`/`x30` with `stp x29, x30, [sp, #-16]!` and restore them with `ldp x29, x30, [sp], #16; ret`.
48+
- This means the saved return address lives at `sp+8` relative to the frame base. With a `char buffer[64]` placed below, the usual overwrite distance to the saved `x30` is 64 (buffer) + 8 (saved x29) = 72 bytes — exactly what we’ll find below.
49+
- The stack pointer must remain 16‑byte aligned at function boundaries. If you build ROP chains later for more complex scenarios, keep the SP alignment or you may crash on function epilogues.
50+
3951
## Finding the offset
4052

4153
### Pattern option
@@ -112,6 +124,8 @@ from pwn import *
112124
# Configuration
113125
binary_name = './ret2win'
114126
p = process(binary_name)
127+
# Optional but nice for AArch64
128+
context.arch = 'aarch64'
115129

116130
# Prepare the payload
117131
offset = 72
@@ -187,6 +201,47 @@ print(p.recvline())
187201
p.close()
188202
```
189203

190-
{{#include ../../../banners/hacktricks-training.md}}
204+
### Notes on modern AArch64 hardening (PAC/BTI) and ret2win
205+
206+
- If the binary is compiled with AArch64 Branch Protection, you may see `paciasp`/`autiasp` or `bti c` emitted in function prologues/epilogues. In that case:
207+
- Returning to an address that is not a valid BTI landing pad may raise a `SIGILL`. Prefer targeting the exact function entry that contains `bti c`.
208+
- If PAC is enabled for returns, naive return‑address overwrites may fail because the epilogue authenticates `x30`. For learning scenarios, rebuild with `-mbranch-protection=none` (shown above). When attacking real targets, prefer non‑return hijacks (e.g., function pointer overwrites) or build ROP that never executes an `autiasp`/`ret` pair that authenticates your forged LR.
209+
- To check features quickly:
210+
- `readelf --notes -W ./ret2win` and look for `AARCH64_FEATURE_1_BTI` / `AARCH64_FEATURE_1_PAC` notes.
211+
- `objdump -d ./ret2win | head -n 40` and look for `bti c`, `paciasp`, `autiasp`.
212+
213+
### Running on non‑ARM64 hosts (qemu‑user quick tip)
191214

215+
If you are on x86_64 but want to practice AArch64:
216+
217+
```bash
218+
# Install qemu-user and AArch64 libs (Debian/Ubuntu)
219+
sudo apt-get install qemu-user qemu-user-static libc6-arm64-cross
220+
221+
# Run the binary with the AArch64 loader environment
222+
qemu-aarch64 -L /usr/aarch64-linux-gnu ./ret2win
223+
224+
# Debug with GDB (qemu-user gdbstub)
225+
qemu-aarch64 -g 1234 -L /usr/aarch64-linux-gnu ./ret2win &
226+
# In another terminal
227+
gdb-multiarch ./ret2win -ex 'target remote :1234'
228+
```
192229

230+
### Related HackTricks pages
231+
232+
-
233+
{{#ref}}
234+
../../rop-return-oriented-programing/rop-syscall-execv/ret2syscall-arm64.md
235+
{{#endref}}
236+
-
237+
{{#ref}}
238+
../../rop-return-oriented-programing/ret2lib/ret2lib-+-printf-leak-arm64.md
239+
{{#endref}}
240+
241+
242+
243+
## References
244+
245+
- Enabling PAC and BTI on AArch64 for Linux (Arm Community, Nov 2024). https://community.arm.com/arm-community-blogs/b/operating-systems-blog/posts/enabling-pac-and-bti-on-aarch64-for-linux
246+
- Procedure Call Standard for the Arm 64-bit Architecture (AAPCS64). https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst
247+
{{#include ../../../banners/hacktricks-training.md}}

src/generic-methodologies-and-resources/basic-forensic-methodology/README.md

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,33 @@ malware-analysis.md
2323
if you are given a **forensic image** of a device you can start **analyzing the partitions, file-system** used and **recovering** potentially **interesting files** (even deleted ones). Learn how in:
2424

2525

26+
{{#ref}}
27+
partitions-file-systems-carving/
28+
{{#endref}}# Basic Forensic Methodology
29+
30+
31+
32+
## Creating and Mounting an Image
33+
34+
35+
{{#ref}}
36+
../../generic-methodologies-and-resources/basic-forensic-methodology/image-acquisition-and-mount.md
37+
{{#endref}}
38+
39+
## Malware Analysis
40+
41+
This **isn't necessary the first step to perform once you have the image**. But you can use this malware analysis techniques independently if you have a file, a file-system image, memory image, pcap... so it's good to **keep these actions in mind**:
42+
43+
44+
{{#ref}}
45+
malware-analysis.md
46+
{{#endref}}
47+
48+
## Inspecting an Image
49+
50+
if you are given a **forensic image** of a device you can start **analyzing the partitions, file-system** used and **recovering** potentially **interesting files** (even deleted ones). Learn how in:
51+
52+
2653
{{#ref}}
2754
partitions-file-systems-carving/
2855
{{#endref}}
@@ -44,6 +71,11 @@ linux-forensics.md
4471
docker-forensics.md
4572
{{#endref}}
4673

74+
75+
{{#ref}}
76+
ios-backup-forensics.md
77+
{{#endref}}
78+
4779
## Deep inspection of specific file-types and Software
4880

4981
If you have very **suspicious** **file**, then **depending on the file-type and software** that created it several **tricks** may be useful.\
@@ -91,6 +123,54 @@ anti-forensic-techniques.md
91123
file-integrity-monitoring.md
92124
{{#endref}}
93125

94-
{{#include ../../banners/hacktricks-training.md}}
95126

96127

128+
## Deep inspection of specific file-types and Software
129+
130+
If you have very **suspicious** **file**, then **depending on the file-type and software** that created it several **tricks** may be useful.\
131+
Read the following page to learn some interesting tricks:
132+
133+
134+
{{#ref}}
135+
specific-software-file-type-tricks/
136+
{{#endref}}
137+
138+
I want to do a special mention to the page:
139+
140+
141+
{{#ref}}
142+
specific-software-file-type-tricks/browser-artifacts.md
143+
{{#endref}}
144+
145+
## Memory Dump Inspection
146+
147+
148+
{{#ref}}
149+
memory-dump-analysis/
150+
{{#endref}}
151+
152+
## Pcap Inspection
153+
154+
155+
{{#ref}}
156+
pcap-inspection/
157+
{{#endref}}
158+
159+
## **Anti-Forensic Techniques**
160+
161+
Keep in mind the possible use of anti-forensic techniques:
162+
163+
164+
{{#ref}}
165+
anti-forensic-techniques.md
166+
{{#endref}}
167+
168+
## Threat Hunting
169+
170+
171+
{{#ref}}
172+
file-integrity-monitoring.md
173+
{{#endref}}
174+
175+
{{#include ../../banners/hacktricks-training.md}}
176+
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# iOS Backup Forensics (Messaging‑centric triage)
2+
3+
{{#include ../../banners/hacktricks-training.md}}
4+
5+
This page describes practical steps to reconstruct and analyze iOS backups for signs of 0‑click exploit delivery via messaging app attachments. It focuses on turning Apple’s hashed backup layout into human‑readable paths, then enumerating and scanning attachments across common apps.
6+
7+
Goals:
8+
- Rebuild readable paths from Manifest.db
9+
- Enumerate messaging databases (iMessage, WhatsApp, Signal, Telegram, Viber)
10+
- Resolve attachment paths, extract embedded objects (PDF/Images/Fonts), and feed them to structural detectors
11+
12+
13+
## Reconstructing an iOS backup
14+
15+
Backups stored under MobileSync use hashed filenames that are not human‑readable. The Manifest.db SQLite database maps each stored object to its logical path.
16+
17+
High‑level procedure:
18+
1) Open Manifest.db and read the file records (domain, relativePath, flags, fileID/hash)
19+
2) Recreate the original folder hierarchy based on domain + relativePath
20+
3) Copy or hardlink each stored object to its reconstructed path
21+
22+
Example workflow with a tool that implements this end‑to‑end (ElegantBouncer):
23+
24+
```bash
25+
# Rebuild the backup into a readable folder tree
26+
$ elegant-bouncer --ios-extract /path/to/backup --output /tmp/reconstructed
27+
[+] Reading Manifest.db ...
28+
✓ iOS backup extraction completed successfully!
29+
```
30+
31+
Notes:
32+
- Handle encrypted backups by supplying the backup password to your extractor
33+
- Preserve original timestamps/ACLs when possible for evidentiary value
34+
35+
36+
## Messaging app attachment enumeration
37+
38+
After reconstruction, enumerate attachments for popular apps. The exact schema varies by app/version, but the approach is similar: query the messaging database, join messages to attachments, and resolve paths on disk.
39+
40+
### iMessage (sms.db)
41+
Key tables: message, attachment, message_attachment_join (MAJ), chat, chat_message_join (CMJ)
42+
43+
Example queries:
44+
45+
```sql
46+
-- List attachments with basic message linkage
47+
SELECT
48+
m.ROWID AS message_rowid,
49+
a.ROWID AS attachment_rowid,
50+
a.filename AS attachment_path,
51+
m.handle_id,
52+
m.date,
53+
m.is_from_me
54+
FROM message m
55+
JOIN message_attachment_join maj ON maj.message_id = m.ROWID
56+
JOIN attachment a ON a.ROWID = maj.attachment_id
57+
ORDER BY m.date DESC;
58+
59+
-- Include chat names via chat_message_join
60+
SELECT
61+
c.display_name,
62+
a.filename AS attachment_path,
63+
m.date
64+
FROM chat c
65+
JOIN chat_message_join cmj ON cmj.chat_id = c.ROWID
66+
JOIN message m ON m.ROWID = cmj.message_id
67+
JOIN message_attachment_join maj ON maj.message_id = m.ROWID
68+
JOIN attachment a ON a.ROWID = maj.attachment_id
69+
ORDER BY m.date DESC;
70+
```
71+
72+
Attachment paths may be absolute or relative to the reconstructed tree under Library/SMS/Attachments/.
73+
74+
### WhatsApp (ChatStorage.sqlite)
75+
Common linkage: message table ↔ media/attachment table (naming varies by version). Query media rows to obtain on‑disk paths.
76+
77+
Example (generic):
78+
79+
```sql
80+
SELECT
81+
m.Z_PK AS message_pk,
82+
mi.ZMEDIALOCALPATH AS media_path,
83+
m.ZMESSAGEDATE AS message_date
84+
FROM ZWAMESSAGE m
85+
LEFT JOIN ZWAMEDIAITEM mi ON mi.ZMESSAGE = m.Z_PK
86+
WHERE mi.ZMEDIALOCALPATH IS NOT NULL
87+
ORDER BY m.ZMESSAGEDATE DESC;
88+
```
89+
90+
Adjust table/column names to your app version (ZWAMESSAGE/ZWAMEDIAITEM are common in iOS builds).
91+
92+
### Signal / Telegram / Viber
93+
- Signal: the message DB is encrypted; however, attachments cached on disk (and thumbnails) are usually scan‑able
94+
- Telegram: inspect cache directories (photo/video/document caches) and map to chats when possible
95+
- Viber: Viber.sqlite contains message/attachment tables with on‑disk references
96+
97+
Tip: even when metadata is encrypted, scanning the media/cache directories still surfaces malicious objects.
98+
99+
100+
## Scanning attachments for structural exploits
101+
102+
Once you have attachment paths, feed them into structural detectors that validate file‑format invariants instead of signatures. Example with ElegantBouncer:
103+
104+
```bash
105+
# Recursively scan only messaging attachments under the reconstructed tree
106+
$ elegant-bouncer --scan --messaging /tmp/reconstructed
107+
[+] Found N messaging app attachments to scan
108+
✗ THREAT in WhatsApp chat 'John Doe': suspicious_document.pdf → FORCEDENTRY (JBIG2)
109+
✗ THREAT in iMessage: photo.webp → BLASTPASS (VP8L)
110+
```
111+
112+
Detections covered by structural rules include:
113+
- PDF/JBIG2 FORCEDENTRY (CVE‑2021‑30860): impossible JBIG2 dictionary states
114+
- WebP/VP8L BLASTPASS (CVE‑2023‑4863): oversized Huffman table constructions
115+
- TrueType TRIANGULATION (CVE‑2023‑41990): undocumented bytecode opcodes
116+
- DNG/TIFF CVE‑2025‑43300: metadata vs. stream component mismatches
117+
118+
119+
## Validation, caveats, and false positives
120+
121+
- Time conversions: iMessage stores dates in Apple epochs/units on some versions; convert appropriately during reporting
122+
- Schema drift: app SQLite schemas change over time; confirm table/column names per device build
123+
- Recursive extraction: PDFs may embed JBIG2 streams and fonts; extract and scan inner objects
124+
- False positives: structural heuristics are conservative but can flag rare malformed yet benign media
125+
126+
127+
## References
128+
129+
- [ELEGANTBOUNCER: When You Can't Get the Samples but Still Need to Catch the Threat](https://www.msuiche.com/posts/elegantbouncer-when-you-cant-get-the-samples-but-still-need-to-catch-the-threat/)
130+
- [ElegantBouncer project (GitHub)](https://github.com/msuiche/elegant-bouncer)
131+
132+
{{#include ../../banners/hacktricks-training.md}}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ pdf-file-analysis.md
3535
{{#endref}}
3636

3737

38+
{{#ref}}
39+
structural-file-format-exploit-detection.md
40+
{{#endref}}
41+
42+
3843
{{#ref}}
3944
png-tricks.md
4045
{{#endref}}
@@ -50,5 +55,3 @@ zips-tricks.md
5055
{{#endref}}
5156

5257
{{#include ../../../banners/hacktricks-training.md}}
53-
54-

0 commit comments

Comments
 (0)