Slide 1

Slide 1 text

1 SUN CTF 2019 Spring Write-Up 会 Cyber 研究会

Slide 2

Slide 2 text

2 Forensics ● Early summer of university ● Oluri is so cute 【キーワード】 Exif ● Welcome to Cyber Study Group 【キーワード】モールス信号 ● A line of the glay

Slide 3

Slide 3 text

3 Early summer of university 天気の良い日に大学で写真を撮ったよ〜

Slide 4

Slide 4 text

4 Early summer of university SUNCTF{7his_f14g_is_n0t_invisi613}

Slide 5

Slide 5 text

5 Oluri is so cute オオルリは可愛い、サイバー研の小鳥。

Slide 6

Slide 6 text

6 Oluri is so cute Document Name : U1VOQ1RGezAxdXJpX2lzX3c0dGNoaW45X3VzfQo= →BASE64 でデコードすると…… SUNCTF{01uri_is_w4tchin9_us} Exiftool で解析すると……

Slide 7

Slide 7 text

7 Welcome to Cyber Study Group オオルリはいつも、サイバー研に来る人を出迎えてくれる。 今日もまた、彼女の声が聞こえる。「ようこそサイバー研究会へ」

Slide 8

Slide 8 text

8 Welcome to Cyber Study Group Audacity で波形解析をしてみると…… 左チャンネルに ・・ ー ・・・ ーー ーーー ・ー・ ・・・ ・ ー・ー・ ーーー ー・・ ・ → モールス信号で変換すると…… ITSMORSECODE

Slide 9

Slide 9 text

9 A line of the glay 一直線にならぶ灰。そのなかにある、仄かなフラグ。

Slide 10

Slide 10 text

10 A line of the glay 各ピクセルの RGB 値を取ってみると…… R G B 228 228 226 227 227 226 229 229 229 233 233 232 227 227 227 232 232 231 214 214 214 ( 中略 ) 214 214 212

Slide 11

Slide 11 text

