fuu32のブログ

精進記録

OtterCTF writeup

ちょうどwireshark/tsharkの使い方を練習していたのでnetworkの問題だけ解きました。
Otterとはカワウソのことらしい(ちなみにsea otterはラッコ(へー

目次

Birdman's Data

問題文
「We recorded some of BirdMan's networking, but a part of it (the important part) got scrambled.」
pcapファイルが与えられるのでwiresharkを用いてみていく。 まずはProtocol Hierarchyをみてどのような通信かを大雑把に把握する。 次に、HTTPが使われているので、HTTPでフィルターをかけてHTTP streamを覗いてみる。

クライアントがwww.txtwizard/net/cryptoに対してGETのリクエストし、レスポンスとしてページの情報が返されている。f:id:fuu32:20181211210422p:plain このサイトは暗号化や復号をしてくれるサイトらしい。

HTTP streamの最後の2つのやり取りではクライアントが平文を送って、それが暗号化されて返ってきている。クライアントのリクエストがPOST /crypto/AES/encrypt/CBC/PKCS5 とあり暗号の種類と使用されたモードまで分かった。

AES暗号の説明は(詳しくないので)割愛するがCBCモードなのでkeyとIV(初期化ベクトル)があれば復号できそう。 HTMLの中に以下の記述があったのでどこを見ればいいのか判別がついた。 (目grepしても分かるけど疲れそう)

        function onEncrypt(token) {
            var target = $('#encryptTarget').val();
            var key = $('#encryptKey').val();
            var iv = $('#encryptIv').val();
            var result = $('#encryptResult');
            var divAlert = $('#encryptAlert');
            var algorithm = $('#encryptAlgorithm').val();
            var mode = $('#encryptMode').val();
            var padding = $('#encryptPadding').val();

            $.ajax({
                type: 'POST',
                cache: false,
                url: '/crypto/' + algorithm + '/encrypt/' + mode + '/' + padding,
                data: { plainText: target, key: key, iv: iv, token: token },
                dataType: 'json',
                async: true,
                beforeSend: function(jqXHR, settings) {
                    divAlert.text("").hide();
                    result.text('');
                },
                success: function (data, textStatus, jqXHR) {
                    result.text(data.cipherText);
                    return;
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    divAlert.text(jqXHR.responseText).show();
                    return;
                }
            });
        }

暗号文とkey,IVが手に入ったので、先ほどのサイトで復号してみると以下のような平文が手に入る。

Chance Something's wrong, I can feel it (Six minutes, Slim Shady, you're on) Just a feeling I've got, like something's about
To happen, but I don't know what If that means, what I think it means, we're in trouble, big trouble, And if he is as bananas as you say, I'm not taking any chances You were just what the doctor ordered I'm beginning to
Feel like a Rap God, Rap God All my people from the front to the back nod, back nod Now who thinks their arms are long
{
Enough to slap box, slap box? They said I rap like a robot, so call
me Rapbot But for me to rap like a computer must be
in my genes I got a laptop in my back pocket My pen'll go off when I half-c*** it Got a fat knot from that rap profit Made a living and a killing off it Ever since Bill Clinton was still in office With Monica Lewinsky feeling on his
Nut-sack I'm an MC still as honest But as rude and indecent as all hell syllables, killaholic (Kill 'em all with) This slickety, gibbedy, hibbedy hip hop You don't really wanna get into a pissing match with this rappidy rap Packing a Mac in the back of the Ac, pack backpack rap, yep, yackidy-yac The
exact same time I attempt these lyrical acrobat stunts while I'm practicing That I'll still be able to break a
Motherf***in' table Over the back of a couple of
_
Faggots and crack it in half
Only
Realized it was ironic I was signed to Aftermath after the fact How could I not blow? All I do is drop F-bombs, feel my wrath of attack Rappers are having a rough time period, here's a Maxipad It's actually disastrously bad For the wack while I'm masterfully constructing this masterpiece as I'm beginning to feel
_
Like a Rap God, Rap God All my people from the front to the back nod, back nod Now who thinks their arms are long enough to slap box, slap box? Let me show you maintaining this s*** ain't that hard, that hard Everybody want the key and the secret to rap
immortality like I have got Well, to be truthful the blueprint's simply rage and youthful exuberance Everybody loves to root
for a nuisance Hit the
Earth like an asteroid, did nothing but shoot for the moon since MC's
_
get taken to school with this music Cause I use it as a vehicle to bust a rhyme Now I lead a new school full of students Me? I'm a product of Rakim, Lakim Shabazz, 2Pac N- -W.A, Cube, hey, Doc, Ren, Yella,
Eazy, thank you, they got Slim Inspired
enough to one day grow up, blow up and be in a position To meet Run DMC and induct them into the motherf***in' Rock n' Roll Hall of Fame Even though I walk in the church and burst in a ball of flames Only Hall of Fame I be inducted in is the alcohol of fame On the wall of shame You fags think it's all a game 'til I walk a flock of flames Off of planking, tell me what in the f*** are you thinking? Little gay looking boy So gay I can barely say it with a straight face looking boy You witnessing a massacre Like you watching a church gathering take place looking boy Oy vey, that boy's gay, that's all they say looking boy You get a thumbs up, pat on the back And a way to go from your label everyday looking boy Hey, looking boy, what you say looking boy? I got a "hell yeah" from Dre looking boy I'mma work for everything I have Never ask nobody for s***, get outta my face looking boy Basically boy you're never gonna be capable To keep up with the same pace looking boy 'Cause I'm beginning to feel like a Rap God, Rap God All my people from the front to the back nod, back nod The way I'm racing around the track, call me Nascar, Nascar Dale Earnhardt of the trailer park, the White Trash God Kneel before General
zorb
}

