0% found this document useful (0 votes)
15 views10 pages

Securing Databases from SQL Injection

Uploaded by

omkarbabar2508
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views10 pages

Securing Databases from SQL Injection

Uploaded by

omkarbabar2508
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PA

GE
INFORMATION SECURITY 10
Project Report on

Securing Databases Against SQL Injection


SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS
FOR THE DEGREE OF
BACHELOR OF TECHNOLOGY

IN

Computer Engineering (Software Engineering)

OF
VISHWAKARMA INSTITUTE OF INFORMATION TECHNOLOGY
Savitribai Phule Pune University
Name Roll No. PRN
Omkar Dattatraya Babar 74 22420276
Prem Nagesh Mhetre 76 22420297
Vedant Kishor Wahile 71 22420176
Tejas Ranjit Deore 72 22420180

UNDER THE GUIDANCE OF

Prof. Madhura Sanap

DEPARTMENT OF COMPUTER ENGINEERING


(SOFTWARE ENGINEERING)

BANSILAL RAMNATH AGARWAL CHARITABLE TRUST’S


VISHWAKARMA INSTITUTE OF INFORMATION TECHNOLOGY
(An Autonomous Institute affiliated to Savitribai Phule Pune University)

2025 - 2026
PA
BANSILAL RAMNATH AGARWAL CHARITABLE TRUST’S GE
10
VISHWAKARMA INSTITUTE OF INFORMATION TECHNOLOGY
(An Autonomous Institute affiliated to Savitribai Phule Pune University)
PUNE – 411037

CERTIFICATE

This is to certify that the Course Project titled “Security Database against SQL

Injection” submitted by Omkar Babar , Prem Mhetre , Vedant Wahile, Tejas Deore

is in partial fulfillment for the award of Degree of Bachelor of Technology in

Computer Engineering (Software Engineering) of Vishwakarma Institute of

Information Technology, Savitribai Phule Pune University. This project report is a

record of bonafide work carried out by him/her under my guidance during the

academic year 2025-26.

Guide HOD, CE(SE)


Prof. Madhura Sanap Dr. Sunil Sangve

Place: VIT, Pune


Date
PA
GE
Bansilal Ramnath Agarwal Charitable Trust’s 10
VISHWAKARMA INSTITUTE OF INFORMATION
TECHNOLOGY, Pune
Department of Computer Engineering (Software engineering)

PROJECT DETAILS

Group No :

Members:

Roll PRN
No. Name of Student Contact No. Email ID

74 22420276 Omkar Dattatraya Babar 9146863286 omkar.22420276@[Link]


76 22420297 Prem Nagesh Mhetre 9172480292 prem.22420297@[Link]
71 22420176 Vedant Kishor Wahile 9172272519 vedant.22420176@[Link]
72 22420180 Tejas Ranjit Deore 9579317136 tejas.22420180@[Link]

Academic Year : 2025-26


Project Title : Securing Databases against SQL
Injection
Project Area : Information Security
Internal Guide : Prof. Madhura Sanap

Signature of Internal Guide


PA
GE
10
1. Acknowledgment

I would like to express my sincere gratitude to my guide, faculty members, and the Department of
Computer Engineering for providing me the opportunity and guidance to work on this project titled
“Securing Databases Against SQL Injection.”

Their continuous support, constructive feedback, and encouragement have helped me to explore
and understand key concepts of database security, web vulnerabilities, and secure software design.

I would also like to thank my classmates and friends who shared their suggestions and helped me
test the application in different scenarios. Finally, I am grateful to all the online learning resources
and documentation that supported the technical development of this project.

2. Introduction
In today’s digital era, databases play a vital role in storing and managing critical information for
websites and applications. Almost every modern web application depends on SQL (Structured
Query Language) to communicate with the database. However, if developers do not validate or
sanitize user inputs properly, attackers can exploit this weakness using SQL Injection (SQLi) —
one of the most dangerous and common security vulnerabilities.

SQL Injection occurs when an attacker manipulates an SQL query by injecting malicious input,
causing the database to execute unintended commands. This can lead to unauthorized access,
data leakage, data modification, and even system compromise.

The purpose of this project is to:

• Understand how SQL Injection attacks are executed.


• Develop a vulnerable demo application to visualize such attacks.
• Implement security measures to prevent these vulnerabilities using secure coding
practices in PHP and MySQL.

This project not only demonstrates how attackers exploit weak input handling but also provides
clear examples of how to fix and secure applications using practical, real-world techniques.
PA
GE
10
3. Literature Survey
Existing Research
Several studies and frameworks have been proposed to detect and prevent SQL injection attacks.
According to the OWASP Top 10 Security Risks, SQL Injection remains among the top three
threats due to its high impact and prevalence.

Early detection techniques involved:

• Manual input validation and sanitization.


• Escaping special characters.
• Limiting database privileges for users.

However, these methods were not foolproof and depended on developer awareness.

Modern Approaches

Recent works, such as the research paper “Enhancing SQL Injection Detection and
Prevention Using Generative Models (IEEE, 2024)”, propose the use of Artificial
Intelligence (AI) and Generative Models to simulate and detect SQL injection patterns
automatically.
Generative models like VAE (Variational Autoencoders) and GANs (Generative Adversarial
Networks) are used to create synthetic attack queries for training detection systems. These
models help identify new types of SQLi payloads that traditional static filters may miss.

Key Findings

• SQL Injection can be exploited through login forms, search bars, or URL parameters.
• The most effective countermeasure is using Prepared Statements or Parameterized
Queries, which separate user input from SQL commands.
• Proper input validation, escaping, hashing, and error handling are critical for a secure
application.

The literature emphasizes that SQL injection is preventable through secure coding practices
combined with awareness and continuous testing.
PA
GE
4. Methodology 10

The methodology for this project involves a two-phase approach — one to demonstrate
vulnerability and another to implement prevention.

Phase 1: Vulnerable System Implementation

1. Design of the Web Application:


Developed using HTML, CSS, PHP, and MySQL.
2. User Modules:
o Login form
o Search form
3. Vulnerability:
Inputs are directly concatenated into SQL queries without validation.
Example vulnerable code:

$email = $_POST['email'];
$password = $_POST['password'];
$sql = "SELECT * FROM users WHERE email='$email' AND password='$password'";
$result = $mysqli->query($sql);

Here, the attacker can enter:

' OR '1'='1' --

which transforms the query into:

SELECT * FROM users WHERE email='' OR '1'='1' -- ' AND password='';

This bypasses authentication and reveals all user data.

Phase 2: Secure System Implementation

1. Secure Coding with PDO:


All SQL queries were rewritten using PDO prepared statements with parameter
binding.
2. Input Validation:
Inputs are validated using PHP filters (filter_var()) and length checks.
3. Password Hashing:
Passwords are stored using PHP’s password_hash() and verified with password_verify().
4. Least Privilege Principle:
A separate database user (app_user) was created with limited privileges instead of using
the root account.
5. Error Handling:
Exceptions are caught and logged; generic error messages are shown to prevent
information disclosure.
PA
GE
6. Testing: 10
SQL injection payloads were executed on both systems — vulnerable and secure — to
verify results.

5. Features Applied by the Application

1. Educational Demonstration:
Allows users to visualize how SQL injection works in a safe, local environment.
2. Dual System:
The project includes both vulnerable and secure versions for comparison.
3. Secure Login System:
Authenticates users safely using hashed passwords and prepared statements.
4. Search Functionality:
Demonstrates safe and unsafe SQL query execution.
5. Input Validation:
Ensures only properly formatted data (like valid emails) is accepted.
6. Password Hashing:
Uses bcrypt to store passwords securely.

6. Important Feature / Working of the Website


A. Vulnerable Version

• Users can log in or search for data.


• The system directly places user input into SQL queries.
• When an attacker enters ' OR '1'='1' --, the query always returns TRUE, allowing
unauthorized access.
• Similarly, using payloads like:
• %' OR '1'='1' --

retrieves all user data from the database.

• This demonstrates how real-world applications can be compromised if input sanitization


is ignored.

B. Secure Version

• The secure pages (login_secure.php, list_secure.php) use PDO prepared statements:


• $stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?");
• $stmt->execute([$email]);
• Input is validated, and malicious payloads are treated as plain text, not executable code.
• The login form verifies credentials using:
• password_verify($password, $user['password']);
• Even if an attacker tries the same injection payloads, the system safely rejects them,
demonstrating complete SQLi prevention.
PA
GE
7. Screenshots of the Results 10
Figure 1: Vulnerable SQL Injection Demonstration

The screenshot shows the Vulnerable Search Form where the user entered the payload:

%' OR '1'='1' --

This query bypassed authentication and returned all records from the database.
PA
GE
Figure 2: Vulnerable SQL Query 10

The application displayed the query:

SELECT id, name, email, password FROM users


WHERE name LIKE '%$q%' OR email LIKE '%$q%'

Since $q was directly injected, all records were exposed.

Fig.3: Prevention Techniques :


PA
GE
10
8. Conclusion

The project “Securing Databases Against SQL Injection” clearly illustrates both the
vulnerability and prevention sides of SQL injection attacks. Through practical implementation, it
proves that insecure coding practices can easily expose sensitive information.

The secure version, on the other hand, showcases how prepared statements, input validation,
and password hashing effectively mitigate these attacks. By comparing both systems, this
project educates developers on the importance of secure coding and database management.

In conclusion, SQL Injection remains a major concern in web security, but with proper
awareness and secure practices, such attacks can be entirely prevented.

9. Future Scope
1. Integration of Machine Learning Models:
Implement anomaly-based detection systems that can identify suspicious database queries
automatically.
2. Automatic Vulnerability Scanner:
Build a tool that scans PHP applications and flags potential SQL injection points.
3. Multi-Layer Security:
Combine SQLi prevention with Cross-Site Scripting (XSS), CSRF, and file upload
security.
4. Web Application Firewall (WAF):
Implement WAF rules to detect and block SQLi payloads in real time.

10. References

1. “Enhancing SQL Injection Detection and Prevention Using Generative Models,” IEEE,
2024.
2. OWASP Foundation, OWASP Top 10 Web Application Security Risks, 2023.
3. PHP Official Documentation — PDO and Prepared Statements, [Link]
4. MySQL Developer Documentation — SQL Security and Best Practices,
[Link]
5. TutorialsPoint, SQL Injection Prevention in PHP, 2024.
6. Cybersecurity & Infrastructure Security Agency (CISA) — Mitigating Injection Attacks,
2023.

Common questions

Powered by AI

The project report identifies several fundamental techniques to prevent SQL Injection vulnerabilities, including the use of Prepared Statements or Parameterized Queries to separate user input from SQL commands, using PHP's PDO with parameter binding, input validation through PHP filters and length checks, password hashing with password_hash(), and enforcing the Least Privilege Principle by using a separate database user with limited privileges. Additionally, proper error handling techniques such as catching exceptions and logging errors without disclosing sensitive information are emphasized .

The project report identifies the use of Prepared Statements or Parameterized Queries as the most effective countermeasure against SQL Injection because they separate user input from SQL commands, which prevents malicious input from altering the query's structure. Unlike traditional input escaping methods, Prepared Statements inherently ensure that input data is processed as values, not executable code, making them a superior option for securing applications against injection attacks .

The project report evaluates the efficacy of secure coding practices by implementing a dual-system approach, comprising both vulnerable and secure versions of the application. The vulnerable version demonstrates how improper input handling can lead to SQL Injection attacks, while the secure version mitigates these vulnerabilities using secure coding practices like Prepared Statements, input validation, and password hashing. Tests conducted using SQL Injection payloads on both versions show that these secure practices effectively prevent unauthorized data access, thus ensuring application security .

The project's methodology involves two phases: the implementation of a vulnerable system and a secure system. In Phase 1, a web application was developed with security flaws to explicitly demonstrate SQL Injection vulnerabilities, such as directly concatenating user inputs into SQL queries without validation. In Phase 2, the secure version implemented advanced security measures like PDO prepared statements with parameter binding, input validation, password hashing, and reduced database privileges. This dual-system approach allowed for a direct comparison of how SQL Injection attacks could be executed on the vulnerable system while being prevented in the secure system .

The project provides educational benefits by offering a practical, hands-on demonstration of SQL Injection attacks in a controlled environment. It includes both a vulnerable and a secure version of a web application, enabling users to visualize attack vectors and compare the effects of insecure versus secure coding practices. By allowing users to see real outcomes of SQL Injection payloads and witness effective prevention methods, the project deepens understanding of web security and emphasizes the importance of adhering to secure coding standards .

The report highlights that awareness and developer practices are crucial in addressing SQL Injection vulnerabilities. It emphasizes that SQL Injection remains a major concern due to developer negligence in input handling and lack of secure coding awareness. By educating developers on the differences between vulnerable and secure versions and demonstrating practical security measures, the project underscores the necessity of adopting security best practices and continuous testing to prevent such attacks .

Input validation is critical in preventing SQL Injection attacks, as highlighted in the project's findings. By validating inputs using PHP filters (filter_var()) and conducting length checks, the project ensures that only properly formatted data is accepted, thus preventing malicious payloads from being executed as SQL commands. Proper input validation acts as the first line of defense by sanitizing user inputs and reducing the attack surface that attackers might exploit through injection techniques .

In the project's secure version, password hashing using PHP's password_hash() contributes to security by ensuring that user passwords are not stored in plaintext or accessible through SQL Injection vulnerabilities. Even if an attacker accesses the database through other vulnerabilities, hashed passwords remain unintelligible and protected. The use of password_verify() in the login process further ensures secure verification of user credentials, adding an additional layer of security to mitigate the impact of potential database breaches .

The project proposes several future advancements to enhance SQL Injection prevention, including the integration of Machine Learning models for anomaly-based detection of suspicious queries, the development of an automatic vulnerability scanner for PHP applications, implementing multi-layer security by combining different security techniques such as SQLi prevention with protections against XSS, CSRF, and file uploads, and deploying a Web Application Firewall (WAF) to detect and block SQL Injection payloads in real time .

Traditional SQL Injection prevention techniques, such as manual input validation, escaping special characters, and limiting database privileges, often depend heavily on developer awareness and have shown to be ineffective against more complex payloads. In contrast, modern approaches utilize Artificial Intelligence and Generative Models like VAE and GANs to automatically simulate and detect SQL Injection patterns that traditional methods may miss. These models help identify new types of SQLi payloads and automate the detection process, thus providing a more robust defense mechanism .

You might also like