CTF for BBA

ゲーム時々CTFやるBBAの日常。

setodaNote CTF 復習編

折角なので解けなかった一部の問題にトライしていくエントリです。

Misc

i_knew_it

アセンブリで書かれたRC4は見た瞬間分かるか - yasulib memo

こちらのブログが元ネタらしい。
私はまだちょっと見た目ではわかってないです。。

flag{RC4}


Network

Digdig

DNSトンネリングの問題。
サブドメインをHEXにすると、フラグの断片のようなものが得られたものの、いくつか組み合わせてみても正解できず。
"Dummy flag"などの言葉も出てきたり、問題名もdigなので、方向性が違うのかと思って競技期間中は諦めてしまった。

改めてサブドメインのみを抜き出してみると、下記のように、[005aa] + [001から始まる数字] + [ASCIIコード]となっている。

005aa002735f69735f44414d
005aa00663655f7472795f53
005aa0034d595f464c41477d
005aa0085f746861747d2066
005aa00a6c61677b444e535f
005aa00b5333637572313779
005aa0076f7272795f666f72
005aa00420666c6167206973
005aa0096c61672069732066
005aa00c5f5431303731217d
005aa011797d323232323232
005aa00d20666c6167206973
005aa00f335f6b33795f3135
005aa00e20666c61677b3768
005aa001666c61677b546869
005aa0105f35336375723137
005aa000666c616720697320
005aa00520666c61677b4e69


[001から始まる数字]でソートし、文字列部分のみ抜き出す。

with open("temp.txt") as f:
     lines = f.readlines()
lines.sort(key = lambda x:x[5:8])
lines2 = [x[8:].strip() for x in lines]
hex_txt = ''.join(lines2)
print(bytes.fromhex(hex_txt))


すると下記のようになり、このうちの一つがフラグ。

b'flag is flag{This_is_DAMMY_FLAG} flag is flag{Nice_try_Sorry_for_that} flag is flag{DNS_S3cur17y_T1071!} flag is flag{7h3_k3y_15_53cur17y}222222'

flag{DNS_S3cur17y_T1071!}


Logger

USB通信データ。
Leftover Capture Dataの3バイト目が変化している。

ctf:lesson:第3回 [情研Wiki]


こちらのエントリで勉強したところ、"Leftover Capture Data"の3バイト目はキーボード入力に対応しているとのこと。
ググるといくつかUSBキーボードとの対応表が出てくるが、正確にやるならusb.orgドキュメンテーションのHID usageを読むのが良いのかも。
下記のページで勉強中。

USB HID Usage ID の Scancode 変換と対応するキー | capyBaral

また、こちらのエントリによると、最初の2バイトが0x20なら右シフトキー(0x02なら左シフト)が押された状態であるとのこと。

Decoding Mixed Case USB Keystrokes from PCAP


それを踏まえて、flagっぽい部分を読み取ると下記。

09 f
0f l
04 a
0a g
2f {
14 Q
1a W
08 E
2d _
0e k
08 e
1c y
05 b
27 0
04 a
15 r
07 d
2d _
15 R
17 T
1c Y
30 }


flag{QWE_keyb0ard_RTY}


tkys_not_enough

wiresharkで開けない。
バイナリエディタで見てみると、NetTrace.etlという文字が見え、netsh traceで取られたパケットキャプチャファイルであることが推察される。
f:id:boxwolf:20210908165005p:plain

【Windows】netsh trace コマンドによるパケットキャプチャ(採取/解析/変換方法) | クラブロ

上記のエントリに従って、Windows Network Monitorでetlファイルからcapファイルに変換すると、Wiresharkで開けるようになる。

Wiresharkで開くと、500番ポートに対してhttp通信している。
このうち、/Z29GbGFn.htmlからのレスポンスを見ると(gzip圧縮されているため、RAW形式で保存し、該当部分を切り出して解凍)

I'm going to practice making origami cranes so that I can fold them for you some day, okay?


flag{netw0rk_shell_2000}


flag{netw0rk_shell_2000}


Web

Mx.Flag

ソースを見てみると、images/favicon.pngassets/css/style.cssが読み込まれている。
このうち、faviconの方がうまく表示されない。

// flag{Mr_Flag_hiding_in_the_favicon}
console.table({place: "favicon.png", png: "false", flag: "true", Look: "me"});


テキストエディタで開いてみるとなんとフラグが書いてある。

flag{Mr_Flag_hiding_in_the_favicon}


