๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœ’๏ธ Capture The Flag (CTF)

[Hero CTF v5] Hyper Loop Write Up

by A Lim Han 2023. 5. 14.

# Hyper Loop Write Up

 

1. ๋ฌธ์ œ ํ™•์ธ ํ›„ ์ฒจ๋ถ€ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ  -->  ์ œ๊ณต๋œ Python ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์›๋ž˜ ํ”Œ๋ž˜๊ทธ๋ฅผ ๋ณต๊ตฌํ•˜๋Š” ๋ฌธ์ œ์ž„์„ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค.

 

 

 

 

2. hyper_loop.py ํŒŒ์ผ์„ ์—ด์–ด ์ฝ”๋“œ ๋ถ„์„

from os import urandom


flag = bytearray(b"Hero{????????????}")
assert len(flag) == 18

for _ in range(32):
    for i, c in enumerate(urandom(6) * 3):
        flag[i] = flag[i] ^ c

print(f"{flag = }")


"""
$ python3 hyper_loop.py 
flag = bytearray(b'\x05p\x07MS\xfd4eFPw\xf9}%\x05\x03\x19\xe8')
"""

--> 18๋ฐ”์ดํŠธ ๊ธธ์ด์˜ ํ”Œ๋ž˜๊ทธ ๋ฌธ์ž์—ด์„ ์ƒ์„ฑํ•˜๊ณ , 32๋ฒˆ ๋ฐ˜๋ณต. ๊ฐ ๋ฐ˜๋ณต์—์„œ 18๋ฐ”์ดํŠธ ๋ฌธ์ž์—ด์˜ ๊ฐ ๋ฌธ์ž๋ฅผ 6๋ฐ”์ดํŠธ ๊ธธ์ด์˜ ๋‚œ์ˆ˜๋ฅผ 3๋ฒˆ XOR ์—ฐ์‚ฐํ•˜์—ฌ ๋ณ€ํ˜•ํ•˜๋Š” ์ฝ”๋“œ

+ ์ตœ์ข…์ ์œผ๋กœ๋Š” ๋ณ€ํ˜•๋œ ์ƒํƒœ์˜ 18๋ฐ”์ดํŠธ ๋ฌธ์ž์—ด์ด ์ถœ๋ ฅ

 

 

 

 

3. ๋ฌธ์ œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• ํƒ์ƒ‰

: ํ”Œ๋ž˜๊ทธ ๋ฌธ์ž์—ด์˜ ์ผ๋ถ€๋ถ„์ธ "Hero{" ์€ ๋ณ€ํ˜•๋˜์ง€ ์•Š์€ ์ƒํƒœ  -->  ์ด ๋ถ€๋ถ„์„ ํ™œ์šฉํ•˜์—ฌ ํ‰๋ฌธ์„ ๋ณต๊ตฌํ•  ์ˆ˜ ์žˆ์Œ

+  ์ฃผ์–ด์ง„ '์ฝ”๋“œ์˜ 32๋ฒˆ ๋ฐ˜๋ณต'๊ณผ ๋™์ผํ•œ ๋ฐฉ์‹์œผ๋กœ 12๋ฐ”์ดํŠธ์˜ ๋ฌธ์ž์—ด์„ 6๋ฐ”์ดํŠธ ๊ธธ์ด์˜ ๋‚œ์ˆ˜๋ฅผ ์ด 2๋ฒˆ XOR ์—ฐ์‚ฐํ•˜๋ฉด ์•”ํ˜ธ๋ฌธ์„ ํ•ด๋…ํ•  ์ˆ˜ ์žˆ์Œ

 

 

 

 

4. ํ‰๋ฌธ ๋ณต๊ตฌ๋ฅผ ์œ„ํ•œ ์Šคํฌ๋ฆฝํŠธ Lets_Solve.py ์ž‘์„ฑ

from os import urandom

encrypted_flag = bytearray(b'\x05p\x07MS\xfd4eFPw\xf9}%\x05\x03\x19\xe8')
assert len(encrypted_flag) == 18

for _ in range(32):
    for i, c in enumerate(urandom(6) * 3):
        encrypted_flag[i] = encrypted_flag[i] ^ c

flag = str(encrypted_flag).replace("\\x", "").replace("'", "")
print("Hero{" + flag + "}")

โ‘  ์•”ํ˜ธํ™” ๋œ ํ”Œ๋ž˜๊ทธ๋ฅผ ๊ฐ€์ ธ์˜ค๊ณ , ์ƒ์„ฑํ•œ ์•”ํ˜ธํ™” ํ‚ค๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ํ•ด๋‹น ํ”Œ๋ž˜๊ทธ๋ฅผ ๋‹ค์‹œ XOR ๋ฐฉ์‹์œผ๋กœ ์•”ํ˜ธํ™”

โ‘ก ๋ฃจํ”„๋Š” ์ด 32๋ฒˆ ๋ฐ˜๋ณต๋˜๋Š”๋ฐ, ๊ฐ ๋ฃจํ”„์—์„œ urandom(6) ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋ฉฐ ๊ธธ์ด๊ฐ€ 6์ธ ๋žœ๋ค ๋ฐ”์ดํŠธ ์‹œํ€€์Šค ์ƒ์„ฑ

โ‘ข ์‹œํ€€์Šค๊ฐ€ 3๋ฒˆ ๋ฐ˜๋ณต๋  ๋™์•ˆ ๊ฐ ๋ฐ”์ดํŠธ๋Š” ์ด์ „์— ์•”ํ˜ธํ™”๋œ ํ”Œ๋ž˜๊ทธ์™€ XOR ์—ฐ์‚ฐ ์ˆ˜ํ–‰

 

+ ์ธ์ฝ”๋”ฉ ๊ณผ์ •์—์„œ ๊ณ„์† ์—๋Ÿฌ๊ฐ€ ๋‚ฌ์œผ๋‚˜, ๊ฒฐ๊ตญ ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜์ง€ ๋ชปํ•˜์˜€๋‹ค.

 

 

'โœ’๏ธ Capture The Flag (CTF)' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

[DownUnder CTF 2023] ๐• Write Up  (0) 2023.09.04
[HSpace CTF 2023] HSpace Free Board Write Up  (0) 2023.09.02
[PwnMe CTF 2023] Tree Viewer WriteUp  (0) 2023.05.07
[PwnMe CTF 2023] Just a XOR WriteUp  (0) 2023.05.06
[UMass CTF 2023] wrathsweatingbuddha WriteUp (Unsolved)  (0) 2023.03.25