A comprehensive guide synthesized from four research articles covering macOS app structure, static and dynamic analysis, binary analysis, dylib hijacking, code injection, and XPC attacks.
macOS thick client pentesting differs significantly from Windows and Linux. The following mindmap covers the major attack domains you need to work through systematically.
Analyze binary architecture (Mach-O), disassemble with Hopper or Ghidra, enumerate entitlements, code signature flags, and linked dylibs.
Phase 3: Dynamic
Monitor processes, files, and network activity. Hook with Frida, debug with lldb, dump memory, and trace with DTrace.
Phase 4: Exploitation
Dylib hijacking, DYLD injection, mach task port injection, XPC abuse, IPC fuzzing, and PT_DENY_ATTACH bypass.
Part 1
Application Structure, SIP & Network Testing
Source: CyberArk Research · Julia Minin & Daniel Rabinovich · Jul 2023
01 / Application Structure
macOS Application Bundle
macOS apps are bundled in .app directories with a standardized hierarchical structure. They appear as single files in Finder but are actually directories. Right click and choose Show Package Contents to inspect them.
Main Mach-O: check architecture, signing, hardened runtime flags
Frameworks/*.dylib
Third party libs with known CVEs; signing mismatches; hijack candidates
Library/LaunchServices/
Privileged helper tools running as root, the primary privilege escalation surface
Library/XPCServices/
XPC services: check authorization policies and process identity validation
02 / Security Controls
Built in Security Protections
Before testing, understand what is protecting the app. These controls need to be accounted for or bypassed.
System Integrity Protection (SIP)
SIP restricts modifications to /System, /bin, /sbin, and /usr, even as root. It also limits debugger attachment and code injection against protected binaries.
# Check SIP status
csrutil status
# Disable SIP (requires Recovery Mode → Terminal)
csrutil disable
# Allow debugging but keep other protections
csrutil enable --without debug
# Reenable after testing
csrutil enable
Warning
Disabling SIP leaves the entire system exposed. Use a dedicated VM or test machine, and reenable it immediately after testing. Never disable SIP on production hardware.
Other Security Layers
Control
What It Does
Pentest Implication
Gatekeeper
Allows only Apple signed or notarized apps to run by default
Must sign test binaries with a valid certificate, or disable Gatekeeper policy
Notarization
Apple scans for malware and validates code signing before issuing a ticket
Limits distributing malicious apps via standard channels; bypass via direct install
App Sandbox
Restricts resource access to what is declared in entitlements
Check entitlements for overpermissions; sandbox escape via XPC helpers
TCC
Controls access to camera, microphone, location, Full Disk Access, and more
Look for TCC bypass via privileged helpers or inherited permissions
Quarantine
Quarantine flag on downloaded files triggers Gatekeeper checks
Remove with xattr -d com.apple.quarantine <file>
AMFI
Apple Mobile File Integrity: validates code signatures at load time
Blocks unsigned or tampered dylib loading; defeats injection without exceptions
03 / Network Testing
Network Interception Setup
SIP blocks the system level hooking needed for proxy interception. Disable it first, then configure Burp.
BurpSuite: Step by Step macOS Setup
Download and install BurpSuite from PortSwigger.
Navigate to Proxy → Options. Set the listener to 127.0.0.1:8080.
Export the Burp CA certificate in .der format (Figure 4 below).
Install the certificate via Keychain Access and set it to Always Trust (Figure 5 below).
Go to System Preferences → Network → Advanced → Proxies. Set the HTTP proxy to 127.0.0.1:8080 (Figure 6 below).
Verify: open a browser and confirm traffic appears in Burp.
// Figure 4: Exporting the Burp CA certificate in .der format// Figure 5: Installing and trusting the Burp certificate in Keychain Access// Figure 6: macOS network proxy settings pointing to Burp at 127.0.0.1:8080
Wireshark: Unencrypted Traffic
For traffic that is not HTTP, or raw protocol analysis, Wireshark captures at the interface level. Look for cleartext credentials, insecure protocols (Telnet, FTP, HTTP), and sensitive data in plaintext streams.
Source: CyberArk Research · Julia Minin & Daniel Rabinovich · Jul 2023
04 / Static File & Binary Analysis
Code Signing & Hardened Runtime
Code Signature Inspection
Start every engagement by pulling code signature metadata. This reveals the certificate chain, TeamIdentifier, signing flags, and hardened runtime status.
# Full code signature details
codesign -dvv "/Applications/TargetApp.app"
# Check if signature is valid
codesign --verify --verbose /Applications/TargetApp.app
# Assess via Gatekeeper policy
spctl --assess --verbose /Applications/TargetApp.app
# Get signing authority and TeamIdentifier
codesign -v -d /Applications/TargetApp.app 2>&1 | grep -E "Authority|TeamIdentifier"
// Figure 2: Flags = 0x0 (no hardened runtime, no restrictions). Prime target.// Figure 3: Flags = 0x10002: hardened runtime enabled (0x10000) plus adhoc signature (0x0002)
Info: TeamIdentifier Bypass
A known bypass exists where the TeamIdentifier field was "not set" on some Apple binaries, allowing adhoc signed binaries to impersonate Apple signed ones through third party code signing API misinterpretation.
Runtime Exceptions in Xcode
Apps may disable specific hardened runtime protections via entitlement backed exceptions. These are your attack surface when runtime is enabled.
// Figure 4: Runtime Exception settings in Xcode. Each enabled exception is a potential attack vector
05 / Entitlements
Entitlement Analysis
Entitlements are key value pairs granting permissions. Auditing them reveals the app's attack surface and which injection or debugging techniques are viable.
# Dump entitlements via codesign
codesign -d --entitlements :- /path/to/app/Contents/MacOS/binary
# Dump via jtool2 (extended otool)
jtool2 --ent /path/to/binary
// Figure 11: Apple Instruments: filesystem and memory monitoring for running applications
Frida: API Hooking
# Install
pip3 install frida-tools
# Hook open() syscall to intercept file access
cat > hook.js << 'EOF'
Interceptor.attach(Module.findExportByName(null, "open"), {
onEnter: function(args) {
console.log("[open] " + Memory.readUtf8String(args[0]) + " mode=" + args[1].toInt32());
}
});
EOF
# Inject into running process by name
frida -n "TargetApp" -l hook.js
# Inject into process by PID
frida -p 1234 -l hook.js
# Spawn and inject
frida -f /Applications/TargetApp.app/Contents/MacOS/TargetApp -l hook.js
// Figure 12: Frida injected into a running process, intercepting open() calls in real time
Memory Analysis with lldb
# Find target PID
ps aux | grep -i "TargetApp"
# Attach lldb to process
lldb --attach-pid 44434
# Dump process memory
(lldb) process save-core /tmp/target.dump
# After exiting lldb, search for secrets
strings /tmp/target.dump | grep -i "password\|Bearer\|token\|secret"
# Inside lldb: inspect memory at address
(lldb) memory read 0x1234abcd --count 64 --format x
# Disassemble function
(lldb) disassemble --name someFunction
# Show process state
(lldb) process status
# List loaded images
(lldb) image list
Note: SIP & get-task-allow
Even with SIP enabled, you can still attach lldb to apps that have the com.apple.security.get-task-allow entitlement set to true. Development builds typically have this; distribution builds do not.
// Figure 13: lldb process save-core creates a full memory dump for offline analysis// Figure 14: Searching the memory dump with strings: credentials and tokens exposed in plaintext// Figure 15: lldb process status: shows current execution state and stop location
DTrace: malloc Tracing
# Trace malloc calls in a process (replace PID)
sudo dtrace -n 'pid$target::malloc:entry { trace(arg0); }' -p <PID>
# Find PID first
ps aux | grep TargetApp
Source: CyberArk Research · Julia Minin & Daniel Rabinovich · Feb 2024
08 / Dylib Hijacking
Dylib Hijacking
Similar to Windows DLL hijacking. An attacker places a malicious dylib where the app expects a legitimate one, causing it to load and execute attacker controlled code within the app's process context and privileges.
Required dylib: must load or the process terminates
Yes, if the path is writable or @rpath points to a writable directory
LC_LOAD_WEAK_DYLIB
Optional dylib: missing means continue without it
High: drop a malicious dylib where the weak one is expected
LC_RPATH
Adds paths to the runtime search list for @rpath resolution
If multiple rpaths exist, an earlier writable path wins
LC_REEXPORT_DYLIB
Reexports symbols from another dylib
Use a proxy/reexport pattern to avoid crashes
Path Variables
@executable_path → path to directory containing the main executable
@loader_path → path to directory containing the binary with the load command
@rpath → resolved from the LC_RPATH list (first match wins)
Finding Hijack Candidates
# Use Patrick Wardle's Dylib Hijack Scanner (GUI)
# https://objective-see.org/products/dhs.html
# Manual: find weak dylibs (missing = safe to place malicious one)
otool -l /path/to/binary | grep LC_LOAD_WEAK_DYLIB -A5
# Find dylibs loaded from @rpath (must also check LC_RPATH paths)
otool -l /path/to/binary | grep LC_LOAD_DYLIB -A5 | grep rpath
# Show all LC_RPATH entries (check for writable paths)
otool -l /path/to/binary | grep LC_RPATH -A3
// Figure 4: LC_LOAD_WEAK_DYLIB entry: missing library, place a malicious dylib at the expected path// Figure 5: Dylib loaded via @rpath: check whether any LC_RPATH points to a user writable directory// Figure 6: Multiple LC_RPATH entries: if a writable path appears before the legitimate one, hijack is possible
Exploitation Conditions
Hijacking succeeds when at least one of these is true:
App has no hardened runtime (flags = 0x0).
App has hardened runtime but com.apple.security.cs.disable-library-validation is set.
A file inside app/Contents/ has an invalid or missing signature.
A weak dylib is expected at a user writable path.
An LC_RPATH entry points to a user writable directory that appears before the legitimate path.
// Figure 3: codesign --verify output showing an invalid signature on the dylib. Hijack viable
# Compile with version compatibility matching the legitimate dylib
gcc -dynamiclib \
-current_version 6.8.0 \
-compatibility_version 6.8.0 \
custom.c -o custom.dylib \
-Wl,-reexport_library "/path/to/legitimate.dylib"
# Set install name to match what the app expects
install_name_tool -id @rpath/custom.dylib custom.dylib
# Update internal reference to point to the real dylib (resolve @rpath)
install_name_tool -change @rpath/custom.dylib \
/full/path/to/legitimate.dylib custom.dylib
# Drop into the primary rpath search location
cp custom.dylib /Applications/Target.app/Contents/Frameworks/custom.dylib
// Figure 7: LC_REEXPORT_DYLIB in the malicious dylib: forwards symbols to the legitimate library, prevents crashes
Verify Execution via Console.app
// Figure 8: Console.app showing the syslog message from the hijacker dylib, confirming code execution
09 / Code Injection
Code Injection Techniques
1. DYLD_INSERT_LIBRARIES: Env Var Injection
Like LD_PRELOAD on Linux. The dynamic linker loads the specified dylib before the app's own dependencies. It only works on processes you launch, not existing ones.
// Figure 9: dyld manual entry for DYLD_INSERT_LIBRARIES: the mechanism behind environment variable code injection
Conditions for Success
With SIP enabled and hardened runtime active, this environment variable is silently ignored unless the app has one or both of:
#include <mach/mach.h>
int main() {
pid_t pid = 4570; /* target PID */
mach_port_t task;
kern_return_t kr = task_for_pid(mach_task_self(), pid, &task);
if (kr != KERN_SUCCESS) {
printf("Failed: %s\n", mach_error_string(kr));
return 1;
}
printf("Got task port 0x%x for PID %d\n", task, pid);
/* now read/write target process memory via task port */
return 0;
}
// Figure 13: AMFI blocking task_for_pid: requires the com.apple.security.cs.debugger entitlement on the injector
Reference
For complete task port injection implementations, see Jonathan Levin's inject.c and Scott Knight's remote thread injection PoC (linked in the Part 3 references).
10 / XPC Attacks
XPC Attacks
XPC (Cross Process Communication) is macOS's primary IPC mechanism. Privileged helper tools communicate with main apps via XPC, a major privilege escalation surface.
Attack Surface
Vector
Description
Message forgery
Craft malicious XPC messages if the service does not validate caller identity
PID reuse
Classic TOCTOU: the PID is checked, then the service PID changes between check and use
Missing entitlement validation
Service does not verify the caller has the required entitlements or code signature
Endpoint authorization bypass
Authorization policies are misconfigured, so access is granted without proper authorization
Privileged helper abuse
Helper at /Library/PrivilegedHelperTools/ runs as root and exposes a dangerous XPC API
# Find XPC services in app bundle
find /Applications/Target.app -name "*.xpc" -o -name "*.launchd.plist"
# Inspect XPC service binary
codesign -dvv Target.xpc/Contents/MacOS/Target
codesign -d --entitlements :- Target.xpc/Contents/MacOS/Target
# Check authorization database entries
security authorizationdb read com.target.privilegedOp
# Monitor XPC traffic (requires SIP disabled or special entitlements)
# Use Frida to hook NSXPCConnection and intercept messages
Further Reading: XPC
theevilbit.github.io/tags/xpc/: a comprehensive XPC attack series. Also: OffSec's Microsoft Teams macOS LPE writeup demonstrates real world XPC privilege escalation.
11 / Quick Reference
Complete Command Reference
Recon & Info Gathering
# Check SIP status
csrutil status
# App architecture
file /Applications/Target.app/Contents/MacOS/Target
lipo -info /Applications/Target.app/Contents/MacOS/Target
# VM detection check (some apps use this)
sysctl hw.model
# Check for PT_DENY_ATTACH (anti-debug)
# Look for ptrace(PT_DENY_ATTACH,0,0,0) in the disassembly
# Sandbox profile
codesign -d --entitlements :- /Applications/Target.app 2>&1 | grep sandbox
Code Signing Full Workflow
# Full signature info
codesign -dvv /Applications/Target.app
# Verify bundle integrity
codesign --verify --deep --verbose /Applications/Target.app
# Gatekeeper assessment
spctl --assess --verbose /Applications/Target.app
# Get all entitlements (requires jtool2)
jtool2 --ent /Applications/Target.app/Contents/MacOS/Target
# Resign a binary (after modification)
codesign -s - --force /path/to/modified/binary # adhoc
codesign -s "Developer ID" --force /path/to/binary # with certificate
# Attach to PID
lldb --attach-pid <PID>
# Common lldb commands
(lldb) process status # current state
(lldb) thread list # all threads
(lldb) image list # loaded images
(lldb) memory read 0x... -c 32 --format x # read memory
(lldb) disassemble --name func # disassemble function
(lldb) process save-core /tmp/dump.bin # memory dump
(lldb) breakpoint set --name objc_msgSend # Objective-C hook point
(lldb) expression (void)NSLog(@"hooked") # evaluate expression
Anti Debug Bypass
# Check if PT_DENY_ATTACH is present
# Look for: ptrace(PT_DENY_ATTACH,0,0,0) in IDA or Ghidra
# Check if the process is being traced
# In source: if (P_TRACED == (info.kp_proc.p_flag & P_TRACED)) ...
# Bypass approach: patch the ptrace call via NOP or modify p_lflag
# Use lldb with debug-enabled SIP mode:
csrutil enable --without debug
Full Tool List
Tool
Category
Use
codesign
Static
Signature inspection, entitlements, verification
otool
Static
Load commands, dylib dependencies, headers
jtool2
Static
Extended otool: entitlements, codesign, and more
nm
Static
Symbol table: function names, language detection
strings
Static
Extract readable strings from a binary
spctl
Static
Gatekeeper policy assessment
Ghidra / Hopper / IDA
Static
Disassembly and decompilation
Dylib Hijack Scanner
Static
Automated dylib hijack candidate finder
Frida
Dynamic
Runtime API hooking and instrumentation
lldb
Dynamic
Debugger: attach, breakpoints, memory read and dump
dtrace
Dynamic
Kernel level tracing, syscall and malloc monitoring
ProcessMonitor
Dynamic
Process creation and termination events
FileMonitor
Dynamic
File system event monitoring
TaskExplorer
Dynamic
Running tasks, open files, loaded dylibs
Crescendo
Dynamic
GUI Procmon equivalent for macOS
Wireshark
Network
Raw packet capture and protocol analysis
BurpSuite
Network
HTTP/HTTPS proxy interception
Apple Instruments
Dynamic
Memory leaks, CPU, and filesystem profiling
Contribute your research
Have a technique, tool, or correction to add? Pull requests are welcome on GitHub.