Excerpt here…

This post is part of a series:

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)
('raw', '\x076\xc6*')
('raw', '(BJ%')
('raw', '\xe2\x83\xbbt')
('raw', '\x0b\x1a9\r')
Username: vortex1 Password: Gq#qu3bF3