Chapter 1
What Can Go Wrong
Welcome to the Course
Hi, I’m Erik. I write and maintain this course, along with the rest of Python Land.
In
What you will harden
| Chapters | What you close |
|---|---|
| 1 | nothing yet: you name what is at risk and prove one weakness with a test |
| 2 and 3 | passwords that a copy of the data gives away |
| 4 | |
| 5 | tokens written into the source |
| 6 | a reader who changes another reader’s books, and endless login guesses |
| 7 | request data that is trusted too early |
| 8 and 9 | requests that another website starts in a user’s browser |
| 10 | plain HTTP |
| 11 | the capstone: eleven weaknesses, and no chapter telling you where to look |
The
One rule
Attack only what you own.
Every attack in this course is aimed at handle() in your own project, either in memory or on 127.0.0.1, the pl_sec.py, takes no host name, so it cannot be pointed anywhere else.
The same techniques work against real services. Using them against a service that is not yours, without its owner’s permission, is against the law in most places and against the point of this course.
Which of these may you attack with what this course teaches?
What the site can and cannot reach
The sandboxes on Python Land have no route to the public internet. No lesson contacts a real website.
The site also has no browser. That matters from Chapter 8 on: which cookies travel with a request, and which page may read which response, are decisions a browser makes. So in Chapters 8 and 9 you write a small model of a browser yourself, one rule at a time, as plain Python
Chapters 8 and 9 are about what a browser does with cookies and other sites. What plays the browser here?
What is in the project
reading_server.pyis the server as HTTP with Python left it, in a reviewed copy, so everyone starts from the same code.http_adapter.pyis the file you know plus one method,do_OPTIONS, which Chapter 9 needs.wire.pyis unchanged.tests/test_attacks.pyis where your attack tests go, andtests/helpers.pyholds small functions those tests use.SECURITY.mdis the list of weaknesses you find. It starts with four empty rows.pl_sec.pyis a helper written for this course. It plays the other side: a client, a thief, an attacker.
Your client, reading_client.py, is not carried forward. Chapter 5 changes the tokens it would have to send, and this course is about the server.
What this course needs from you
You need HTTP with Python:
handle(request, state), and the request and responseit works with; cookies and a session kept on the server;
Basic credentials on login and bearer tokens on writes, and when a server answers 401 and when 403;
a
digest from hashlib,, and secrets.token_urlsafe;tests that call the handler directly and run with
python -m pytest -q.
Python Fundamentals II is recommended, not required. http_adapter.py contains a class. You read it once, and no exercise asks you to write one.
Meet Monty
Monty is Python Land’s learning guide, beside every lesson. Ask for a second explanation, a hint that does not hand you the answer, or help reading an error.
When you are signed in, your free account includes 5 Monty helps a day, shared across all courses. A good first question here:
In plain words, what did my reading list server check before it let a request change a book?
The next lesson looks at that server through the eyes of someone who wants to misuse it.
Guided gives you up to 50 Monty helps a day. Questions, hints, error explanations, extra practice, and code reviews share the same daily allowance. The counter shows what is left and when it resets. Every lesson and ordinary exercise retry remains free.