<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Burpsuite%2FSQL_Injection%2FOld</id>
	<title>Burpsuite/SQL Injection/Old - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://charlesreid1.com/w/index.php?action=history&amp;feed=atom&amp;title=Burpsuite%2FSQL_Injection%2FOld"/>
	<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Burpsuite/SQL_Injection/Old&amp;action=history"/>
	<updated>2026-06-19T22:33:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.12</generator>
	<entry>
		<id>https://charlesreid1.com/w/index.php?title=Burpsuite/SQL_Injection/Old&amp;diff=29376&amp;oldid=prev</id>
		<title>Unknown user: Created page with &quot;{{Main|SQL Injection}}  This page contains notes on how to use Burp Suite to perform SQL injection attacks.   =Union Attacks=  {{Main|SQL Injection/UNION Attack}}   ==Determin...&quot;</title>
		<link rel="alternate" type="text/html" href="https://charlesreid1.com/w/index.php?title=Burpsuite/SQL_Injection/Old&amp;diff=29376&amp;oldid=prev"/>
		<updated>2022-03-17T00:45:02Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;{{Main|SQL Injection}}  This page contains notes on how to use Burp Suite to perform SQL injection attacks.   =Union Attacks=  {{Main|SQL Injection/UNION Attack}}   ==Determin...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Main|SQL Injection}}&lt;br /&gt;
