SudoHopeX 'Krishna Dwivedi' SudoHopeX 🥷🚩

A Ray of Hope in the circuitry, Igniting curiosity.

( Ethical Hacker )

SQL Injection: Research Paper

calendar Jun 15, 2025 clock 10-15 min read tag Article


SQL Injection

Drafted by Krishna Dwivedi

Objective

The Main goal is to Learn, Understand & get familiar with:

What is SQL (Structured Query Language) ??

SQL is Developed in 1970s and became the standard database management language. If a website needs to access the database on its server to manipulate (i.e. store, read, update, delete) data (information), it uses SQL to handle that request (called Query).

SQL is a broad and flexible language that gives Database designers a huge number of possibilities. Most designers create databases with their own unique set of SQL rules (or queries) to best suit their particular business needs. We can’t simply copy and paste one database’s SQL query onto another, because different databases may have been built in completely different ways.

What is SQLi (SQL Injection) ??

If a web developer isn’t careful, and they might build their site in such a way that a malicious actor can cause unintended effects in its database. That's how SQLis happen.

The hacker inputs, or injects, malicious SQL code (a form of malware known as the payload) on the website and fools it into delivering that code to its database as a legitimate query to be executed by the DB.

Real Life Analogy

Imagine you're at a bank, filling out a form to check your account balance. But someone else walks in and writes something sneaky on their form, like

“Show my balance; then give me money from everyone’s account.”

If the bank doesn’t properly check what’s written, it might follow those harmful instructions and do the task stated.

Similar are the SQLis that allows attackers to bypass security and execute malicious payloads to perform some action

How SQLi Works ??

1. Normal Login Scenario

User enters login details:

Username => admin and Password => adminpasswd

The web application might run this SQL query:

SELECT * FROM users WHERE username = 'admin' AND password = 'password123';

If the credentials are correct, the user is logged in (as demonstrated below 👇)


2. Malicious Input Example (SQL Injection)

An attacker enters:

Username => admin' -- and Password => (left blank)

This changes the SQL query to:

SELECT * FROM users WHERE username = 'admin' -- ' AND password = '';

The -- is a SQL comment, so everything after it is ignored. The query now only checks if the username is "admin", bypassing the password check.

3. Result

The attacker gains unauthorized access to the admin account without knowing the password. (as demonstrated below 👇)

Conclusion: This happens because user input is directly inserted into SQL queries without validation or escaping.

Ways to Perform SQL Injection (SQLi)

1. SQL Injection via User Input

This is the most common method. Websites that collect user input (e.g., forms, comment sections) without proper input sanitization are vulnerable. Attackers inject SQL code instead of normal input, causing the server to execute malicious commands.

Example: An attacker submits SQL code through a job application form instead of their real name to manipulate how the server processes the data.

2. SQL Injection via Cookie Modification

Cookies can store user-specific data. If a server blindly trusts cookie values without validation, attackers can modify them to inject SQL commands into the backend database.

3. SQL Injection via Server Variables

Server variables (like headers and user agent strings) are often logged or processed by applications. If the data isn't sanitized, an attacker can inject SQL through these variables.

4. SQL Injection via Automated Hacking Tools

Tools like SQLMap automate the detection and exploitation of SQL injection vulnerabilities. While useful for security testing, they can also be used maliciously.

5. Second-Order SQL Injection

This advanced method stores a harmless-looking SQL payload in the database that only becomes dangerous when triggered later during processing. It bypasses initial input validation by executing at a later stage.

Analogy: It's like someone pretending their name is "Nobody" to avoid getting in trouble — it works at first, but later it causes even more problems when others try to figure out what really happened.

Types of SQLi

1. In-Band SQLi (Classic SQLi)

This is the most straightforward and commonly exploited form of SQLi, where attackers both launch the attack and receive results using the same communication channel.

2. Inferential SQLi (Blind SQLi)

No data is directly returned to the attacker; instead, they infer results based on application behaviour or response time.

3. Out-of-Band SQLi

Exploits functionalities where data is transferred over different channels, like HTTP or DNS.

4. Advanced SQLi Techniques

Effects of SQLi

For Individuals

For Businesses

Examples

Common Ethical Hacking & Pentesting Tools

Sqlmap

Burp Suite

OWASP ZAP

Web Apps & Labs to Practice SQL Injection (SQLi)

PortSwigger Web Security Academy
OWASP Broken Web Applications (BWA) VM
Hack The Box (HTB) Academy & Labs
TryHackMe
OWASP Juice Shop
Vulnweb (by Acunetix)
Acunetix Vulnerable Web App (VWA)
Web Security Dojo
VulnHub – Web App Focused VMs
PentesterLab

SQLi Attacks Case Studies (Brief)

Tamil Nadu Government Portal (April 2025) Indian Government Website (May 2025) Parivahan iRAD Portal (August 2023) BSNL Data Breach (December 2023) Sikkim Manipal University (SMU) Portal Indonesian Educational Platform Breach (2025) ResumeLooters Data Breach (2024)

Prevention Strategies

Effective prevention combines foundational and advanced methods:

Summary Table


     SQLi Type	               Description	                       Example Attack	                                 Prevention Strategy
     In-Band (Error-Based)     Extracts info via errors                ' OR 1=1--                                        Parameterized queries
     In-Band (Union-Based)     Combines queries for data extraction    ' UNION SELECT username, password FROM users--    Input validation and least privilege
     Inferential (Blind)       Infers data from responses              ' WAITFOR DELAY '00:00:05'--                      WAF integration
     Out-of-Band               Uses external channels                  DNS exfiltration payloads                         Monitoring and MFA
     Second-Order              Stored payloads executed later          '; DROP TABLE users;--                            Validate stored data
     Stacked Queries           Chains multiple statements              SELECT * FROM users; DROP TABLE data;--           Disable multi-query execution
        

Conclusion

This exploration into SQL Injection (SQLi) has provided a comprehensive understanding of how SQL works and how vulnerabilities in its implementation can be exploited through SQLi attacks.

We’ve delved into the mechanics of SQLi, examined various types and methods of exploitation, and studied real-world examples to highlight its potential impact. Ethical hacking and penetration testing tools were introduced as essential resources for identifying such vulnerabilities.

Additionally, practical labs and case studies helped reinforce learning and skill-building. Most importantly, we discussed preventive strategies and best practices to safeguard applications from SQLi threats. With this foundational knowledge, learners are now better equipped to recognize, mitigate, and defend against SQL injection vulnerabilities in real-world environments.

Further articles to Explore
30 Days to Master XSS with Games, Challenges and Labs + Running & Configuring Python venv3 in Linux +
Go to top