Redirect

ソースの一番下部に不審なscriptがある。

<script>!function(){var ref = document.referrer;var domain = ref.match(/^http([s]?):\/\/([a-zA-Z0-9-_\.]+)(:[0-9]+)?/)[2];if(domain == "www.google.com" || domain == "www.google.co.jp" ){location.href = atob('aHR0cHM6Ly9jdGYuc2V0b2Rhbm90ZS5uZXQvd2ViMDA0L2JXRnNhMmwwLmh0bWw=');}}();</script>


googleから飛んできた場合に、別の場所にリダイレクトするscriptらしいというのはわかったが、Refererヘッダを設定しては動かん…と悩んで詰まった。
document.referrerRefererヘッダを参照しているわけではなく、ブラウザによって値がセットされるということに後から気づいた。
(考えてみれば当然っちゃ当然)

なので、一つひとつリダイレクトの流れを追っていく必要がある。
まずは上記にBase64エンコードされて記載されているhttps://ctf.setodanote.net/web004/bWFsa2l0.htmlcurlで取得してみると、

<!DOCTYPE HTML>
<html>
  <head>
    <title>start</title>
    <noscript>
      <meta http-equiv=refresh content="1; URL=https://ctf.setodanote.net/web004/noscript.html">
    </noscript>
    <script>
      !function() {
        var params = new URL(window.location.href).searchParams;
        if(Array.from(params).length > 0){
          location.href = 'https://ctf.setodanote.net/web004/bm9mbGFn/?'+params;
        }else{
          location.href = 'https://ctf.setodanote.net/web004/bWFsa2l0.html?callback=wantFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200';
        }
      }();
    </script>
  </head>
  <body>
    <p>Find out the flag.</p>
  </body>
</html>

クエリなしなので、次はhttps://ctf.setodanote.net/web004/bWFsa2l0.html?callback=wantFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200

<!DOCTYPE HTML>
<html>
  <head>
    <title>start</title>
    <noscript>
      <meta http-equiv=refresh content="1; URL=https://ctf.setodanote.net/web004/noscript.html">
    </noscript>
    <script>
      !function() {
        var params = new URL(window.location.href).searchParams;
        if(Array.from(params).length > 0){
          location.href = 'https://ctf.setodanote.net/web004/bm9mbGFn/?'+params;
        }else{
          location.href = 'https://ctf.setodanote.net/web004/bWFsa2l0.html?callback=wantFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200';
        }
      }();
    </script>
  </head>
  <body>
    <p>Find out the flag.</p>
  </body>
</html>

今度はクエリがあるので、https://ctf.setodanote.net/web004/bm9mbGFn/?callback=wantFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200

<html>
  <head>
    <title>Next</title>
    <noscript>
      <meta http-equiv=refresh content="1; URL=https://ctf.setodanote.net/web004/noscript.html">
    </noscript>
    <script>
      !function() {
        var params = new URL(window.location.href).searchParams;
        location.href = 'https://ctf.setodanote.net/web004/bmV4dG5leHQ/?'+params
      }();
      </script>
  </head>
  <body>
  <p>No flag here. Go to next.</p>
  </body>
</html>

次はhttps://ctf.setodanote.net/web004/bmV4dG5leHQ/?callback=wantFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200

<html>
  <head>
    <title>Next-Next</title>
    <noscript>
      <meta http-equiv=refresh content="1; URL=https://ctf.setodanote.net/web004/noscript.html">
    </noscript>
    <script>
      !function() {
        var params = new URL(window.location.href).searchParams;
        location.href = 'https://ctf.setodanote.net/web004/b25lLXR3by10aHJlZQ/?'+params
      }();
      </script>
  </head>
  <body>
  <p>No flag here too. Go to next.</p>
  </body>
</html>

次。https://ctf.setodanote.net/web004/b25lLXR3by10aHJlZQ/?callback=wantFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200

<html>
  <head>
    <title>Branching point</title>
    <noscript>
      <meta http-equiv=refresh content="1; URL=https://ctf.setodanote.net/web004/noscript.html">
    </noscript>
    <script>
      !function() {
        var params = new URL(window.location.href).searchParams;
        if (params.get('callback') == 'getFlag') {
          location.href = 'https://ctf.setodanote.net/web004/dGFjaGlrb21hX2thd2FpaV95b25l/?' + params;
    }else{
          location.href = 'https://ctf.setodanote.net/web004/ZGFtbXlmbGFn/?' + params;
    }
      }();
      </script>
  </head>
  <body>
  <p>You need the correct parameters to get the flag.</p>
  </body>
