Enum Databases
Theory
When exploiting SQL injection vulnerabilities, or when you gain access to the database itself, 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 or even users and permissions informations.
Practice
Database version
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:
SELECT @@version
Database Names
When performing SQL injections, it can be useful to know the names of the databases that are present on the targeted server. Enumerating the database names allows you to identify which databases are available and potentially gain insight into the server's configuration and architecture. This information can be used to craft more targeted and effective SQL injection attacks.
We can enum the current database with the following query:
SELECT database();
We can list all databases with the following query:
SELECT schema_name FROM information_schema.schemata;
Tables Names
The next step in performing SQL injections is to enumerate the tables that are present within each database. Enumerating the table names can provide valuable information about the structure and content of the databases.
SELECT table_name FROM information_schema.tables;
SELECT table_name FROM information_schema.tables WHERE table_schema = DATABASE();
Columns Names
Next step is to enumerate columns within tables.It's a crucial step in the process of exploiting a SQL injection vulnerability.
SELECT column_name FROM information_schema.columns WHERE table_name = 'TABLE-NAME-HERE';
DB Users
Additionally, we may enumerate DB users with following queries.
#Get all users
SELECT * FROM mysql.user;
#Get current user
SELECT user();
Permissions & Privileges
Sometimes it can be useful to enumerate user's permissions or privileges. We can acheive this with the following queries.
#Show privileges granted to the current MySQL user
mysql> SHOW GRANTS;
#Show privileges granted to a particular MySQL user account from a given host
mysql> SHOW GRANTS FOR 'user_name'@'host';
mysql> SHOW GRANTS FOR 'root'@'localhost';
Resources
Last updated
Was this helpful?