脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - 利用Python半自动化生成Nessus报告的方法

利用Python半自动化生成Nessus报告的方法

2021-06-07 00:47Bypass Python

这篇文章主要介绍了利用Python半自动化生成Nessus报告的方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

0x01 前言

nessus是一个功能强大而又易于使用的远程安全扫描器,nessus对个人用户是免费的,只需要在官方网站上填邮箱,立马就能收到注册号了,对应商业用户是收费的。当然,个人用户是有16个ip限制,通过企业邮箱可以体验免费7天的nessus专业版,ip无限制。

nessus激活码获取地址:https://www.tenable.com/products/nessus/activation-code

利用Python半自动化生成Nessus报告的方法

0x02 nessus使用

登录后通过new scan创建扫描任务,扫描完成后,我们即可导出扫描报告。nessus提供4种报告类型导出:

利用Python半自动化生成Nessus报告的方法

我们选择html类型,report选择custom,croup by 选择host,导出html报告。

利用Python半自动化生成Nessus报告的方法

但这些报告还需要进一步整理成我们想要的格式,并且去掉不必要的消息,得到最终我们希望能够得到信息。

那首先我们确认一下,想要得到的信息是哪些呢?

1、服务器ip

2、漏洞危害级别

3、漏洞名称

这三个最基本的信息,对我来说就差不都足够了,我就知道哪些服务器存在高危漏洞,并提供解决漏洞修复建议。

0x03 python脚本

通过解析html文件,获取相关漏洞信息,并输出到csv文件。

?
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#! /usr/bin/env python
 
# _*_ coding:utf-8 _*_
 
#author:aaron
 
 
 
from lxml import etree
 
import csv
 
import sys
 
 
 
host=''
 
title=''
 
result_list=[]
 
def htm_parse(l):   
 
  if '#d43f3a' in etree.tostring(l):
 
    info=u"严重 - "+l.text
 
  elif '#ee9336' in etree.tostring(l):
 
    info=u"高危 - "+l.text
 
  elif '#fdc431' in etree.tostring(l):
 
    info=u"中危 - "+l.text
 
  elif '#3fae49' in etree.tostring(l):
 
    info=u"低危 - "+l.text     
 
  elif '#0071b9' in etree.tostring(l):
 
    info=u'信息泄露 - '+l.text
 
  else:
 
    info='parsing error,check that the versions are consistent.'
 
  return info
 
def main(filename):
 
  html = etree.parse(filename,etree.htmlparser())
 
  ls =html.xpath('/html/body/div[1]/div[3]/div')
 
  for i in ls:
 
    if "font-size: 22px; font-weight: bold; padding: 10px 0;" in etree.tostring(i):
 
      host=i.text
 
    elif "this.style.cursor" in etree.tostring(i):
 
      result=host+" - "+htm_parse(i)
 
      print result
 
      result_list.append(result)
 
  return result_list
 
if __name__ == '__main__':
 
  filename=sys.argv[1]
 
  list_host = main(filename)
 
  with open('result.csv','wb') as f:
 
    f.write(u'\ufeff'.encode('utf8'))
 
    w = csv.writer(f)
 
    w.writerow(['服务器ip','漏洞级别','漏洞编号','漏洞名称'])
 
    for i in list_host:
 
      data=i.split('-',3)
 
      w.writerow([item.encode('utf8') for item in data])

脚本运行效果如下:

利用Python半自动化生成Nessus报告的方法

在同目录下生成result.csv,内容如下:

利用Python半自动化生成Nessus报告的方法

最后,通过excel进行相关信息的筛选、删除和整理,最后汇总成报告。

0x04 小结

本文提供了一个demo,用于半自动化生成nessus报告,有需要的话,可入库扩展,增加自动翻译,提供修复建议等。nessus中文漏洞库可参见这个项目,nessusreportinchinese:半自动化将 nessus 英文报告(csv格式)生成中文 excel ,中文漏洞库已有700多条常见漏洞。

github地址:https://github.com/funnykun/nessusreportinchinese

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.cnblogs.com/xiaozi/p/10490199.html

延伸 · 阅读

精彩推荐