SQL Injection Bypass in Login Forms
Suppose that you test an application for the SQL injection vulnerability. You know that the backend database is based on Microsoft SQL Server. In the login/password form, you enter the following credentials: Based on the above credentials, which of the following SQL commands are you expecting to be executed by the server, if there is indeed an SQL injection vulnerability? - 
Community Votes
67% of anonymous learners picked answer B. Votes are pick records left by other test-takers — they are not the verified answer.
Community Insight
The core concept tested is how an attacker closes the original single quote, injects 'OR 1=1', and uses '--' to nullify the remaining WHERE clause conditions.
This question explores the mechanics of SQL injection within a Microsoft SQL Server login form, specifically how input manipulation alters the backend query structure. The correct answer identifies the precise syntax required to close the initial string, inject a tautology, and comment out the password validation.
Many learners select Option D because they assume the closing quote from the original query must appear after the comment symbol. However, this results in invalid SQL syntax where the comment effectively ignores that trailing quote, leaving the statement malformed or logically incorrect for the specific injection payload.
Community Discussion (8 comments)
Comments & Corrections
No comments yet — spotted an error or have a note? Share it below.
Expert Analysis
Why the Answer Is Correct
Option B represents the standard successful SQL injection payload structure when injected into a username field. The input 'attack' closes the opening single quote of the UserName parameter. The 'or 1=1' part creates a condition that always evaluates to true, bypassing authentication. The '--' sequence initiates a comment, instructing the SQL Server to ignore all subsequent characters in the query string, including the rest of the WHERE clause (such as the password check). This results in a syntactically valid and logically exploitable command.Why the Other Options Are Wrong
Option A contains a syntax error with an extra misplaced apostrophe ('attack’ ’). Option C incorrectly merges the username value with the injection logic without proper closure of the first string, resulting in 'attack or 1=1 -- which treats the entire string as a literal value rather than executable logic. Option D includes a trailing single quote after the comment symbol ('--'). In SQL, everything after '--' is ignored; therefore, having a stray quote there does not make the query valid in the way intended by the injection, and often leads to syntax errors if the parser expects strict termination, whereas Option B cleanly terminates the logic via the comment.Community Comment Notes
Community consensus is split between B and D, but technical analysis strongly favors B. Users like NikoTomas argue for D based on PortSwigger examples, noting that the original query's closing quote might remain visible in the final executed string. However, as HeyacedoGomez points out, Option B provides the correct SQL syntax where the comment properly negates the rest of the query. The key distinction is that '--' makes everything after it irrelevant, so the presence or absence of a trailing quote is less critical than the clean execution of the bypass logic found in B.Exam Strategy
When analyzing SQL injection options, look for the sequence: Close Quote -> Inject Logic (e.g., OR 1=1) -> Comment Out Rest (--). Ensure the resulting full query is syntactically valid SQL. Do not get distracted by the exact visual representation of the original query's closing quote if the comment symbol renders it moot.
Frequently Asked Questions
Why is Option D considered incorrect despite some community votes?
Option D includes a trailing quote after the comment symbol '--'. Since '--' ignores all subsequent text, that quote is syntactically orphaned or ignored, making B the cleaner, standard injection payload that reliably bypasses the check.
What happens if I don't use '--' in the injection?
Without '--', the SQL parser will attempt to execute the remaining parts of the original query (like the password comparison), likely causing a syntax error or failing the authentication check because the logical structure remains intact.