Question 1 Report
SQL injection is a type of cyber attack that targets databases through web applications.
(a) Describe how an SQL injection attack works. [3]
(b) State two types of damage that a successful SQL injection attack could cause. [2]
(c) Describe three methods that a developer can use to prevent SQL injection attacks. [3]
(d) The following SQL query is used in a login form:
SELECT * FROM users WHERE username = '' + input + '' AND password = '' + input + ''
Explain how an attacker could exploit this query to bypass the login check.
[2]
(e) A company is choosing between SQL injection prevention and cross-site scripting (XSS) prevention as priorities. Describe what a cross-site scripting attack is. Explain two differences between SQL injection and XSS attacks.
[4]
(a) How an SQL injection attack works [3]
The attacker enters malicious SQL code into an input field on a web form, such as a login box, search bar, or registration form. [1]
If the web application does not properly validate or sanitise the user input, the SQL code is passed directly to the database server as part of the query, rather than being treated as plain text data. [1]
The malicious SQL code is then executed by the database, potentially allowing the attacker to view confidential data, modify or delete records, or bypass authentication checks entirely. [1]
(b) Two types of damage from a successful SQL injection [2]
(c) Three methods to prevent SQL injection attacks [3]
(d) How an attacker could exploit the given login query [2]
The attacker could enter a value such as ' OR '1'='1 as the username. [1]
This modifies the SQL query so that the WHERE condition always evaluates to TRUE (since '1'='1' is always true), causing the database to return all user records and allowing the attacker to log in without knowing a valid password. [1]
(e) Cross-site scripting and differences from SQL injection [4]
Cross-site scripting (XSS) is an attack where malicious scripts (typically JavaScript) are injected into a trusted website. When other users visit the page, the malicious script executes in their browsers, potentially stealing session cookies, redirecting users to fake sites, or capturing keystrokes. [1]
Difference 1: SQL injection targets the server-side database by manipulating SQL queries, while XSS targets client-side users by injecting scripts into web pages that execute in their browsers. [1]
Difference 2: SQL injection can result in direct data theft or modification from the database, while XSS typically steals session cookies, captures user input, or redirects users to fraudulent sites. [1]
Everything you need to excel in your exams