Nmap你只会-sV?这些高级扫描技巧90%的安全工程师不知道
Nmap你只会-sV?这些高级扫描技巧90%的安全工程师不知道
前两天群里有个小伙子问我:"Nmap我天天用,就是-sV扫个端口版本,还能玩出花来?"
能。Nmap的强大远不止端口扫描。今天分享几个实战中真正好用的高级技巧,都是我在渗透测试和安全评估中反复验证过的。
0x01 基础扫盲:你真的会用-sV吗?
大多数人这样用:
nmap -sV 192.168.1.100
但其实-sV有几个容易忽略的参数:
# 设置版本检测强度(0-9,默认7)
# 强度越高越准,但越慢
nmap -sV --version-intensity 9 192.168.1.100
# 只扫描特定端口的版本
nmap -sV -p 80,443,8080 192.168.1.100
# 配合-O做操作系统识别
nmap -sV -O --osscan-guess 192.168.1.100
0x02 NSE脚本:Nmap的杀手锏
NSE(Nmap Scripting Engine)才是Nmap最强大的部分。它有600+个脚本,覆盖漏洞检测、信息收集、暴力破解等场景。
常用脚本分类
# 漏洞检测类
nmap --script vuln 192.168.1.100
# 信息收集类
nmap --script banner,http-title,http-headers 192.168.1.100
# 暴力破解类(慎用,注意锁定策略)
nmap --script brute -p 22,3306 192.168.1.100
# 指定单个脚本
nmap --script http-enum -p 80 192.168.1.100
实战中最好用的5个脚本
1. http-enum — Web目录枚举
nmap --script http-enum -p 80,443 target.com
这个脚本会自动扫描常见的Web目录和文件,相当于轻量版的dirb。速度快,适合初期信息收集。
2. ssl-heartbleed — 心脏出血检测
nmap --script ssl-heartbleed -p 443 target.com
一键检测目标是否存在心脏出血漏洞。
3. smb-vuln-ms17-010 — 永恒之蓝检测
nmap --script smb-vuln-ms17-010 -p 445 192.168.1.0/24
内网横向移动时必用。扫描整个C段只需要几秒。
4. http-sql-injection — SQL注入检测
nmap --script http-sql-injection -p 80 target.com
自动检测Web应用中的SQL注入点,虽然不如sqlmap深入,但速度优势明显。
5. dns-brute — 子域名爆破
nmap --script dns-brute --script-args dns-brute.threads=10 target.com
快速爆破子域名,比很多专门的子域名工具还快。
0x03 高级扫描策略
绕过IDS/IPS的扫描技巧
# 分片扫描(将数据包分片,绕过简单检测)
nmap -f 192.168.1.100
# 使用诱饵IP(混入假源IP)
nmap -D RND:10 192.168.1.100
# 慢速扫描(降低被检测概率)
nmap --scan-delay 3s --max-rate 10 192.168.1.100
# 使用特定源端口(绕过端口过滤)
nmap --source-port 53 192.168.1.100
# Idle扫描(利用僵尸主机,完全隐蔽)
nmap -sI zombie_host:port target
大规模网络扫描优化
# 快速扫描整个B段(仅SYN扫描+常用端口)
nmap -sS -F --min-rate 5000 10.0.0.0/16
# 并行主机发现
nmap -sn -PE -PP -PS80,443 -PA80,443 --min-parallelism 100 10.0.0.0/24
# 输出为可解析格式
nmap -sV -oX scan_results.xml 192.168.1.0/24
# 用xsltproc转换为HTML报告
xsltproc scan_results.xml -o report.html
自定义端口扫描
# 全端口扫描(1-65535)
nmap -p- 192.168.1.100
# 扫描特定端口范围
nmap -p 1-1024,8000-9000 192.168.1.100
# 扫描UDP端口(慢但必要)
nmap -sU -p 53,69,161,500,5353 192.168.1.100
# TCP+UDP同时扫描
nmap -sS -sU -p T:80,443,U:53,161 192.168.1.100
0x04 Nmap脚本编写入门
NSE脚本用Lua写,入门很简单。写一个检测特定HTTP头的脚本:
-- http-security-headers.nse
local http = require "http"
local shortport = require "shortport"
local stdnse = require "stdnse"
description = [[
检测HTTP响应中是否包含安全相关Header
]]
categories = {"safe", "discovery"}
portrule = shortport.http
action = function(host, port)
local response = http.get(host, port, "/")
if not response or not response.header then
return "无法获取HTTP响应"
end
local results = {}
local headers_to_check = {
"X-Frame-Options",
"X-Content-Type-Options",
"X-XSS-Protection",
"Content-Security-Policy",
"Strict-Transport-Security"
}
for _, header in ipairs(headers_to_check) do
if response.header[header] then
table.insert(results, header .. ": " .. response.header[header])
else
table.insert(results, header .. ": MISSING")
end
end
return table.concat(results, "\n")
end
使用自定义脚本:
nmap --script ./http-security-headers.nse -p 80 target.com
0x05 实战技巧总结
- 扫描顺序:先-sn做主机发现,再-F快速端口扫描,最后针对性深入扫描
- 时间控制:生产环境用-T2或-T3,测试环境可以用-T4
- 结果存档:始终用-oA保存所有格式(.xml/.nmap/.gnmap),方便后续处理
- 脚本组合:不要一次跑太多脚本,按需组合效率更高
- UDP别忘了:很多关键服务(DNS、SNMP、IPSec)跑在UDP上
Nmap用了这么多年,每次应急还是会翻man page。工具不在多,在于用得精。
觉得有用就点个赞,有问题评论区交流。关注"安全值班室",持续分享安全工具实战技巧。
标签: Nmap, 渗透测试, 信息收集, NSE脚本
分类: 安全工具
关注「安全值班室」公众号
每天AI安全早报 + 实战攻防案例 + 网安学习路线连载
浙公网安备 33010602011771号