Odyssey
Description
Author: @HuskyHacks
Remember reading The Odyssey in high school? Well I sure don’t, because I never did my homework. But I really wanted to get back into the classics and give it a fair shake. The problem is I have a fourth grade reading level and that book is waaaaaay too long.
To solve this, I made a server that reads out tiny chunks of The Odyssey, one at a time, so I can take my time reading it! How is Odysseus gonna get himself out of this one?
Solution
So reading the description says it all, we have a long file to read, and we are prompted to read it section by section. Pressing ENTER will advance to the next section. As shown below:
To interact with the server and automate the process, we can use the pwn
module in Python. To sum up, this script will be simulating pressing ENTER
to advance to the next section of the book, and once we find the flag, it will break out of the loop and print the flag once it is found. Here is the script we called odyssey.py
:
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
from pwn import *
import re
conn = remote('challenge.nahamcon.com', 30617)
flag_pattern = re.compile(r'flag\{[0-9a-f]{32}\}')
while True:
try:
data = conn.recvuntil(b'Press enter to continue...\n', timeout=1)
if data:
print(data.decode('utf-8'))
match = flag_pattern.search(data.decode('utf-8'))
if match:
print(f"Flag found: {match.group(0)}")
break
)
conn.sendline('')
except EOFError:
print("Server closed the connection.")
break
except Exception as e:
print(f"Error: {e}")
break
conn.close()
Here is another version using the socket
module instead of pwn
module:
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
import socket
def solve_challenge():
host = "challenge.nahamcon.com"
port = 31795
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((host, port))
while True:
data = s.recv(4096).decode('utf-8')
if not data:
break
print(data)
if 'flag{' in data.lower() or 'ctf{' in data.lower():
print("\n[+] Flag found!")
return
s.send(b'\n')
print("[-] Reached end of transmission without finding flag")
if __name__ == "__main__":
Running our script using python:
1
> python3 odyssey.py
Flag
flag{0b51aae6b09b85d1bb13b0b8c3003a6a}