Nmap结合vulscan和nmap-vulner扫描结果解析

007bug2021-07-06 16:19:01

工作需求

工作过程中遇到高危端口扫描的需求,客户要求对目标资产进行全端口扫描,并将开放的端口及该端口可能存在的CVE漏洞进行格式化输出。由于目标较多,且客户无POC探测需求。

故使用nmap+vulscan+nmap-vulner+python脚本,基于软件版本进行扫描并编写python脚本将xml文档解析为excel格式输出

基本知识-nmap常用参数

复习一下nmap常见参数

-sS          SYN半连接扫描,需root权限

-sT          TCP三次握手扫描,较慢,不建议使用

-sV          探测端口服务banner信息

-Pn          不进行主机存活扫描,直接扫描指定端口

-v           在shell界面显示当前扫描过程

-oN/oX/oG   将nmap扫描结果输出为正常/XML/grep格式,建议格式为xml,扫描结果更完整,更易解析。

-iL  file      读取文本内容作为扫描目标

--script xxx  使用内置脚本进行扫描

NSE内置脚本下载安装

nmap-vulner和vulscan都是为了增强Nmap的版本检测,为特定服务(如SSH,RDP,SMB等)生成相关的CVE信息。

nmap-vulner脚本下载

进入到nmap内置脚本目录下

cd /usr/share/nmap/script/

下载脚本

git clone https://github.com/vulnersCom/nmap-vulners.git

更新脚本库

nmap --script-updatedb

vulscan脚本下载

进入到nmap内置脚本目录下

cd /usr/share/nmap/script/

下载脚本

git clone https://github.com/scipag/vulscan.git

更新漏洞库

cd vulscan/utilities/updater/

chmod+x updateFiles.sh

./updateFiles.sh

扫描

命令:

结合vulscan和nmap-vulners两个脚本进行扫描

nmap --script nmap-vulners/ --script-args vulscandb=scriptvuldb.csv -sV -Pn 10.211.55.7 10.211.55.3 -v -p1-65535 -T4 --oX nmap.xml

XML解析

Python解析脚本如下:

# -*- coding: UTF-8 -*-
# @Time :2021/7/5 10:08 上午
# @File :nmap_parser.py

import xml.dom.minidom as xmldom
import openpyxl

firstline_list=["IP地址","开放端口","应用软件","软件版本","CVE漏洞编号"]
info_list=[]

with open("nmapxml.xml", "r", encoding="utf-8") as f:
dom = xmldom.parse(f)  # 读取xml文件
root = dom.documentElement  # 获得xml文件中的元素对象
a = root.childNodes  # 获得所有子节点

# def ip_info():
#     global ip_list
#     for i1 in a:
#         if i1.nodeName=="hosthint":
#             ip=i1.getElementsByTagName("address")
#             for i2 in ip:
#                 if i2.getAttribute("addrtype") == "ipv4":
#                     host=i2.getAttribute("addr")
#                     ip_list.append(host)
#         else:
#             pass

def port_info():
host=root.getElementsByTagName("host")
for i1 in host:
a=i1.childNodes
for i2 in a:
if i2.nodeName=="address":
if i2.getAttribute("addrtype")=="ipv4":
# ip_list.append((i2.getAttribute("addr")))
host=i2.getAttribute("addr")
# ip_list.append(host)
# print("存活主机:",host)  #输出ip地址
if i2.nodeName=="ports":
# print(host)
b=i2.childNodes
for i3 in b:
x=0
x=x+1
if i3.nodeName=="port":
c=i3.childNodes
for i4 in c:
if i4.nodeName=="service":
# print("port")
#有几个开放端口就有几个ip地址
# sheet.cell(row=1, column=i + 1).value = i3.getAttribute("portid")
# port_info=i3.getAttribute("portid")+i4.getAttribute("product")+i4.getAttribute("version")
# port_list.append(i3.getAttribute("portid"))
# version_list.append(i4.getAttribute("product"))
# version_list.append(i4.getAttribute("version"))

