[corCTF 2022] whack-a-frog
whack-a-frog
๋๋ฆ ์ฌ๋ฏธ์์๋ forensic ๋ฌธ์ ์๋ค.
๋ฌธ์ ํ์ด์ง๋ฅผ ๋ณด๋ฉด ๋ฌด์ํ ์ฐ๋ฌผ์ ๊ฐ๊ตฌ๋ฆฌ๋ค์ด ๋ค๋ฅผ ๋ฐ๊ฒจ์ค๋ค. ํด๋ฆญํ ์ํ๊ณ ๋๋๊ทธํ๋ฉด ๊ทธ ๊ฒฝ๋ก์ ์๋ ๊ฐ๊ตฌ๋ฆฌ๋ค์ด ์ฐ๋ฌผ ์์ผ๋ก ์จ๋๋ค. ์ด๊ฒ๋ง ๋ด์๋ ๋ฌด์จ ๋ฌธ์ ์ธ์ง ๋ชจ๋ฅด๊ฒ ๋ค.
.pcap ํ์ฅ์๋ผ wireshark๋ก ํ์ผ์ ์ด์ด HTTPํํฐ๋ฅผ ๊ฑธ์๋๋ x, y, event ์ธ์๊ฐ ๋์ด๊ฐ๋ค.
x, y ๋ ๋ง์ฐ์ค์ ์ขํ, event๋ ๋ง์ฐ์ค ํด๋ฆญ ์ฌ๋ถ๋ฅผ ์๋ ค์ฃผ๋ ๊ฒ ๊ฐ๋ค. ํด๋ฆญํ ์ํ๋ก ์ด๋ํ ๊ธธ์ด FLAG๋ฅผ ์ป์ ์ ์์ ๊ฒ ๊ฐ๋ค.
์ด๋ฅผ ์์๋ด๊ธฐ ์ํด ํจํท์ plain text๋ฅผ ์ถ์ถํด์ x, y, event๋ฅผ ํ์ฑํด์ ์ฌ์ฉํ๋ฉฐ ๋ ๊ฒ ๊ฐ๋ค.
ํ์ด์ฌ ์ฒ์ ๋ฐฐ์ธ ๋ ์ ๋ง ์ ๋ฐฐ์ฐ๋์ง ๋ชฐ๋์๋ Python์ turtle ๋ชจ๋๋ก ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋ดค๋ค.
Exploit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import turtle as t
with open("./frog.txt", "r", encoding='UTF8') as f:
data = f.readlines()
f.close()
def parse_text(data): #parse data
x = []
y = []
event = []
for string in data:
if "event" in string:
question_split = string.split("?")[1]
ampersand_split = question_split.split("&")
x.append(ampersand_split[0].split("=")[1])
y.append(ampersand_split[1].split("=")[1])
event.append(ampersand_split[2].split(" ")[0].split("=")[1])
print_flag(x, y, event)
return 0
def print_flag(X, Y, EVENT): #draw FLAG with turtle
t.penup()
for i, j, eve in zip(X, Y, EVENT):
if eve == "mousedown":
t.pendown()
if eve == "mousemove":
t.goto(int(i), -int(j))
if eve == "mouseup":
t.penup()
parse_text(data)
์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํด ๊ทธ๋ฆผ์ ๊ทธ๋ ค๋ณด๋ฉด
์ด๋ ๊ฒ LILYXO ๋ผ๋ ๋ฌธ์์ด์ด ๋ํ๋๋ค. ์ด ๋ฌธ์์ด์ด FLAG์๋ค.
Turtle ๋ชจ๋์ ์ฌ์ฉํ์ง ์๋๋ผ๋ ๋ณ์ฐ๊ธฐ๋ก๋ ํ์ด๊ฐ ๊ฐ๋ฅํ๋ค.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
with open("./frog.txt", "r") as f:
data = f.readlines()
f.close()
def parse_text(data):
x = []
y = []
event = []
for string in data:
if "event" in string:
question_split = string.split("?")[1]
ampersand_split = question_split.split("&")
x.append(ampersand_split[0].split("=")[1])
y.append(ampersand_split[1].split("=")[1])
event.append(ampersand_split[2].split(" ")[0].split("=")[1])
print_flag(x, y, event)
return 0
def print_flag(X, Y, EVENT):
height = 100
width = 700
table = [ [ ' ' for _ in range(width) ] for _ in range(height) ]
mousedown = 1
for i, j, eve in zip(X, Y, EVENT):
if eve == "mousedown":
mousedown = 0
elif eve == "mousemove" and mousedown == 0:
table[int(j)][int(i)] = "*"
elif eve == "mouseup":
mousedown = 1
for j in table:
for i in j:
print(i, end = "")
print("")
parse_text(data)
๊ฐ์ธ์ ์ผ๋ก Turtle graphics๋ฅผ ์ฌ์ฉํ๋๊ฒ ์ข ๋ ํธํ๋ ๊ฒ ๊ฐ๋ค.
๊ทธ๋ฆผ์ ๊ทธ๋ฆด ๋ ๋ฐฐ์ด์ ์ผ์ชฝ ์๋ฅผ (0, 0) ์ผ๋ก ์ฒ๋ฆฌํ๋๋ฐ,
Turtle graphics๋ฅผ ์ด์ฉํ ๋์๋ t.goto(int(i), -int(j)) ์ฒ๋ผ y์ขํ์ -๋ฅผ ๋ถ์ฌ ์์๋ก ์ฒ๋ฆฌํด ์ฃผ์ด์ผ ์ ํํ ๊ทธ๋ฆผ์ด ๊ทธ๋ ค์ง๋ค.
FLAG : corctf{LILYXOX}
