Injection: when data becomes code

Injection is a value being read as code by something that runs code. This set checks that you can spot where the crossing happens, and that you know an argument list and a query parameter keep a value a value.

4 questions 1 task Read the lesson

Questions

Each one is marked as you go, and the explanation arrives straight after, which is the part worth reading.

4 questions, marked as you go.

1 What turns a name value into a command in the greeting server?
2 Why does subprocess.run(["echo", "hello", name], shell=False) stop the injection?
3 What does the ? in "... where name = ?" do in a parameterised query?
4 Why does percent-encoding a semicolon not defeat the injection?

Tasks

These need your own device. Run the command in Termux, then paste what it printed. The marking looks at what the output means, so spacing, version numbers and ordering do not matter. If you have not installed anything yet, the lesson covers the setup.

Pass a hostile value as an argument and watch it stay inert

This runs the fixed greeting, which passes the name as an argument to a program rather than to a shell. The name here contains a semicolon and a second command. Run it and paste what comes back.

Run this in Termux On your own device. Nothing on this page executes it. The command runs in your terminal, and this box only reads what you paste back.

python3 -c "import subprocess; name='world; id'; out=subprocess.run(['echo','hello',name],shell=False,capture_output=True,text=True).stdout; print(out,end=''); print('lines:',len(out.strip().split(chr(10))))"
Marking your own work Both halves of this are checked in your browser, with no server involved, so nothing stops you from pasting output you did not run. The tasks are written so that the easiest way to pass one is to actually do it and read the result, which is the whole intention.

All sets Read the lesson