Skip to contentExploitQuest

What Injection Is

Every injection bug is the same shape: data crosses into code because the two were joined by gluing strings together. See the shape once and you see it everywhere.

2 min readNot yet reviewed
Wrenlearner

People say "SQL injection" like it is one specific trick. Is it?

Rookmentor

It is one specific mistake, and it has one specific cure. The trick is just what the mistake lets an attacker do. Start with the mistake.

Data that becomes code

A program keeps data and code in separate worlds. Your name is data; the instruction that looks your name up is code. Injection is what happens when data crosses the border into code — when something you typed stops being treated as a value and starts being treated as an instruction.

It crosses that border for one reason, every time: the program built its instruction by gluing strings together, and your text was one of the pieces. Once your text is part of the instruction, anything that reads as an instruction *is* one.

How the bug is written

query = "select * from users where name = '" + input + "'"

What an attacker sends

input = "' OR 1=1 --"

The application meant the quotes to wrap a value. The attacker closes the first quote early, writes a condition of their own, and comments out the rest. Nothing was hacked; the string was just built to say something else.

Before we run anything: why does OR 1=1 return every row, rather than an error?