Skip to main content

Hands-On Web Exploitation: Performing SQL Injection Attacks on My Own Web Application

Updated 10 min readMarkdown
Hands-On Web Exploitation: Performing SQL Injection Attacks on My Own Web Application

Learning about cybersecurity concepts through articles and tutorials is useful, but understanding how vulnerabilities actually work requires hands-on experience.

Recently, I started working on a personal Web Exploitation Project where I built a deliberately vulnerable web application and tested it using different attack techniques.

For this project, I created a locally hosted web application called Nexa Portal using Flask and SQLite. The goal was to understand how common web vulnerabilities work by simulating attacks against an application I control.

One of the first areas I explored was SQL Injection (SQLi).

In this article, I'll walk through the SQL injection attacks I performed, explain how each technique works, and share what I learned from exploiting a vulnerable search feature.

All testing described here was performed against my own local application in a controlled environment.

1. Introducing the Web Exploitation Project

The idea behind this project was relatively straightforward: build a web application, introduce a controlled vulnerability, and then attempt to exploit it.

Rather than relying entirely on pre-built vulnerable environments, I wanted to understand both sides of the process:

  • How a web application handles incoming requests.
  • How user input interacts with a database.
  • How vulnerabilities can be exploited.
  • What information an attacker might be able to retrieve.
  • How application behavior changes when an attack succeeds.

For the application itself, I used the following technologies:

Technology Purpose
Python Main programming language
Flask Web application framework
SQLite Database management
HTML/CSS Application interface

The application runs locally on my computer and provides a simple web interface for interacting with its database.

For the SQL injection portion, I focused on the application's search functionality.

2. Understanding the Vulnerability

Before performing any attacks, I needed to understand where the vulnerability existed.

Nexa Portal contains a search feature that allows users to search through information stored in its database.

When someone submits a search term, the Flask application takes that input and constructs a SQL query to retrieve matching records.

The vulnerable implementation directly concatenates user input into the SQL statement.

Conceptually, the query follows this structure:

SELECT *
FROM products
WHERE column_1 LIKE '%USER_INPUT%'
   OR column_2 LIKE '%USER_INPUT%'
   OR column_3 LIKE '%USER_INPUT%';

The important detail is that the application inserts the user's input directly into the SQL query.

This creates an opportunity for an attacker to introduce SQL syntax into the search field rather than simply searching for ordinary text.

For example, instead of entering a product name, an attacker could submit input containing SQL operators, conditions, or additional query instructions.

If the application interprets that input as part of the SQL statement, the original query can behave differently than intended.

This is the fundamental vulnerability I wanted to investigate.

3. Performing the SQL Injection Attacks

I divided the SQL injection portion of the project into four attack exercises.

Each exercise explored a different way an attacker could manipulate the application's database queries or retrieve information from the database.

Attack 4.1 – Boolean-Based SQL Injection

The first technique I explored was Boolean-based SQL injection.

This technique involves injecting conditions that evaluate to either TRUE or FALSE and observing how the application responds.

The idea is to determine whether an attacker can influence the results returned by the database simply by changing the conditions inside a SQL query.

For my first test, I submitted the following payload into the search field:

' OR 1=1 -- 

Here's what the individual components mean:

  • ' attempts to close the original SQL string.
  • OR introduces an additional condition.
  • 1=1 is a condition that always evaluates to TRUE.
  • -- begins a SQL comment, causing the remaining portion of the query to be ignored in the relevant SQL context.

Because the injected condition is always true, it can change the logic of the original search query.

I also tested the opposite behavior using a condition that always evaluates to FALSE:

' AND 1=2 -- 

Since 1=2 is false, the database evaluates the injected condition differently.

By comparing the application's responses to the true and false conditions, I could observe how manipulating SQL logic affected the search results.

This exercise demonstrated how a seemingly ordinary search field could become a way to interfere with database query logic.

Attack 4.2 – SQL Syntax Error Injection

The second exercise focused on triggering SQL errors.

Applications sometimes expose database error messages when they encounter malformed SQL statements.

These errors can reveal useful information about how the application communicates with its database.

For this test, I submitted a single quote:

'

A single quote can interfere with the syntax of a dynamically constructed SQL query because it may leave a string literal improperly terminated.

When the database receives an invalid query, it may generate a syntax error.

Depending on how the application handles database exceptions, the error can reveal information about the underlying query or database implementation.

This technique is particularly interesting because an attacker does not necessarily need to successfully retrieve database records to learn something about the application's internal behavior.

Even an error response can provide clues about the technology and query structure behind a website.

Attack 4.3 – UNION-Based SQL Injection