</html>

お、callback=getFlagなら別のところに飛びそう。ということで、https://ctf.setodanote.net/web004/dGFjaGlrb21hX2thd2FpaV95b25l/?callback=getFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200

<html>
  <head>
    <title>GO!GO!GO!</title>
    <noscript>
      <meta http-equiv=refresh content="1; URL=https://ctf.setodanote.net/web004/noscript.html">
    </noscript>
    <script>
      !function() {
        var params = new URL(window.location.href).searchParams;
        var callback = params.get('callback');
        var data1    = params.get('data1');
        var data2    = params.get('data2');
        var data3    = params.get('data3');
        var data4    = params.get('data4');
        if (callback == 'getFlag' && data1 == "2045" && data2 =="0907" && data3 == "BiancoRoja" && data4 =="1704067200") {
          location.href = 'https://noisy-king-d0da.setodanote.net/?'+params;
    }else{
      location.href = 'https://ctf.setodanote.net/web004/ZGFtbXlmbGFn/hint.html?'+params;
    }
      }();
      </script>
  </head>
  <body>
  <p>Yes! Go to next.</p>
  </body>
</html>

指定されたパラメータと共にhttps://noisy-king-d0da.setodanote.net/?callback=getFlag&data1=2045&data2=0907&data3=BiancoRoja&data4=1704067200にアクセスすると、フラグが降ってくる。

flag{Analyz1ng_Bad_Red1rects}


OSINT

tkys_eys_only

競技中は、左上の40.75N 73.98Wばかり見ていて詰んでいた。

URLの方に入力されている座標(40.749444-73.968056)の方を見なければならなかった。
google mapで上記座標を検索すればよい。国連事務局ビル。

flag{United_Nations}


N-th_prime

720575940379279362^56であることはググってすぐわかったが、そこで止まってしまった。

こちらのページに2のべき乗番目の素数が載っている。

mersenneforum.org - View Single Post - Riemann, Goldbach does not know!

また、こちらのツールで計算してもよかったらしい。

github.com


flag{2991614170035124397}


secret_operation

画像にあるURL(https://green-pond-97ff.setodanote.net/)に普通にアクセスすると、Country: JPと表示される。
そこで、画像と同じCityにあるロシアのフリープロキシを設定してアクセスすると、下記のような感じに。
f:id:boxwolf:20210908225728p:plain
プロキシは下記で探した。

Russia Proxy Server List - Russian Proxies


下部のLinkを押すと別ページに飛ぶが、BASIC認証を求められる。
なので、まずは@aarron142857について調べてみると、下記のツイートをいいねしている。
f:id:boxwolf:20210908230504p:plain

そこで、下記のツイートの画像をzipにして解凍すると、中から更にpngが出てくる。
f:id:boxwolf:20210908230651p:plain

f:id:boxwolf:20210908231121p:plain

Username: J.S
Password: right_next_to_you

上記認証情報でログインすると、フラグ画面。
f:id:boxwolf:20210908231456p:plain

このテクニックは勉強になったなぁ。

flag{=we_can_change_tomorrow=}


Crypto

lets_bake

bakeと書いてあるのでCyberChefだろうというのは競技中に気づいたが、解けなかった。
セパレータが]b2[かと思っていたら、]b2[sだったらしい。

]b2[sをセパレータとしてbase64デコードすると、CyberChefのレシピが出てくるので、inputをその通りにbakeすればよい。

From_Base64('A-Za-z0-9+/=',true)
From_Hex('None')
Fork('%','_',false)
RC4({'option':'UTF8','string':'chef'},'Latin1','Latin1')

f:id:boxwolf:20210908184141p:plain
flag{hello_baked_cipher}


WEARECIA

We are CIA という意味で、下記を示しているらしい。

クリプトス - Wikipedia

問題文の前半部分はK1と同一。これは特殊なヴィジュネル暗号らしい。

The Kryptos Sculpture Solutions

上記の表を見ながら手作業で解読したが、オンラインツールでも使用するアルファベットが指定できるのでできる模様。な、なんだってー

Vigenere Cipher - Online Decoder, Encoder, Solver, Translator


Between subtle shading and the absence of light lies the nuance of iqlusion
Flag is we are the nations first line of defense


flag{WEARETHENATIONSFIRSTLINEOFDEFENSE}