Skip to content

Latest commit

 

History

History
273 lines (188 loc) · 14.4 KB

File metadata and controls

273 lines (188 loc) · 14.4 KB

UNIWA

UNIVERSITY OF WEST ATTICA
SCHOOL OF ENGINEERING
DEPARTMENT OF COMPUTER ENGINEERING AND INFORMATICS

University of West Attica · Department of Computer Engineering and Informatics


Information Technology Security

SQL Injection

Vasileios Evangelos Athanasiou
Student ID: 19390005

GitHub · LinkedIn


Supervision

Supervisor: Ioanna Kantzavelou, Associate Professor

UNIWA Profile · LinkedIn

Co-supervisor: Angelos Georgoulas, Assistant Professor

Scholar · LinkedIn


Athens, May 2023



INSTALL

SQL Injection

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.


1. Prerequisites

1.1 Operating System

Recommended environments:

  • Linux (preferred)
    • Ubuntu 16.04 / 18.04 / 20.04
    • SEED Ubuntu VM (fully compatible)

1.2 Required Software

1.2.1 MySQL Server

The laboratory uses MySQL as the backend database.

Install MySQL:

sudo apt update
sudo apt install -y mysql-server

Verify installation:

mysql --version

Start MySQL service:

sudo systemctl start mysql
sudo systemctl enable mysql

1.2.2 MySQL Client (CLI)

Installed automatically with MySQL Server.

Verify:

mysql -u root -p

1.2.3 Web Stack (for Web-based SQL Injection)

If you want to reproduce web-form SQL injection scenarios:

Install LAMP stack:

bash
sudo apt install -y apache2 php php-mysql

Verify Apache:

http://localhost

2. Installation

2.1 Clone the Repository

git clone https://github.com/Information-Technology-Security/SQL-Injection.git
cd SQL-Injection

3. Database Setup

3.1 Log in to MySQL as Root

sudo mysql -u root

3.2 Create the Database

CREATE DATABASE Users;
USE Users;

3.3 Create the Vulnerable Table

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)
);

3.4 Insert Sample Data

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');

4. Running the Laboratory Exercises

4.1 Basic Query Execution

SELECT * FROM credential WHERE Name='Samy';

4.2 SQL Injection Example (SELECT)

Malicious Input:

' OR 1=1 --

Resulting Query:

SELECT * FROM credential WHERE Name='' OR 1=1 --';

Returns all records, demonstrating data leakage.

4.3 SQL Injection in UPDATE Statement

UPDATE credential SET Password='hacked_hash' WHERE ID=7 OR 1=1;

Updates all users, demonstrating privilege escalation.


5. Countermeasure Demonstration

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

6. Troubleshooting

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

7. Open the Documentation

  1. Navigate to the docs/ directory
  2. Open the report corresponding to your preferred language:
    • English: SQL-Injection.pdf
    • Greek: Έγχυση-SQL.pdf