flyingllama87/p4wned

GitHub: flyingllama87/p4wned

一套针对 Perforce 服务器默认配置漏洞的自动化安全研究工具集。

Stars: 0 | Forks: 0

# p4wned Perforce (Helix Core) 安全研究工具和 nuclei 模板。 **研究文章:** https://morganrobertson.net/p4wned/ 请阅读上述链接获取完整细节。 **目标受众:** Perforce 服务器管理员、渗透测试人员、安全工程师 ## 要求 | 工具 | 依赖 | |---|---| | `p4wned.py` | Python 3,`p4` CLI 二进制文件(参见下文) | | `p4ghost.py` | Python 3,`p4` CLI 二进制文件,本地 `p4d` 实例(参见安装步骤) | | `p4-auth-hammer` | g++,Perforce C++ API,OpenSSL 1.1.1(参见 [`p4-auth-hammer/README.md`](p4-auth-hammer/README.md)) | | JavaScript 工具 | Node.js(无外部依赖) | | Nuclei 模板 | [Nuclei](https://github.com/projectdiscovery/nuclei) v3+ | | Metasploit 模块 | [Metasploit Framework](https://github.com/rapid7/metasploit-framework) | **获取 `p4` 二进制文件**(`p4wned.py` 和 `p4ghost.py` 所需): ``` # 受 Perforce 使用条款约束:https://www.perforce.com/legal wget https://ftp.perforce.com/perforce/r25.2/bin.linux26x86_64/p4 chmod +x p4 ``` ## 背景 Perforce 服务器暴露自定义二进制 TCP 协议(默认端口 1666)。许多安装使用不安全的默认设置——未认证用户列表、服务器信息泄露、可访问的远程 depot、无密码要求,以及登录尝试无速率限制。所有工具均利用这些默认设置,无需凭证即可工作。 ## 工具 ### p4wned.py — 完整安全扫描器 主要扫描器。使用 `p4` CLI 二进制文件枚举用户、测试凭据、列出 depot 并生成报告。 ``` python3 p4wned.py [-brute] [-audit] [-parallel N] ``` **选项:** | 标志 | 描述 | |---|---| | `-brute` | 启用暴力模式——对所有发现的账户测试密码 | | `-audit` | 完整审计模式——即使发现漏洞也继续测试所有用户 | | `-parallel N` | 并行密码尝试数(默认:1) | **配置**(在脚本顶部编辑): | 变量 | 描述 | |---|---| | `INPUT_FILE` | 目标列表(`ip:port`,每行一个)——默认 `perforce-servers.txt` | | `P4_CMD` | `p4` 二进制文件路径——默认 `./p4` | | `TOP_PASSWORDS_FILE` | 暴力破解词表——默认 `top-passwords.txt` | | `KNOWN_CREDS_FILE` | 已知凭据对,优先尝试 | | `REPORT_FILE` | 输出报告路径 | **功能:** - 检测 ASCII 与 Unicode 服务器模式 - 枚举用户(若 `run.users.authorize=0`) - 测试空密码和已知/常用凭据 - 列出 depot 名称并采样最近文件路径 - 检查被攻破账户的 `super` 组成员资格 - 输出结构化文本报告 **控制台输出:** ``` $ python3 p4wned.py ___ _ _ __ __ __ __ ___ / _ \ || |/ / /\ \ \/\ \ \/__\/ \ / /_)/ || |\ \/ \/ / \/ /_\ / /\ / / ___/|__ _\ /\ / /\ //__/ /_// \/ |_| \/ \/\_\ \/\__/___,' P4WNED - 0wning P4 servers via shit security defaults since Y2K+25 · Sniffs out user accounts, blank passwords, weak creds, and dumb settings. · Confirms depots access and those juicy "super" user accounts. · Drops a tidy report so you can fix the mess before the Skids arrive Authorised targets only, brotendo. Use on your own servers or at your own risk. ============================================================================== === Processing: 192.0.2.10:1666 (perforce.example-studio.com) === [INFO] Testing user 'super' for security issues... [INFO] User 'super' does not exist. [INFO] Users listing accessible: build, designer1, jsmith, lead_prog, svc_build [INFO] Testing user 'build' for security issues... [INFO] Testing user 'designer1' for security issues... [INFO] Testing user 'jsmith' for security issues... [INFO] Testing user 'lead_prog' for security issues... [INFO] Testing user 'svc_build' for security issues... [INFO] Added new credential for 192.0.2.10:1666: user='svc_build', password='None' [INFO] Saving updated credentials after finding valid credentials for svc_build on 192.0.2.10:1666 [INFO] Report saved to perforce-report-p4wned-1775436520.txt ``` **报告文件**(`perforce-report-p4wned-*.txt`): ``` Perforce Security Scan Report Server: 192.0.2.10:1666 (perforce.example-studio.com) Status: Insecure Note: Insecure via user 'svc_build' (no password) == Depots == Depot depot 2025/11/03 local depot/... 'Default depot' Depot assets 2024/08/19 local assets/... 'Asset depot' == Last 10 Changes == Change 1047 on 2025/11/03 14:22:11 by lead_prog@DESKTOP-BUILD01 Merge branch feature/ai-pathfinding Change 1046 on 2025/11/03 09:44:38 by designer1@DESKTOP-ART02 Updated character rig exports == Depot Details == Depot: depot -- Root Directories -- //depot/Source //depot/Content //depot/Config This depot is a non-Unreal Engine Depot. ------------------------------------------------------------ Summary Report Server: 192.0.2.10:1666 - Insecure - Note: Insecure via user 'svc_build' (no password) ``` ### p4ghost.py — 远程 depot 扫描器 通过隐藏的 `remote` 用户测试未认证远程 depot 访问。漏洞利用方式是在本地运行一个攻击者控制的 `p4d` 实例——目标服务器在服务器到服务器的协议过程中连接回它,从而在过程中泄露其 depot 文件列表。 **安装**(一次性): ``` # 受 Perforce 使用条款约束:https://www.perforce.com/legal wget https://ftp.perforce.com/perforce/r24.2/bin.linux26x86_64/p4d wget https://ftp.perforce.com/perforce/r25.2/bin.linux26x86_64/p4 chmod +x p4d p4 # 在端口 1818 上启动纯 ASCII p4d(用作攻击者的服务器) mkdir p4root_attacker ./p4d -r ./p4root_attacker -p 1818 -d # 在单独端口(1819)上启动用于 Unicode 目标的无编码 p4d mkdir p4root_attacker_unicode ./p4d -r ./p4root_attacker_unicode -xi # convert to unicode mode ./p4d -r ./p4root_attacker_unicode -p 1819 -d ``` ``` python3 p4ghost.py [-skipnolicense] [-report FILE] [-p4cmd PATH] [-unicodeport PORT] [-nonunicodeport PORT] [-timeout SECS] ``` ``` # 使用上述本地攻击服务器的示例调用 python3 p4ghost.py targets.txt -nonunicodeport 1818 -unicodeport 1819 ``` **参数:** | 参数 | 描述 | |---|---| | `input_file` | 目标列表(`ip:port`,每行一个) | | `-skipnolicense` | 跳过返回 `Server license: none` 的服务器 | | `-report FILE` | 输出报告路径 | | `-p4cmd PATH` | `p4` 二进制文件路径(默认 `./p4`) | | `-unicodeport PORT` | 本地 Unicode `p4d` 端口,用作攻击服务器 | | `-nonunicodeport PORT` | 本地非 Unicode `p4d` 端口 | | `-timeout SECS` | 命令超时时间 | 受影响版本:所有低于 2025.1 且 `security < 4` 的版本(默认 0)。 ### p4-auth-hammer — 暴力破解 PoC(C++) 证明 `p4d` 在 `security < 3` 时无法有效限制认证尝试的 PoC。使用 Perforce C++ API 每分钟对单个账户实现 >300,000 次登录尝试。 ``` ./p4_auth_hammer_poc [-ticketauth] ``` **构建**(需要 Perforce C++ API 和 OpenSSL 1.1.1——参见 [`p4-auth-hammer/README.md`](p4-auth-hammer/README.md) 获取完整安装步骤): ``` bash p4-auth-hammer/p4_auth_hammer_poc_build.sh ``` **模式:** - 默认:直接密码认证(`security < 3`)。绕过全部速率限制。每分钟 >300,000 次尝试。 - `-ticketauth`:票据登录(`security >= 3`)。启用速率限制(`dm.user.loginattempts`)。 自动检测 SSL 和 Unicode 服务器,并自动调节线程数以实现最大吞吐量。 **修复建议:** `p4 configure set security=3`(或 4)。参见 [`p4-auth-hammer/README.md`](p4-auth-hammer/README.md) 获取完整细节。 ## JavaScript 工具 独立的 Node.js 脚本。除 Node.js 标准库外无依赖。所有脚本自动检测 SSL 与明文 TCP、ASCII 与 Unicode 服务器模式——无需标志。 **目标文件格式:** 每行一个 `host:port`,未指定端口时默认为 1666。以 `#` 开头的行将被忽略。 ``` p4testascii.example.net:1666 p4testunicode.example.net:1666 p4testunicode.example.net:1667 ``` **自动检测:** 优先尝试明文 TCP。如果服务器响应 Perforce SSL 错误消息(`"Failed client connect, server using SSL"`),则通过 `rejectUnauthorized: false` 重试 TLS(接受自签名证书)。优先尝试 ASCII 模式;如果服务器返回 Unicode 错误消息,则使用 `unicode` 参数重试连接。 ### perforce-users.js — 用户枚举 利用 `run.users.authorize=0`(默认)枚举所有用户账户而无需认证。 ``` node javascript/perforce-users.js [targets_file] ``` 输出:`[host:port] [tcp|ssl] username "Full Name"` ### perforce-info.js — 服务器信息泄露 利用 `dm.info.hide=0`(默认)提取服务器版本、内部地址、根路径和许可证字符串。 ``` node javascript/perforce-info.js [targets_file] ``` 输出: ``` [host:port] [tcp|ssl] Version : P4D/LINUX26X86_64/2024.2/2877946 Server Addr: internal-hostname:1666 Server Root: /opt/perforce/p4root License : Acme Corp ``` ### perforce-passwordless.js — 无密码账户检测 查找未设置密码的用户账户。使用标记输出格式(`tag` 参数)检测 `Password` 字段的缺失。无密码账户允许直接未认证登录。 ``` node javascript/perforce-passwordless.js [targets_file] ``` 输出:`[host:port] [tcp|ssl] [PASSWORDLESS] username "Full Name"` ### perforce-remote.js — 远程 depot 文件枚举 通过 `rmt-DbPipe` 服务器到服务器 RPC 利用隐藏的 `remote` 用户直接读取 `db.rev` 表,提取 depot 文件路径和变更号,无需认证。受影响版本:低于 2025.1 且 `security < 4`。 ``` node javascript/perforce-remote.js [targets_file] ``` 输出: ``` [host:port] [tcp|ssl] 42 file(s) in depot: [change=7] [2024-11-03] //depot/src/main.cpp [change=3] [2024-09-12] //depot/config/database.yml ``` ### perforce-keys.js — 全局键值枚举 从 Perforce 服务器提取全局键/计数器值。键可能包含构建编号、内部版本字符串和配置。 ``` node javascript/perforce-keys.js [targets_file] ``` 输出:`[host:port] [tcp|ssl] keyname = value` ## Nuclei 模板 适用于 [Nuclei](https://github.com/projectdiscovery/nuclei) 的模板。所有模板在执行 JavaScript 载荷前使用 TCP 握手步骤确认 Perforce 服务器存在。模板采用与 JavaScript 工具相同的自动检测方式。 ### 检测 | 模板 | ID | 描述 | |---|---|---| | `perforce-detect.yaml` | `perforce-detection` | 通过二进制协议握手检测 Perforce 服务器。性:信息 | ### 漏洞模板 **限制:** 不支持 SSL,仅限端口 1666。有关更多信息请参见 JavaScript 工具。 | 模板 | ID | 严重性 | CVSS | 描述 | |---|---|---|---|---| | `perforce-user-extraction.yaml` | `perforce-user-enumeration` | 中危 | 5.3 | 未认证用户列表——ASCII 与 Unicode 服务器。提取用户名、邮箱、全名。 | | `perforce-info-disclosure.yaml` | `perforce-info-disclosure` | 中危 | 5.3 | 服务器信息泄露——版本、内部地址、根路径、许可证。 | | `perforce-passwordless-users.yaml` | `perforce-passwordless-users` | 高危 | 9.1 | 查找未设置密码的账户。 | | `perforce-remote-depot-unauth.yaml` | `perforce-remote-depot-access-unauth` | 高危 | 7.5 | 通过 `remote` 用户进行远程 depot 访问——ASCII 与 Unicode 服务器。提取文件路径和变更号。受影响:低于 2025.1 且 `security < 4`。 | ## Metasploit 模块 三个辅助扫描器模块以及一个共享库 mixin,用于处理 Perforce 二进制协议。这些模块涵盖与独立工具相同的漏洞——用户枚举、无密码账户检测和远程 depot exploitation。 所有模块自动检测 ASCII 与 Unicode 服务器模式。支持 SSL。 | 模块 | 描述 | |---|---| | `auxiliary/scanner/perforce/perforce_user_enum` | 未认证用户列表——提取用户名、邮箱、全名及最后访问时间 | | `auxiliary/scanner/perforce/perforce_passwordless` | 检测未设置密码的账户 | | `auxiliary/scanner/perforce/perforce_remote_depot` | 通过隐藏的 `remote` 用户进行远程 depot 文件枚举。受影响:低于 2025.1 且 `security < 4` | 源文件位于 `metasploit/` 目录。已在 Metasploit Framework 提交 PR。 **快速修复参考:** | 问题 | 修复 | |---|---| | 用户枚举 | `p4 configure set run.users.authorize=1` | | 信息泄露 | `p4 configure set dm.info.hide=1` | | 无密码用户 | 为所有账户设置密码;`p4 configure set dm.user.noautocreate=2` | | 远程 depot 访问 | 升级至 2025.1+ 或 `p4 configure set security=4` | | 认证速率限制 | `p4 configure set security=3`(启用 `dm.user.loginattempts` 的有效锁定) | | 全部问题 | `p4 configure set security=4` 加上上述单项设置——`security=4` 可修复远程漏洞,但不会隐藏用户列表或服务器信息 |
标签:C++工具, DevOps安全, g++, GNU通用公共许可证, Helix Core, JavaScript工具, Metasploit模块, MITM代理, Node.js, Nuclei模板, OpenSSL, PB级数据处理, Perforce, Python 3, SEO, TCP协议, 二进制协议, 代码生成, 信息泄露, 协议分析, 口令暴力破解, 威胁模拟, 安全扫描, 安全运维, 客户端工具, 数据可视化, 时序注入, 未认证访问, 权限提升, 渗透测试工具, 用户模式钩子绕过, 逆向工具