Tips and Tricks (beginner tutorial)

PUBLISHED ON 11/04/2020 — EDITED ON 24/04/2020 — 247CTF, INFOSEC
#!/usr/bin/env python3

URL="b488472d0611f3e7.247ctf.com"
PORT=50393

from pwn import *

# Connect to the server
conn = remote(URL,PORT)

# b'Welcome to the 247CTF addition verifier!\r\n'
print(conn.recvline())

# b'If you can solve 500 addition problems, we will give you a flag!\r\n'
print(conn.recvline())

for i in range(500):
    # What is the answer to 158 + 64?
    s = conn.recvline().decode("utf-8")

    a = int(s.split()[5])
    b = int(s.split()[7].strip('?'))

    # Send result
    result = (str(a+b)).encode("utf-8")
    conn.sendline(result) # sendline() automatically adds '\r\n'

    # b'Yes, correct!\r\n'
    print(conn.recvline())

# Get the flag answer at the end
print(conn.recvline())

conn.close()

See Also