编写masscan报告转换脚本

admin 2021年4月2日20:38:38gv7.me评论133 views2912字阅读9分42秒阅读模式

由于nmap扫描比较慢,有时候需要使用masscan对大段ip进行快速扫描。为了后续方便数据处理,往往需要将数据以xls的形式进行统计,但是masscan只支持xml,json,list等格式输出,并不支持直接输出xls格式。最近有正好这个需求,于是写了个小脚本来转换一下。

一、编码

file: masscan-report-converter.py

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#coding=utf-8
import os
import sys
import time
import argparse
import xml.dom.minidom
import xlsxwriter
from xlsxwriter import Workbook

'''
author: c0ny1
date: 2018-09-28 18:23
'''

def convert_masscan_report(xml_path,xls_path):
workbook = xlsxwriter.Workbook(xls_path)
worksheet = workbook.add_worksheet('Scan info')
worksheet.autofilter("A1:H1") #设置过滤
worksheet.freeze_panes(1, 0) #冻结窗格

worksheet.lastrow = 0
summary_header = ["addr", "port", "state", "protocol", "addrtype", "reason", "reason_ttl", "scan_endtime"]
for idx, item in enumerate(summary_header):
worksheet.write(0, idx, item,workbook.add_format({"bold": True}))
worksheet.lastrow += 1

DOMTree = xml.dom.minidom.parse(xml_path)
data = DOMTree.documentElement
nodelist = data.getElementsByTagName('host')
host_info = {}
for node in nodelist:
scan_endtime = node.getAttribute('endtime')
scan_endtime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(int(scan_endtime)))
address_node = node.getElementsByTagName('address')
addrtype = address_node[0].getAttribute('addrtype')
addr = address_node[0].getAttribute('addr')
port_node = node.getElementsByTagName('port')
for port in port_node:
protocol = port.getAttribute('protocol')
portid = port.getAttribute('portid')
state_element = port.getElementsByTagName('state')
state = state_element[0].getAttribute('state')
reason = state_element[0].getAttribute('reason')
reason_ttl = state_element[0].getAttribute('reason_ttl')
print '[+] | %s | %s | %s | %s | %s | %s | %s | %s |' % (addr,portid,state,protocol,addrtype,reason,reason_ttl,scan_endtime)
scan_info = [addr,portid,state,protocol,addrtype,reason,reason_ttl,scan_endtime]
for i in range(0,len(scan_info)):
worksheet.write(worksheet.lastrow, i, scan_info[i])
worksheet.lastrow += 1
workbook.close()

if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", metavar="XML", help="path to xml input")
parser.add_argument("-o", "--output", metavar="XLS", help="path to xlsx output")

if len(sys.argv) == 1:
sys.argv.append('-h')

args = parser.parse_args()

if args.input:
xml_path = args.input
else :
exit('[*] please use -i set xml path!')

if os.path.lexists(xml_path) == False:
exit('[*] %s does not exist!',xml_path)

if args.output:
xls_path = args.output
else:
xls_path = './masscan_report.xls'

convert_masscan_report(xml_path,xls_path)

目前脚本已经收集到我的WorkScript项目中,地址如下:

https://github.com/c0ny1/WorkScripts/tree/master/masscan-report-converter

二、使用步骤

1.使用masscan进行扫描,扫描结果以xml保存
1
masscan.exe -p21,22,23,80,7001,5900 10.0.0.0/8 --rate=100000 -oX scan_result.xml
2.使用上面写的脚本转换出xls格式的报告
1
masscan-report-converter.py -i scan_result.xml -o scan_result.xls

最终效果如下:

文章来源于gv7.me:编写masscan报告转换脚本

相关推荐: 优化批量破解shadow

一般在对客户所有linux机器进行弱口令检查时,如果在线进行破解的话,先不说影响业务,破解速率很慢,而且必须保证可以破解期间保持访问。这时将在线破解变成让客户提供shadow,我们破解shadow就有优势多了。后来k哥提供了一个批量调用john the rip…

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年4月2日20:38:38
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  编写masscan报告转换脚本 http://cn-sec.com/archives/318071.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: