Nmap常用命令

Nmap常用操作

Tip1

# 主机发现,5.21 之前为 -sP
sudo nmap -sn 192.168.56.0/24

# 端⼝扫描
sudo nmap -sT --min-rate 10000 -p- 192.168.56.110 -oN nmapscan/ports

# 端⼝数据格式化
grep open nmapscan/ports.nmap | awk -F'/' '{print $1}' | paste -sd ','
ports=$(grep open nmapscan/ports.nmap | awk -F'/' '{print $1}' | paste -sd ',')
echo $ports

# 详细信息扫描
sudo nmap -sT -sV -sC -O -p80,111,777 192.168.56.110 -oN nmapscan/info

# udp扫描
sudo nmap -sU -p- 192.168.56.110 -oN nmapscan/udp

# 漏洞脚本扫描
sudo nmap --script=vuln -p80,111,777 192.168.56.110 -oN nmapscan/vuln

参数含义

  -sn : Ping扫描 - 禁用端口扫描,在 5.21 之前为 -sP
  -sT : TCP 全连接扫描
  --min-rate <数字>:发送包的速度不低于<数字>每秒,指定最低速率
  -p <端口范围>:仅扫描指定端口,例:-p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
  -p-  : 扫描所有端口 1-65535
  -oA <基本名>:一次性以三种主要格式(.nmap,.xml,.gnmap)输出
  -sV:探测开放端口以确定服务/版本信息
  -O:启用操作系统探测
  -sU:UDP扫描
  -sC:等同于 --script=default ,执行默认的脚本扫描
  --script=<Lua脚本>:<Lua脚本>是一个逗号分隔的目录、脚本文件或脚本类别列表,常用的 default 默认运行的脚本,通常用于基本的信息收集和漏洞探测, vuln 扫描已知漏洞的脚本, exploit 利用已知漏洞的脚本

Tip2

mkdir /tmp/nmapscan ; cd /tmp/nmapscan
sudo nmap -n -v -sS -p- 192.168.56.110 -oN nmapscan/posts -Pn
nmap -n -v -sC -sV -p80,111,777 192.168.56.110 -oN nmapscan/info

Tip3

高级扫描

sudo nmap --packet-trace -n --disable-arp-ping -Pn -p- 192.168.7.172
sudo nmap -Pn -sT -sV --reason --disable-arp-ping -p 22,80,443,3306,20008 192.168.7.172

# top1000扫描
sudo nmap --packet-trace -n --disable-arp-ping -Pn --top-ports 1000 192.168.7.172

--packet-trace :显示发送和接收的所有数据包
-n/ -R :从不进行DNS解析/总是解析
--disable-arp-ping : 关闭 arp ping
--reason : 显示端口处于特定状态的原因

常用654端口


-p 1,7,9,13,19,21-23,25,37,42,49,53,69,79-81,85,105,109-111,113,123,135,137-139,143,161,179,222,264,384,389,402,407,443-446,465,500,502,512-515,523-524,540,548,554,587,617,623,689,705,771,783,873,888,902,910,912,921,993,995,998,1000,1024,1030,1035,1090,1098-1103,1128-1129,1158,1199,1211,1220,1234,1241,1300,1311,1352,1433-1435,1440,1494,1521,1530,1533,1581-1582,1604,1720,1723,1755,1811,1900,2000-2001,2049,2082,2083,2100,2103,2121,2199,2207,2222,2323,2362,2375,2380-2381,2525,2533,2598,2601,2604,2638,2809,2947,2967,3000,3037,3050,3057,3128,3200,3217,3273,3299,3306,3311,3312,3389,3460,3500,3628,3632,3690,3780,3790,3817,4000,4322,4433,4444-4445,4659,4679,4848,5000,5038,5040,5051,5060-5061,5093,5168,5247,5250,5351,5353,5355,5400,5405,5432-5433,5498,5520-5521,5554-5555,5560,5580,5601,5631-5632,5666,5800,5814,5900-5910,5920,5984-5986,6000,6050,6060,6070,6080,6082,6101,6106,6112,6262,6379,6405,6502-6504,6542,6660-6661,6667,6905,6988,7001,7021,7071,7080,7144,7181,7210,7443,7510,7579-7580,7700,7770,7777-7778,7787,7800-7801,7879,7902,8000-8001,8008,8014,8020,8023,8028,8030,8080-8082,8087,8090,8095,8161,8180,8205,8222,8300,8303,8333,8400,8443-8444,8503,8800,8812,8834,8880,8888-8890,8899,8901-8903,9000,9002,9060,9080-9081,9084,9090,9099-9100,9111,9152,9200,9390-9391,9443,9495,9809-9815,9855,9999-10001,10008,10050-10051,10080,10098,10162,10202-10203,10443,10616,10628,11000,11099,11211,11234,11333,12174,12203,12221,12345,12397,12401,13364,13500,13838,14330,15200,16102,17185,17200,18881,19300,19810,20010,20031,20034,20101,20111,20171,20222,22222,23472,23791,23943,25000,25025,26000,26122,27000,27017,27888,28222,28784,30000,30718,31001,31099,32764,32913,34205,34443,37718,38080,38292,40007,41025,41080,41523-41524,44334,44818,45230,46823-46824,47001-47002,48899,49152,50000-50004,50013,50500-50504,52302,55553,57772,62078,62514,65535