The third exercise explored UNION-based SQL injection.

This technique takes advantage of the SQL UNION operator, which allows the results of multiple SELECT statements to be combined.

Normally, a website's search functionality retrieves information from a particular table.

However, if the underlying query is vulnerable, an attacker may be able to introduce another SELECT statement and attempt to retrieve information from a different table.

For this attack, I first needed to account for an important SQL requirement.

The queries being combined using UNION generally need to return the same number of columns, with compatible data types in corresponding positions.

In my testing, the vulnerable search query required a five-column result structure.

After establishing that requirement, I tested a UNION-based injection designed to combine the original search results with information from another database table.

The significance of this technique is that an attacker may be able to retrieve information that the application never intended to display through its search functionality.

For example, a vulnerable product search feature could potentially become an entry point for accessing information stored elsewhere in the database.

This exercise demonstrated how SQL injection can extend beyond manipulating search results and potentially expose information from other database tables.

Attack 4.4 – Database Schema and Data Extraction

The fourth exercise focused on understanding the database structure and retrieving information stored within it.

An attacker generally benefits from knowing how a database is organized before attempting to retrieve specific information.

This is where database metadata becomes important.

Since my application uses SQLite, I explored its internal sqlite_master table.

SQLite maintains information about database objects, including tables, indexes, views, and triggers, in this internal schema table.

By exploiting the vulnerable search functionality, I tested whether information from sqlite_master could be retrieved through SQL injection.

This provided insight into the database's structure and the tables available within it.

After exploring the schema, I moved on to testing whether information from the database's user-related records could also be retrieved.

The important distinction here is between discovering the database structure and extracting the actual information stored inside it.

The process can be understood in two stages:

  1. Schema discovery: Identifying database objects and understanding how the database is organized.
  2. Data extraction: Attempting to retrieve records from tables identified during the discovery process.

This exercise demonstrated how a vulnerability in one application feature could potentially expose information belonging to other parts of the database.

It also highlighted why database access should be treated as a serious security boundary.

4. What I Learned From These Attacks

Performing these exercises helped me understand SQL injection in a much more practical way.

Before this project, I understood the general concept of SQL injection: attackers manipulate user input to interfere with database queries.

However, implementing and testing the attacks helped me understand the different techniques involved and how they produce different results.

Here are some of my main takeaways:

Boolean-based injection is about manipulating logic.

An attacker can introduce conditions that change how the database evaluates an existing query. Comparing TRUE and FALSE responses can reveal whether the input is affecting the query.

Database errors can reveal useful information.

A failed query is not necessarily harmless. Detailed error messages can expose information about an application's database interactions.

UNION injection can expose information from other tables.

A vulnerable query may allow an attacker to combine results from different database queries, potentially accessing information outside the application's intended search functionality.

Database metadata is valuable to attackers.

Understanding the database schema helps attackers identify tables and other objects that may contain valuable information.

Most importantly, these exercises showed me that a vulnerability in one seemingly minor application feature can have consequences beyond that individual feature.

5. Project Scope and Current Progress

The SQL injection exercises described in this article represent the portion of the Web Exploitation Project I have completed so far.

For this stage, I focused specifically on the vulnerable search functionality and the four SQL injection exercises discussed above.

I have not implemented or tested login authentication, product detail lookup, administrative product modification, or a contact form as part of this work.

I wanted to keep the scope focused on understanding and demonstrating SQL injection before expanding the application with additional functionality and attack scenarios.

6. What's Next?

SQL injection is only one area of web application security I want to explore through this project.

As I continue developing the Web Exploitation Project, I plan to explore additional attack techniques and understand how different vulnerabilities affect web applications.

I also want to expand the defensive side of the project by investigating how security tools can identify suspicious activity, how application logs can provide evidence of attacks, and how vulnerabilities can be addressed.

The broader goal is to create a practical project that demonstrates both the offensive and defensive sides of cybersecurity.

Final Thoughts

This project has been a great opportunity to move beyond simply reading about SQL injection and actually understand how the attacks work.

Building my own application gave me a controlled environment where I could experiment with different SQL injection techniques, observe how the application responded, and investigate what information could potentially be exposed.

The biggest lesson for me was that web application security is not just about understanding individual vulnerabilities. It is also about understanding how applications, databases, and user input interact with one another.

I'll continue documenting my progress as I explore more areas of web exploitation and cybersecurity.

Project: Web Exploitation Project
Github: https://github.com/ved-p-coder/Web-Exploitation-Project

This article documents hands-on security testing performed against my own locally hosted application.

No comments yet. Be the first to comment.