=Start=
缘由:
做安全的一般都会用到Nmap进行端口扫描,在小范围内进行扫描时Nmap绝对是首选——丰富的扫描选项/模块、较高的准确度;在大范围的扫描中,你应该选择Masscan,因为它速度奇快,而且准确率还可以接受。它们都支持自定义结果的输出格式,其中比较通用的就是XML格式(Masscan为了尽量和Nmap做到兼容,除了扫描选项比较像之外,输出结果的XML格式也基本兼容)。扫描完了之后需要对结果进行解析,这就是本文的具体场景需求。
参考解答:
1.解析Masscan的XML格式扫描结果
#!/usr/bin/env python
# coding=utf-8
import sys, time
import xmltodict
def main():
    with open('./masscan_result.xml') as fp:
        xml_obj = xmltodict.parse(fp.read())
        nmaprun = xml_obj['nmaprun']
        host = nmaprun['host']
        for entry in host[:10]:  #调试阶段只打印前10条记录
            port = entry['ports']['port']
            if int(port['@portid']) == 80:
                name = entry['address']['@addr']
                print 'http://' + name + '/'
            elif int(port['@portid']) == 443:
                name = entry['address']['@addr']
                print 'https://' + name + '/'
            elif int(port['@portid']) == 21:
                name = entry['address']['@addr']
                print 'ftp://' + name + '/'
            else:
                name = entry['address']['@addr']
                print 'http://' + name + ':' + str(port['@portid']) + '/'
if __name__ == '__main__':
    time_start = time.time()
    try:
        main()
    except KeyboardInterrupt:
        print 'Killed by user'
        sys.exit(0)
    print "Spend {0} seconds.\n".format(time.time() - time_start)
2.解析Nmap的XML格式扫描结果
#!/usr/bin/env python
# coding=utf-8
import sys, time
import xmltodict
def main():
    fp_content = ''
    try:
        with open(sys.argv[1]) as fp:
            fp_content = fp.read().replace('\n', '')
    except IOError:
        print 'File IO Error'
        sys.exit(-1)
    nmap_xml = xmltodict.parse(fp_content)
    nmaprun = nmap_xml['nmaprun']
    scanhost = nmaprun['host']
    for i in scanhost:
        address = i['address']['@addr']
        port1 = dict(i)
        try:
            if int(port1['ports']['port']['@portid']) > 0:
                port2 = port1['ports']['port']['@portid']
                if port2 == '80':
                    print 'http://'+address+'/'
                elif port2 == '443':
                    print 'https://'+address+'/'
                else:
                    print 'http://'+address+':'+port2+'/'
        except:
            port2 = i['ports']['port']
            for z in port2:
                x = z['@portid']
                if x == '80':
                    print 'http://'+address+'/'
                elif x == '443':
                    print 'https://'+address+'/'
                else:
                    print 'http://'+address+':'+x+'/'
if __name__ == '__main__':
    time_start = time.time()
    try:
        main()
    except KeyboardInterrupt:
        print 'Killed by user'
        sys.exit(0)
    print "Spend {0} seconds.\n".format(time.time() - time_start)
参考链接:
=EOF=
《 “用Python解析Masscan/Nmap的扫描结果” 》 有 13 条评论
常见端口号对应的服务名称
https://github.com/ncrocfer/whatportis
http://www.iana.org/assignments/port-numbers
网络协议、应用、参考、技术等的速查清单
http://packetlife.net/library/cheat-sheets/
常见端口对应服务
http://packetlife.net/media/library/23/common_ports.pdf
目标端口扫描+系统服务指纹识别
https://github.com/ring04h/wyportmap
子域名收集工具
https://github.com/ring04h/wydomain
动态多线程敏感信息泄露检测工具
https://github.com/ring04h/weakfilescan
https://github.com/laramies/theHarvester
https://github.com/killswitch-GUI/SimplyEmail
https://github.com/lijiejie/BBScan
https://github.com/lijiejie/subDomainsBrute
https://github.com/lijiejie/GitHack
https://github.com/lijiejie/htpwdScan
全球DNS搜索引擎
https://www.dnsdb.io/zh-cn/
设置Masscan/Nmap扫描目标的排除列表
https://nmap.org/man/zh/man-briefoptions.html
https://nmap.org/book/man-target-specification.html
`
#排除某些主机/网段
–exclude $host1[,$host2[,…]]
#排除文件中指定的IP列表
–excludefile $exclude_file
`
https://github.com/robertdavidgraham/masscan#how-to-scan-the-entire-internet
`
–excludefile $exclude_file
`
渗透测试中常见的端口
https://www.secpulse.com/archives/54880.html
`
1. Web类(Web漏洞/敏感目录)
2. 数据库类(扫描弱口令)
3. 特殊服务类(未授权/命令执行类/漏洞)
4. 常用端口类(扫描弱口令/端口爆破)
`
将Nmap的扫描报告转换成XLS格式的Python脚本(Python script for converting nmap reports into XLS)
https://github.com/mrschyte/nmap-converter
对于需要建设资产管理,徘徊在nmap/zmap/masscan高效且漏扫等情况下对比,可以尝试ivre,类似小型的zoomeye
https://github.com/cea-sec/ivre
https://ivre.rocks/
BruteSpray是一个用Python写的从Nmap的扫描结果(GNMAP格式)中自动识别服务类型并调用Medusa进行爆破的工具
https://github.com/x90skysn3k/brutespray
如果是调用Medusa或Hydra这样的工具的话,感觉还不如直接用Patator(https://github.com/lanjelot/patator)这个Python写的单文件爆破工具来的方便。
Howl: 网络设备 web 服务指纹扫描与检索
https://github.com/0xbug/Howl
`
利用 flask 开发 api,通过调用 api 来实现添加任务或检索数据;
利用 celery 来进行异步调用 masscan 扫描开放端口的主机再利用 whatweb 来进行扫描,然后保存数据到 elasticsearch 方便检索;
`
CMS识别 python gevent实现
https://github.com/boy-hack/gwhatweb
SiteScan: 网站基本信息自动扫描系统
https://github.com/jasonsheh/SiteScan
一个快速简单地识别WEB服务器类型、CMS类型、WAF类型、WHOIS信息、以及语言框架的小脚本
https://github.com/zerokeeper/WebEye
https://raw.githubusercontent.com/zerokeeper/WebEye/master/config.txt
编写masscan报告转换脚本
http://gv7.me/articles/2018/masscan-report-converter/
护网自动化脚本
https://mp.weixin.qq.com/s/uHNx28XFZ5M6KwykMC4Jsg
`
# 前言
为了护网需要写了这么个小脚本,本文主要介绍下这个自动化工具的实现思路,以及这个工具的使用方法。
# 本文主要内容
1、Masscan与NMAP联动
2、扫描结果解析工具
3、几款开源工具 Eyewitness、tomcat-weak-password-scanner、漏洞发现、brutespray
NMAP是渗透测试人员广泛使用的老牌开源工具,功能强大,但扫描速度较慢。Masscan号称是世界上最快的扫描器,但功能较单一。很多经验丰富的渗透大佬都会将这两个东西结合在一起使用。
我们在红队前期充分收集目标企业的IP资产后,即可以使用CIDR等IP的表示方法导入扫描器。目前暂不支持目标域名的导入方式有两个原因:
1、DNS信息收集的过程有点慢
2、为了尽量保证精准度,暂时不想加入太多功能
==
1. Masscan与NMAP联动
2. 扫描结果解析工具
3. Eyewitness
EyeWitness功能:
1、它的快照可以让我们更直观地识别资产,通过网站类型快速判断网段是否属于目标。
2、更直观的看所使用的到应用是什么。
3、判断是否存在登陆页面,识别常见登陆后台。
4、RDP登陆账户显示。
4. 漏洞检测
1、漏洞指纹(Weblogic、Shiro、Strust2、Solr等…)
2、CMS识别(Seeyon、通达、泛微、Discuz、DeDeCms等…)
3、服务爆破(MSSQL、SSH、VNC、FTP、TELNET等…)
5. 服务爆破
爆破使用的是brutespray开源工具,可以直接提取nmap的xml扫描结果,然后进行对应的服务爆破。
`