Affinity CTF Lite Writeup

この大会は2020/11/17 3:00(JST)~2020/11/18 3:00(JST)に開催されました。
今回もチームで参戦。結果は1116点で690チーム中100位でした。
自分で解けた問題をWriteupとして書いておきます。

Welcome! (OTHER 1)

問題にフラグが書いてあった。

AFFCTF{This_is_just_to_check_if_ALL_is_ok}

DiscOrder (MISC 5)

Discordに入り、#2020-liteチャネルのトピックを見ると、フラグが書いてあった。

Welcome to AFFCTF 2020. Good Flag Hunting!  ```AFFCTF{Pr0p3r_C0ms_aR3_4lways_g00d!}```
AFFCTF{Pr0p3r_C0ms_aR3_4lways_g00d!}

DIGme (OSINT 10)

$ dig -t txt www.affinityctf.com

; <<>> DiG 9.11.3-1ubuntu1.13-Ubuntu <<>> -t txt www.affinityctf.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 58424
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;www.affinityctf.com.		IN	TXT

;; ANSWER SECTION:
www.affinityctf.com.	5	IN	TXT	"QUZGQ1RGe0hlcmUnNXkwdXJUcmVhNXVyZX0="

;; Query time: 117 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Tue Nov 17 22:37:27 JST 2020
;; MSG SIZE  rcvd: 97

あやしいbase64文字列があるので、デコードする。

$ echo QUZGQ1RGe0hlcmUnNXkwdXJUcmVhNXVyZX0= | base64 -d
AFFCTF{Here'5y0urTrea5ure}
AFFCTF{Here'5y0urTrea5ure}

Black Dots (STEGO 10)

小さい白黒のドットの画像ファイルが添付されている。横に白は0、黒は1で2進数にし、デコードする。

from PIL import Image

img = Image.open('image.png').convert('L')
w, h = img.size

bin_flag = ''
for y in range(h):
    for x in range(w):
        v = img.getpixel((x, y))
        if v == 0:
            bin_flag += '1'
        else:
            bin_flag += '0'

flag = ''
for i in range(0, len(bin_flag), 8):
    flag += chr(int(bin_flag[i:i+8], 2))

print flag
AFFCTF{MonochromatiC ThinkinG}

One is missing (STEGO 10)

$ strings full_of__cuteness.jpg | grep AFFCTF
Hidden.txtAFFCTF{HIDDENKITTEN}PK
AFFCTF{HIDDENKITTEN}

Revendless64 (STEGO 30)

逆順にしてbase64デコードすることを繰り返す。

with open('z', 'r') as f:
    data = f.read()

while True:
    try:
        data = data[::-1]
        data = data.decode('base64')
    except:
        break

flag = data[::-1]
print flag
AFFCTF{s1mPle_Rev4s_D0Ne_oNe1}

Char Wrap (FORENSICS 10)

$ strings charwrap
    :
AFFCTF{yH
ou_foundH
_somethiH
ng!}
    :
AFFCTF{you_found_something!}

Shifter Salad (CRYPTO 10)

アルファベットのみシフト数を増やしていく。

import string

enc = 'AGHFXK{5ai5b1cee10z}'

flag = ''
i = 0
for c in enc:
    if c in string.uppercase:
        index = (string.uppercase.index(c) - i) % 26
        flag += string.uppercase[index]
        i += 1
    elif c in string.lowercase:
        index = (string.lowercase.index(c) - i) % 26
        flag += string.lowercase[index]
        i += 1
    else:
        flag += c

print flag
AFFCTF{5ub5t1tut10n}

Hongqiao (CRYPTO 10)

sha1のようなので、CrackStationでクラックする。

AFFCTF{Unimaginatively}

dias skeerG tneicna (CRYPTO 20)

以下の表のような対応になっていると推測し、対応付ける。

  5 4 3 2 1
5 A B C D E
4 F G H I K
3 L M N O P
2 Q R S T U
1 V W X Y Z
※Iの箇所はJになることもある。
554545532245{22434223_4223_42212322_55_234234313551_34553131423344}
A F F C T F {T H I S _I S _J U S T _A _S I M P L E _M A P P I N G }
AFFCTF{THIS_IS_JUST_A_SIMPLE_MAPPING}

BreakMe (CRYPTO 500)

RSA暗号。公開鍵パラメータのnを素因数分解する。

p = 286748798713412687878508722355577911069
q = 300290718931931563784555212798489747397

あとはそのまま復号する。

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

with open('public.pem', 'r') as f:
    pub_data = f.read()

with open('encrypted.txt', 'rb') as f:
    c = bytes_to_long(f.read())

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

p = 286748798713412687878508722355577911069
q = 300290718931931563784555212798489747397

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

復号結果は以下の通り。

Ca1シ隴5蕈 AFFCTF{PermRecord}
AFFCTF{PermRecord}

Collision Course (CRYPTO 500)

100000b以下で、"AFFCTF"が含まれる2つの異なるファイルで、同じmd5になるものをアップロードすればよい。
baseに"AFFCTF"を含めて、fastcollでファイルを作成する。

$ cat base.txt
AFFCTF
$ ./clone-fastcoll/fastcoll base.txt
Generating first block: .....
Generating second block: S10.
use 'md5sum md5_data*' check MD5

md5_data1とmd5_data2をアップロードする。
f:id:satou-y:20201128131524p:plain

Checking, please wait...
String found in the first file
String found in the second file
Checking if files are different...
Files are different
Checking if files are MD5 Hash is the same for both files...
MD5Hashes are the same. You were right. The flag is: AFFCTF{One_Way_Or_Another}
AFFCTF{One_Way_Or_Another}