Plaid CTF 2012 参加記

日本からの参加チームは、次の通りでした。

  • 24位 Tachikoma 1689点
  • 38位 sutegoma2 1096点
  • 41位 自分とこ 1047点
  • 50位 p03p0wn 840点
  • 180位 kbb 40点
  • 225位 Alphard 15点
  • 242位 takahashi clan 15点

なかなかよい接戦で、楽しかったです。
また、問題も種類・数ともに多く、それぞれ面白い問題となっていました。
RPGとの複合化も図られており、良質なCTFとは、まさにこれのことか!という感じ。
以下、Writeupが続きます。


Addition is Hard [15] (Puzzles) (199 teams solved this!)


Addition is hard!
0x0 +0x7068703f = ?
Answer in decimal
Hint: Look at pCTF 2011's "Division is Hard" challenge.

0を足しても0x7068703fに決まってるじゃんかー!と思いきや、そうでもない。
ヒントを頼りにググってみると、言語のバグ関係の問題らしい。
しかし、何言語かが分からない。
よーく見ると、0x7068703fというのは、ASCIIコードっぽい。
試しにStirlingで打ってみると、"phpc" となったので、php関係で調べてみると、最近そういうバグfixがあったらしい。

このバグ通りに計算した値がKEYとなる。


The answer is 0x7068703f * 2 = 3771785342
KEY: 3771785342

Editors [100] (Pirating) (25 teams solved this!)


We recently gained access to a log of a robot operative interacting with computer.
We are unsure what he was up to but we know it is of the upmost importance to figure it out.
Hint: 1. In /etc/sudoers, editor=/usr/bin/emacs
2. Try out yourself!
3. By the state of the machine, we mean either 'on' or 'off'.

キーロガーの記録が渡される。いろんなエディタやらWMやらを使った痕跡がある。
次の4つを調べる必要がある。

  • 何回 sudoers の editor を書き換えたか
  • いくつの shell が動作したか
  • 最終的に editor の値はどうなったか
  • コンピュータの状態はどうなっているか(on or off)

Notepad2で見ると、結構綺麗に送られたキーが分かる。(ステマじゃないよw)
tecoもedもscreenもtmuxも使ったことがないので、仮想PCのUbuntuを使って、
実際に操作してみた。screenとかtmuxとか便利じゃん!!(今度から使おう・・。)

