๐ฆ Python XOR Write Up
1. ๋ฌธ์ ํ์ธ ํ ์ฒจ๋ถ ํ์ผ ๋ค์ด๋ก๋
2. ๋ค์ด๋ฐ์ XOR.py ํ์ผ์ ์ด์ด ์ฝ๋ ๋ถ์
from string import punctuation
# ํน์ ๋ฌธ์(punctuation)๋ฅผ ๊ฐ์ ธ์ ์ํ๋ฒณ๊ณผ ํน์ ๋ฌธ์์ ๋ฆฌ์คํธ ์์ฑ
alphabet = list(punctuation)
# ์ํธ๋ฌธ
data = "bHEC_T]PLKJ{MW{AdW]Y"
def main():
ใ
คใ
ค# ๋ณตํธํ ํค ์ ์
ใ
คใ
คkey = ('')
ใ
คใ
ค# ๋ฐ์ดํฐ๋ฅผ ๋ณตํธํํ์ฌ ํ๋ฌธ ์ป๊ธฐ
ใ
คใ
คdecrypted = ''.join([chr(ord(x) ^ ord(key)) for x in data])
ใ
คใ
ค# ๋ณตํธํ๋ ๋ฉ์์ง ์ถ๋ ฅ
ใ
คใ
คprint(decrypted)
# main ํจ์๋ฅผ ์คํํ์ฌ ๋ณตํธํ ์ํ
main()
++ XOR ์ํธํ ํค๊ฐ ๊ณต๊ฐ๋์ง X
--> ์ํธํ ํค๋ฅผ ์์๋ด๊ฑฐ๋, ๋ชจ๋ ๊ฒฝ์ฐ์ ์๋ฅผ ๋์ ํด๋ณด๋ ๋ฐฉ์์ผ๋ก ํ๋ฌธ ๋ณต๊ตฌ ๊ฐ๋ฅ
3. XOR ๋ณตํธํ๋ฅผ ์ํ Python ์คํฌ๋ฆฝํธ ์์ฑ
from string import punctuation
alphabet = list(punctuation)
data = "bHEC_T]PLKJ{MW{AdW]Y"
def decrypt_with_key(key):
ใ
คใ
คdecrypted = ''.join([chr(ord(x) ^ ord(key)) for x in data])
ใ
คใ
คreturn decrypted
def main():
ใ
คใ
คfor possible_key in alphabet: # ๋ชจ๋ ๊ฐ๋ฅํ ํค ์กฐํฉ์ ์๋
ใ
คใ
คใ
คใ
คdecrypted_data = decrypt_with_key(possible_key)
ใ
คใ
คใ
คใ
คprint(f"Key: {possible_key}, Decrypted Data: {decrypted_data}")
main()
++ < Line 1 >
: string ๋ชจ๋์์ ๋ชจ๋ ๊ตฌ๋์ ๋ฌธ์๊ฐ ํฌํจ๋์ด ์๋ punctuation ๋ฌธ์์ด์ ๊ฐ์ ธ์ด
++ < Line 2 ~ 3 >
: punctuation ๋ฌธ์์ด์ ๋ฆฌ์คํธ๋ก ๋ณํํ์ฌ alphabet ๋ณ์์ ์ ์ฅ + ๋ณตํธํํ ๋ฐ์ดํฐ๋ฅผ data ๋ณ์์ ์ ์ฅ
++ < Line 6 ~ 8 >
: XOR ๋ณตํธํ๋ฅผ ์ํํ๋ ํจ์๋ก, ๋ณตํธํ๋ ํ๋ฌธ์ ๋ฐํ
++ < Line 10 ~ 13 >
: alphabet ๋ฆฌ์คํธ์ ๊ฐ ๋ฌธ์๋ฅผ ์ํํ๋ฉด์ ๊ฐ๋ฅํ ๋ชจ๋ ํค ์กฐํฉ์ ์๋ --> ๋ฐ์ดํฐ ๋ณตํธํ ํ decrypted_data ๋ณ์์ ์ ์ฅ๋ ๊ฒฐ๊ณผ๋ฅผ ์ถ๋ ฅ
4. ์์ฑํ Python ์คํฌ๋ฆฝํธ ์คํ --> FLAG ํ์์ ํ๋ฌธ ๋ฐ๊ฒฌ
Key: !, Decrypted Data: Cidb~u|qmjkZlvZ`Ev|x
Key: ", Decrypted Data: @jga}vrnihYouYcFu{
Key: #, Decrypted Data: Akf`|w~sohiXntXbGt~z
Key: $, Decrypted Data: Flag{python_is_e@sy}
Key: %, Decrypted Data: Gm`fzqxuino^hr^dArx|
Key: &, Decrypted Data: Dnceyr{vjml]kq]gBq{
Key: ', Decrypted Data: Eobdxszwklm\jp\fCpz~
Key: (, Decrypted Data: J`mkw|uxdcbSeSiLuq
Key: ), Decrypted Data: Kaljv}tyebcRd~RhM~tp
Key: *, Decrypted Data: Hboiu~wzfa`Qg}QkN}ws
Key: +, Decrypted Data: Icnhtv{g`aPf|PjO|vr
Key: ,, Decrypted Data: Ndiosxq|`gfWa{WmH{qu
Key: -, Decrypted Data: Oehnryp}afgV`zVlIzpt
Key: ., Decrypted Data: Lfkmqzs~bedUcyUoJysw
Key: /, Decrypted Data: Mgjlp{rcdeTbxTnKxrv
Key: :, Decrypted Data: XryengjvqpAwmA{^mgc
Key: ;, Decrypted Data: Ys~xdofkwpq@vl@z_lfb
Key: <, Decrypted Data: ^tychalpwvGqkG}Xkae
Key: =, Decrypted Data: _ux~bi`mqvwFpjF|Yj`d
Key: >, Decrypted Data: \v{}ajcnrutEsiEZicg
Key: ?, Decrypted Data: ]wz|`kbostuDrhD~[hbf
Key: @, Decrypted Data:
;$
Key: [, Decrypted Data: 9 ?
Key: \, Decrypted Data: >''8
&
&9
๏ฟฝ
Key: ^, Decrypted Data: <
% %:
Key: _, Decrypted Data: =๏ฟฝ$$
Key: `, Decrypted Data: (%#?4=0,+*-7!7=9
Key: {, Decrypted Data: 3>8$/&+701๏ฟฝ6,๏ฟฝ:,&"
Key: |, Decrypted Data: 49?#(!,0761+=+!%
Key: }, Decrypted Data: 58>") -1670*<* $
Key: ~, Decrypted Data: 6;=!*#.2543)?)#'
5. ๋ค์ ๋ฌธ์ ํ๋ฉด์ผ๋ก ๋์์ ๋ฐ๊ฒฌํ FLAG ์ ๋ ฅ --> ๋ฌธ์ ํด๊ฒฐ ์ฑ๊ณต
'โ๏ธ Capture The Flag (CTF)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Cake CTF 2023] Country DB - 92 Write Up (0) | 2023.11.11 |
---|---|
[CSAW CTF 2023] Baby's First Write Up (0) | 2023.09.16 |
[DownUnder CTF 2023] ๐ Write Up (0) | 2023.09.04 |
[HSpace CTF 2023] HSpace Free Board Write Up (0) | 2023.09.02 |
[Hero CTF v5] Hyper Loop Write Up (0) | 2023.05.14 |