CTF/CCE 2021

[Clear] CCE 2021 ptmd Writeup

Vardy 2021. 9. 27. 19:11

제공되는 서버에 nc로 접속하면 +,-,*,/ 연산이 주어진다. 짧은 제한시간안에 100문제를 해결해야 플래그가 나온다.

python pwntools를 활용하여 수식을 분석하고 답을 전송하는 코드를 통해 플래그 획득이 가능하다.

from pwn import *
import base64
import binascii
import sys

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


p=remote("20.194.123.97", 11111)
i=0
while(i<101) :
    if i==100 :
        print(p.recvall())
        break
    firstline = p.recvuntil('>>')
    print(firstline)
    x = firstline.split(b'\n')[-2].split(b' ')[0].decode('utf-8')
    y = firstline.split(b'\n')[-2].split(b' ')[2].decode('utf-8')
    z = firstline.split(b'\n')[-2].split(b' ')[4].decode('utf-8')
    p.send(calc(int_or_float(x), int_or_float(y), int_or_float(z)))
    i += 1
    print(i)
    #print(p.recvuntil('>>'))
p.close()

주의할점은 수식에 소수가 활용되는 경우가 있기 때문에 (1)과 같이 .이 포함될 경우 float으로 형변환을 해주는 과정이 필요하다.

 

FLAG = cce2021{70045baef6c3f6f133fa40824cf8185ac0e9fa3f2874a033f431c6d8f9d4517a07a32b8f3b42816d3c850f9b04441d14d85c87d4f1394427}

 

반응형