Python Programming
Python is the language security people reach for when they need something done quickly. Exploit scripts, CTF solvers, file parsers, and one-off tools to decode a blob of Base64 are almost always Python, because it takes a few lines to do what C takes a page for. Every exploit in Binary Exploitation is a Python script, and the Pwntools Guide assumes you can already write one.
This course teaches Python as a working tool. It starts with the syntax and built-in data structures, moves through functions, classes and files, and finishes with the standard-library modules and packages that turn programming challenges from an afternoon into a few minutes. If you already know another language, most of the early lessons will go quickly; the value is in learning what Python gives you for free.
Course Layout
- Getting Started. How Python runs code, the indentation rules, variables and types, and control flow.
- Data Structures. The built-in types you will use in every script: strings, lists, tuples and sets, dictionaries, and the bytes that security work lives in.
- Functions & Modules. Writing reusable functions and splitting code into modules.
- Objects & Errors. Defining your own types with classes, and handling what goes wrong with exceptions.
- Files & Text. Reading and writing files, and pulling structure out of text with regular expressions.
- Tooling. Installing third-party code into virtual environments, and checking your own with pytest.
- Problem-Solving Toolkit. The libraries that make challenges short: functools and itertools, specialized containers, NumPy for grids and matrices, and NetworkX for graph problems.
Work through the first five sections in order. Tooling and the Problem-Solving Toolkit stand on their own, so take them as you need them.
python3 in a terminal next to the lesson and try each example as you read it. Python's interactive prompt is the fastest way to check what a method returns or what an error looks like.Toolchain
All you need is Python 3.10 or newer, which most Linux distributions ship as python3. Check yours:
python3 --versionPython 3.12.7The later lessons use third-party packages such as NumPy and NetworkX. Packages & Environments shows how to install them with uv into a project's own environment, instead of into the system Python.
print is a statement and strings are bytes. Everything here is Python 3. If a snippet from the internet fails with a SyntaxError on print, that is why.