■■ SQL Injection Cheat Sheet
■ What is SQL Injection?
SQL Injection is a web security vulnerability that allows an attacker to interfere with the queries that
an application makes to its database. It typically allows attackers to view data that they are not
normally able to retrieve.
■ Example of SQL Injection
Intended Query:
SELECT * FROM users WHERE username = 'admin' AND password = '1234';
Malicious Input (Password): ' OR '1'='1
Resulting Query:
SELECT * FROM users WHERE username = 'admin' AND password = '' OR
'1'='1';
■ Types of SQL Injection
Type
Description
Classic/Inline
Injecting directly into a visible query.
Blind SQLi
No visible error messages; attacker infers logic.
Time-Based
Uses delays (e.g., SLEEP) to determine behavior.
Error-Based
Extracts data via DBMS error messages.
Union-Based
Uses UNION operator to combine queries.
■■ How to Prevent SQL Injection
1. Use Prepared Statements / Parameterized Queries.
2. Validate and sanitize user input.
3. Use ORM libraries (like SQLAlchemy, Django ORM).
4. Limit database user permissions.
5. Use Web Application Firewalls (WAF).
■ Tools to Test SQL Injection (Ethical Hacking)
Tool
Use
sqlmap
Automated SQL injection & database takeover tool.
Burp Suite
Web vulnerability scanner.
OWASP ZAP
Free open-source web security tool.