portid=i3.getAttribute("portid")
a=i4.getAttribute("product")
product=a.replace(" ","")

version=i4.getAttribute("version")
info=host+" "+portid+" "+product+" "+version
info_list.append(info)
print("存活主机:",host,"开放端口:",portid,"banner:",product,version)#输出端口banner

if i4.nodeName=="script":
d=i4.childNodes
for i5 in d:
if i5.nodeName =="table":
e=i5.childNodes
for i6 in e:
if i6.nodeName == "table":
f=i6.childNodes
cve=' '
for i7 in f:
if i7.nodeName == "elem" and i7.getAttribute("key") == "id" and str(i7.firstChild.data).startswith("CVE"):
# name1 = str(i7.firstChild.data)
# # print(name1)
# if name1.startswith("CVE"):
#     vul_info=name1
cve=i7.firstChild.data
# vul_list.append(i7.firstChild.data)
# print("CVE编号:",cve)
info = host + " " + portid + " " + product + " " + version+" "+cve
info_list.append(info)


def data2excel():
book = openpyxl.Workbook()
sheet = book.active
index=0
for i in range(len(firstline_list)):
sheet.cell(row=1,column=i+1).value=firstline_list[i]
for i1 in info_list:
index +=1
listA=i1.split(" ",6)
sheet.append(listA)
book.save('nmap2excel.xlsx')



if __name__ == '__main__':
port_info()
data2excel()

解析结果如下:

xml2excel输出如下:

nmaphost
本作品采用《CC 协议》,转载必须注明作者和本文链接
网络扫描:系统识别
2021-08-02 16:57:52
通过工具识别目标主机上的服务指纹信息。
网络扫描:服务识别
2021-08-01 07:03:59
这里的服务是指系统中用来提供服务的一些程序,如文件传输服务(FTP)、远程登录服务(SSH)等,在这些服务中包括一些指纹信息,如端口、服务名、提供商及版本等。本文介绍对服务信息进行识别的方法。
标志信息是指一些主机或服务响应的欢迎信息或版本信息。例如,登录FTP服务后,可能返回的标志信息为220(vsFTPd 3.0.3)或220 Welcome to blah FTP service.。这些信息可以帮测试人员确认服务类型。本文介绍获取标志信息的方法。
在实施局域网扫描之前,需要对其网络环境有所了解,如网络范围、经过的路由等,然后才可以确定扫描的目标。本文对局域网网络环境进行简单介绍。
vulnhub 靶场 napping
2022-09-29 07:34:39
信息收集主机发现:sudo nmap -sn 192.168.56.1/24. -sC Performs a script scan using the default set of scripts. It is equivalent to --script=default. Some of the scripts in this category are considered intrusive and should not be run against a target network without permission.-sV Enables version detection, as discussed above. Alternatively, you can use -A, which enables version detection among other things.-p This option specifies which ports you want to scan and overrides the default. Individual port numbers are OK, as are ranges separated by a hyphen . The beginning and/or end values of a range may be omitted, causing Nmap to use 1 and 65535, respectively. So you can specify -p- to scan ports from 1 through 65535. Scanning port zero is allowed if
使用nmap+vulscan+nmap-vulner+python脚本,基于软件版本进行扫描并编写python脚本将xml文档解析为excel格式输出
近期对nmap的操作系统识别功能造了个轮子,用golang实现了一遍,想未来能用于扫描器,资产发现/管理系统
Nmap渗透测试指南
2022-04-20 13:05:55
nmap -sS -Pn -n --open --min-hostgroup 4 --min-parallelism 1024 --host-timeout 30 -T4 -v -oG E:\ip\result3.txt -iL E:\ip\ip.txt
利用nmap脚本对MS SQL Server 进行渗透测试,获取目标用户名、数据库表等信息。获取数据库版本信息使用ms-sql-info脚本获取目标数据库版本等信息nmap -p 14
Nmap 经常使用的场景及用法。
007bug
暂无描述