偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

聊聊 Wafw00f 源碼及流量特征

安全 應(yīng)用安全
所謂源碼解析并不會(huì)完整分析其源碼中的所有功能,比如 日志、輸出、展示 等功能不在我們分析的范圍內(nèi),而其對(duì) WAF 的檢測(cè)邏輯、所發(fā)流量的特征、WAF 識(shí)別的指紋等將是重點(diǎn)要分析的地方。

wafw00f介紹

這不是本次的重點(diǎn),相關(guān)介紹及使用方法相信大家已經(jīng)了解,所以此處就直接引用其開(kāi)發(fā)者對(duì)該工具的介紹。

1668779762_63778ef2c9b5f811b18aa.png!small?1668779761475

To do its magic, WAFW00F does the following:

  • Sends a normal HTTP request and analyses the response; this identifies a number of WAF solutions.通過(guò)發(fā)送正常的?HTTP?請(qǐng)求并且分析其返回包,判斷其是否使用 WAF ,若使用確認(rèn)WAF類型
  • If that is not successful, it sends a number of (potentially malicious) HTTP requests and uses simple logic to deduce which WAF it is.若是無(wú)法通過(guò)正常的?HTTP?請(qǐng)求結(jié)果分析出是否使用WAF以及其類型,則構(gòu)造惡意的請(qǐng)求通過(guò)簡(jiǎn)單的邏輯再次進(jìn)行判斷
  • If that is also not successful, it analyses the responses previously returned and uses another simple algorithm to guess if a WAF or security solution is actively responding to our attacks.如果這也不成功,它會(huì)分析之前返回的響應(yīng),并使用另一種簡(jiǎn)單的算法來(lái)猜測(cè)?WAF或安全解決方案是否正在積極響應(yīng)我們的攻擊

使用場(chǎng)景/方法

這不是本次的重點(diǎn),想要具體了解其用法去其github主頁(yè)即可

??https://github.com/EnableSecurity/wafw00f??

本工具的作用上面已經(jīng)很詳細(xì)的描述出來(lái)了,概括一下很簡(jiǎn)單:探測(cè)目標(biāo)是否存在WAF,也可以說(shuō)wafw00f是一個(gè)Web應(yīng)用防火墻(WAF)指紋識(shí)別的工具。

使用方法不難,此處不做介紹,若想進(jìn)一步了解見(jiàn):WEB 防火墻探測(cè)工具 -- wafw00f 使用教程 - General 的個(gè)人博客

wafw00f 源碼解析

所謂源碼解析并不會(huì)完整分析其源碼中的所有功能,比如 日志、輸出、展示 等功能不在我們分析的范圍內(nèi),而其對(duì) WAF 的檢測(cè)邏輯、所發(fā)流量的特征、WAF 識(shí)別的指紋等將是重點(diǎn)要分析的地方。

流程:

  • 解析源碼含義,分析特征
  • 抓包觀察

源碼文件結(jié)構(gòu)

為了方便大家之后去看源碼,此處簡(jiǎn)單描述一下源碼的組成,其中沒(méi)有描述的說(shuō)明其用不大,大家自己去看就知道了,其中標(biāo)注important是本工具的主要功能文件,后續(xù)將重點(diǎn)說(shuō)明。

1668779769_63778ef9467c1c452a6b5.png!small?1668779767856

  • bin
  • lib

asciiarts.py

evillib.py用于向目標(biāo)建立連接發(fā)起請(qǐng)求( important )

  • plugins?用于判斷各個(gè)WAF的指紋 ( important )

aliyundun.py阿里云盾的特征值匹配文件

huaweicloud.py****華為云的特征值匹配文件

baidu.py百度云加速的特征匹配文件

……

還有很多特征文件大家自己去看就好

  • __init__.py
  • main.py該工具主要的檢測(cè)、判斷功能的類與函數(shù)都在該文件中實(shí)現(xiàn)( important )
  • manager.py?加載plugins?中的WAF?指紋判斷文件識(shí)別目標(biāo)WAF類型
  • wafprio.py

