Table of Contents
Why Is ‘OR 1=1’ a Classic Technique for SQL Injection Authentication Bypass?
Learn how the 1=1 condition in an SQL injection attack creates a statement that always evaluates to true, allowing attackers to bypass authentication. Understand the logic behind this classic SQLi technique and how it manipulates database queries.
Question
What does the condition 1=1 achieve in SQL injection?
A. It resets database sessions
B. It prevents query execution
C. It always evaluates to true, bypassing authentication
D. It encrypts database responses
Answer
C. It always evaluates to true, bypassing authentication
Explanation
1=1 makes conditions true, tricking SQL queries.
The condition 1=1 is a tautology, meaning it is a statement that is always logically true. In an SQL injection attack, it is used to manipulate a query’s WHERE clause to make the entire condition evaluate to true, thereby bypassing security checks like authentication.
Consider a typical, insecure login query:
SELECT * FROM users WHERE username = ‘user_input’ AND password = ‘password_input’;
An attacker can exploit this by entering a malicious string into the username field. If the attacker provides the input ‘ OR 1=1 –, the backend database will process the following query:
SELECT * FROM users WHERE username = ” OR 1=1 –‘ AND password = ‘…’;
Here is a breakdown of the injection:
- The first single quote (‘) closes the string for the username field.
- OR 1=1 introduces a new condition. The database evaluates the WHERE clause for each row. Since 1=1 is always true, the entire OR expression becomes true, regardless of what the username was.
- The — (a comment indicator in SQL) tells the database to ignore the rest of the line, effectively removing the AND password = ‘…’ check from the query.
Because the WHERE clause is now universally true for all rows in the users table, the query returns every record. In a login scenario, the application might then grant access using the credentials of the first user returned, who is often an administrator.
The other options are incorrect:
A. It resets database sessions: This condition has no effect on database session management.
B. It prevents query execution: It does the opposite; it ensures the query successfully executes and returns more data than intended.
D. It encrypts database responses: This has no relationship to encryption. It is a logical manipulation, not a cryptographic one.
Ethical Hacking with Metasploit, SQL & Crypto certification exam assessment practice question and answer (Q&A) dump including multiple choice questions (MCQ) and objective type questions, with detail explanation and reference available free, helpful to pass the Ethical Hacking with Metasploit, SQL & Crypto exam and earn Ethical Hacking with Metasploit, SQL & Crypto certificate.