Course contentsShow
← Security
Lesson 572 of 3,05213. Web Security - Injection AttacksFree lesson

Database Fingerprinting via SQL Injection

Techniques to identify MySQL, PostgreSQL, MSSQL, Oracle through injection points.

Database Fingerprinting via SQL Injection

What you'll learn: How to identify which database system (MySQL, PostgreSQL, MSSQL, Oracle) is running behind an SQL injection vulnerability.

Why Fingerprinting Matters

Once you've discovered an SQL injection point, knowing which database you're attacking is crucial. Each database has unique syntax, functions, and system tables. It's like finding a locked door—you need to know what type of lock it is before choosing the right tools.

Core Fingerprinting Techniques

Version-Specific Comments: Different databases handle SQL comments differently. MySQL uses # or -- , while MSSQL uses --, and Oracle requires -- with a space. Injecting comment syntax reveals what's accepted.

Database-Specific Functions: Each database has signature functions:

  • MySQL: VERSION(), DATABASE(), CONCAT()
  • PostgreSQL: version(), current_database()
  • MSSQL: @@VERSION, DB_NAME()
  • Oracle: banner FROM v$version

Inject payloads like ' AND 1=1 AND version()='x to trigger errors revealing the database type.

String Concatenation Differences: Databases concatenate strings differently:

  • MySQL: CONCAT('a','b') or 'a' 'b'
  • PostgreSQL: 'a' || 'b'
  • MSSQL: 'a' + 'b'
  • Oracle: 'a' || 'b' (but requires FROM dual)

Testing these variations tells you which syntax works.

Error Message Analysis: Deliberately triggering errors (error-based injection) often reveals database versions directly. MySQL errors look different from PostgreSQL or Oracle errors—they include vendor-specific keywords and formatting.

Timing Differences: Each database has unique sleep/delay functions for time-based blind injection: SLEEP() (MySQL), pg_sleep() (PostgreSQL), WAITFOR DELAY (MSSQL), DBMS_LOCK.SLEEP() (Oracle).

Key Takeaway: Database fingerprinting uses vendor-specific SQL syntax, functions, comments, and error messages to identify the underlying DBMS, allowing attackers to tailor their exploitation techniques accordingly.