&lt;br /&gt;
This page contains notes on how to use Burp Suite to perform SQL injection attacks.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Union Attacks=&lt;br /&gt;
&lt;br /&gt;
{{Main|SQL Injection/UNION Attack}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining Number of Columns Returned for an Attack==&lt;br /&gt;
&lt;br /&gt;
{{Main|SQL_Injection/UNION_Attack#Determining_Number_of_Columns_Returned_for_an_Attack}}&lt;br /&gt;
&lt;br /&gt;
===Example - Determine Number of Columns===&lt;br /&gt;
&lt;br /&gt;
Fire up Burp Suite, switch to the Proxy tab, and open the browser. Log into the Port Swigger training site online.&lt;br /&gt;
&lt;br /&gt;
Here is a simple e-commerce website with a built-in SQL injection vulnerability:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 1.png|500px]]&lt;br /&gt;
&lt;br /&gt;
Note the &amp;lt;code&amp;gt;category=xyz&amp;lt;/code&amp;gt;, which is the insecure portion of the application - this value is substituted into an SQL query without being sanitized first&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 2.png|500px]]&lt;br /&gt;
&lt;br /&gt;
We use the UNION SELECT payloads in this case. Trying with 1 or 2 NULL values returns a server error:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 3.png|500px]]&lt;br /&gt;
&lt;br /&gt;
But once we try with 3 NULL values, the server successfully renders the page &lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 4.png|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Another Example: Order By, and Non-Microsoft SQL Server===&lt;br /&gt;
&lt;br /&gt;
MS SQL databases accept &amp;lt;code&amp;gt;--&amp;lt;/code&amp;gt; to start comments, but if it&amp;#039;s not an MS SQL database, it may not accept the &amp;lt;code&amp;gt;--&amp;lt;/code&amp;gt;. Instead, you need to use a hash sign to terminate the query early.&lt;br /&gt;
&lt;br /&gt;
In this case, the procedure covered above needs to change slightly. Let&amp;#039;s also cover how to use ORDER BY instead of SELECT NULL.&lt;br /&gt;
&lt;br /&gt;
We start with the same vulnerable web application with its vulnerable &amp;quot;category&amp;quot; URL parameter:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/filter?category=xyz&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Start out by browsing to that page in the Burp proxy. Turn on Intercept Traffic and refresh the page. You should now see the request for the /filter URL, with its &amp;quot;category&amp;quot; value set.&lt;br /&gt;
&lt;br /&gt;
Now right click on this request, and send to repeater. Then you can turn off Intercept Traffic, and switch over to Repeater.&lt;br /&gt;
&lt;br /&gt;
Here&amp;#039;s what the un-tampered-with request might look like:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9a.png|500px]]&lt;br /&gt;
&lt;br /&gt;
Now we can use the following SQL query in place of the category: &amp;lt;code&amp;gt;&amp;#039; ORDER BY 1--&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
(This will try to order the results that are being returned by the /filter URL by the first column. Increment to 2, 3, 4, etc. to discover how many columns the SQL query being attacked is returning.)&lt;br /&gt;
&lt;br /&gt;
This request, when URL-encoded, is easy enough that we probably don&amp;#039;t need Burp to do it for us: &amp;lt;code&amp;gt;&amp;#039;+ORDER+BY+1--&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
However, in some cases, this will still return a 500 error:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9b.png|500px]]&lt;br /&gt;
&lt;br /&gt;
In this case, we can try terminating the query string with a hash sign: &amp;lt;code&amp;gt;&amp;#039; ORDER BY 1 #&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The hash sign must be URL-encoded, and Burp Suite will come in handy because it has built-in capabilities to obtain the URL-encoded version of a string.&lt;br /&gt;
&lt;br /&gt;
When in repeater, and modifying the request URL, you can type the SQL query in a way that is NOT URL-encoded, and then select the text, and click Command-U to URL-encode the text.&lt;br /&gt;
&lt;br /&gt;
Before:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9c.png|500px]]&lt;br /&gt;
&lt;br /&gt;
After:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9d.png|500px]]&lt;br /&gt;
&lt;br /&gt;
Once we send that request, we see the server return a 200 code, meaning we can continue on with our ORDER BY attacks to enumerate columns.&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9e.png|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Determining Column Data Types==&lt;br /&gt;
&lt;br /&gt;
{{Main|SQL_Injection/UNION_Attack#Determining_Column_Data_Types}}&lt;br /&gt;
&lt;br /&gt;
===Example - Determine Data Type of Columns===&lt;br /&gt;
&lt;br /&gt;
Start with the same vulnerable e-commerce application, and still using the un-sanitized &amp;quot;category&amp;quot; variable. Start by repeating the attack shown above, to verify we are still dealing with the same number of columns:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/filter?category=&amp;#039;+UNION+SELECT+NULL,NULL,NULL--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
confirm that the page renders and does not return any error, indicating we are dealing with 3 columns:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 5.png|500px]]&lt;br /&gt;
&lt;br /&gt;
Now we modify the query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/filter?category=&amp;#039;+UNION+SELECT+&amp;#039;a&amp;#039;,NULL,NULL--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This returns an internal server error, so the first column is not a string type:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 6.png|500px]]&lt;br /&gt;
&lt;br /&gt;
When we try the second column, the web application successfully renders the page, which means the second column returned is a string type:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/filter?category=&amp;#039;+UNION+SELECT+NULL,&amp;#039;a&amp;#039;,NULL--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 7.png|500px]]&lt;br /&gt;
&lt;br /&gt;
The last column is not a string type either,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/filter?category=&amp;#039;+UNION+SELECT+NULL,NULL,&amp;#039;a&amp;#039;--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 8.png|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Retrieving Data from Other Columns==&lt;br /&gt;
&lt;br /&gt;
{{Main|SQL_Injection/UNION_Attack#Retrieving_Data_from_Other_Columns}}&lt;br /&gt;
&lt;br /&gt;
===Example - Retrieve Data from Other Columns===&lt;br /&gt;
&lt;br /&gt;
Start with the same e-commerce web application with the same SQL injection vulnerability in the category variable.&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9.png|500px]]&lt;br /&gt;
&lt;br /&gt;
We start by repeating the two SQL injection attacks covered above, to verify that the products page is returning two fields, and that both fields are strings.&lt;br /&gt;
&lt;br /&gt;
Now, we know that the products category page is fetching two string columns, and so we can do a UNION attack and fetch two other string columns. In this case, the username and password columns of the users table.&lt;br /&gt;
&lt;br /&gt;
Craft the SQL injection query:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/filter?category=&amp;#039;+UNION+SELECT+username,password+FROM+users--&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will create a query that is the union of usernames/passwords with the (empty) products query:&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 10.png|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Retrieving Multiple Values in One Column==&lt;br /&gt;
&lt;br /&gt;
{{Main|SQL_Injection/UNION_Attack#Retrieving_Multiple_Values_in_One_Column}}&lt;br /&gt;
&lt;br /&gt;
===Example - Retrieving Multiple Values in One Column===&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 11.png|500px]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Examining the Database=&lt;br /&gt;
&lt;br /&gt;
{{Main|SQL Injection/UNION Attack#Examining the Database}}&lt;br /&gt;
&lt;br /&gt;
==Querying the Database Type and Version==&lt;br /&gt;
&lt;br /&gt;
{{Main|SQL_Injection/UNION_Attack#Querying_the_Database_Type_and_Version}}&lt;br /&gt;
&lt;br /&gt;
===Example - Retrieving Database Version from Oracle===&lt;br /&gt;
&lt;br /&gt;
===Example - Retrieving Database Version from MySQL and MS SQL===&lt;br /&gt;
&lt;br /&gt;
Working with the vulnerable web app with the category parameter that is vulnerable to SQL injection.&lt;br /&gt;
&lt;br /&gt;
We start by finding the number of columns. In the process, we find that &amp;lt;code&amp;gt;--&amp;lt;/code&amp;gt; doesn&amp;#039;t work as a statement-terminating sequence, but &amp;lt;code&amp;gt;#&amp;lt;/code&amp;gt; does.&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9b.png|500px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9c.png|500px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 9d.png|500px]]&lt;br /&gt;
&lt;br /&gt;
When we inject &amp;lt;code&amp;gt;&amp;#039; ORDER BY 1 #&amp;lt;/code&amp;gt; the application is ok&lt;br /&gt;
&lt;br /&gt;
When we inject &amp;lt;code&amp;gt;&amp;#039; ORDER BY 2 #&amp;lt;/code&amp;gt; the application is ok&lt;br /&gt;
&lt;br /&gt;
When we inject &amp;lt;code&amp;gt;&amp;#039; ORDER BY 3 #&amp;lt;/code&amp;gt; the application crashes, so there are 2 columns being returned&lt;br /&gt;
&lt;br /&gt;
We can verify the columns being returned are text (which we can deduce from the UI, which has two text fields for each product) by injecting &amp;lt;code&amp;gt;&amp;#039; UNION SELECT &amp;#039;a&amp;#039;,&amp;#039;a&amp;#039; #&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This returns a 200, meaning there are 2 columns of text returned by the SQL query we are injecting&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 10d.png|500px]]&lt;br /&gt;
&lt;br /&gt;
Last, we know that we can get the version of the server (https://charlesreid1.com/wiki/SQL_Injection/UNION_Attack#Querying_the_Database_Type_and_Version) by using &amp;lt;code&amp;gt;SELECT @@version&amp;lt;/code&amp;gt;, but this returns a string with the version number, and we have to make two columns for the union query to work.&lt;br /&gt;
&lt;br /&gt;
We inject the following query: &amp;lt;code&amp;gt;&amp;#039; UNION SELECT @@version,NULL #&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This will put the version in one column and nothing in the other. This adds one more product to the bottom of the list of products, which contains the SQL server version number.&lt;br /&gt;
&lt;br /&gt;
This sequence shows entering the injected query in plain text, then using Command-U to render it in URL encoding, then the resulting request (note the version number in the bottom right of the third image):&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 10e.png|500px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 10f.png|500px]]&lt;br /&gt;
&lt;br /&gt;
[[Image:SQL Injection UNION Attack Burp 10g.png|500px]]&lt;br /&gt;
&lt;br /&gt;
=Resources=&lt;br /&gt;
&lt;br /&gt;
==Links==&lt;br /&gt;
&lt;br /&gt;
Port Swigger Burp Suite training material:&lt;br /&gt;
&lt;br /&gt;
* What is SQL injection? https://portswigger.net/web-security/sql-injection&lt;br /&gt;
* SQL injection union attacks: https://portswigger.net/web-security/sql-injection/union-attacks&lt;br /&gt;
* Examining the database: https://portswigger.net/web-security/sql-injection/examining-the-database&lt;br /&gt;
* Blind SQL injection: https://portswigger.net/web-security/sql-injection/blind&lt;br /&gt;
* Cheat sheet: https://portswigger.net/web-security/sql-injection/cheat-sheet&lt;br /&gt;
&lt;br /&gt;
==YouTube==&lt;br /&gt;
&lt;br /&gt;
SQL injection lab 7 - querying db type/version on oracle: https://www.youtube.com/watch?v=neeY0iVa_0A&lt;br /&gt;
&lt;br /&gt;
SQL injection lab 8 - querying db type/version on mysql and ms sql: https://www.youtube.com/watch?v=MFTk_LNRW0g&lt;br /&gt;
&lt;br /&gt;
==YouTube==&lt;br /&gt;
&lt;br /&gt;
Helpful video covering the MySQL and MS SQL version vulnerabilities: https://www.youtube.com/watch?v=MFTk_LNRW0g&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Burpsuite]]&lt;br /&gt;
[[Category:Security]]&lt;br /&gt;
[[Category:SQL Injection]]&lt;br /&gt;
[[Category:SQL]]&lt;/div&gt;</summary>
		<author><name>Unknown user</name></author>
	</entry>
</feed>