実際に操作してみれば分かるけど、ed と emacs によって sudoers は2回書き換えられている。
他のエディタ操作はダミー。editor は、最終的に /usr/bin/teco に書き換えられてる。
ログにある OB や OC はカーソルキー、[3~ はBackspaceキーのキーコード。
teco はリポジトリになかったから、ダウンロードしてきて入れた。
shell の数は、接続元のshell、sshコマンドによる接続先のshell、そこでのrootのshell×分割数4の合計6。
(ずっと4だと思ってて、最初なかなか得点できなかった・・。)
最後の ./exec は、/sbin/poweroff のリンクなので、コンピュータの電源は切れる。

KEY: 2/usr/bin/teco6off

3D [100] (Potpourri) (129 teams solved this!)


The robots appear to be testing some kind of new camera technology but we haven't quite figured it out yet.
Understanding this imaging could be crucial to our understanding the enemy and winning the war.
http://ctf.plaidctf.com/media/files/3d-4e5132069964e0d61c0fbd9099dea498/edbd4701d0b9d2a33a743e96f7bc8f3b

中身をみると、何枚もJPGが入ってる。デジカメ名でググってみると、3D静止画というやつらしい。
PCでなんとか見れないんだろうかと探してみたけど、見つからなかった。
仕方ないので、Stirlingで手動でチマチマ切り出した。w

KEY: 3d_giv35_m3_a_h3adach3

Paste [100] (Practical Packets) (85 teams solved this!)


Robot hackers, like their human counter parts, have a largely unmet need to dump large amounts of text
to their peers. We recently got access to one of their servers and are providing you with the files.
What have they been talking about?
http://23.21.4.176/8f6998e93eb49429e35ff74b2719dc7e/
http://23.21.4.176/8f6998e93eb49429e35ff74b2719dc7e/source.zip

パケットを見てみると、何やらへんなクッキーが大量にある。
さらにソースを見ていくと、cookie.php や make_followup.php に PASTE_ADMIN に関するクッキーの処理が見つかる。
そこで、クッキーを編集して、値を全部TRUEに書き換え。(Chrome Extensionのこいつが便利すぎて嬉しい。)
加えて、display_paste.php を見ていくと、渡した値に ".txt" をつけて require している個所が見つかる。
READMEにあるように、include_url_allow が許可されているとして、試しにサーバに適当なphpをtxtで設置してみる。
結果、それが include されるようになった。("^^http://*****/***" みたいな感じでpostしとけばいい。)


後は、ディレクトリ内のファイルを見てみると、"key.php" があった。
中身を出して、終わり。

KEY: s0m3_php_d3v5_actua11y_d0_th15

ECE's Revenge II [500] (Potpourri) (22 teams solved this!)


Our aerial reconnaissance drones recently sighted these new robot prototypes
but we cannot figure out how to turn them on (INSERT INAPPROPIATE JOKE).
Can you help us solve the mystery and get their electrons flowing?
http://ec2-23-20-214-191.compute-1.amazonaws.com/8f05e96b3986c333240ab1ecf03a2bb2/

これホンマ大変だった。。
ただ回路を読めばいいだけなんだけど。ひたすら解析するだけなんだけど。
写真がとにかく見づらくて、大変だった。
めんどくさいので、Board1とBoard3を解いて、Board2は総当たりしました。
Board3については特に、プログラムコードに落としてチェックもしました。あまり意味はなかった。
各ボードのスイッチの正解は、以下の通り。
米印は、繋がれてないスイッチなので、何でもよい。

  • 101001**
  • 00111***
  • 0100****

最初、スイッチをONにすると電流が流れると勘違いしてて、何度も混乱しました。
電流は、抵抗が少ない方に流れるので、スイッチが接地接続されている場合、
ONにすると電気は本体に流れなくなります(だよね?)。

Congratulations! The key is: 1_pr3f3r_p0tat0_ch1p5

Torrents [200] (Practical Packets) (54 teams solved this!)


It turns out that robots, like humans, are cheap and do not like paying for their movies and music. We were able to intercept some torrent downloads but are unsure what the file being downloaded was. Can you figure it out?
http://ctf.plaidctf.com/media/files/torrent-c8e72ed2b54f8905e76bc12e676db9f7/torrent.pcap

BitTorrentプロトコルなんて知るかー!!できるかーー!!!と思っていたけど、
とりあえずプロトコルの仕様を見てみると、意外と単純でした。
Wiresharkでピアからの受信データのみを生データで保存。
適当なスクリプトC言語で書いて、ファイル化。
mp3が出てきたので、曲名などを打ち込んでみるも、ダメ。
う〜ん?と思ってファイルを舐めてみると、key.txtとかありました。これかー!

    // きたないこーど
    while ( !feof(fp) ) {
        len = fgetc(fp) * 0x1000000 + fgetc(fp) * 0x10000 + fgetc(fp) * 0x100 + fgetc(fp);
        mode = fgetc(fp);
        printf( "Loading... mode: %d\n", mode );
        if ( mode != 7 ) {
            // not piece
            fread( buf, len-1, 1, fp );
            continue;
        }
        place = fgetc(fp) * 0x1000000 + fgetc(fp) * 0x10000 + fgetc(fp) * 0x100 + fgetc(fp);
        printf("%d piece load....\n", place);
        offset = fgetc(fp) * 0x1000000 + fgetc(fp) * 0x10000 + fgetc(fp) * 0x100 + fgetc(fp);
        fseek( outfp, 0x8000 * place + offset, 0 );
        fread( buf, sizeof(char)*len-1-4-4, 1, fp );
        printf( "%2x - %2x\n", buf[0], buf[0x4000-1] );
        fwrite( buf, sizeof buf, 1, outfp );

    }


KEY: t0renz0_v0n_m4tt3rh0rn

The Game [100] (Potpourri) (63 teams solved this!)


Robots enjoy some strange games and we just can't quite figure this one out. Maybe you will have better luck than us.
23.22.16.34:6969

2つの数字が示されて、どっちが大きいか答える問題。
ただし、数字の大小は関係ない模様?
残念ながらこの問題は解く前に時間切れとなってしまったので、真相は分からない。
この問題では、出てくる値がある程度決まっている。
そこで、値を辞書に追加していき、大小関係を記録していく。
それをひたすら繰り返せば、解ける。。と思うんだけど。。
何分、時間切れとなってしまった今となっては、謎のままである。くやしい。

# きたないこーど
#!/usr/bin/env ruby1.9

require 'socket'

anstbl1 = []
anstbl2 = []

s = TCPSocket.open( "23.22.16.34", 6969 )

acnt = 0
smaller = []

while 1
  fst = s.gets
  l1 = s.gets
  l2 = s.gets
  wh = s.gets
  
  cnt = fst.split(" ")[3]
  if cnt.to_i > 50
    print fst
    print l1
    print l2
    print wh
  end
  val1 = l1.split(" ")[3]
  val2 = l2.split(" ")[3]

  decval1 = val1.hex
  decval2 = val2.hex

  flg = 0
  for k in 0..anstbl1.size-1
    if anstbl1[k].to_i == decval1 && anstbl2[k].to_i == decval2
      s.puts("1")
      flg = 1
      break
    elsif anstbl1[k].to_i == decval2 && anstbl2[k].to_i == decval1
      s.puts("2")
      flg = 1
      break
    end
  end
  if flg == 0
    if decval1 > decval2
      s.puts("1")
    else
      s.puts("2")
    end

  end

  log1 = s.gets
  d = s.gets
  log2 = s.gets
  acnt = acnt + 1

  if cnt.to_i > 50
    print log1
    print d
    print log2
  end

def AddHash(a,b)
  f = File.open( "dictionary", "a+" )
  f.write( a.to_s + "\n" + b.to_s + "\n" )
  f.close

end

  if d == "Correct!\n"
    if flg==1
      print "O"
    else
      print "o"
    end
  else
    if flg==1
      print "X\n"
    else
      print "x\n"
    end
    if flg == 0
      if decval1 > decval2
        anstbl1 << decval2
        anstbl2 << decval1
        AddHash( decval2, decval1 )
      else
        anstbl1 << decval1
        anstbl2 << decval2
        AddHash( decval1, decval2 )
      end
    end
  end

  if acnt % 10 == 0
    anstbl1 = []
    anstbl2 = []
    ddt = File.read( "dictionary" )
    ddtar = ddt.split( "\n" )
    0.step( ddtar.size-1, 2 ) do |k|
      anstbl1 << ddtar[k]
      anstbl2 << ddtar[k+1]
    end
  end

  if cnt.to_i >= 74
    print s.gets
    print s.gets
    print s.gets
    print s.gets
    print s.gets
    print s.gets
    print s.gets
    print s.gets
    break
  end

end

s.close
Supercomputer 1 [50] (Pirating) (48 teams solved this!)


Computing one big number is hard, but apparently the robots can do four? Please help us!
What is the first number?
http://ctf.plaidctf.com/media/files/supercomputer-be5a905eda9bc2e60e34cfa6271cce59/supercomputer

これも後少しというところでタイムアップ。
64ビット用のELF実行ファイルだったので、仮想マシンの64bit Backtrack上でいろいろテスト。
実際に動かしてみたり、objdump -d やら ltrace やら使ってみると、
どうやら大量のループ処理が行われている模様。
ループ処理後に、値が正しいかのチェックがあったので、
そのチェック値に書き換えて、ループを強制的に抜けるように書き換えてみたけど、
別の値が正常に生成されず、ダメ。
(objdump -d からコードを見て、該当箇所を stirling で書き換える感じで改変してました。)


で、コードを見ていくと、次のような処理があった。


ループ回数だけループ {
変数A++;
変数B++;
変数C++;
変数D++;
}

ループ回数が増えれば増えるほど、ここの処理がどんどん重くなってしまう。
なので、ループ回数だけ直接足すように書き換えればOK。
あと少しだっただけに、惜しかった。。

考察

大変面白いCTFでした。ここには書いてない問題もたくさん出題されていて、どれも面白くできてます。
RPGとの複合化が斬新でした。これからいろんなCTFが増えていくんでしょうね。
バイナリ解析がとにかく苦手なので、もっといろんなコマンドを使えるようになりたい。
特に gdb は使えるようにならないと、この先生きていけない気がする・・・。

最後に

素敵なCTFをありがとう!!!!!!!!!!!!!!! > ppp
参加者の方々はおつかれさまでしたっ!
一緒に楽しく参加してくれた ada_u さん、ありがとうございましたっ!
また一緒に参加しましょー!