上述非important的文件起到的作用多是一些起到 輸出選項(xiàng)、連接 等功能的文件/函數(shù),所以不做特殊介紹

基本流程

請(qǐng)求的流程并不復(fù)雜,和最開(kāi)始介紹處的流程如出一轍:

  • 發(fā)送正常HTTP?請(qǐng)求,并判斷是否存在WAF若存在根據(jù)指紋判斷其類型
  • 若正常HTTP?檢測(cè)不出WAF?,則附加惡意的請(qǐng)求嘗試出發(fā)WAF并分析其類型

最后所謂的根據(jù)算法猜測(cè),流量特征不明顯,不在此次分析的范圍內(nèi),實(shí)際用處也不大。

請(qǐng)求運(yùn)行流程( important)

以第一次的正常HTTP請(qǐng)求探測(cè)為例(其余的都一致)。

1668779774_63778efe6b5b2740e1822.png!small?1668779773039

由于對(duì) Python 并不是太了解,所以作用域的表示采用了C++中的::(若是不對(duì)請(qǐng)及時(shí)指出會(huì)做更改)。

main.py分析

完整的源碼就不放在這占地方了,大家隨時(shí)可到其github主頁(yè)獲取,此處直接分析其重點(diǎn)部分

由上述流程可以看出,所有的請(qǐng)求均是從class WAFW00F中發(fā)起,所以該類就是我們分析的重中之重!

請(qǐng)求的具體實(shí)現(xiàn)(比如請(qǐng)求中攜帶了哪些內(nèi)容)將在分析evillib.py文件是分析,此處主要分析何時(shí)要發(fā)出何種請(qǐng)求。

從main()函數(shù)出發(fā)看其邏輯:(解析參數(shù)等功能將直接略過(guò))

沒(méi)有指定其余參數(shù)

  • 對(duì)輸入的URL?做相關(guān)處理后放到target?中傳入WAFW00F進(jìn)行處理

attacker = WAFW00F(target, debuglevel=options.verbose, path=path,followredirect=options.followredirect, extraheaders=extraheaders,proxies=proxies)

# 若請(qǐng)求沒(méi)有結(jié)果則說(shuō)明目標(biāo)網(wǎng)站或本地網(wǎng)絡(luò)有問(wèn)題
if attacker.rq is None:
log.error('Site %s appears to be down' % hostname)
continue

  • 由于第一次做的是常規(guī)探測(cè),若此處就匹配到了WAF的指紋則輸出結(jié)束即可,具體的輸出等邏輯不是重點(diǎn),略過(guò);
  • 若無(wú)法分析出其是否存在WAF?或匹配不出WAF?則通過(guò)identwaf()函數(shù)進(jìn)步拼湊惡意參數(shù)進(jìn)行探測(cè);
waf = attacker.identwaf(options.findall)
log.info('Identified WAF: %s' % waf)
  • 進(jìn)入identwaf()?函數(shù)后,便會(huì)嘗試匹配各個(gè)WAF的特征;
def identwaf(self, findall=False):
detected = list()
try:
self.attackres = self.performCheck(self.centralAttack)
except RequestBlocked:
return detected
for wafvendor in self.checklist:
self.log.info('Checking for %s' % wafvendor)
if self.wafdetections[wafvendor](self):
detected.append(wafvendor)
if not findall:
break
self.knowledge['wafname'] = detected
return detected

這就是基本的流程。

解析來(lái)如果還沒(méi)有確定出WAF便會(huì)進(jìn)入其自己提供的一個(gè)算法,但這并不是我們對(duì)流量特征分析所要關(guān)注的地方,所以就不探討了。

下面到了激動(dòng)人心的時(shí)刻,WAFW00F類中到底是如何實(shí)現(xiàn)的呢?

class WAFW00F

