ペンギン技術 blog

CTFのWriteupなどを記載していこうと思います

SECCON Beginners CTF 2022 Writeup

SECCON Beginners CTF 2022
https://score.beginners.azure.noc.seccon.jp
のWriteupです
3問しか解けていませんが・・・

misc

H2

capture.pcapがあり、その中からフラグを探す

問題には以下のようなgo言語のスクリプト(一部のみ抜粋)が添付されていたため、
プロトコルhttp2で絞込を行い、送信元ポート番号8080で、レスポンス部分のみで絞り込んだ
その後、wiresharkの機能で"x-flag"を検索したところ、フラグが見つかった

func main() {
  handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    if r.URL.Path == SECRET_PATH {
      w.Header().Set("x-flag", "<secret>")
    }
    w.WriteHeader(200)
    fmt.Fprintf(w, "Can you find the flag?\n")
  })

  h2s := &http2.Server{}
  h1s := &http.Server{
    Addr:    ":8080",
    Handler: h2c.NewHandler(handler, h2s),
  }

wireshark

crypto

CoughingFox

以下のスクリプトで暗号化されたフラグを渡される

from random import shuffle

flag = b"ctf4b{XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}"

cipher = []

for i in range(len(flag)):
    print (i)
    f = flag[i]
    print (f)
    c = (f + i)**2 + i
    cipher.append(c)

shuffle(cipher)
print("cipher =", cipher)

元のスクリプトを読み、復号スクリプトを作る
結果がシャッフルされているので、べき乗がぴったり戻せる(整数になる)パターンを総当たりで探す

from random import shuffle
import math

flag = b"ctf4b{XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX}"

#フラグ(シャッフル後)
cipherB = [12147, 20481, 7073, 10408, 26615, 19066, 19363, 10852, 11705, 17445, 3028, 10640, 10623, 13243, 5789, 17436, 12348, 10818, 15891, 2818, 13690, 11671, 6410, 16649, 15905, 22240, 7096, 9801, 6090, 9624, 16660, 18531, 22533, 24381, 14909, 17705, 16389, 21346, 19626, 29977, 23452, 14895, 17452, 17733, 22235, 24687, 15649, 21941, 11472]

dic = {1: "A"}  #結果を入れる

#元に戻す処理
cnt = 0
for j in cipherB:  #暗号文の数だけ繰り返す
    for i in range(len(flag)):  #シャッフルされているので、すべての数について総当たりする
        c1 = j - i
        c2 = math.sqrt(c1)
        c3 = c2 - i
        if c3.is_integer():  #整数かどうか(位置が一致し、復号できる場合のみ)
            # iは元の位置 iの番号順に答えを並べなおすと、フラグが出てくる
            # asciiコードに戻す
            dic[i] = chr(int(c3)) #結果を追加する
        cnt +=1

#キーで並び替えする
dic2 = sorted(dic.items())

# listの右側(値)だけ取り出し
for v in dic2:
    print(v[1], end='')  #改行なしで出力
print('')
$ python3 rev_problem2.py
ctf4b{Hey,Fox?YouCanNotTearThatHouseDown,CanYou?}

reversing

Quiz

stringsコマンドで見てみる

$ strings quiz
:
ctf4b{w0w_d1d_y0u_ca7ch_7h3_fl4g_1n_0n3_sh07?}
Welcome, it's time for the binary quiz!
Q1. What is the executable file's format used in Linux called?
    Linux
    1) ELM  2) ELF  3) ELR
:

実行結果

$ ./quiz
Welcome, it's time for the binary quiz!
ようこそ、バイナリクイズの時間です!

Q1. What is the executable file's format used in Linux called?
    Linuxで使われる実行ファイルのフォーマットはなんと呼ばれますか?
    1) ELM  2) ELF  3) ELR
Answer : 2
Correct!

Q2. What is system call number 59 on 64-bit Linux?
    64bit Linuxにおけるシステムコール番号59はなんでしょうか?
    1) execve  2) folk  3) open
Answer : 1
Correct!

Q3. Which command is used to extract the readable strings contained in the file?
    ファイルに含まれる可読文字列を抽出するコマンドはどれでしょうか?
    1) file  2) strings  3) readelf
Answer : 2
Correct!

Q4. What is flag?
    フラグはなんでしょうか?
Answer : ctf4b{w0w_d1d_y0u_ca7ch_7h3_fl4g_1n_0n3_sh07?}
Correct! Flag is ctf4b{w0w_d1d_y0u_ca7ch_7h3_fl4g_1n_0n3_sh07?}