Learn raw socket programming with OverTheWire Vortex, manipulating binary data in Python to solve network-based challenges.
Walkthrough
Level 0 - Raw socket receive/send
import socket
import struct
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('vortex.labs.overthewire.org', 5842))
res = 0 # final result to send
for i in range(0, 4): # we expect 4 numbers
data = s.recv(4) # each number is an unsigned int, which takes 4 bytes
print('raw', data)
iData = struct.unpack('I', data)[0] # convert from byte to int (I)
res += iData # add to final result
s.sendall(struct.pack("I", res)) # send result as bytes, converted from an int (I)
print(s.recv(1024))
('raw', '\x076\xc6*')
('raw', '(BJ%')
('raw', '\xe2\x83\xbbt')
('raw', '\x0b\x1a9\r')
Username: vortex1 Password: Gq#qu3bF3
Going further
- Linux training with overthewire [Part 7/10: Krypton 1-5]: the previous wargame
- Crack & Hack cheatsheet: enumeration and exploitation commands