一上來(lái)就中了大獎(jiǎng):

class WAFW00F(waftoolsengine):

xsstring = '<script>alert("XSS");</script>'
sqlistring = "UNION SELECT ALL FROM information_schema AND ' or SLEEP(5) or '"
lfistring = '../../../../etc/passwd'
rcestring = '/bin/cat /etc/passwd; ping 127.0.0.1; curl google.com'
xxestring = '<!ENTITY xxe SYSTEM "file:///etc/shadow">]><pwn>&hack;</pwn>'

WAFW00F這個(gè)工具所要構(gòu)造拼接的惡意代碼在一開(kāi)始就全部列出了,而且在之后的使用中絕無(wú)變化,要構(gòu)造惡意的請(qǐng)求就是從上述5個(gè)字符串中選擇1個(gè)或多個(gè)直接使用。

可以看到改用據(jù)用于判斷是否存在WAF的語(yǔ)句就以下五類:

  • XSS類                     <script>alert("XSS");</script>
  • SQL注入類              UNION SELECT ALL FROM information_schema AND ' or SLEEP(5) or '
  • 遍歷類                    ../../../../etc/passwd
  • 命令執(zhí)行/拼接類    /bin/cat /etc/passwd; ping 127.0.0.1; curl google.com
  • XXE類                     <!ENTITY xxe SYSTEM "file:///etc/shadow">]><pwn>&hack;</pwn>

那么有了這些語(yǔ)句,WAFW00F又該如何拼接呢?

def normalRequest(self):
return self.Request()

def customRequest(self, headers=None):
return self.Request(headers=headers)

def nonExistent(self):
return self.Request(path=self.path + str(random.randrange(100, 999)) + '.html')

def xssAttack(self):
return self.Request(path=self.path, params= {'s': self.xsstring})

def xxeAttack(self):
return self.Request(path=self.path, params= {'s': self.xxestring})

def lfiAttack(self):
return self.Request(path=self.path + self.lfistring)

def centralAttack(self):
return self.Request(path=self.path, params={'a': self.xsstring, 'b': self.sqlistring, 'c': self.lfistring})

def sqliAttack(self):
return self.Request(path=self.path, params= {'s': self.sqlistring})

def oscAttack(self):
return self.Request(path=self.path, params= {'s': self.rcestring})

具體邏輯并不難理解,拿出幾種幾個(gè)來(lái)說(shuō)一下。

1:def xssAttack(self)

def xssAttack(self):
return self.Request(path=self.path, params= {'s': self.xsstring})

例如給一個(gè)簡(jiǎn)單的例子:我們傳給wafw00f的URL為:http://127.0.0.1:9000則經(jīng)過(guò)該參數(shù)拼接后的請(qǐng)求就為:

http://127.0.0.1:9000/?s=<script>alert("XSS");</script>(URL編碼前 )。

2:def centralAttack(self):

def centralAttack(self):
return self.Request(path=self.path, params={'a': self.xsstring, 'b': self.sqlistring, 'c': self.lfistring})

例如給一個(gè)簡(jiǎn)單的例子:我們傳給wafw00f的URL為:http://127.0.0.1:9000則經(jīng)過(guò)該參數(shù)拼接后的請(qǐng)求就為:

http://127.0.0.1:9000/?s=<script>alert("XSS");</script>&b=UNION SELECT ALL FROM information_schema AND ' or SLEEP(5) or '&c=../../../../etc/passwd(URL編碼前 )

從前面的流程可以看出,在def identwaf(self, findall=False):中調(diào)用的拼接的語(yǔ)句的方法就是本方法,拼接進(jìn)三個(gè)語(yǔ)句,

其他的邏輯相同。

evillib.py分析

上面只是在上層對(duì)要拼接哪些參數(shù)進(jìn)行構(gòu)造,實(shí)際上組合成完整的 HTTP 報(bào)文調(diào)用requests.get()進(jìn)行請(qǐng)求的是在該文件中。

