coLinux日記

coLinuxはフリーソフトを種として、よろずのシステムとぞなれりける。

bashcheck シェルスクリプトの動作について

2014-10-15 23:56:45 | Bash
Shellshock 検証用に、bashcheck というシェルスクリプトが公開されています。

https://github.com/hannob/bashcheck/blob/master/bashcheck


使い方は、bashcheck ファイルを chmod で実行可能にして以下のように実行するだけです。

$ ./bashcheck [another_bash]

最初の引数で別の bash が指定できます。省略すると標準の bash で、こちらの環境では /usr/local/bin/bash です。

これを利用して、patch 25 から patch 30 までの bash 毎に実行してみました。

Bash version 4.3.0(1)-release

Variable function parser active, maybe vulnerable to unknown parser bugs
Vulnerable to CVE-2014-6271 (original shellshock)
Vulnerable to CVE-2014-7169 (taviso bug)
Vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Vulnerable to CVE-2014-6277 (lcamtuf bug #1)
Vulnerable to CVE-2014-6278 (lcamtuf bug #2)


Bash version 4.3.25(1)-release

Variable function parser active, maybe vulnerable to unknown parser bugs
Not vulnerable to CVE-2014-6271 (original shellshock)
Vulnerable to CVE-2014-7169 (taviso bug)
Vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Vulnerable to CVE-2014-6277 (lcamtuf bug #1)
Vulnerable to CVE-2014-6278 (lcamtuf bug #2)


Bash version 4.3.26(2)-release

Variable function parser active, maybe vulnerable to unknown parser bugs
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Vulnerable to CVE-2014-6277 (lcamtuf bug #1)
Vulnerable to CVE-2014-6278 (lcamtuf bug #2)


Bash version 4.3.27(3)-release

Variable function parser pre/suffixed [%%, upstream], bugs not exploitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Found non-exploitable CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Found non-exploitable CVE-2014-6277 (lcamtuf bug #1)
Found non-exploitable CVE-2014-6278 (lcamtuf bug #2)


Bash version 4.3.28(2)-release

Variable function parser pre/suffixed [%%, upstream], bugs not exploitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Found non-exploitable CVE-2014-6277 (lcamtuf bug #1)
Found non-exploitable CVE-2014-6278 (lcamtuf bug #2)


Bash version 4.3.29(3)-release

Variable function parser pre/suffixed [%%, upstream], bugs not exploitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Not vulnerable to CVE-2014-6277 (lcamtuf bug #1)
Found non-exploitable CVE-2014-6278 (lcamtuf bug #2)


Bash version 4.3.30(4)-release

Variable function parser pre/suffixed [%%, upstream], bugs not exploitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Not vulnerable to CVE-2014-6277 (lcamtuf bug #1)
Not vulnerable to CVE-2014-6278 (lcamtuf bug #2)


ちなみに、前回アップデートした pidora の /bin/bash はこのような結果です。


Bash version 4.2.48(1)-release

Variable function parser pre/suffixed [(), redhat], bugs not exploitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Not vulnerable to CVE-2014-6277 (lcamtuf bug #1)
Found non-exploitable CVE-2014-6278 (lcamtuf bug #2)


となって、4.3.29 とほぼ同じです。具体的には、以下のような別のテストでワーニングになっています。

(4.3.29)
# env BASH_FUNC_x%%='() { _;}>_[$($())] { echo x;}' /bad/bash43-29 -c :
x

(/bin/bash)
# env 'BASH_FUNC_x()'='() { _;}>_[$($())] { echo x;}' /bin/bash -c :
x

ちなみに、4.3.30 ではこのようになります。

# env BASH_FUNC_x%%='() { _;}>_[$($())] { echo x;}' bash -c :
bash: x: line 0: syntax error near unexpected token `{'
bash: x: line 0: `x () { _;}>_[$($())] { echo x;}'
bash: error importing function definition for `x'
#

# env 'BASH_FUNC_x()'='() { _;}>_[$($())] { echo x;}' bash -c :
#

shellshock を切っ掛けに bash の脆弱性のテストを Pidora で行ってきましたが、Raspberry Pi でも十分テストに利用できますね。
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Pidora における Bash の Shellshock アップデートについて

2014-10-14 01:06:49 | Raspberry Pi
前回 のBash 4.3 patch 28 の修正の後、patch 29 と patch 30 がでました。これを、 patch 28 をコンパイルしたディレクトリ(ここでは ./bash-4.3)に対して適用して、再コンパイルします。Raspberry Pi では、約 13 分でした。

patch 30 以降はパッチが出ていないため、Shellshock 問題は一応収束したようです。

さて、pidora としては、正式ではないですが、「チケット #1402(new defect)」が提供されています。

早速、適用してみます。ちなみに yum localinstall は、rpm ファイルをインストールするためのものです。

# /bin/bash --version | head -1
GNU bash, version 4.2.47(1)-release (armv6hl-koji-linux-gnu)
# cp /bin/bash bad/bash4.2.47
#
# yum localinstall -y http://pidora.ca/pidora/misc/bash-4.2.48-2.fc20.armv6hl.rpm
Loaded plugins: langpacks, refresh-packagekit
bash-4.2.48-2.fc20.armv6hl.rpm | 921 kB 00:14
Examining /var/tmp/yum-root-OYjh84/bash-4.2.48-2.fc20.armv6hl.rpm: bash-4.2.48-2.fc20.armv6hl
Marking /var/tmp/yum-root-OYjh84/bash-4.2.48-2.fc20.armv6hl.rpm as an update to bash-4.2.47-2.fc20.armv6hl
Resolving Dependencies
--> Running transaction check
---> Package bash.armv6hl 0:4.2.47-2.fc20 will be updated
---> Package bash.armv6hl 0:4.2.48-2.fc20 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
Package Arch Version Repository Size
================================================================================
Updating:
bash armv6hl 4.2.48-2.fc20 /bash-4.2.48-2.fc20.armv6hl 3.3 M

Transaction Summary
================================================================================
Upgrade 1 Package

Total size: 3.3 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction (shutdown inhibited)
Updating : bash-4.2.48-2.fc20.armv6hl 1/2
Cleanup : bash-4.2.47-2.fc20.armv6hl 2/2
Verifying : bash-4.2.48-2.fc20.armv6hl 1/2
Verifying : bash-4.2.47-2.fc20.armv6hl 2/2

Updated:
bash.armv6hl 0:4.2.48-2.fc20

Complete!
#
# /bin/bash --version | head -1
GNU bash, version 4.2.48(1)-release (armv6hl-koji-linux-gnu)

となります。これをテストすると、2) すなわち、

env 'x=() { :;}; echo vulnerable' 'BASH_FUNC_x()=() { :;}; echo vulnerable' bash -c "echo test"

が、以下のような結果になる以外は、4.3.30と同じ結果になります。

/bin/bash: warning: x: ignoring function definition attempt
/bin/bash: error importing function definition for `BASH_FUNC_x'
test

これは一応問題ないので、このままこの /bin/bash を利用してもよさそうです。
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Shellshockの検証用シェルスクリプトの動作について その2

2014-10-04 09:52:00 | Raspberry Pi
前回、5種類の Shellshock のテストシェルスクリプトの動作を示しましたが、追加分の動作をまとめてみます。

6) (CVE-2014-6278)
x_func='() { echo vulnerable; }' bash -c x_func



version 4.3.28
bash: x_func: command not found


version 4.2.47
vulnerable


version 4.3.25
vulnerable


version 4.3.26
vulnerable


version 4.3.27
bash43-27: x_func: command not found



7) (CVE-2014-6277、./test005-bad等はシェルスクリプトファイル名)
HTTP_COOKIE="() { x() { _; }; x() { _; } <<`perl -e '{print "A"x1000}'`; }" bash -c :


version 4.3.28 (何も出力されない)

version 4.2.47
./test005-bad: line 6: 4174 Segmentation fault HTTP_COOKIE="() { x() { _; }; x() { _; }


version 4.3.25
./test005-bad25: line 7: 4179 Segmentation fault HTTP_COOKIE="() { x() { _; }; x() { _; }


version 4.3.26
./test005-bad26: line 7: 4186 Segmentation fault HTTP_COOKIE="() { x() { _; }; x() { _; }


version 4.3.27 (何も出力されない)



8) (CVE-2014-7187、4.3は問題ないようです。)
(for x in {1..200} ; do echo "for x$x in ; do :"; done; for x in {1..200} ; do echo done ; done) | bash || echo "CVE-2014-7187 vulnerable, word_lineno"



version 4.3.28(何も出力されない)

version 4.2.47(何も出力されない)

version 4.3.25(何も出力されない)

version 4.3.26(何も出力されない)

version 4.3.27(何も出力されない)


9) (CVE-2014-6278)
x='() { _; } >_[$($())] { echo vulnerable; }' /usr/local/bin/bash -c "echo test"


version 4.3.28
test


version 4.2.47
vulnerable
test


version 4.3.25
vulnerable
test


version 4.3.26
vulnerable
test


version 4.3.27
test



10) (CVE-2014-7186、test009-bad 等はシェルスクリプトファイル名)
bash -c 'true <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF' || echo "CVE-2014-7186 vulnerable, redir_stack"


version 4.3.28
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')
bash: warning: here-document at line 0 delimited by end-of-file (wanted `EOF')


version 4.2.47
./test009-bad: line 7: 4300 Segmentation fault /bin/bash -c 'true <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF'
CVE-2014-7186 vulnerable, redir_stack


version 4.3.25
./test009-bad25: line 7: 4305 Segmentation fault bash43-25 -c 'true <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF'
CVE-2014-7186 vulnerable, redir_stack


version 4.3.26
./test009-bad26: line 7: 4309 Segmentation fault bash43-26 -c 'true <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF'
CVE-2014-7186 vulnerable, redir_stack


version 4.3.27
./test009-bad27: line 7: 4313 Segmentation fault bash43-27 -c 'true <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF <<EOF'
CVE-2014-7186 vulnerable, redir_stack


10番目のテストが、bash 4.3.27 と bash 4.3.28 で動作が異なる場合です。4.3.27 までは Segmentation fault を起こしてしまいます。
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

Shellshock の検証用シェルスクリプトの動作について

2014-10-02 20:11:02 | Raspberry Pi
この記事を書く前に、bash 4.3 patch 28 が出ましたので、先にそちらを示します。

# wget get http://ftp.jaist.ac.jp/pub/GNU/bash/bash-4.3-patches/bash43-028
# wget get http://ftp.jaist.ac.jp/pub/GNU/bash/bash-4.3-patches/bash43-028.sig
# gpg2 --verify bash43-028.sig
gpg: Signature made Thu Oct 2 02:23:01 2014 JST using DSA key ID 64EA74AB
gpg: Good signature from "Chet Ramey <chet@cwru.edu>" [unknown]
gpg: WARNING: This key is not certified with a trusted signature!
gpg: There is no indication that the signature belongs to the owner.
Primary key fingerprint: 7C01 35FB 088A AF6C 66C6 50B9 BB58 69F0 64EA 74AB
#

前回コンパイルしたbash-4.3 ディレクトリに対してこのパッチをあてます。事前に /usr/local/bin/bash は、bash43-27 として待避しておきます。修正ファイルは少ないので、Raspberry Pi でもすぐに再コンパイルできます。

# bash --version | head -1
GNU bash, version 4.3.27(1)-release (armv6l-unknown-linux-gnueabihf)
# cd bash-4.3
# patch -p0 <../bash43-028
patching file parse.y
patching file y.tab.c
Ignoring potentially dangerous file name ../bash-4.3/patchlevel.h
patching file patchlevel.h
# make
....................
# make install 2>&1 | tee Install.log
....................
#
# bash --version | head -1
GNU bash, version 4.3.28(2)-release (armv6l-unknown-linux-gnueabihf)

4.3.28(2)で、(2)となっているのは、一度コンパイルした後で、ソースファイルを修正してコンパイルした回数を表します。patch 27 まであてて一度コンパイルしてから、patch 28 をあてて再コンパイルしたので (2) です。

さて、前回、Shellshock 対策で、bash 4.3 patch 27 をインストールしましたが、ついでに Pidora 2014 のオリジナル /bin/bash と、patch 25 (bash 4.3.25) と patch 26 (bash 4.3.26) も作成して、公開されている 5種類の Shellshock のテストシェルスクリプトの動作をまとめてみました。


1) (CVE-2014-6271)
env 'x=() { :;}; echo vulnerable' bash -c "echo test"

version 4.3.27(1) patch 27 まで bash43-27
test


version 4.2.47(1) Pidora2014 オリジナル版 /bin/bash
vulnerable
test


version 4.3.25(1) patch 25 まで bash43-25
bash43-25: warning: x: ignoring function definition attempt
bash43-25: error importing function definition for `x'
test


version 4.3.26(1) patch 26 まで bash43-26
bash43-25: warning: x: ignoring function definition attempt
bash43-25: error importing function definition for `x'
test



2)
env 'x=() { :;}; echo vulnerable' 'BASH_FUNC_x()=() { :;}; echo vulnerable' bash -c "echo test"

version 4.3.27(1)
test


version 4.2.47(1)
vulnerable
/bin/bash: BASH_FUNC_x(): line 0: syntax error near unexpected token `)'
/bin/bash: BASH_FUNC_x(): line 0: `BASH_FUNC_x() () { :;}; echo vulnerable'
/bin/bash: error importing function definition for `BASH_FUNC_x'
test


version 4.3.25(1)
bash43-25: warning: x: ignoring function definition attempt
bash43-25: error importing function definition for `x'
bash43-25: error importing function definition for `BASH_FUNC_x()'
test


version 4.3.26(1)
bash43-26: warning: x: ignoring function definition attempt
bash43-26: error importing function definition for `x'
bash43-26: error importing function definition for `BASH_FUNC_x()'
test



3) (CVE-2014-7186, ./test001-bad等はシェルスクリプトファイル名)
env 'f=() { :<<a<<b<<c<<d<<e<<f<<g<<h<<i<<j<<k<<l<<m<<n
a
b
c
d
e
f
g
h
i
j
k
l
m
n
}' bash -c 'echo test'


version 4.3.27(1)
test


version 4.2.47(1)
./test001-bad: line 18: 26253 Segmentation fault env 'f=() { :<<a<<b<<c<<d<<e<<f<<g<<h<<i<<j<<k<<l<<m<<n
a
b
c
d
e
f
g
h
i
j
k
l
m
n
}' /bin/bash -c 'echo test'


version 4.3.25(1)
./test001-bad25: line 18: 26270 Segmentation fault env 'f=() { :<<a<<b<<c<<d<<e<<f<<g<<h<<i<<j<<k<<l<<m<<n
a
b
c
d
e
f
g
h
i
j
k
l
m
n
}' bash43-25 -c 'echo test'


version 4.3.26(1)
./test001-bad26: line 18: 26307 Segmentation fault env 'f=() { :<<a<<b<<c<<d<<e<<f<<g<<h<<i<<j<<k<<l<<m<<n
a
b
c
d
e
f
g
h
i
j
k
l
m
n
}' bash43-26 -c 'echo test'



4)
bash -c "export f=1 g='() {'; f() { echo 2;}; export -f f; bash -c 'echo \$f \$g; f; env | grep ^f='"

version 4.3.27(1)
1 () {
2
f=1


version 4.2.47(1)
/bin/bash: g: line 1: syntax error: unexpected end of file
/bin/bash: error importing function definition for `g'
1
2
f=1
f=() { echo 2


version 4.3.25(1)
bash43-25: g: line 1: syntax error: unexpected end of file
bash43-25: error importing function definition for `g'
1
2
f=1
f=() { echo 2


version 4.3.26(1)
bash43-26: g: line 1: syntax error: unexpected end of file
bash43-26: error importing function definition for `g'
1
2
f=1
f=() { echo 2



5) (CVE-2014-7169)
cd /tmp; rm -f /tmp/echo; env 'x=() { (a)=>\' bash -c "echo date"; cat /tmp/echo


version 4.3.27(1)
date
cat: /tmp/echo: No such file or directory


version 4.2.47(1)
/bin/bash: x: line 1: syntax error near unexpected token `='
/bin/bash: x: line 1: `'
/bin/bash: error importing function definition for `x'
Thu Oct 2 12:37:38 JST 2014


version 4.3.25(1)
bash43-25: x: line 1: syntax error near unexpected token `='
bash43-25: x: line 1: `'
bash43-25: error importing function definition for `x'
Thu Oct 2 12:38:09 JST 2014


version 4.3.26(1)
bash43-26: x: line 1: syntax error near unexpected token `='
bash43-26: x: line 1: `'
bash43-26: error importing function definition for `x'
date
cat: /tmp/echo: No such file or directory



今回調べきれなかったので、4.3.27 と 4.3.28 の違いを示すシェルスクリプトは見つかりませんでした。もちろん 4.3.28 は、上述の5つのテストすべて 4.3.27と同じ結果です。

Pidora 2014 と Raspberry Pi でも十分テストや検証ができることが分かります。やはり動作する Linux ディストリビューションの種類も豊富で、SDカード一枚で気軽にOSすら変更できる Raspberry Pi は、1台は手元に置いておきたいマシンですね。
コメント
  • X
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする