01 / Foundations / 30 min READ + PRACTICE
Python for security experiments.
Practice byte strings, files, exceptions, timeouts, logging, virtual environments and tests.
Bytes are the wire format
A network socket sends bytes, not Python strings. Encode explicitly as UTF-8 when constructing requests and decode received data only when the protocol defines an encoding. Hex output helps when data is not text.
Make failure visible
Use bounded timeouts and catch specific errors. Log host, port and a concise failure reason without recording credentials or raw session cookies. Prefer context managers for files and sockets so resources close even when an experiment fails.
payload = 'hello lab'.encode('utf-8')
print(payload.hex())
print(bytes.fromhex(payload.hex()).decode('utf-8')) Build in a virtual environment
Keep each experiment in its own folder with README.md, requirements.txt and tests. Work from the standard library first; add dependencies only when their benefit is clear. Never commit real tokens or private traffic captures.
Try it in your lab
Write a function that converts a UTF-8 message into hexadecimal and back; test an accented word and an invalid byte sequence.
Make sure it clicks
What happens when a socket recv() call returns b""?
A prompt you can adapt
Write pytest tests for my Python bytes-to-text helper, including invalid UTF-8 input and a documented error message.How to set up OpenCode ↗