wafw00f中若沒(méi)有通過(guò)—headers指定頭部的話,會(huì)使用自己默認(rèn)的—headers這個(gè)默認(rèn)的 headers 就定義在該文件中。

def_headers = {'Accept'         : 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'Accept-Encoding': 'gzip, deflate',
'Accept-Language': 'en-US,en;q=0.9',
'DNT' : '1', # Do Not Track request header
'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3770.100 Safari/537.36',
'Upgrade-Insecure-Requests': '1' #
}

默認(rèn)情況下,接下來(lái)通過(guò)requests.get()請(qǐng)求時(shí)便會(huì)使用該頭部,

def Request(self, headers=None, path=None, params={}, delay=0, timeout=7):
try:
time.sleep(delay)
if not headers:
h = self.headers
else: h = headers
req = requests.get(self.target, proxies=self.proxies, headers=h, timeout=timeout,
allow_redirects=self.allowredir, params=params, verify=False)
self.log.info('Request Succeeded')
self.log.debug('Headers: %s\\n' % req.headers)
self.log.debug('Content: %s\\n' % req.content)
self.requestnumber += 1
return req
except requests.exceptions.RequestException as e:
self.log.error('Something went wrong %s' % (e.__str__()))

指紋的識(shí)別

拿Huawei Cloud WAF的指紋來(lái)說(shuō)

#!/usr/bin/env python
'''
Copyright (C) 2022, WAFW00F Developers.
See the LICENSE file for copying permission.
'''

NAME = 'Huawei Cloud Firewall (Huawei)'

def is_waf(self):
schemes = [

# 匹配 cookie
self.matchCookie(r'^HWWAFSESID='),
# 匹配 header 中的 Server
self.matchHeader(('Server', r'HuaweiCloudWAF')),
# 匹配 body
self.matchContent(r'hwclouds\\.com'),
self.matchContent(r'hws_security@')
]
if any(i for i in schemes):
return True
return False

CSDN使用華為云防護(hù)

1668779785_63778f0905b4c22ca27ee.png!small?1668779783711

其余腳本見(jiàn):wafw00f/wafw00f/plugins at master · EnableSecurity/wafw00f

wafw00f 流量

1668779788_63778f0ccb052e89a938d.png!small?1668779787707

1668779791_63778f0faeaf4c7812b12.png!small?1668779790449

本文作者:Deutsh, 轉(zhuǎn)載請(qǐng)注明來(lái)自FreeBuf.COM

責(zé)任編輯:武曉燕 來(lái)源: FreeBuf.COM
相關(guān)推薦

2023-10-08 12:14:42

Sentinel流量控制

2023-08-09 09:11:57

算法分發(fā)效果

2021-09-08 06:51:53

CountDownLa閉鎖源碼

2019-07-23 07:30:27

特征工程加密流量安全

2017-09-06 14:32:50

開(kāi)源協(xié)議CEO

2014-12-31 15:05:11

Android流量監(jiān)控

2021-07-07 05:00:17

初始化源碼

2021-09-07 07:53:42

Semaphore 信號(hào)量源碼

2020-07-02 22:42:18

Java異常編程

2020-04-21 22:59:50

Redis搭建選舉

2017-03-06 16:51:52

Java泛型實(shí)現(xiàn)

2019-08-13 08:18:31

Windows 10錯(cuò)誤0xa00f429Windows

2010-07-08 14:02:35

UML建模流程

2021-10-11 09:41:20

React位運(yùn)算技巧前端

2021-12-30 22:50:32

KafkaConsumer 源碼

2021-08-10 07:00:00

Nacos Clien服務(wù)分析

2020-05-06 22:07:53

UbuntuLinux操作系統(tǒng)

2012-05-21 13:35:35

應(yīng)用流量

2023-07-10 08:01:37

軟件行業(yè)GPT

2022-02-28 09:31:02

開(kāi)發(fā)環(huán)境后端前端
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)