《ssh 命令注入漏洞 (cve-2017-1000117)分析》 命令注入... ·...
TRANSCRIPT
https://cert.360.cn
《SSH 命令注入漏洞
(CVE-2017-1000117)分析》
安全报告:SSH 命令注入漏洞(CVE-2017-1000117)分析
报告编号:B6-2017-081101
报告来源:360 网络安全响应中心
报告作者:RickyHao,C1tas
更新日期:2017 年 8 月 11 日
https://cert.360.cn
目 录
0x00 背景介绍 .......................................................................................... 3
0x01 漏洞概述 .................................................................................................. 3
0x02 漏洞攻击面影响 ...................................................................................... 3
1. 影响面 .......................................................................................................... 3
2. 影响版本 ...................................................................................................... 4
3. 修复版本 ...................................................................................................... 4
0x03 漏洞详情 .................................................................................................. 4
1. 技术细节 ...................................................................................................... 4
0x04 漏洞利用验证 .......................................................................................... 9
0x05 修复建议 .................................................................................................. 9
0x06 时间线 .................................................................................................... 10
0x07 参考文档 ................................................................................................ 10
https://cert.360.cn
0x00 背景介绍
Amalicious third-partycangiveacrafted"ssh://..."URLtoanunsuspectingvictim,andanattempttovisittheURLcanresult inanyprogramthatexistsonthevictim'smachinebeingexecuted.SuchaURLcouldbeplacedinthe.gitmodulesfileofa malicious project, and an unsuspecting victim could be tricked into running "gitclone--recurse-submodules"totriggerthevulnerability.--https://www.mail-archive.com/[email protected]/msg1466490.html
在 2017 年 8 月 10 日 Junio C Hamano 发布了这一问题。
0x01 漏洞概述
恶意人员可以通过巧妙构造“ssh://…”链接,让受害人在执行程序等情况
下访问该恶意链接,从而达到命令执行的目的。该链接可以被放在 git 项目
的 .gitmodules 文件下,这样当受害人对一个项目进行“git clone
--recurse-submodules”操作时,就会引发安全问题。
360CERT 进行了紧急分析,目前该分析报告仅以 Git 为例,但漏洞影响包
括但不限于 Git,SVN,CVS,HG,Gitlab,GithubDesktop,SourceTree 等。
0x02 漏洞攻击面影响
影响面
该漏洞主要由“ssh://…”链接造成,如 Git,SVN,CVS,HG 等工具,在
解析 SSH 链接的时候都会触发这个漏洞。此外,若是其他程序在解析 SSH 链接
的时候,不做相应的处理,就会触发该漏洞。
经过 360CERT 研判后确认,漏洞风险等级高,影响范围广。
https://cert.360.cn
影响版本
Versions prior to 2.14.1 of the Git
修复版本
Git v2.14.1
0x03 漏洞详情
技术细节
该漏洞主要由于 SSH 链接在 hostname 部分,若是用“-”开头,那么
会导致 ssh 命令将 hostname 误认为这是一个选项。因此,我们可以利用
“-oProxyCommand”选项来达到命令执行的目的。
在 进 行 git clone 时 候 会 调 用 到 git/connect.c 中 “ struct
child_process *git_connect(int fd[2], const char *url,const char *prog,
int flags) ” 函 数 。 其 接 受 到 的 参 数 url 为 命 令 中 “ git clone
xxx://xxxxxxxxxx/xx(.git)”的 xxx://xxxxxxxxxx/xx(.git)部分。在该函数中
会对传入的这个字符串进行 parse,提取其协议部分。在满足协议为 ssh://
的时候会进入该函数的 else 部分。
https://cert.360.cn
然后根据下面的流程调用本地的 ssh
https://cert.360.cn
• 首先获得本地的 ssh 路径,然后 push 进 conn->args
• 然后获得 url 中 ssh_host 部分再拼接路径
• 最后调用 start_command 函数进行命令执行
start_command 的定义在 git/run-command.c
int start_command(struct child_process *cmd)
https://cert.360.cn
将传入的 cmd 经过处理赋值给 argv
经过 execve 这个函数进行命令执行。但是在这个这个命令执行的内容
是 “/usr/bin/ssh ̀ ssh_host` path”而 ssh 命令的-o 参数在一定程度上是
可以执行命令的
https://cert.360.cn
例如
“ssh -oProxyCommand=gnome-calculator xxx”将会在本地打开
gnome 的计算器
所以如果我们在 clone 操作的时候将连接指定为
git clone ssh://-oProxyCommand=gnome-calculator/cert
将取得同样的命令执行的效果
漏洞修复
在 v2.14.1 的 commit 中,可以看到 git_connect 函数中执行之前对 ssh_host进行了验证
验证内容为新增的这个函数
该函数对 ssh_host 的第一个字符进行了校验防止为-的情况抑制了向 ssh 传
递参数的情况并且在多处对传入的 host,port都做了该函数的过滤
https://cert.360.cn
0x04 漏洞利用验证
注:利用演示 https://asciinema.org/a/v88k2fTHB3CXPnadOrM62pcAr
0x05 修复建议
a) 官方更新公告(非正式版本呢,需自行更新)
https://www.mail-archive.com/[email protected]/msg146
6490.html
b) 目 前 各 个 发 行 版 源 还 未 更 新 修 复 版 本 v2.14.1 , 用 户 可 以 在
https://github.com/gitster/git 上自行下载编译。
https://cert.360.cn
c) 未更新的用户,在 clone 项目的时候,请尽量注意 .gitmodules 等文件
中有无恶意链接来预防安全问题。
0x06 时间线
2017-8-10 官方首次发布安全通告
2017-8-11 360CERT 完成对漏洞的分析并形成报告
0x07 参考文档
https://www.mail-archive.com/[email protected]/msg146
6490.html
https://github.com/gitster/git/commit/4274c698f46a9bc45834c490
4e7e113450c042fb