Try at your own risk. I am not responsible for your own deeds. For educational purpose only.
SQL Injection Basics - Union Based [Detailed Tutorial]
What Is SQL Injection?
SQL Injection is one of the most commonly found vulnerabilities present on the web, It holds the number one place in Owasp Top 10. A SQL Injection can be defined as an attack in which we append SQL queries in order to extract the data present in the database. This normally occurs due to lack of input validation. SQL Injection can also commonly used by attackers to bypass authentication, however here, we would focus on Data extraction with SQL Injection.Finding A Vulnerable Website
In order to begin with this tutorial, you would need a vulnerable website. Either, you could use the one, which i would be mentioning in this tutorial, or you could find your own. You could use variety of google dorks for this purpose. Here are some of the common dorks to find a SQL Injection vulnerability:inurl:/general.php?*id=*
inurl:/careers-detail.asp?id=
inurl:/WhatNew.asp?page=&id=
inurl:/gallery.asp?cid=
inurl:/publications.asp?type=
inurl:/mpfn=pdview&id=
inurl:/reservations.php?id=
inurl:/list_blogs.php?sort_
inurl:/eventdetails.php?*=
inurl:/commodities.php?*id=
inurl:/recipe-view.php?id=
inurl:product.php?mid=
inurl:view_ad.php?id=
inurl:/imprimir.php?id=
inurl:/prodotti.php?id=
inurl:index.cgi?aktion=
inurl:/default.php?id=
inurl:/default.php?portalID=
inurl:/*.php?id=
inurl:/articles.php?id=
inurl:/os_view_full.php?
inurl:/Content.asp?id=
inurl:/CollectionContent.asp?
Alternatively to save your self some time, you could use a neat tool called "Xcode Exploit Scanner" which would use built in dorks in order to find a SQL injection vulnerability.
Testing For SQL Injection
http://www.outreachforyouth.We would test the above website for a SQL injection vulnerability. Which could clearly from the url that recordID parameter is accepting the input, these places are more likely to have a sql injection vulnerability as there are chances that the input validation is not performed. So in order to test for a SQL Injection vulnerability, we would insert a ', after the input, this would break the query. Depending upon the database, we would get different types of errors.
On appending the ', we get an error:
Request: http://www.outreachforyouth.
we get the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line 1
Determining The Number Of Columns:
In Mysql, an order by command is used to order a sequence in a particular order, here we would be using an order by command to determine the number of columns. Our first request would look like:
http://www.outreachforyouth.
The page loads fine.
We would keep increasing the order by command number until we get an error, which would usually be something like "Unknown column in 'order clause'" or something similar to it. So in this case
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
Hence we conclude that the number of columns are 11.
String Method
In above example, the column count were found by integer method. However, sometimes, we would need to use string method in order to find columns count, In that case, no matter how you much you increase the order count the page will load fine, in those cases, you would keep the ' appended when determining the column count.
Example:
http://www.outreachforyouth.
Finding A Vulnerable Coulmn
Next, we would need to find the vulnerable column, which would be used to extract data from the database. We would use a Union command, which is the combination of two select statements in order to extract the data. Along with it, we will also place a negative sign just after the equal sign.
Example
http://www.outreachforyouth.
So, as you can look at the above picture is that we see 3,4 and 6th column on the page. This shows us that these particular columns are being used to display information on the web page and can be used to extract information from the database.
Other Methods
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
Fingerprinting The Database
The next step would be to use the vulnerable column in order to finger print the database. We would use the following commands.user() - Shows the current user.
version() - Displays the database version (Super Important)
database() - Displays the name of the database.
Let's finger print the database information.
Example:
http://www.outreachforyouth.
http://www.outreachforyouth.
http://www.outreachforyouth.
Extracted Information
Database Version: 5.1.66-cll
User: outreach_db_user@localhost
Database: outreach5
We are lucky that we have version 5 here, therefore it's possible for us to extract the table names, however, if the version would have been less than 5, we would had to guess the table names, because in mysql version 4, there is no information_schema which links all the databases.
Extracting The Table Names
Now, we add queries to extract the table names from the current database, we would use group_concat inside the vulnerable column order to extract all the tables.
Note: If we would just use concat, we would be able to extract only one table name.
Example
http://www.outreachforyouth.

This would extract all the table names. However most of them would be unimportant for us, we are in search for the tables such as users, administrators etc. So therefore to filter out our search to only extract tables from the current database.
Example
http://www.outreachforyouth.
Extracted Tables
church testimonies,description, testimonies,users
We have successfully extracted four tables, however the most important data would be contained inside the users tables.
Converting The Table Names To Hex Or Mysql Char
Most of the times the table names would not work when extracting data from a table, therefore i would recommend you to either convert the table_names to hex or my sql char. You can google for online tools or use hackbar in order to convert.
Hex Equivalent:
User = 0x5573657273
Mysql Char Equivalnet:
User = CHAR(117, 115, 101, 114, 115)
So now our query would become:
Example
http://www.outreachforyouth.
So, what the above query is asking is to return all the columns in table from information_schema.columns where the table name is the char equivalent of users.
So, three columns were returned inside the users table:
id, name, password.
Now it's time to extract the id, name and password from the users table.
Our final query would be:
Example
http://www.outreachforyouth.
So, in the above query we are just asking the database for the data behind the id, name and password from the table users. You may have noticed that we used concat here instead of group_concat, this is because, we wanted just to extract the password for the first user which is always the administrator.
In order to format it well, we can use table exits.
Example:
http://www.outreachforyouth.
So finally we have extracted the username and password from the database. Some websites store the passwords in form of hashes, you would mostly see MD5 hashes, if you come across a MD5 hash, You can use tons of services online to decrypt the hash. My favorite is Md5 decrpyter (http://www.md5decrypter.co.
Hiding Queries From The Administrators
In order to avoid administrators noticing the attack, we would need to append sp_password at the end of the query. Here is the query:Example:
http://www.outreachforyouth.
Queries Summary
Vulnerability
Determining the number of Columns
http://www.outreachforyouth.
Union Comman to find vulnerale Columns
Version Detection
User detection
http://www.outreachforyouth.
Database
http://www.outreachforyouth.
Database Version: 5.0.675
User: outreach_db_user@localhost
Database: outreach5
Extracting the tables
Table
churchtestimonies,description, testimonies,users
Extracting Passwords Using Table Exits
http://www.outreachforyouth.
Enjoy....
Anything Can Be Hacked: 18) Hacking A Website In A Very Easy Way. (Sql Injection) >>>>> Download Now
ReplyDelete>>>>> Download Full
Anything Can Be Hacked: 18) Hacking A Website In A Very Easy Way. (Sql Injection) >>>>> Download LINK
>>>>> Download Now
Anything Can Be Hacked: 18) Hacking A Website In A Very Easy Way. (Sql Injection) >>>>> Download Full
>>>>> Download LINK LU