文章摘要
FreeBSD系统中kgssapi.ko模块存在堆栈缓冲区溢出漏洞(CVE-2026-4747),影响多个版本。攻击者可通过NFS服务器(端口2049/TCP)远程执行内核代码获取root权限。漏洞源于svcrpcgssvalidate()函数未检查RPCSECGSS凭证长度,导致128字节栈缓冲区溢出。
文章总结
FreeBSD kgssapi.ko RPCSEC_GSS 堆栈缓冲区溢出漏洞分析 (CVE-2026-4747)
漏洞概述
影响版本:FreeBSD 13.5 (
漏洞类型:远程内核代码执行(可获得root权限反向shell)
漏洞详情
根本原因
在sys/rpc/rpcsec_gss/svc_rpcsec_gss.c文件中,svc_rpc_gss_validate()函数存在堆栈缓冲区溢出漏洞:
- 该函数使用128字节的栈缓冲区(
rpchdr[])重构RPC头部 - 先写入32字节固定RPC头字段
- 然后无边界检查地拷贝RPCSEC_GSS凭证体(
oa_length字节) - 当凭证体超过96字节(128-32)时会导致栈溢出
修复方案
FreeBSD 14.4-RELEASE-p1版本添加了边界检查:
c
if (oa->oa_length > sizeof(rpchdr) - 8 * BYTES_PER_XDR_UNIT) {
rpc_gss_log_debug("auth length %d exceeds maximum", oa->oa_length);
return (FALSE);
}
利用条件
必要条件
- NFS服务器启用并加载kgssapi.ko模块
- 配置MIT Kerberos KDC(用于RPCSEC_GSS认证)
- 攻击者需拥有有效的Kerberos票据(即使是普通用户权限)
技术难点
- GSS上下文建立:需要完成Kerberos握手获取有效票据
- 线程限制:FreeBSD默认每个CPU核心生成8个NFS线程,利用过程需要至少2个CPU(16线程)
- 堆栈布局:实际返回地址偏移为凭证体第200字节(初始假设168字节有误)
利用过程
多阶段攻击策略
- 第一阶段:建立Kerberos GSS上下文
- 第二阶段:发送特制RPCSEC_GSS DATA数据包触发溢出
- 第三阶段:通过ROP链实现内核内存写入
- 第四阶段:使用kthread_exit()干净终止NFS工作线程
整个攻击需要15轮完成: - 第1轮:使BSS段可执行 - 第2-14轮:分片写入432字节shellcode - 第15轮:执行shellcode
Shellcode功能
入口函数:
- 栈迁移到安全区域
- 清除DR7调试寄存器
- 调用kproc_create创建新内核进程
工作函数:
- 设置exec参数(/bin/sh和反向shell命令)
- 调用kern_execve执行特权shell
- 清除P_KPROC标志确保正常返回用户态
技术挑战
- 寄存器偏移错误:实际RIP偏移比预期多32字节
- GSS令牌兼容性:MIT与Heimdal库的差异导致初始认证失败
- 调试寄存器继承:内核调试器遗留的断点导致trap 1异常
- 数据传递限制:400字节凭证限制下分片传递432字节shellcode
- 线程耗尽问题:单CPU环境(8线程)无法完成15轮攻击
结果验证
成功利用后将获得uid 0(root)的反向shell连接,完整攻击耗时约45秒(15轮×3秒/轮)。
防护建议
- 及时升级到已修复版本
- 如无需RPCSEC_GSS功能,卸载kgssapi.ko模块
- 限制NFS服务的网络访问范围
- 实施严格的Kerberos票据管理策略
评论总结
总结评论内容如下:
AI生成漏洞利用代码的能力
- 主要观点:Claude AI并非自主发现漏洞,而是在给定CVE报告后生成利用代码
- 论据:"Key point is that Claude did not find the bug it exploits. It was given the CVE writeup" (magicalhippo)
- 发展潜力:"I wouldn't be surprised if...have a go at the source code...and get it pumping out CVEs" (magicalhippo)
相关技术讨论
- FreeBSD安全缺陷:"FreeBSD 14.x has no KASLR...no stack canaries" (ptx引用原文)
- 比较研究:"NetBSD apparently has it" (ptx)
- 漏洞普遍性:"Pick a file you can find one" (dheerajmp)
研究价值与影响
- 技术突破:"chaining multiple bugs into a working remote exploit without a human in the loop" (alcor-z)
- 实际风险:"is this realistically exploitable on anything with default configs" (alcor-z)
- 发展趋势:"LLMs are getting good at finding and exploiting these" (panstromek)
研究透明度
- 方法公开:"Appreciate the full prompt history" (m132)
- 资源链接:"would have been a better link" (fragmede)
社会影响
- 双重用途:"can be a blessing or curse" (sheepscreek)
- 新闻价值:"still considered newsworthy" (sheepscreek)
关键引用保留: - 英文:"Key point is that Claude did not find the bug it exploits" (magicalhippo) - 中文:"Claude并没有自主发现漏洞" (magicalhippo观点总结) - 英文:"chaining multiple bugs into a working remote exploit without a human in the loop" (alcor-z) - 中文:"将多个漏洞串联成远程攻击链而无需人工干预" (alcor-z观点总结)