🖥️
Offensive security concepts
  • Introduction
  • 💿Virtualbox network setup
    • What is VirtualBox?
    • NAT
    • NAT network
    • Bridged adapter
    • Internal network
    • pfSense
    • vboxmanage
    • Overview
  • 🕵️OSINT
    • What is OSINT?
    • Google dorks
    • Metadata
    • Social media
      • osintagram
  • Tools
    • waybackurls
    • recon-ng
    • sherlock
    • maltego
    • theHarvester
    • photon
  • 😨Social Engineering
    • What is social engineering?
    • 7 tricks of social engineering
    • Email phishing
    • Typosquatting
    • Compiled resources
  • 😈MitM attack
    • What is MitM attack?
    • ARP spoof/poison
    • DNS spoof/poison
    • HTTP MitM attack
    • ICMP redirect attack
    • DHCP spoofing
    • Evil twin attack
    • Experiment (guest network)
    • Compiled resources
  • 🔌UPnP exploitation
    • What is UPnP?
    • What is SSDP?
    • IGD functions
    • LAN devices
    • Compiled resources
  • Network Reconnaissance & Attacks
    • What is network hacking?
  • 1️⃣Network live host discovery
    • What is network live host discovery?
    • nmap
    • arp-scan
    • masscan
  • 2️⃣Network port scan/services enumeration
    • What is network port scan/services enumeration?
    • nmap
    • netcat
  • 3️⃣Network services vulnerability scanning & exploitation
    • What is network vulnerability scanning/exploitation?
    • 20/21 ~ FTP
    • 22 ~ SSH
    • 25 ~ SMTP
    • 53 ~ DNS
    • 80/443 ~ HTTP/HTTPS
    • 110 ~ POP3
    • 111/2049 ~ RPC/NFS
    • 139/445 ~ SMB
    • 143 ~ IMAP
    • 3389 ~ RDP
  • Vulnerability & exploitation
    • Database
    • Metasploit
    • Msfvenom
  • Misconfigurations
    • .DS_Store
  • Web Application Penetration Testing
    • Introduction
    • Directories/URLs gathering
    • Subdomain enumeration
    • File inclusion & Path traversal
    • Insecure Direct Object Reference (IDOR)
    • Upload vulnerabilities
      • File extension cheat-sheet
    • SSRF
    • CSRF
    • XSS
    • SQL injection
  • Authentication/session management
    • JSON Web Token (JWT)
    • OAuth weaknesses
  • Webshell
  • Web API pentesting
    • Resources
    • Methodology
    • jq
    • httpx
    • ParamSpider
  • Web app pentesting methodology
  • OWASP
    • OWASP top 10
    • OWASP API top 10
    • Web Security Testing Guide (WSTG)
  • General web knowledge
    • URI standard (RFC 3986)
    • HTTP headers
  • 🛣️Attacks on routing protocols
    • What are attacks on routing protocols?
    • BGP hijacking
  • 🏕️To explore
    • MQTT
    • Routersploit
    • DNS rebinding attack
    • LLMNR/mDNS poisoning
  • 👤Anonymity
    • VPN
    • Proxychains
    • TOR
    • Obfuscation
  • Credentials brute-force/cracking
    • Introduction
    • Windows SAM database
    • Dictionary attack
    • Rainbow attack
      • Hash database
    • Tools
      • Hydra
      • John the ripper
      • Hashcat
      • hash-identifier
  • Post-exploitation
    • Gaining shell
      • netcat
      • socat
      • powershell
      • bash
      • PHP
    • Repository
  • Privilege escalation
    • Linux
      • Repositories
      • Enumeration
      • Vulnerabilities exploit
        • General
        • Kernel exploit
        • Sudo
        • SUID
        • Capabilities
        • Cronjobs
        • $PATH
        • NFS (target-machine)
        • Filesystem sharing
          • NFS (attacker-machine)
    • Windows
      • Password harvesting
      • Vulnerabilities exploit
        • Scheduled tasks
        • AlwaysInstallElevated
        • Service misconfigurations
          • Insecure permissions on service executable
          • Unquoted service path
          • Insecure service permission
        • Abusing privileges
  • Ⓜ️MITRE ATT&CK
    • Introduction
  • 🧰Tools/services
    • Introduction
    • Web hacking
      • Password brute-forcing
      • Web fuzzing
      • Burp Suite (Community)
      • nikto
      • ZAP (Zed Attack Proxy)
      • nuclei
    • Information gathering/reconnaissance
    • Network hacking
      • nmap (general overview)
      • scapy
      • bettercap
    • General
      • impacket
    • Wordlists
      • cewl
  • Professional report writing
    • Report template
      • Web applicaton pentesting
        • OWASP report layout
  • Tasks on-the-go
    • Note taking on-the-go
    • Other tips
  • Practice
    • Metasploitable 2
    • TryHackMe
  • Operational Security (OpSec)
    • Hardening
      • General
      • VirtualBox
      • Web Browser
  • Write-ups
    • TryHackMe
      • Silver Platter
      • Light
      • OWASP Top 10 - 2021 (task 22)
      • Pickle Rick
    • OverTheWire
      • Untitled
    • OWASP
      • OWASP Juice Shop
      • OWASP WebGoat
  • AI prompt
    • ChatGPT
