Examining the DB
Last updated
Last updated
When exploiting SQL injection vulnerabilities, it is often necessary to gather some information about the database itself. This includes the type and version of the database software, and the contents of the database in terms of which tables and columns it contains.
Different databases provide different ways of querying their version. You often need to try out different queries to find one that works, allowing you to determine both the type and version of the database software.
The queries to determine the database version for some popular database types are as follows:
Database type | Query |
---|---|
Microsoft, MySQL |
|
Oracle |
|
PostgreSQL |
|
For example, you could use a UNION
attack with the following input:
' UNION SELECT @@version--
This might return output like the following, confirming that the database is Microsoft SQL Server, and the version that is being used:
Microsoft SQL Server 2016 (SP2) (KB4052908) - 13.0.5026.0 (X64) Mar 18 2018 09:11:49 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows Server 2016 Standard 10.0 <X64> (Build 14393: ) (Hypervisor)