UNIVERSITY OF WEST ATTICA
SCHOOL OF ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING AND INFORMATICS
Information Technology Security
Vasileios Evangelos Athanasiou
Student ID: 19390005
Supervision
Supervisor: Ioanna Kantzavelou, Associate Professor
Co-supervisor: Angelos Georgoulas, Assistant Professor
Athens, May 2023
This laboratory project focuses on Information Technology Security, with emphasis on SQL Injection vulnerabilities and database management within a MySQL environment. The lab was conducted as part of the 8th semester curriculum for Computer Engineering and Information Technology at the University of West Attica (UNIWA).
The main objective is to understand how databases are structured and accessed, how SQL queries operate, and how improper handling of user input can lead to serious security vulnerabilities such as SQL Injection.
| Section | Path / File | Description |
|---|---|---|
| 1 | assign/ |
Official laboratory exercise specifications |
| 1.1 | assign/Exercise 3 (SQL Injection)_2023.pdf |
Assignment description (English) |
| 1.2 | assign/Άσκηση 3 (SQL Injection)_2023.pdf |
Assignment description (Greek) |
| 2 | docs/ |
Technical reports and theoretical background |
| 2.1 | docs/SQL-Injection.pdf |
Laboratory report and analysis (English) |
| 2.2 | docs/Έγχυση-SQL.pdf |
Laboratory report and analysis (Greek) |
| 3 | screens/ |
Experimental results and attack demonstrations |
| 3.1 | screens/Activity1/ |
Database enumeration and data extraction |
| 3.2 | screens/Activity2/ |
Authentication bypass and web-based SQL injection |
| 3.3 | screens/Activity4/ |
Unsafe backend statements and privilege escalation |
| 3.4 | screens/*.png |
Additional execution results and database state changes |
| 4 | README.md |
Repository overview and usage instructions |
Understanding the target is the first step in identifying a potential injection point. The document outlines the following structure for the credential table:
- Database Name:
Users - Target Table:
credential - Key Fields: The table includes
ID,Name,EID,Salary,birth,SSN,PhoneNumber,Address,Email,NickName, andPassword. - Field Types: Numerical data like
IDandSalaryuseint, while textual data likeNameandPhoneNumberusevarchar.
An SQL injection attack occurs when an attacker "injects" malicious SQL code into an input field, which is then executed by the backend database. Using the commands from the lab as examples:
- Standard Query: A legitimate search for a user might look like:
SELECT * FROM credential WHERE Name='Samy';.- The Vulnerability: If the application does not sanitize input, an attacker could input
' OR '1'='1into a name field.
- The Result: The executed command becomes:
SELECT * FROM credential WHERE Name='' OR '1'='1'; Because '1'='1' is always true, the database returns every record in the table, bypassing authentication or privacy controls.
The document highlights what an attacker stands to gain and how developers attempt to mitigate these risks:
- Sensitive Information: Successful injection can expose SSN (Social Security Numbers), Salary details, and Address information. +1
- Password Protection: To prevent simple credential theft, passwords in this environment are stored as digests calculated by a hash algorithm (specifically SHA-1). +1
- Example Hash: A password for the user "Alice" appears as
fdbe918bdae83000aa54747fc95fe0470fff4976. Even if an attacker uses SQL injection to download the table, they still need to "crack" these hashes to get the actual passwords.
The lab demonstrates the importance of proper database management to prevent unauthorized access:
- Input Validation: Ensuring that only expected data types (like int for salary) are accepted.
- Authentication: Logging into the MySQL server requires specific root credentials.
- Hashing: Never storing passwords in plain text.
In the laboratory exercise, the following SQL command is used to retrieve specific user data:
SELECT * FROM credential WHERE Name='Samy';If a web application accepts user input (e.g., a name field) and directly concatenates it into the SQL query without validation or sanitization, an attacker can alter the query’s logic.
' OR 1=1 --SELECT * FROM credential WHERE Name='' OR 1=1 --';Because 1=1 is always true, the condition evaluates to true for every row in the table.
As a result, the database returns all 6 rows of the credential table instead of a single user, exposing sensitive data such as:
- SSN
- Salary
- Address and contact information
- Password hashes for all users
The lab demonstrates inserting new users and updating passwords. SQL Injection in an UPDATE statement can be even more damaging than in a SELECT.
UPDATE credential SET Password='[hash]' WHERE ID=7;If the ID value is taken directly from user input, an attacker can manipulate the update condition.
7 OR 1=1UPDATE credential SET Password='hacker_hash' WHERE ID=7 OR 1=1;Since 1=1 is always true, every row in the table is updated.
This means:
- All users’ passwords are replaced with the attacker’s chosen hash
- Legitimate users are locked out
- The attacker gains control over all accounts
The most effective defense against the SQL Injection vulnerabilities demonstrated in this lab is the use of Prepared Statements (also known as Parameterized Queries).
Instead of dynamically building SQL strings with user input, the application sends a query template to the database using placeholders.
SELECT * FROM credential WHERE Name = ?;The database parses and compiles the SQL structure without any user input.
User input is sent separately and bound to the placeholder as a literal value.
The database treats the input strictly as data, not executable SQL. If an attacker provides:
' OR 1=1the database searches for a user whose name is literally ' OR 1=1, rather than executing the injected logic.
- User input is never interpreted as part of the SQL command.
- Ensures fields like ID or Salary are handled as integers, not strings containing hidden SQL logic.
- The database can reuse the compiled query plan for multiple executions, improving efficiency.
This guide describes how to set up the required environment and reproduce the SQL Injection laboratory exercises using MySQL in a controlled academic setting.
The project is part of the Information Technology Security course at the University of West Attica (UNIWA).
Warning
This project demonstrates real security vulnerabilities.
It must be executed only in an isolated laboratory environment (local machine or virtual machine).
Never apply these techniques to production systems.
Recommended environments:
- Linux (preferred)
- Ubuntu 16.04 / 18.04 / 20.04
- SEED Ubuntu VM (fully compatible)
The laboratory uses MySQL as the backend database.
Install MySQL:
sudo apt update
sudo apt install -y mysql-serverVerify installation:
mysql --versionStart MySQL service:
sudo systemctl start mysql
sudo systemctl enable mysqlInstalled automatically with MySQL Server.
Verify:
mysql -u root -pIf you want to reproduce web-form SQL injection scenarios:
Install LAMP stack:
bash
sudo apt install -y apache2 php php-mysql
Verify Apache:
http://localhostgit clone https://github.com/Information-Technology-Security/SQL-Injection.git
cd SQL-Injectionsudo mysql -u rootCREATE DATABASE Users;
USE Users;CREATE TABLE credential (
ID INT PRIMARY KEY,
Name VARCHAR(50),
EID VARCHAR(20),
Salary INT,
birth DATE,
SSN VARCHAR(20),
PhoneNumber VARCHAR(20),
Address VARCHAR(100),
Email VARCHAR(50),
NickName VARCHAR(50),
Password VARCHAR(100)
);INSERT INTO credential VALUES
(1, 'Samy', 'E001', 50000, '1990-01-01', '123-45-6789', '2101234567', 'Athens', 'samy@example.com', 'samy', 'hash1'),
(2, 'Alice', 'E002', 52000, '1992-03-10', '987-65-4321', '2107654321', 'Piraeus', 'alice@example.com', 'alice', 'fdbe918bdae83000aa54747fc95fe0470fff4976');SELECT * FROM credential WHERE Name='Samy';Malicious Input:
' OR 1=1 --Resulting Query:
SELECT * FROM credential WHERE Name='' OR 1=1 --';Returns all records, demonstrating data leakage.
UPDATE credential SET Password='hacked_hash' WHERE ID=7 OR 1=1;Updates all users, demonstrating privilege escalation.
Prepared Statements (Conceptual Example)
SELECT * FROM credential WHERE Name = ?;- SQL logic is compiled separately
- User input is treated strictly as data
- Injection payloads are neutralized
| Issue | Cause | Solution |
|---|---|---|
| Cannot connect to MySQL | Service not running | sudo systemctl start mysql |
| Access denied for root | Auth plugin issue | Use sudo mysql |
| Queries fail | Wrong database | USE Users; |
| Injection not working | Input sanitized | Verify unsafe query logic |
- Navigate to the
docs/directory - Open the report corresponding to your preferred language:
- English:
SQL-Injection.pdf - Greek:
Έγχυση-SQL.pdf
- English:
