UUT CTF Writeup

この大会は2019/4/25 22:30(JST)~2019/4/28 22:30(JST)に開催されました。
今回もチームで参戦。結果は1374点で441チーム中15位でした。
自分で解けた問題をWriteupとして書いておきます。

Web WarmUp (Web 10)

HTMLソースにこう書いてあった。

<!-- Flag -->
<p style="color:rgba(255, 0, 0, 0.001);">The Flag is: UUTCTF{P0SCon: Welcome to UUTCTF! Happy hacking ;)}</p>
UUTCTF{P0SCon: Welcome to UUTCTF! Happy hacking ;)}

Solve the Crypto (Crypto 25)

Fermat法でnを素因数分解できるので、そのまま復号する。

from Crypto.PublicKey import RSA
from Crypto.Util.number import *

def isqrt(n):
    x = n
    y = (x + n // x) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

def fermat(n):
    x = isqrt(n) + 1
    y = isqrt(x * x - n)
    while True:
        w = x * x - n - y * y
        if w == 0:
            break
        elif w > 0:
            y += 1
        else:
            x += 1
    return x - y, x + y

with open('pub.key', 'r') as f:
    pub_data = f.read()

pubkey = RSA.importKey(pub_data)
n = pubkey.n
e = pubkey.e

with open('enc.message', 'rb') as f:
    c = bytes_to_long(f.read())

p, q = fermat(n)

phi = (p - 1) * (q - 1)
d = inverse(e, phi)
m = pow(c, d, n)

flag = long_to_bytes(m)
print flag

実行結果は以下の通り。

Nfsタ・"xァリF・オx。縲・゚モ繃E゙碵・jョ哮ウV・イ轄L4ウチ抄[レラ靕農イ籟・メ-Dォ。「ミfuuoク_ーDnエ+μェセ枻ク⊇Mー SGllcl9pc3RfZGVpbmVfRmxhZ2dl

だが、そのままフラグにはならず、最後の方にBase64文字列があるので、デコードする。

$ echo SGllcl9pc3RfZGVpbmVfRmxhZ2dl | base64 -d
Hier_ist_deine_Flagge
UUTCTF{Hier_ist_deine_Flagge}

Break the RSA (Crypto 50)

Fermat法でnを素因数分解できるので、そのまま復号する。

from Crypto.Util.number import *

def isqrt(n):
    x = n
    y = (x + n // x) // 2
    while y < x:
        x = y
        y = (x + n // x) // 2
    return x

def fermat(n):
    x = isqrt(n) + 1
    y = isqrt(x * x - n)
    while True:
        w = x * x - n - y * y
        if w == 0:
            break
        elif w > 0:
            y += 1
        else:
            x += 1
    return x - y, x + y

n = 114869651319530967114595389434126892905129957446815070167640244711056341561089
e = 113
c = 102692755691755898230412269602025019920938225158332080093559205660414585058354

p, q = fermat(n)

phi = (p - 1) * (q - 1)
d = inverse(e, phi)
m = pow(c, d, n)

flag = long_to_bytes(m)
print flag
UUTCTF{easy sH0Rt RSA!!!}

Find the Word Flag (Forensics 75)

word\document.xmlのスペース数がばらばらで不自然。最大14くらいなので、2つでASCIIコード(16進数2桁)になると予測して、デコードする。

codes = [0x55, 0x55, 0x54, 0x43, 0x54, 0x46, 0x7b, 0x4d, 0x65, 0x61, 0x6e, \
    0x69, 0x6e, 0x67, 0x66, 0x75, 0x6c, 0x47, 0x61, 0x58, 0x73, 0x7d]

flag = ''
for code in codes:
    flag += chr(code)

print flag
UUTCTF{MeaningfulGaXs}

The Criminal (Forensics 150)

pcapファイルが与えられている。NetworkMinerで開き、Filesを見てみる。
No.90296にfl4g.7z.x-7z-compressedがあるので抽出する。この7zファイルはパスワードがかかっている。
No.88888にsecret_password-1024x64.pngがあるので、抽出する。
f:id:satou-y:20190430155343p:plain
ヒントにパスワードは小文字であることが記載されているので、それを念頭に画像に書いてあるパスワードを読み取る。さらに拡大して画像をよく見ると、Dの中の文字はDになっていて、PASSWORDのOの中の文字は0、FORの中の文字はOになっていることに気を付け、パスワードを読み取る。

this_is_th3_s3cr3t_passw0rd_for_flag

このパスワードで通った。解凍し展開したflag.txtにフラグが書いてあった。

UUTCTF{d0_n0t_sav3_pa$$word_in_public}