11 A line of the glay 上から 7 番目の RGB 値の各値が極端に小さくなっている → ASCII コードでは { の値が英数字に比べて大きいことに着目する → 上から 7 文字は SUNCTF{ であるはずだから、ここで比較して検討する 「 S 」の ASCII コードは 82 、「 { 」の ASCII コードは 123 →RGB 値の各値は 1 番目 ( S ) のほうが 7 番目 ( { ) より大きい → 「引き算を行っているのではないか」という推測が成り立つ → ここで、 RGB 値の各値と 255 との差を取ってみる

Slide 12

Slide 12 text

12 A line of the glay 各値と 255 との差をとってみると…… R G B 合計 ASCII 27 27 29 83 S 28 28 29 85 U 26 26 26 78 N 22 22 23 67 C 28 28 28 84 T 23 23 24 70 F 41 41 41 123 { ( 中略 ) 41 41 43 125 }

Slide 13

Slide 13 text

13 A line of the glay これを Python でプログラムすると…… ( https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/a_line_of_the_glay/src/solver.py ) SUNCTF{614ck_is_my_f4vorit3_c010r}

Slide 14

Slide 14 text

14 Web ● You cannot see the flag! 【キーワード】ヘッダー ● Single Page HTML Viewer 【キーワード】フロントエンドバリデーション ● Cyber Study Group OPAC 【キーワード】 SQL インジェクション

Slide 15

Slide 15 text

15 You cannot see the flag! フラグは見えない。ならば……。 URL にアクセスしても You cannot see the flag! としか書かれていない → ページに表示されている部分にはフラグの文字列がない → 表示されていない部分にフラグの文字列があると考える そこで、 [F12] を押して開発ツールを起動する →[ ネットワーク ] タブを選択し、ページをリロードしてみる

Slide 16

Slide 16 text

16 You cannot see the flag! 応答ヘッダー内にフラグの文字列が記載してある SUNCTF{th3_h34d3r_is_in_th3_sh4d0w}

Slide 17

Slide 17 text

17 Single Page HTML Viewer 配布されている ZIP ファイルを解凍すると、 Dockerfile が含まれている → 中身を確認すると、 /flag というファイルにフラグの文字列が記載されている そこで、フォームの Path に /flag と入力して送信する →Error: Access Denied と表示されてしまう →index.html を見ると、「 flag という文字列が含まれる」もしくは「 .html と いう文字列を含まない」場合は Access Denied を表示していることがわかる HTML ファイルの構造を見られるシングルページアプリケーションを作りました! バリデーションもきちんと施したので、安全なアプリケーションです。

Slide 18

Slide 18 text

18 Single Page HTML Viewer そこで、 query.php に直接アクセスしてみる →{“content”: “

Access Denied<\/p>\n”} と表示される → こちらからアクセスできることがわかった また、 PHP のソースコードもあわせて確認してみる → こちらには「 flag という文字列を含む」 Path であってもバリデーションを 通ることがわかる → ということは、 query.php に直接 /flag という Path を POST すれば良い

Slide 19

Slide 19 text

19 Single Page HTML Viewer {“page”: “/flag”} を持つ JSON を query.php に POST する SUNCTF{fr0nt3nd_va1id4ti0n_is_us3fu1_but_d4ng3r0us}

Slide 20

Slide 20 text

20 Cyber Study Group OPAC サイバー研究会内にある本を検索できる OPAC を構築しました。 脆弱性が存在するかもしれませんが、決して悪用しないでください。

Slide 21

Slide 21 text

21 Cyber Study Group OPAC まず、 SQL インジェクションに対する脆弱性があるか確かめる → 「 a’ OR 1 = ‘1 」という SQL 文を入力する → すべての本が表示されたため、脆弱性があることを確認できた

Slide 22

Slide 22 text

22 Cyber Study Group OPAC フラグの文字列が含まれるテーブルを探したい → 「 a’ UNION SELECT 2,table_name,2,2 FROM INFORMATION_SCHEMA.tables -- 」を入力する → テーブル名が一覧表示される

Slide 23

Slide 23 text

23 Cyber Study Group OPAC flags という名前のテーブルが見つかったので、カラム名を調べる → 「 a’ UNION SELECT 2,column_name,2,2 FROM INFORMATION_SCHEMA.columns WHERE table_name = ‘flags’ -- 」を入力する →flag という名前のカラムが見つかる

Slide 24

Slide 24 text

24 Cyber Study Group OPAC テーブル名とカラムが出揃ったので、フラグを取得する → 「 a’ UNION SELECT 2,flag,2,2 FROM flags -- 」を入力する SUNCTF{b3_c4r3fu1_s91_p4r4m373rs}

Slide 25

Slide 25 text

25 Crypto ● Write a map freely 【キーワード】ブロック暗号 ● Zero and One 【キーワード】 2 進数 ● How do you like wednesday? 【キーワード】シーザー暗号 ● Alice and Bob 【キーワード】 Diffie-Hellman 鍵交換

Slide 26

Slide 26 text

26 Zero and One 暗号化されたフラグが 0 と 1 だけで成り立っている →2 進数であることがわかる ● problem.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/zero_and_one/src/problem.py ● result.txt https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/zero_and_one/result.txt 1011010010110001100110110010001110110100

Slide 27

Slide 27 text

27 Zero and One ● convert_to_ASCII 関数は、与えられた配列から一文字ずつ取り出し、 ASCII コードに変換している ● main 関数では、 convert_to_ASCII 関数から返された配列から一文字ずつ 取り出し、 8 桁の 2 進数に変換して文字列 enc_flag の末尾に結合している → 暗号化されたフラグを 8 桁ずつ取り出し、 ASCII コードに変換したのち、 そこから文字列に戻すことで、フラグを復号できる

Slide 28

Slide 28 text

28 Zero and One SUNCTF{jus7_c0nv3rt_h3x4d3mic41_numb3r_t0_bin4ry_numb3r} solver の一例 solver.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/zero_and_one/src/solver.py

Slide 29

Slide 29 text

29 How do you like wednesday? 変数 rand_int の値によって、フラグの文字列の ASCII コードがずらされている → シーザー暗号を復号する要領と同じく、ずらされた分を元に戻す ● problem.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/how_do_you_like_wednesday/src/problem.py ● result.txt https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/how_do_you_like_wednesday/result.txt お見舞いするぞ!!

Slide 30

Slide 30 text

30 How do you like wednesday? ● 配列 ord_arr には、フラグを配列化した flag_arr から 1 文字ずつ取り出 し、 ASCII コードから変数 rand_int 分引かれたものが挿入されている ● その後 ord_arr の要素を取り出して文字に戻し、文字列にしたの ち、 BASE64 でエンコードしている → 変数 rand_int の値は 1 から 16 であるため、この値を推測することでフラ グを復号することができる

Slide 31

Slide 31 text

31 How do you like wednesday? SUNCTF{0n_ch4n_is_4_p0pul4r_m4sc07_0f_H7B} solver の一例 solver.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/how_do_you_like_wednesday/src/solver.py

Slide 32

Slide 32 text

32 Write a map freely ● problem.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/write_a_map_freely/src/problem.py ● result.txt https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/write_a_map_freely/result.txt さあ地図を書こう、輝く未来へ向けて。 フラグの文字列を 6 文字ずつ分けて 6x6 の正方行列にした後、様々な操作を 行って暗号化している → これを元に戻すようにプログラムを組めば復号できる

Slide 33

Slide 33 text

33 Write a map freely ● 関数 init ではフラグを 6 文字ずつに分けて配列 arr に挿入し、その後の for 文で arr の要素を 1 つずつ取り出して 1 文字ずつ ASCII コードに変換して ord_arr に 挿入し、 ord_arr の要素数が 6 になると、 ord_arr を配列 ord_map に挿入する ● 関数 aki では引数に与えた行列の各要素に対応する m2 の要素を足し合わせ、行 列 m を返り値にもつ ● 関数 asuka では引数に与えた行列の各要素に対し、要素が 2 で割り切れる数で あればその要素を 2 倍し、行列 m を返り値にもつ

Slide 34

Slide 34 text

34 Write a map freely ● 関数 kanako では引数に与えた行列の各要素に対し、要素が 3 で割り切れる数で あればその要素に 9 を足し合わせ、行列 m を返り値にもつ ● 関数 joint では for 文で引数に与えた行列の各行において、 map 関数で要素の 型を int 型から str 型に変換して結合して変数 enc_m の末尾に結合し、 enc_m を返り値にもつ

Slide 35

Slide 35 text

35 Write a map freely ● 与えられた暗号化したフラグを 3 文字ずつ区切る ● 関数 kanako を逆計算するために、配列に含まれる 3 で割り切れる要素から 9 を差し引く ● 関数 asuka を逆計算するために、配列に含まれる 2 で割り切れる要素を 2 で割る ● 関数 aki を逆計算するために、行列 m2 と同様の要素を持つ配列との差を取 る ● 各要素を ASCII コードから文字に戻して文字列の末尾に結合する

Slide 36

Slide 36 text

36 Write a map freely solver の一例 solver.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/write_a_map_freely/src/solver.py SUNCTF{m4pping_c4us3_ch4nge_0f_s3ts}

Slide 37

Slide 37 text

37 Alice and Bob ● problem.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/alice_and_bob/src/problem.py ● result.txt https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/alice_and_bob/result.txt アリスとボブは、秘密のお手紙をやり取りしようとしています。 あなたはアリスの回線を盗聴し、「大切な数字」を手にしました……。

Slide 38

Slide 38 text

38 Alice and Bob Diffie-Hellman 鍵交換について x, p a b A = x ^ a mod p B = x ^ b mod p Ka = B ^ a mod p Kb = A ^ b mod p Ka = Kb = x ^ ab mod p x: 実数 p: 大きな素数 a, b: 秘密の値 Ka, Kb: 鍵

Slide 39

Slide 39 text

39 Alice and Bob もし 2 人の通信を盗聴している人物がいるとしたら…… x, p, A, B 現時点でこれら 4 つから鍵を生成する方法はない

Slide 40

Slide 40 text

40 Alice and Bob 今回は Alice の秘密の値が漏洩している →Bob の identify と Alice の private int から鍵を求められる 共通鍵の求め方は K = B ^ a mod p この鍵を求めて AES 暗号を解くことで、フラグを復号できる

Slide 41

Slide 41 text

41 Alice and Bob solver の一例 solver.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/alice_and_bob/src/solver.py SUNCTF{4lic3_w4nts_t0_ki11_B06_4nd_sh3_w4nts_t0_g3t_his_w341th}

Slide 42

Slide 42 text

42 Misc ● Crash and Splash! 【キーワード】ハッシュ衝突 ● EZ ● Rough PNG Image

Slide 43

Slide 43 text

43 Crash and Splash! 関数 gen_hash で変数 hash に ASCII コードの合計を含んでいる → 同じ合計値になるような文字列の組み合わせを見つける ● problem.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/crash_and_splash/src/problem.py ● result.txt https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/crash_and_splash/result.txt まてまてまてー!とまれー!うごけー! ( サーバルが轢かれる音 )

Slide 44

Slide 44 text

44 Crash and Splash! ● 関数 gen_hash ではフラグの文字列を 1 文字ずつ配列 text_list に代入し、各要 素を ASCII コードに変換し、変数 hash に足し合わせている →ASCII コードの合計が 4541 になるような文字列をフォームに入力する ( 例 )12349DEFGHKMOPQRSTUVWYZ_{}abcdefghijmnopqrstuvwxz

Slide 45

Slide 45 text

45 Crash and Splash! SUNCTF{sprit3_4nd_c0c4_c014_is_v3ry_sp14sh_drink!}

Slide 46

Slide 46 text

46 EZ ● problem.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/ez/src/problem.py ● result.txt https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/ez/result.txt This question is so easy! 与えられた result.txt は BASE64 エンコードされている → 一度デコードしてファイル形式を確かめてみる

Slide 47

Slide 47 text

47 EZ ● BASE64 でデコードするとバイナリが現れる ● file コマンドでバイナリを見てみると zlib で圧縮されていることが分かる → これを zlib で解凍すると BASE64 でエンコードしたファイルが現れる →zlib で圧縮と BASE64 でエンコードを繰り返していると推測できる

Slide 48

Slide 48 text

48 EZ solver の一例 solver.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/ez/src/solver.py SUNCTF{3nc0d3_4nd_c0mpr3ss_4nd_3nc0d3_4nd_c0mpr3ss}

Slide 49

Slide 49 text

49 Rough PNG Image ● problem.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/rough_png_image/src/problem.py ● problem.png https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/rough_png_image/problem.png この PNG 画像はとてもザラザラしている…… 見たところ画像内には赤色と黒色しか存在しない → 赤色のビットがフラグに関わっていると推測できる

Slide 50

Slide 50 text

50 Rough PNG Image 各ビットの値を RGB 値の赤色ビットを抽出すると…… 60 104 116 109 108 62 60 104 101 97 100 62 60 116 ( 中略 ) 110 116 101 110 116 61 34 83 85 78 67 84 70 44 77 105 32 67 84 70 32 50 48 49 57 32 83 112 114 105 110 103 61 34 102 101 116 99 104 105 110 103 34 62 70 101 116 99 49 62 60 112 62 76 111 114 101 109 32 105 112 115 117 109 100 117 110 116 32 117 116 32 108 97 98 111 114 101 32 101 97 118 ( 中略 ) ( 中略 ) 101 115 116 105 111 110 95 105 115 95 109 105 115 99 39 44 116 46 102 108 97 103 61 101 46 102 108 97 103 125 0 0

Slide 51

Slide 51 text

51 Rough PNG Image この表の数字を ASCII コードとして文字に変換すると…… < h t m l > < h e a d > < t ( 中略 ) n t e n t = “ S U N C T F , M i C T F 2 0 1 9 S p r i n g = “ f e t c h i n g “ > F e t c 1 > < p > L o r e m i p s u m d u n t u t l a b o r e e a v ( 中略 ) ( 中略 ) e s t i o n _ i s _ m i s c ‘ , t . f l a g = e . f l a g } →HTML が現れた

Slide 52

Slide 52 text

52 Rough PNG Image solver の一例 solver.py https://raw.githubusercontent.com/siebold-cyber/sunctf-2019-spring/master/rough_png_image/src/solver.py 生成された HTML ファイルを開いてみると…… SUNCTF{H7ML_fi13_c4n_c0nv3rt_t0_PNG_fi13}