Powered by GitBook
On this page
  • Important notes in SQL
  • 1. INFORMATION_SCHEMA
  • Types of SQL injection attacks
  • Example of Blind SQLi
  • Practical challenge
  1. Web Application Penetration Testing

SQL injection

Structured-Query Language (SQL) injection attack. SQL is standard language for storing, manipulating and retrieving data in databases.

PreviousXSSNextAuthentication/session management

Last updated 3 months ago

Important notes in SQL

1. INFORMATION_SCHEMA

INFORMATION_SCHEMA provides access to database metadata, information about the MySQL server such as the name of a database or table, the data type of a column, or access privileges.

INFORMATION_SCHEMA.TABLES

A particular metadata provided by INFORMATION_SCHEMA would be TABLES. This provides information about all tables and views within a database.

The TABLES table has these columns:

  1. TABLE_CATALOG

The name of the catalog to which the table belongs.

  1. TABLE_SCHEMA

The name of the schema (database) to which the table belongs.

  1. TABLE_NAME

The name of the table.

  1. TABLE_TYPE

BASE TABLE for a table, VIEW for a view, or SYSTEM VIEW for an INFORMATION_SCHEMA table.

INFORMATION_SCHEMA.COLUMNS

Another metadata provided would be COLUMNS, which table provides information about columns in tables.

The COLUMNS table has these columns (only shown a few):

  1. TABLE_CATALOG

The name of the catalog to which the table containing the column belongs.

  1. TABLE_SCHEMA

The name of the schema (database) to which the table containing the column belongs.

  1. TABLE_NAME

The name of the table containing the column.

  1. COLUMN_NAME

The name of the column.

Information about INFORMATION_SCHEMA.TABLES retrieved from:

Information about INFORMATION_SCHEMA.COLUMNS retrieved from:

Types of SQL injection attacks

  1. In-Band SQLi

In-Band SQL Injection is the easiest type to detect and exploit; In-Band just refers to the same method of communication being used to exploit the vulnerability and also receive the results, for example, discovering an SQL Injection vulnerability on a website page and then being able to extract data from the database to the same page.

  1. Blind SQLi

Unlike In-Band SQL injection, where we can see the results of our attack directly on the screen, blind SQLi is when we get little to no feedback to confirm whether our injected queries were, in fact, successful or not, this is because the error messages have been disabled, but the injection still works regardless.

Possible feedbacks that can help us in a blind SQLi attack:

a) Boolean response based

b) Time based

  • Using the built-in SLEEP() method

  • The SLEEP() method will only ever get executed upon a successful UNION SELECT statement.

  1. Out-of-Band SQLi

Out-of-band SQL Injection isn't as common as it either depends on specific features being enabled on the database server or the web application's business logic, which makes some kind of external network call based on the results from an SQL query.

Example of Blind SQLi

Suppose there is a login form with input fields for username and password. The SQL query may something like this:

select * from users where username=<input> and password=<input> LIMIT 1;

As long as this SQL statement resolves to a true value, the login will succeed. Without proper validation, an attacker can maliciously inject SQL commands to force the query to be true without having a valid username/password pair.

In this case, the input to the password field would look something like this:

' OR 1=1;--

This input does the following:

  • ': Escape from the password field

  • OR: logical statement

  • 1=1: A statement that always resolves to a true value

  • ;: Indicates the end of SQL query statement

  • --: Comments out everything after

Knowledge taken from the following TryHackMe tutorial:

Practical challenge

TASK 8 from:

Challenge Objective

Your objective in this challenge is to identify and exploit a Union SQL Injection vulnerability present in the ID parameter of the /about/ID endpoint. By leveraging this vulnerability, your task is to launch an attack to retrieve the notes about the CEO stored in the database.

  1. 1'

  • To force an error:

Invalid statement:

SELECT firstName, lastName, pfpLink, role, bio FROM people WHERE id = 1';

The information provided in the error message tells us about the SQL query used

  1. 8 UNION ALL SELECT group_concat(column_name),null,null,null,null FROM information_schema.columns WHERE table_name='people'

  • The value 8 (or any other values that does not match an entry in the database) is used to force the first part of the query to not return any results, so as to allow us to view the results from the subsequent UNION statement

  • Displays all the columns in the people table

  1. 8 UNION SELECT notes,null,null,null,null from people where id=1;

  • The ID of the CEO is 1

  • This query will retrieve the content stored in the notes

TryHackMeTryHackMe
MySQL :: MySQL Information Schema :: 4.8 The INFORMATION_SCHEMA COLUMNS Table
Logo
Burp Suite: RepeaterTryHackMe
Logo
SQL Injection Cheat SheetInvicti
MySQL :: MySQL 8.4 Reference Manual :: 28.3.38 The INFORMATION_SCHEMA TABLES Table
Logo
Logo
Logo
MySQL :: MySQL 8.4 Reference Manual :: 28.2 INFORMATION_SCHEMA Table Reference
Logo