[CTF Writeup / Misc] LA CTF 2024 - gacha

[CTF Writeup / Misc] LA CTF 2024 - gacha



안녕하세요. 이번 글에서는 LA CTF 2024에 출제된 Misc 문제 gacha의 writeup을 작성해보도록 하겠습니다.


문제 설명








All my friends have been getting into genshin and honkai recently and keep sending me pictures. However, they keep hiding their favorite characters, demanding for more money for their gacha pulls.

Can you free zhongli my waifu???


문제 설명이고, package.sh 파일과 이미지 파일이 첨부되어 있습니다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
dd if=/dev/urandom ibs=1 count=128 > secret.key
rm -rf chall
mkdir -p chall
cp img/fiscl.png chall/
 
# add flag to uwu
magick img/uwu.png \
    -weight 50000 -fill red -pointsize 96 \
    -draw "text 50,540 '`cat flag.txt`'" \
    PNG24:flag.png
 
magick img/owo.png -encipher secret.key chall/owo.png
magick flag.png -encipher secret.key chall/uwu.png
rm flag.png
 
rm -f chall.zip
zip -9r chall.zip chall/
 
cs

package.sh


sh 코드를 보면, uwu.png와 owo.png가 동일한 secret.key로 암호화 되어 있고, uwu.png에는 flag가 추가되어 있습니다.


owo.png uwu.png

owo.png와 uwu.png는 위와 같이 알아볼 수 없게 되어 있습니다.


exiftool로 확인해보니 Ciphernonce가 동일하고 CTR 모드로 암호화되어 있어, uwu.png 파일과 owo.png 파일을 XOR 연산 하면 secret.key가 사라지고 원본 이미지의 XOR 된 이미지가 나오게 됩니다.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
from PIL import Image
import numpy as np
 
image_a = Image.open("chall/owo.png")
image_b = Image.open("chall/uwu.png")
 
array_a = np.array(image_a)
array_b = np.array(image_b)
 
xor_result = np.bitwise_xor(array_a, array_b)
 
result_image = Image.fromarray(xor_result)
 
result_image.save("chall/result.png")
cs

파이썬 코드를 실행하면 result.png 파일이 생성됩니다.


FLAG











result.png를 확인해보니 FLAG가 있습니다.



lactf{zh0ng_l7_x_ch7ld3_b4t_w7th_x0r}




댓글