SQL Injection Lab Mod
SQL Injection Lab Mod
Lifecycle
SQL Injection
derived from
https://www.wired.com/story/gab-hack-data-breach-ddosecrets/
injection vulnerability in the site—
a common web bug in which a
text field on a site doesn't
differentiate between a user's
input and commands in the site's
code, allowing a hacker to reach
in and meddle with its backend
SQL database. “
SDLC / D. Moser, M. Moser / SoSe 2023 / Slide 3
The Fundamental Cause
• The above SQL statement only reflects the rows for which the
predicate in the WHERE clause is TRUE.
• The predicate is a logical expression; multiple predicates can be
combined using keywords AND and OR.
SDLC / D. Moser, M. Moser / SoSe 2023 / Slide 12
SQL Tutorial: WHERE Clause
mysql> SELECT * FROM employee WHERE EID='EID5001';
+----+------+---------+-----------+--------+------------+
| ID | Name | EID | PASSWORD | Salary | SSN |
+----+------+---------+-----------+--------+------------+
| 2 | Bob | EID5001 | passwd123 | 80000 | 555-66-555 |
+----+------+---------+-----------+--------+------------+
1 row in set (0.00 sec)
• The first query returns a record that has EID5001 in EID field
• The second query returns the records that satisfy either EID=‘EID5001’ or
Name=‘David’
SDLC / D. Moser, M. Moser / SoSe 2023 / Slide 13
SQL Tutorial: WHERE Clause
• If the condition is always True, then all the rows are affected by the SQL
statement
mysql> SELECT * FROM employee WHERE 1=1;
+----+---------+---------+-----------+--------+------------+
| ID | Name | EID | PASSWORD | Salary | SSN |
+----+---------+---------+-----------+--------+------------+
| 1 | Alice | EID5000 | passwd123 | 80000 | 555-55-555 |
| 2 | Bob | EID5001 | passwd123 | 80000 | 555-66-555 |
| 3 | Charlie | EID5002 | passwd123 | 80000 | 555-77-555 |
| 4 | David | EID5003 | passwd123 | 80000 | 555-88-555 |
+----+---------+---------+-----------+--------+------------+
4 rows in set (0.00 sec)
• This 1=1 predicate looks quite useless in real queries, but it will become
useful in SQL Injection attacks
mysql> SELECT
substring(SSN,5,2) SubSSN,
cast(substring(SSN,5,2) as decimal)+1 Next
FROM employee;
+--------+------+
| SubSSN | Next |
+--------+------+
| 55 | 56 |
| 66 | 67 |
| 77 | 78 |
| 88 | 89 |
+--------+------+
4 rows in set (0.00 sec)
UPDATE employee
SET password='secret', salary=10000000
WHERE eid='35' #' and
password='$oldpwd'