CTF/DEF CON CTF Qualifier 2022

[Clear] DEF CON CTF Qualifier 2022 mic check 1 Writeup

Vardy 2022. 6. 1. 22:49

check 문제로 간단한 pwntools 활용 문제가 나왔다. nc로 서버에 접속하면, 나름 복잡한 수식이 주어지는데, 시간 제한이 짧아서 실제 계산해서 답을 제출하기는 불가능에 가깝다.

따라서, pwntools를 활용하여 데이터를 파싱하고, 연산을 수행하여 제출하는 코드를 작성하면 플래그를 반환해준다.

from pwn import *
import base64
import binascii
import sys

def int_or_float(x) : 
    if "." in x :
        return float(x)
    else :
        return int(x)
def calc(x,y,z) :
    x = int(x)
    z = int(z)
    if y == b'+' :
        return x+z
    elif y == b'-' :
        return x-y
    elif y == b'*' :
        return x*y
    elif y == b'/' :
        return x/y
    else :
        print("error")


p=remote("simple-service-c45xrrmhuc5su.shellweplayaga.me", 31337)
i=0
while(i<101) :
    if i==100 :
        print(p.recvall())
        break
    if i==0 :
        firstline = p.recv(1024)
        print(firstline)
        p.send(b'ticket{WaterlineBoat4662n22:EXaWuOTYEMx7sGV8DyBIWBSYLrkS-K8IPvT3INIA44Sz40VF}\n')
        i +=1
        pass
    line = p.recv(1024)
    print(line)
    x = line.split(b' ')[0].decode('utf-8')
    y = line.split(b' ')[1]
    z = line.split(b' ')[2].decode('utf-8')
    print(x) 
    print(y)
    print(z)
    result = calc(x,y,z)
    result_to_byte = str(result).encode('utf-8')
    print(result_to_byte)
    print(type(result_to_byte))
    p.send(result_to_byte+b'\n')
    
    i += 1
p.close()
반응형