这篇文章在微信公众号上发过,这里的版本比微信上的新。
nmap工具介绍
nmap是一款开源免费的网络发现(Network Discovery)和安全审计(Security Auditing)工具。
官方文档位置,https://nmap.org/book/toc.html
nmap套件包含以下几个部分,我只用过nmap命令:
- nmap:命令行组件
- Zenmap:图形界面,Python语言编写,适用linux以及windows平台
- Ncat:a flexible data transfer, redirection, and debugging tool
- Ndiff:a utility for comparing scan results
- Nping:a packet generation and response analysis tool
我理解nmap主要由抓包工具 + NSE组成。抓包工具只需要了解,Windows平台是npcap抓包而Linux平台使用libpcap。NSE为脚本引擎,用于扩展nmap的能力。
NSE以及脚本介绍
NSE全称Nmap Script Engine,支持用Lua语言编写的脚本对nmap进行功能扩展。nmap安装时已经提供了大量脚本,Linux环境下这些脚本在/usr/share/nmap/scripts/
或者/usr/local/share/nmap/scripts
,视nmap安装位置。除了使用这些默认脚本,用户也可以编写自己的脚本来扩展nmap的功能。
脚本分类
nmap脚本共14大类,每大类下有很多具体的脚本。可以直接使用整个分类,也可以具体使用某个脚本。
- auth: 负责处理鉴权证书绕开鉴权的脚本
- broadcast: 在局域网内探查更多服务开启状况如dhcp/dns/sqlserver等服务
- brute: 提供暴力破解方式针对常见的应用如http/snmp等
- default: 使用-sC或-A选项扫描时候默认的脚本提供基本脚本扫描能力
- discovery: 对网络进行更多的信息如SMB枚举、SNMP查询等
- dos: 用于进行拒绝服务攻击
- exploit: 利用已知的漏洞入侵系统
- external: 利用第三方的数据库或资源例如进行whois解析
- fuzzer: 模糊测试的脚本发送异常的包到目标机探测出潜在漏洞
- intrusive: 入侵性的脚本此类脚本可能引发对方的IDS/IPS的记录或屏蔽
- malware: 探测目标机是否感染了病毒、开启了后门等信息
- safe: 此类与intrusive相反属于安全性脚本
- version: 负责增强服务与版本扫描Version Detection功能的脚本
- vuln: 负责检查目标机是否有常见的漏洞Vulnerability如是否有MS08_067
使用方法
首先搜索相关脚本,这里示例搜索和pgsql相关的脚本。
kali@PT:~$ nmap --script-help *pgsql*
Starting nmap 7.60 ( https://nmap.org ) at 2020-07-02 15:31 CST
pgsql-brute
Categories: intrusive brute
https://nmap.org/nsedoc/scripts/pgsql-brute.html
Performs password guessing against PostgreSQL.
可以看到结果中有一个相关脚本,pgsql-brute,提供对PostgreSQL的密码猜解功能。运行这个脚本。
kali@PT:~$ nmap -p 22 -sV --script pgsql-brute <ip>
PORT STATE SERVICE VERSION
5432/tcp open postgresql PostgreSQL DB 9.5.0 - 9.5.3
| pgsql-brute:
| root => Trusted authentication
| admin => Trusted authentication
| administrator => Trusted authentication
| webadmin => Trusted authentication
| sysadmin => Trusted authentication
| netadmin => Trusted authentication
| guest => Trusted authentication
| user => Trusted authentication
| web => Trusted authentication
|_ test => Trusted authentication
pgsql-brute.nse源码
nmap完全开源,所以它的源码也是非常好的学习资料。
简单看看pgsql-brute.nse的源码,主要是想找到字典位置。源码位于 /usr/share/nmap/scripts/pgsql-brute.nse
# 可以看到爆破字典来源于unpwdb,unpwdb源码位于/usr/share/nmap/nselib/unpwdb.lua,查看其源码得知字典在以下位置:
# /usr/share/nmap/nselib/data/passwords.lst
# /usr/share/nmap/nselib/data/usernames.lst
# 查看两个字典文件的内容,发现并没有针对PostgreSQL的弱口令,并且字典数据也不是很多。
# 所以完全可以自己写一个针对PostgreSQL弱口令爆破的NSE脚本。
local usernames, passwords
status, usernames = unpwdb.usernames()
if ( not(status) ) then return end
status, passwords = unpwdb.passwords()
if ( not(status) ) then return end
漏洞扫描
可以直接使用 nmap --script vuln
,调用nmap默认扫描大类的所有脚本对目的IP进行漏洞扫描。
可以对脚本进行更新,nmap --script-updatedb
nmap自带的漏扫功能以前比较弱,现在已经集成了默认添加了nmap-vulners的vulners.nse。
nmap-vulners 默认查询VulDB,MITRE CVE,SecurityFocus等多个漏洞数据库,功能还是很强大的。
# 安装vulners,实际默认已包含
git clone --depth=1 https://github.com/vulnersCom/nmap-vulners.git
cp nmap-vulners/vulners.nse /usr/share/nmap/scripts/
nmap --script-updatedb
# 安装http-vulners-regex
cp nmap-vulners/http-vulners-regex.nse /usr/share/nmap/scripts/
cp nmap-vulners/http-vulners-regex.json /usr/share/nmap/nselib/data/
cp nmap-vulners/http-vulners-paths.txt /usr/share/nmap/nselib/data/
nmap --script-updatedb
# 使用vulners,必须带-sV参数以提供版本信息
nmap -sV --script vulners [--script-args mincvss=<arg_val>] <target>
#使用http-vulners-regex
nmap --script http-vulners-regex.nse [--script-args paths={"/"}] <target>
同时,我们还可以安装第三方的vulscan。
vulscan查询的数据库和nmap-vulners基本重合,只是它具备离线扫描功能,并且有更灵活的参数控制。
默认安装的数据库:
- scipvuldb.csv - https://vuldb.com
- cve.csv - https://cve.mitre.org
- securityfocus.csv - https://www.securityfocus.com/bid/
- xforce.csv - https://exchange.xforce.ibmcloud.com/
- expliotdb.csv - https://www.exploit-db.com
- openvas.csv - http://www.openvas.org
- securitytracker.csv - https://www.securitytracker.com (end-of-life)
- osvdb.csv - http://www.osvdb.org (end-of-life)
# 安装
cd /usr/share/nmap/scripts
git clone --depth=1 https://github.com/scipag/vulscan.git
# 保持数据库最新(非必须)
chmod +x vulscan/utilities/updater/updateFiles.sh
bash vulscan/utilities/updater/updateFiles.sh
# 使用vulscan
# 一次只查一个数据库
nmap -sV --script=vulscan/vulscan.nse --script-args vulscandb=exploitdb.csv <target>
# 一次性查询所有数据库
nmap --script vulscan -sV <target>
其他
-
可以使用 xsltproc 转化 xml 格式的报告为html,便于阅读。
xsltproc -o results/report_vuln.html results/report_vuln.xml
-
偶尔遇到扫描过程中报段错误
可以先使用
-vv
参数获取目的ip的基本信息,然后再进行进一步扫描。
或者不要使用-iL命令,每个IP分开扫描。 -
常用公开漏洞库
国内的主要包括:
- CNNVD:中国国家漏洞库(中国国家信息安全漏洞库)
- CNVD:中国国家信息安全漏洞共享平台(国家信息安全漏洞共享平台)
- WooYun:乌云安全漏洞报告平台(WooYun.org | 自由平等开放的漏洞报告平台)
- SCAP中文社区:(安全内容自动化协议)
- Sebug漏洞库(Sebug漏洞库: 漏洞目录、安全文档、漏洞趋势)
国外的主要有:
- CVE漏洞库
- NVD
- SecurityFocus
- Secunia
- OSVDB
- Metasploit(官网的以及在Exploit-db上发布的一些漏洞)
- PacketStorm
- SecurityReason
资料都是自己之前在浏览一些安全资讯网站(solidot、Freebuf等)收集到的,来自广大网友的分享&提醒建议。
还有就是如果想得到一些最新的漏洞信息,订阅一些大牛的blog作为信息源是很有必要的,这也算是第1/2手信息了吧~~作者:耀祖
链接:https://www.zhihu.com/question/24793210/answer/28993361
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。