~/d4nnyX

← CPTS

SQL Injection Fundamentals

Web · CPTS

  • Web
  • SQL Injection
  • Databases

The idea

SQL injection happens when user input is concatenated straight into a query, so the input can change the query's logic. Doing it by hand first — before reaching for a tool — is what makes the automated stage make sense.

How I work through it

Prove it. A single quote that breaks the response, and a boolean pair that behaves differently, confirms the injection:

' OR 1=1 -- -
' AND 1=2 -- -

Read data with UNION. Find the column count, then select from the schema to map tables and dump credentials:

' ORDER BY 4 -- -
' UNION SELECT 1,table_name,3,4 FROM information_schema.tables -- -
' UNION SELECT 1,username,password,4 FROM users -- -

Go further where allowed. Depending on the DBMS and privileges, I test reading local files (LOAD_FILE) or writing a web shell (INTO OUTFILE) into the web root.

Pitfalls I watch for

  • Comment syntax and string functions differ by engine — MySQL, MSSQL and Postgres each need their own payloads, so I fingerprint the DBMS first.
  • When there is no visible output, I switch to blind techniques (boolean or time-based) rather than assuming the input is safe.
  • The real fix is parameterised queries, not input filtering — blocklists get bypassed, prepared statements do not.

Takeaway

Confirm, enumerate the schema, extract, then escalate to the file system if the privileges allow. Understanding the manual UNION path is what makes everything after it — including SQLMap — readable.