Skip to content

About

Practical implementation of in-band SQL Injection vulnerabilities techniques (Piggybacked query, End Of Line Comment, Tautology) using Node.js, PostgreSQL and Docker.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

SQL Injection Demo

Platform Language Backend Infra

Overview

This project is a demonstration of an in-band SQL Injection attack. The primary goal is to show how an attacker can extract sensitive data or bypass authentication by inserting malicious SQL queries into web input fields.

The application architecture consists of a Node.js web server utilizing the pg module to connect to a PostgreSQL database, I also used pgAdmin as a database management interface. The entire environment is containerized and orchestrated using Docker.

Key Features

This demo focuses on Authentication Bypass, allowing an attacker to evade login mechanisms. The vulnerability exists because my application builds the SQL query by directly concatenating user input without validation: SELECT * FROM users WHERE username = '${username}' AND password = '${password}'.

You can simulate three different types of in-band attacks:

  • Tautology: By entering ' OR '1'='1 in the password field, the attacker creates a WHERE clause that is always true. This returns all rows in the table, effectively violating confidentiality by exposing all records without authorization.
  • End-of-line Comment: By entering admin' -- in the username field, the SQL comment (--) forces the database to ignore the rest of the query, including the password check. This grants unauthorized access to the admin profile, compromising data confidentiality.
  • Piggybacked Query: By entering '; UPDATE users SET password = 'newPass' WHERE username = 'admin'; -- in the password field, a second malicious query is appended. This executes both the original query and the update query, changing the admin's password so violating both system integrity and confidentiality. Moreover, by using this same technique, the application includes a button that allows you to maliciously drop the entire table and reveal the database version in use.

Application Preview

SQLi App Preview


How to Run

Prerequisites

  1. Docker Desktop (required for running the local server and database containers).
  2. A local code editor (like VS Code).

Setup Steps

  1. Environment Variables Configuration

    • To keep credentials secure, this project uses a .env file.
    • Create a new file named .env in the root directory.
    • Copy the structure from .env.example and fill in your desired passwords for PostgreSQL and pgAdmin.
  2. Start the Infrastructure You don't need to manually run npm install locally, as the Dockerfile handles dependency installation during the build process. Just open your terminal in the root directory of the project and run:

    docker-compose up --build -d
  3. Access the Web Application Once the containers are running, open your browser and navigate to the login page: http://localhost:3000

Database Management (pgAdmin)

You have two ways to inspect the database depending on your preferred workflow:

Option A: pgAdmin Desktop App (Recommended) If you have the native pgAdmin application installed on your machine:

  • Open the pgAdmin app.
  • Add a new server connection.
  • Set the Host to localhost and the Port to 5432.
  • Use the username postgres and the database password you defined in your .env file.

Option B: pgAdmin via Web Browser If you prefer using the containerized pgAdmin web interface:

  • Navigate to http://localhost:8080 in your browser.
  • Log in using the PGADMIN_DEFAULT_EMAIL and PGADMIN_DEFAULT_PASSWORD you set in your .env file (e.g., users@users.com / root).
  • Add a new server connection.
  • Important: Set the Host to db (since it is communicating within the Docker network) and the Port to 5432.
  • Use the username postgres and your database password.

About

Practical implementation of in-band SQL Injection vulnerabilities techniques (Piggybacked query, End Of Line Comment, Tautology) using Node.js, PostgreSQL and Docker.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages