247CTF - My Magic Bytes

Socket challenge requiring automation to solve 500 arithmetic problems programmatically. Use Python with pwntools to interface with the remote service and automate the solution.

Key Considerations

  • Library: pwntools for socket communication
  • Custom delimiter: Uses \r\n instead of standard \n
  • Approach: Parse math expressions dynamically and compute answers

Solution

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
import pwn

HOST = "7a3875d00fa5d462.247ctf.com"
PORT = 50337

pwn.context.log_level = "info"
pwn.tube.newline = b"\r\n"


def solve_challenge():
conn = None
try:
conn = pwn.remote(HOST, PORT)

for i in range(500):
conn.recvuntil(b"answer to ")
question_line = conn.recvline().decode().strip()
expression = question_line.replace("?", "")
result = int(eval(expression))
conn.sendline(str(result).encode())
pwn.log.info(f"Progress: [{i + 1}/500] Solved: {expression} = {result}")

pwn.log.success("500 problems solved! Waiting for flag...")
conn.interactive()

except Exception as e:
pwn.log.error(f"An error occurred: {e}")

finally:
if conn:
pwn.log.info("Connection closed.")
conn.close()


if __name__ == "__main__":
solve_challenge()

Execution Output

1
2
3
4
5
6
7
8
❯ python tcp_auto.py
[+] Opening connection to 7a3875d00fa5d462.247ctf.com on port 50337: Done
...
[*] Progress: [499/500] Solved: 221 + 474 = 695
[*] Progress: [500/500] Solved: 4 + 449 = 453
[+] 500 problems solved! Waiting for flag...
[*] Switching to interactive mode
247CTF{flag_here}