๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๐Ÿด‍โ˜ ๏ธ CTF ๐Ÿด‍โ˜ ๏ธ/๐Ÿงฎ ์•”ํ˜ธํ•™ ๐Ÿงฎ

[Dream Hack - Crypto] likeb64

๋ฐ˜์‘ํ˜•

Base64 ์ •๋ฆฌ

Base64๋Š” 6๋น„ํŠธ์”ฉ ๋ฌถ์–ด์„œ ์ธ์ฝ”๋”ฉ ํ‘œ์— ๋”ฐ๋ผ ํŠน์ • ๋ฌธ์ž๋กœ ๋งคํ•‘๋ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ 3๋ฐ”์ดํŠธ(24๋น„ํŠธ)์˜ ๋ฐ์ดํ„ฐ๋ฅผ 4๊ฐœ์˜ Base64 ๋ฌธ์ž๋กœ ์ธ์ฝ”๋”ฉํ•ฉ๋‹ˆ๋‹ค.

์œ—์ค„์ด ๋น„ํŠธ์— ๋Œ€์‘๋˜๋Š” Ascii ์ฝ”๋“œ ๋ฌธ์ž์—ด, ์•„๋žซ์ค„์ด Base64 ํ‘œ์— ํ•ด๋‹นํ•˜๋Š” ์ธ์ฝ”๋”ฉ๋œ ๋ฌธ์ž์—ด์ž…๋‹ˆ๋‹ค. Base64๋Š” 3๋ฐ”์ดํŠธ์”ฉ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ, ์›๋ณธ ๋ฐ์ดํ„ฐ์˜ ๋ฐ”์ดํŠธ ๊ธธ์ด๊ฐ€ 3์˜ ๋ฐฐ์ˆ˜๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ํŒจ๋”ฉ์„ ์ถ”๊ฐ€ํ•˜๊ณ  ‘=’ ์œผ๋กœ ๋‚˜ํƒ€๋ƒ…๋‹ˆ๋‹ค.

 

ํ’€์ด ๋ฐฉ๋ฒ•

flag_enc: IREHWYJZMEcGCODGMMbTENDDGcbGEMJZGEbGEZTFGYaGKNRTMIcGIMBSGRQTSNDDGAaWGYZRHEbGCNRQMUaDOMbEMRTGEYJYGUaWGOJQMYZHa===

hint : ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef

ํžŒํŠธ๊ฐ€ 32๊ฐœ์˜ ๋ฌธ์ž์—ด์ธ ๊ฒƒ์„ ๋ณด๊ณ  5bit๋ฅผ ๋ฌถ์–ด์„œ ์ธ์ฝ”๋”ฉํ•˜๋Š” ๊ฒƒ์ด ์•„๋‹๊นŒ ์ถ”์ธกํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

ํ”Œ๋ž˜๊ทธ ํ˜•์‹์ด DH{…} ์ผ ๊ฒƒ์ด๋ฏ€๋กœ ์œ„์˜ ๊ฐ€์ •์— ํž˜์„ ์‹ค์„ ์ˆ˜ ์žˆ๋‹ค.

 

ํ’€์ด ์ฝ”๋“œ

flag_enc = "IREHWYJZMEcGCODGMMbTENDDGcbGEMJZGEbGEZTFGYaGKNRTMIcGIMBSGRQTSNDDGAaWGYZRHEbGCNRQMUaDOMbEMRTGEYJYGUaWGOJQMYZHa==="
chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
flag_binary = ""

# Base32 Table ์ƒ์„ฑ 
# {A:0, B:1, C:2, ... }
base32_table = {char : bin(i)[2:].zfill(5) for i, char in enumerate(chars)}

# flag_enc ๋ฅผ bit ์—ด๋กœ ๋ณ€ํ™˜
for i in range(0, len(flag_enc)) : 
    if flag_enc[i] == "=" :
        flag_binary += "00000"
    else :
        flag_binary += base32_table.get(flag_enc[i])

# bit ์—ด์„ 8bit ์”ฉ ascii ์ฝ”๋“œ๋กœ ๋ณ€ํ™˜
flag_ascii = [ chr(int(flag_binary[i : i+8],2)) for i in range(0, len(flag_binary), 8)]

FLAG = "".join(flag_ascii)
print(FLAG)

 

๋ฐ˜์‘ํ˜•