Back to Skills

macos-process-injection

macOS process injection playbook. Use when you need to inject code into running or launching macOS processes via dylib hijacking, DYLD environment variables, XPC exploitation, Mach port manipulation, or Electron/Chromium abuse.

1,320stars179forksUpdated 7/9/2026

Security Assessment

Critical Risk(0/100)

Detected risks:

Persistence([SKILL.md] LaunchD, [DYLIB_XPC_TECHNIQUES.md] launchd, [DYLIB_XPC_TECHNIQUES.md] LaunchD)
Secret Exposure([DYLIB_XPC_TECHNIQUES.md] token =)
Command Injection([SKILL.md] child_process, [DYLIB_XPC_TECHNIQUES.md] child_process)
Privilege Escalation([SKILL.md] RunAs)
Security Score0/100

About macos-process-injection

A technical playbook for injecting code into running or launching macOS processes, aimed at security researchers and red-team practitioners who need to understand the platform's injection vectors and their prerequisites. It emphasizes details that general knowledge often misses — entitlement requirements and System Integrity Protection (SIP) constraints that determine whether a given technique works. It begins with DYLD_INSERT_LIBRARIES injection, using the dynamic linker to preload a dylib, and tabulates when it is possible: normal non-hardened binaries allow it, while Hardened Runtime, SIP-protected Apple binaries, SUID/SGID binaries, and sandboxed apps strip the environment variable, unless the com.apple.security.cs.allow-dyld-environment-variables entitlement is present. It provides compile-and-inject examples and shell one-liners to enumerate injectable targets by inspecting codesign flags and entitlements. Dylib hijacking is covered in three forms — weak dylib hijacking (LC_LOAD_WEAK_DYLIB), @rpath hijacking against writable LC_RPATH directories, and dylib proxying that re-exports a legitimate library's symbols while running attacker code — with otool, nm, and dyldinfo commands for dependency enumeration. XPC exploitation covers service discovery and client-validation weaknesses, notably the PID reuse race condition against PID-based checks (contrasted with audit-token, code-signature, and entitlement validation that resist it). A Mach ports section explains task_for_pid and related APIs, their root/entitlement requirements, and post-exploitation capabilities such as memory read/write and thread injection, along with port namespace manipulation. The document also references companion material — a macos-security-bypass skill for defeating TCC, Gatekeeper, or SIP, a Linux privilege-escalation cross-reference, and a deeper DYLIB_XPC_TECHNIQUES reference with step-by-step methodology, XPC walkthroughs, and Mach port patterns. Throughout, comparison tables map each technique to its requirement and outcome, making it a reference for assessing which injection paths a hardened or unhardened macOS target actually exposes.

FAQ

When can DYLD_INSERT_LIBRARIES injection work?

Against normal non-hardened binaries; Hardened Runtime, SIP-protected Apple binaries, SUID/SGID binaries, and sandboxed apps strip the variable, unless the com.apple.security.cs.allow-dyld-environment-variables entitlement is present.

What forms of dylib hijacking are covered?

Weak dylib hijacking (LC_LOAD_WEAK_DYLIB), @rpath hijacking when an rpath directory is writable, and dylib proxying that re-exports the original library's symbols while running attacker code.

What is the XPC PID reuse attack?

A race condition against services that validate clients by PID — the PID passes the check, the legitimate process exits, and the attacker forks to reuse that PID; audit-token, code-signature, and entitlement checks are not vulnerable.

What does task_for_pid enable?

With root and a non-SIP-protected target, it returns the target's task port for full memory read/write and thread injection via APIs like thread_create_running.

What tools enumerate a binary's dylib dependencies?

otool (-L for dependencies, -l for full load commands including rpaths and weak refs), nm for exported symbols, and dyldinfo for detailed dependency info on pre-Ventura systems.

All Files

2 files
SKILL.md12.8 KB
View
DYLIB_XPC_TECHNIQUES.md11.0 KB
View

Install macos-process-injection

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill