RC4 ์ํธํ ๊ณผ์
RC4๋ 256 byte ๋น๋ฐํค ๋์นญํค ์๊ณ ๋ฆฌ์ฆ์ผ๋ก, ๋์ผํ ํค๋ฅผ ์ฌ์ฉํ์ฌ ๋ฉ์์ง๋ฅผ ์ํธํํ๊ณ ๋ณตํธํํ๋ค. ์ํธํ ๊ณผ์ ์ KSA(Key Scheduling Algorithm)์ PRGA(Pseudo-Random Generation Algorithm) ๋ ๊ฐ์ง ์ฃผ์ ์๊ณ ๋ฆฌ์ฆ์ผ๋ก ์ด๋ฃจ์ด์ง๋ค.
ํค ์คํธ๋ฆผ ์์ฑ
https://www.youtube.com/watch?v=kfdvlaOD1ig&t=172s
S๋ฐฐ์ด: 0๋ถํฐ 255๊น์ง ๊ฐ์ ๊ฐ์ง.
K๋ฐฐ์ด: key ๊ฐ์ ๊ฐ์ง.
KSA ์๊ณ ๋ฆฌ์ฆ์ ํตํด ํค ์ค์ผ์ค๋ง ์ํ.
PRGA ์๊ณ ์ฆ์ ํตํด ํค์คํธ๋ฆผ ๋์ถ.
์ํธํ
์ํธ๋ฌธ = ํ๋ฌธ xor ํค์คํธ๋ฆผ
๋ณตํธํ
ํ๋ฌธ = ์ํธ๋ฌธ xor ํค์คํธ๋ฆผ
๋ฌธ์ ํ์ด
RC4์์๋ ๋์ผํ key๋ฅผ ์ฌ์ฉํ ๋, ๋์ผํ ํค์คํธ๋ฆผ์ด ์์ฑ๋๋ ๊ฒ์ ์ ์ ์๋ค. ๋, ์ํธ๋ฌธ = ํ๋ฌธ xor ํค์คํธ๋ฆผ ์ด๋ฏ๋ก ํ๋์ ์ํธ๋ฌธ, ํ๋ฌธ ์์ผ๋ก ํค์คํธ๋ฆผ์ ์ ์ ์๋ค.
## ํ๋ฌธ
praw1 = "and now your song is on repeat and i an dancing on to your heartbeat and when you're gone, i fell incomplete so if you want the truth i just wanna be part of your symphony"
plain1 = zlib.compress(praw1.encode())
print(f'{plain1 = }')
## ๋ค์ด๋ก๋ ํ ์ํธ๋ฌธ
encd1 = "79w2m1cCcODPMUDPnb26dT1K1R7LSH6pIX5sqELToLdbJFguTlCLt1qhYjo1n3+/Xn0JjKcOHKdjBtihKAj5c3B42+uTlwBBagyiBIAp++cXV2xzjI8lpC2HT7F1vc7fikGP0EEF+MMPqh7/uZiGqqhHeRQYcdCAqQ=="
cipher1 = base64.b64decode(encd1)
print(f'{cipher1 = }')
## ํค์คํธ๋ฆผ
keystream = bytes([plain1[i] ^ cipher1[i] for i in range(0, len(plain1))])
print(f'{keystream = }')
ํค์คํธ๋ฆผ์ ๊ตฌํ์ผ๋ฏ๋ก flag (= flag์ํธ๋ฌธ xor ํค์คํธ๋ฆผ)๋ฅผ ๊ตฌํ ์ ์๋ค.
encd_flag = '79xw2pGnwu5JGddMSGhq02ZfYmmJOwoVULyEJPHDaw=='
enc_flag = base64.b64decode(encd_flag)
press_flag = bytes([enc_flag[i] ^ keystream[i] for i in range(0, len(enc_flag)) ])
flag = zlib.decompress(press_flag)
print(flag)
์ฐธ๊ณ
https://minseosavestheworld.tistory.com/173
https://www.piolink.com/kr/service/Security-Analysis.php?bbsCode=security&vType=view&idx=90
'๐ดโโ ๏ธ CTF ๐ดโโ ๏ธ > ๐งฎ ์ํธํ ๐งฎ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Dream Hack - Crypto] Double DES (0) | 2024.05.29 |
---|---|
[Dream Hack - Crypto] Padding Oracle (0) | 2023.12.29 |
[Dream Hack - Crypto] Pyploit (2) | 2023.12.18 |
[Dream Hack - Crypto] [LINE CTF 2021] babycrypto1 (2) | 2023.12.12 |
[Dream Hack - Crypto] X-Time Pad (0) | 2023.12.09 |