明らかに改行がおかしいのでいい感じに幅を変えてエスパーすると文頭を縦読みしたのがFlagだと分かる。 CTF{EmiNeM_FOR_LifE_gEez} (ちなみにこの平文はEminemの歌詞らしい。)

Look At Me

問題文
「My otter played with my PC while I was recording...」

pcapファイルが与えられる。wiresharkで開くとUSBの通信の記録みたいだ。 どこかのwriteup記事でマウスの軌道を記録していて、それを復元するそうなものを見たことがあったのでこの問題もその類だと思った。 まずは、どのようなディバイスなのか知りたい。 それにはこのサイトが役に立つと思う。 CTF Series : Forensics — tech.bitvijays.com

GET SEDCRIPTOR Response DEVICパケットを見るとベンダーと製品が判明する。f:id:fuu32:20181211212519p:plain

どうやらWacomタブレットのようだ。過去のwriteupを漁ると同じことをしている記事があったのでここからはそちらを参考にして解いている。

BITSCTF – Tom and Jerry (50 points) – tunelko.

まず、不要と思われるデータをフィルタ機能で排除。

((usb.transfer_type==0x01)&&(frame.len==37))

ここではLengthが37のパケットが多かったのでそれを残す形をとった。 次にleftover capture dataについて、これは実際のデータでありそれ以上でもそれ以下でもない(らしい Analysing USB traffic - Wireshark Q&A) なのでleftover capture dataからタブレットのどの位置に書かれたのかが分かりそう。 このタブレットの場合、leftover capture dataは全体で10bytesあり以下のフォーマットをとる。

header X Y Pressure suffix
02:f0 b4:0f b6:17 00:00 20:00

このX,Y,Pressureの値を抽出して、描画すればFlagがわかるだろう。 ここからはtshark(wiresharkCUI版)を用いてデータを加工していく。 tsharkのオプションは tshark - The Wireshark Network Analyzer 2.6.5を参照。

tshark -r new.pcapng -T fields -e usb.capdata -Y usb.capdata > extracted.txt

これでleftover capture dataの部分がテキストファイルに書き込まれている。 -r で読み出すファイルを指定し、-T で出力するテキストのフォーマットを指定し、-eは-T でfieldsを指定した時に出力したいフィールドを指定している。-Yは指定したフィールドで絞り込みを行うオプションである。 次に以下のコマンドを実行する。 参考にしたサイトには

First tries were frustrated because little endian representation. We need to extract positions 3,4 for X and 5,6 for Y but first we must somehow swap those bytes. So first, filter with awk magic interesting data:

って書いてあるけれど、リトルエンディアンだから順番をいい感じにしなければいけないみたい?

awk -F: '{x=$3$4;y=$5$6}{z=$7}$1=="02"{print x,y,z}' extracted.txt > hex 

ここでは':'区切りで3,4番目のフィールドをXに、5,6番目のフィールドをYに7番目のフィールドをZに代入し、$1(headerの値)が"02"なら出力する形をとっている。

X,Y,Pressureのデータが得られたので、以下のようなスクリプトを書いて実行する。

#!/usr/bin/python
from pwn import *

for i in open('hex').readlines():
    ii = i.strip().split(' ')
    x = int(ii[0],16)
    y = int(ii[1],16)
    z = int(ii[2],16)

    if z > 0:
        print u16(struct.pack(">H",x)),u16(struct.pack(">H",y))
$ python solver2.py > output.txt
$ gnuplot 
gnuplot> plot "output.txt"
gnuplot> 

そうすると期待通りタブレットに書かれた文字を復元することができた。
f:id:fuu32:20181211225758p:plain
pngでダウンロードして convert -flip output.png output.png をすれば見やすくなる。 f:id:fuu32:20181211225941p:plain CTF{0TR_U58}

Otter Leak

問題文
「We found out that one of the Otters been leaking information from our network! Find the leaked data. Format: CTF{flag all uppercase}」

pcapファイルが与えられる。wiresharkで開いてprotocal Hierarchyをみるとこんな感じ。f:id:fuu32:20181211231824p:plain ん〜smb2が怪しそう。smbはwindowsネットワークでのファイル共有プロトコルらしいが、詳細や仕様などは他の記事に任せるとしてとりあえずオブジェクトをエクスポートしてみる。File->Export Objects->SMBでいくつかのファイルが保存できるだろう。

fileコマンドで調べるとほとんどのファイルは very short file (no magic)が返ってきて、実際に中身を見ることができるのでそれらすべての中身を表示させると下のようになる。

$ cat * 
LS0gLS0tLS0gLi0uIC4uLi4uIC4gLS0tIC0gLS0uLi4gLi4uLS0gLi0uIC4uIC0uIC0uLi4gLS4uLi4gLi4uLi0=

どう見てもbase64エンコードされてそうなのでデコードしてみる。

$ echo "LS0gLS0tLS0gLi0uIC4uLi4uIC4gLS0tIC0gLS0uLi4gLi4uLS0gLi0uIC4uIC0uIC0uLi4gLS4uLi4gLi4uLi0=" | base64 -d 
-- ----- .-. ..... . --- - --... ...-- .-. .. -. -... -.... ....-

この溢れ出るトンツー感、モールス信号だと思ったので復号した。(https://morsecode.scphillips.com/translator.html) CTF{M0R5EOT73RINB64}

感想

あと一問残っていたけれど、時間内にときれなくて残念。個人的には2問目が面白かった。 色々遠回りして解いたので必要そうな部分を選んで書いたけれど、writeup書くの疲れて後半にかけて雑になってしまった。文章作成能力を上げていきたい。間違いや疑問があったらご指摘ください。