[corCTF 2022] whack-a-frog
나름 재미있었던 forensic 문제였다. 덕분에 Python 파일 관련 문법을 좀 익힐 수 있었던 것 같다.
문제 페이지를 들어가보면 무수한 우물한 개구리들이 나를 반겨준다. 클릭한 상태로 드래그하면 그 경로에 있는 개구리들이 우물 속으로 숨는다. 이것만 봐서는 무슨 문제인지 모르겠으니 첨부파일을 확인해 보았다.
pcap 확장자라 wireshark로 파일을 열어 HTTP필터를 걸었더니 x, y, event인자가 넘어간다.
x, y는 마우스의 좌표, event는 마우스 클릭 여부를 알려주는 것 같다. 주어진 길을 따라가면서 표시를 해주면 FLAG를
얻을 수 있을 것 같다.
이를 위해 필터링된 패킷들을 plain text로 추출해서 x, y, event를 파싱하여 사용하면 될 것 같다.
파이썬 처음 배울 때 정말 왜 배우는지 몰랐었던 Python의 turtle 모듈로 그림을 그려봤다.
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 모듈을 사용하지 않더라도 해당 위치에 '*'을 출력해주는 방법으로도 풀이가 가능하다.
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)
개인적으론 Turtel Graphic을 사용하는게 좀 더 편했던 것 같다.
그림을 그릴 때 배열은 왼쪽 위를 (0, 0) 으로 처리하는데, Turtle Graphics는 정 중앙을 (0, 0)으로 처리하기 때문에 Turtle Grapics를 이용할 때에는 t.goto(int(i), -int(j)) 처럼 y좌표에 -를 붙여 음수로 처리해주어야 정확한 그림이 그려진다.