-p 1,7,9,13,19,21,22,23,25,37,42,49,53,69,79,80,81,85,105,109,110,111,113,123,135,137,138,139,143,161,179,222,264,384,389,402,407,443,444,445,446,465,500,502,512,513,514,515,523,524,540,548,554,587,617,623,689,705,771,783,873,888,902,910,912,921,993,995,998,1000,1024,1030,1035,1090,1098,1099,1100,1101,1102,1103,1128,1129,1158,1199,1211,1220,1234,1241,1300,1311,1352,1433,1434,1435,1440,1494,1521,1530,1533,1581,1582,1604,1720,1723,1755,1811,1900,2000,2001,2049,2082,2083,2100,2103,2121,2199,2207,2222,2323,2362,2375,2380,2381,2525,2533,2598,2601,2604,2638,2809,2947,2967,3000,3037,3050,3057,3128,3200,3217,3273,3299,3306,3311,3312,3389,3460,3500,3628,3632,3690,3780,3790,3817,4000,4322,4433,4444,4445,4659,4679,4848,5000,5038,5040,5051,5060,5061,5093,5168,5247,5250,5351,5353,5355,5400,5405,5432,5433,5498,5520,5521,5554,5555,5560,5580,5601,5631,5632,5666,5800,5814,5900,5901,5902,5903,5904,5905,5906,5907,5908,5909,5910,5920,5984,5985,5986,6000,6050,6060,6070,6080,6082,6101,6106,6112,6262,6379,6405,6502,6503,6504,6542,6660,6661,6667,6905,6988,7001,7021,7071,7080,7144,7181,7210,7443,7510,7579,7580,7700,7770,7777,7778,7787,7800,7801,7879,7902,8000,8001,8008,8014,8020,8023,8028,8030,8080,8081,8082,8087,8090,8095,8161,8180,8205,8222,8300,8303,8333,8400,8443,8444,8503,8800,8812,8834,8880,8888,8889,8890,8899,8901,8902,8903,9000,9002,9060,9080,9081,9084,9090,9099,9100,9111,9152,9200,9390,9391,9443,9495,9809,9810,9811,9812,9813,9814,9815,9855,9999,10000,10001,10008,10050,10051,10080,10098,10162,10202,10203,10443,10616,10628,11000,11099,11211,11234,11333,12174,12203,12221,12345,12397,12401,13364,13500,13838,14330,15200,16102,17185,17200,18881,19300,19810,20010,20031,20034,20101,20111,20171,20222,22222,23472,23791,23943,25000,25025,26000,26122,27000,27017,27888,28222,28784,30000,30718,31001,31099,32764,32913,34205,34443,37718,38080,38292,40007,41025,41080,41523,41524,44334,44818,45230,46823,46824,47001,47002,48899,49152,50000,50001,50002,50003,50004,50013,50500,50501,50502,50503,50504,52302,55553,57772,62078,62514,65535

其他

学习笔记/Hacker/assets/nmap1.jpg

学习笔记/Hacker/assets/nmap2.jpg

# 注:192.168.56.1 为目标IP地址
# 1. 纯扫描,默认情况下,nmap会发出一个arp ping扫描,且扫描目标tcp端口,范围为1-10000。
nmap 192.168.56.1

# 2. Nmap普通扫描增加输出冗长(非常详细)
nmap -vv 192.168.56.1

# 3. 端口扫描
nmap 192.168.56.1 -p 80  # 指定定单个端口
nmap 192.168.56.1 -p 1-100 # 多个端口
nmap 192.168.56.1 -p- # 所有端口
nmap -sP 10.1.112.89 # Ping扫描
nmap -sS 192.168.56.1 -p 80 # SYN半连接扫描
nmap -sT 192.168.56.1 -p 80  # TCP全连接扫描
nmap -sU 192.168.56.1 # UDP扫描
nmap -sF  192.168.56.1 # FIN,目标可能有IDS/IPS系统的存在,防火墙可能过滤掉SYN数据包,发送一个FIN标志的数据包不需要完成TCP的握手

# 4. 路由追踪
nmap --traceroute 192.168.56.1

# 5. 扫描一个网段
nmap -sP 192.168.56.1/24

# 6. 扫描目标主机版本(不是很准确)
nmap -O 192.168.56.1 -p 80

# 7. 扫描目标服务版本
nmap -O -sV 192.168.56.1 -p 80

# 8. 全面扫描(包含了1-10000端口ping扫描,操作系统扫描,脚本扫描,路由跟踪,服务探测)
nmap -A 192.168.56.1 -p-

# 9. 保存结果
nmap -A 192.168.56.1 -p- -oN nmap1

# 10. nmap命令混合式扫描
nmap -vv -p1-100 -o 192.168.56.1

# 11. 扫描多个目标
nmap 192.168.56.1 127.0.0.2
nmap 192.168.56.1-100 # 扫描 IP 地址范围内的所有主机
nmap -iL target.txt # namp在同一目录下,扫描这个txt内的所有主机