Skip to content

Commit af64c1d

Browse files
authored
Merge pull request #2052 from HackTricks-wiki/research_update_src_macos-hardening_macos-security-and-privilege-escalation_macos-files-folders-and-binaries_macos-memory-dumping_20260325_132445
Research Update Enhanced src/macos-hardening/macos-security-...
2 parents 0e416bf + 4381ae1 commit af64c1d

2 files changed

Lines changed: 95 additions & 2 deletions

File tree

src/SUMMARY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- [Pentesting Methodology](generic-methodologies-and-resources/pentesting-methodology.md)
1212
- [Fuzzing Methodology](generic-methodologies-and-resources/fuzzing.md)
1313
- [External Recon Methodology](generic-methodologies-and-resources/external-recon-methodology/README.md)
14+
- [Database Leaks](generic-methodologies-and-resources/external-recon-methodology/database-leaks.md)
1415
- [Wide Source Code Search](generic-methodologies-and-resources/external-recon-methodology/wide-source-code-search.md)
1516
- [Github Dorks & Leaks](generic-methodologies-and-resources/external-recon-methodology/github-leaked-secrets.md)
1617
- [Pentesting Network](generic-methodologies-and-resources/pentesting-network/README.md)

src/macos-hardening/macos-security-and-privilege-escalation/macos-files-folders-and-binaries/macos-memory-dumping.md

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Another important memory-related file in MacOS systems is the **memory pressure
2424

2525
In order to dump the memory in a MacOS machine you can use [**osxpmem**](https://github.com/google/rekall/releases/download/v1.5.1/osxpmem-2.1.post4.zip).
2626

27-
**Note**: The following instructions will only work for Macs with Intel architecture. This tool is now archived and the last release was in 2017. The binary downloaded using the instructions below targets Intel chips as Apple Silicon wasn't around in 2017. It may be possible to compile the binary for arm64 architecture but you'll have to try for yourself.
27+
**Note**: This is mostly a **legacy workflow** now. `osxpmem` depends on loading a kernel extension, the [Rekall](https://github.com/google/rekall) project is archived, the latest release is from **2017**, and the published binary targets **Intel Macs**. On current macOS releases, especially on **Apple Silicon**, kext-based full-RAM acquisition is usually blocked by modern kernel-extension restrictions, SIP, and platform-signing requirements. In practice, on modern systems you will more often end up doing a **process-scoped dump** instead of a whole-RAM image.
2828

2929
```bash
3030
#Dump raw format
@@ -52,7 +52,99 @@ sudo su
5252
cd /tmp; wget https://github.com/google/rekall/releases/download/v1.5.1/osxpmem-2.1.post4.zip; unzip osxpmem-2.1.post4.zip; chown -R root:wheel osxpmem.app/MacPmem.kext; kextload osxpmem.app/MacPmem.kext; osxpmem.app/osxpmem --format raw -o /tmp/dump_mem
5353
```
5454

55-
{{#include ../../../banners/hacktricks-training.md}}
55+
## Live process dumping with LLDB
56+
57+
For **recent macOS versions**, the most practical approach is usually to dump the memory of a **specific process** instead of trying to image all physical memory.
58+
59+
LLDB can save a Mach-O core file from a live target:
60+
61+
```bash
62+
sudo lldb --attach-pid <pid>
63+
(lldb) process save-core /tmp/target.core
64+
```
65+
66+
By default this usually creates a **skinny core**. To force LLDB to include all mapped process memory:
67+
68+
```bash
69+
sudo lldb --attach-pid <pid>
70+
(lldb) process save-core /tmp/target-full.core --style full
71+
```
72+
73+
Useful follow-up commands before dumping:
74+
75+
```bash
76+
# Show loaded images and main binary
77+
(lldb) image list
78+
79+
# Inspect mapped regions and permissions
80+
(lldb) memory region --all
81+
82+
# Dump only one interesting range
83+
(lldb) memory read --force --outfile /tmp/region.bin --binary <start> <end>
84+
```
85+
86+
This is usually enough when the goal is to recover:
87+
88+
- Decrypted configuration blobs
89+
- In-memory tokens, cookies, or credentials
90+
- Plaintext secrets that are only protected at rest
91+
- Decrypted Mach-O pages after unpacking / JIT / runtime patching
92+
93+
If the target is protected by the **hardened runtime**, or if `taskgated` denies the attach, you typically need one of these conditions:
5694

95+
- The target carries **`get-task-allow`**
96+
- Your debugger is signed with the proper **debugger entitlement**
97+
- You are **root** and the target is a non-hardened third-party process
98+
99+
For more background on obtaining a task port and what can be done with it:
100+
101+
{{#ref}}
102+
../macos-proces-abuse/macos-ipc-inter-process-communication/macos-thread-injection-via-task-port.md
103+
{{#endref}}
104+
105+
## Selective dumps with Frida or userland readers
106+
107+
When a full core is too noisy, dumping only **interesting readable ranges** is often faster. Frida is especially useful because it works well for **targeted extraction** once you can attach to the process.
108+
109+
Example approach:
110+
111+
1. Enumerate readable/writable ranges
112+
2. Filter by module, heap, stack, or anonymous memory
113+
3. Dump only the regions that contain candidate strings, keys, protobufs, plist/XML blobs, or decrypted code/data
114+
115+
Minimal Frida example to dump all readable anonymous ranges:
116+
117+
```javascript
118+
Process.enumerateRanges({ protection: 'rw-', coalesce: true }).forEach(function (range) {
119+
try {
120+
if (range.file) return;
121+
var dump = range.base.readByteArray(range.size);
122+
var f = new File('/tmp/' + range.base + '.bin', 'wb');
123+
f.write(dump);
124+
f.close();
125+
} catch (e) {}
126+
});
127+
```
128+
129+
This is useful when you want to avoid giant core files and only collect:
130+
131+
- App heap chunks containing secrets
132+
- Anonymous regions created by custom packers or loaders
133+
- JIT / unpacked code pages after changing protections
134+
135+
Older userland tools such as [`readmem`](https://github.com/gdbinit/readmem) also exist, but they are mainly useful as **source references** for direct `task_for_pid`/`vm_read` style dumping and are not well-maintained for modern Apple Silicon workflows.
136+
137+
## Quick triage notes
138+
139+
- `sysctl vm.swapusage` is still a quick way to check **swap usage** and whether swap is **encrypted**.
140+
- `sleepimage` remains relevant mainly for **hibernate/safe sleep** scenarios, but modern systems commonly protect it, so it should be treated as an **artifact source to check**, not as a reliable acquisition path.
141+
- On recent macOS releases, **process-level dumping** is generally more realistic than **full physical memory imaging** unless you control boot policy, SIP state, and kext loading.
142+
143+
## References
144+
145+
- [https://www.appspector.com/blog/core-dump](https://www.appspector.com/blog/core-dump)
146+
- [https://afine.com/to-allow-or-not-to-get-task-allow-that-is-the-question](https://afine.com/to-allow-or-not-to-get-task-allow-that-is-the-question)
147+
148+
{{#include ../../../banners/hacktricks-training.md}}
57149

58150

0 commit comments

Comments
 (0)