UMassCTF 2022 Writeup

この大会は2022/4/2 7:00(JST)~2022/4/4 7:00(JST)に開催されました。
今回もチームで参戦。結果は248点で314チーム中221位でした。
自分で解けた問題をWriteupとして書いておきます。

quickmaths (misc)

$ nc 34.148.103.218 1228
You must solve 1000 of these math problems that are outputted in the following format {number} {operation} {number} to get the flag. 
Division is integer division using the // operator. 
The input is being checked through python input() function. 
Good luck! 

46 * -28

四則演算の問題が1000問出題されるので、計算はevalに任せ答えていく。

#!/usr/bin/env python3
import socket

def recvuntil(s, tail):
    data = b''
    while True:
        if tail in data:
            return data.decode()
        data += s.recv(1)

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('34.148.103.218', 1228))

data = recvuntil(s, b'luck! \n').rstrip()
print(data)
data = recvuntil(s, b'\n').rstrip()
print(data)

for i in range(1000):
    print('Round %d' % (i + 1))
    data = recvuntil(s, b'\n').rstrip()
    print(data)
    ans = eval(data)
    print(ans)
    s.sendall(str(ans).encode() + b'\n')
    data = recvuntil(s, b'\n').rstrip()
    print(data)

data = recvuntil(s, b'\n').rstrip()
print(data)

実行結果は以下の通り。

You must solve 1000 of these math problems that are outputted in the following format {number} {operation} {number} to get the flag.
Division is integer division using the // operator.
The input is being checked through python input() function.
Good luck!

Round 1
29 + 98
127
  :
Round 996
80 * 96
7680
Correct!
Round 997
6 * 85
510
Correct!
Round 998
8 * 11
88
Correct!
Round 999
51 // 56
0
Correct!
Round 1000
-57 // -15
3
Correct!
UMASS{s3v3naten1n3}
UMASS{s3v3naten1n3}