nmap基础知识

nmap是一款著名的网络探测工具,常用于进行主机发现,端口扫描以及服务检测等。
输入nmap不带参数,可以得到以下帮助提示:

Nmap 7.50SVN ( https://nmap.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:
  Can pass hostnames, IP addresses, networks, etc.
  Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
  -iL <inputfilename>: Input from list of hosts/networks
  -iR <num hosts>: Choose random targets
  --exclude <host1[,host2][,host3],...>: Exclude hosts/networks
  --excludefile <exclude_file>: Exclude list from file
HOST DISCOVERY:
  -sL: List Scan - simply list targets to scan
  -sn: Ping Scan - disable port scan
  -Pn: Treat all hosts as online -- skip host discovery
  -PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports
  -PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
  -PO[protocol list]: IP Protocol Ping
  -n/-R: Never do DNS resolution/Always resolve [default: sometimes]
  --dns-servers <serv1[,serv2],...>: Specify custom DNS servers
  --system-dns: Use OS's DNS resolver
  --traceroute: Trace hop path to each host
SCAN TECHNIQUES:
  -sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
  -sU: UDP Scan
  -sN/sF/sX: TCP Null, FIN, and Xmas scans
  --scanflags <flags>: Customize TCP scan flags
  -sI <zombie host[:probeport]>: Idle scan
  -sY/sZ: SCTP INIT/COOKIE-ECHO scans
  -sO: IP protocol scan
  -b <FTP relay host>: FTP bounce scan
PORT SPECIFICATION AND SCAN ORDER:
  -p <port ranges>: Only scan specified ports
            Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
  --exclude-ports <port ranges>: Exclude the specified ports from scanning
  -F: Fast mode - Scan fewer ports than the default scan
  -r: Scan ports consecutively - don't randomize
  --top-ports <number>: Scan <number> most common ports
  --port-ratio <ratio>: Scan ports more common than <ratio>
SERVICE/VERSION DETECTION:
  -sV: Probe open ports to determine service/version info
  --version-intensity <level>: Set from 0 (light) to 9 (try all probes)
  --version-light: Limit to most likely probes (intensity 2)
  --version-all: Try every single probe (intensity 9)
  --version-trace: Show detailed version scan activity (for debugging)
SCRIPT SCAN:
  -sC: equivalent to --script=default
  --script=<Lua scripts>: <Lua scripts> is a comma separated list of directories, script-files or script-categories
  --script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts
  --script-args-file=filename: provide NSE script args in a file
  --script-trace: Show all data sent and received
  --script-updatedb: Update the script database.
  --script-help=<Lua scripts>: Show help about scripts.
           <Lua scripts> is a comma-separated list of script-files or
           script-categories.
OS DETECTION:
  -O: Enable OS detection
  --osscan-limit: Limit OS detection to promising targets
  --osscan-guess: Guess OS more aggressively
TIMING AND PERFORMANCE:
  Options which take <time> are in seconds, or append 'ms' (milliseconds),
  's' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).
  -T<0-5>: Set timing template (higher is faster)
  --min-hostgroup/max-hostgroup <size>: Parallel host scan group sizes
  --min-parallelism/max-parallelism <numprobes>: Probe parallelization
  --min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>: Specifies probe round trip time.
  --max-retries <tries>: Caps number of port scan probe retransmissions.
  --host-timeout <time>: Give up on target after this long
  --scan-delay/--max-scan-delay <time>: Adjust delay between probes
  --min-rate <number>: Send packets no slower than <number> per second
  --max-rate <number>: Send packets no faster than <number> per second
FIREWALL/IDS EVASION AND SPOOFING:
  -f; --mtu <val>: fragment packets (optionally w/given MTU)
  -D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys
  -S <IP_Address>: Spoof source address
  -e <iface>: Use specified interface
  -g/--source-port <portnum>: Use given port number
  --proxies <url1,[url2],...>: Relay connections through HTTP/SOCKS4 proxies
  --data <hex string>: Append a custom payload to sent packets
  --data-string <string>: Append a custom ASCII string to sent packets
  --data-length <num>: Append random data to sent packets
  --ip-options <options>: Send packets with specified ip options
  --ttl <val>: Set IP time-to-live field
  --spoof-mac <mac address/prefix/vendor name>: Spoof your MAC address
  --badsum: Send packets with a bogus TCP/UDP/SCTP checksum
OUTPUT:
  -oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
     and Grepable format, respectively, to the given filename.
  -oA <basename>: Output in the three major formats at once
  -v: Increase verbosity level (use -vv or more for greater effect)
  -d: Increase debugging level (use -dd or more for greater effect)
  --reason: Display the reason a port is in a particular state
  --open: Only show open (or possibly open) ports
  --packet-trace: Show all packets sent and received
  --iflist: Print host interfaces and routes (for debugging)
  --append-output: Append to rather than clobber specified output files
  --resume <filename>: Resume an aborted scan
  --stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML
  --webxml: Reference stylesheet from Nmap.Org for more portable XML
  --no-stylesheet: Prevent associating of XSL stylesheet w/XML output
MISC:
  -6: Enable IPv6 scanning
  -A: Enable OS detection, version detection, script scanning, and traceroute
  --datadir <dirname>: Specify custom Nmap data file location
  --send-eth/--send-ip: Send using raw ethernet frames or IP packets
  --privileged: Assume that the user is fully privileged
  --unprivileged: Assume the user lacks raw socket privileges
  -V: Print version number
  -h: Print this help summary page.
EXAMPLES:
  nmap -v -A scanme.nmap.org
  nmap -v -sn 192.168.0.0/16 10.0.0.0/8
  nmap -v -iR 10000 -Pn -p 80
SEE THE MAN PAGE (https://nmap.org/book/man.html) FOR MORE OPTIONS AND EXAMPLES

官方的帮助文档按照以上类别顺序对每个类别和参数进行了详细的说明,详情可见https://nmap.org/book/man.html
在阅读了官方文档后,对其中重要的地方进行了记录,记录内容如下:

nmap中除了选项以外,其他的都会被视为主机
**target:** 
1.主机名/ip地址+掩码的形式如(192.168.192.0/24)
2.四节中可以使用连字符如(192.168.192.0-254 或者192.168.3-5,7.4)
3.文件形式,参数包括
    -iL , (#表示备注,IP地址可以是命令行中的任意形式)
    -iR 随机扫描,0表示一直扫描,如nmap -Pn -sS  -p 80 -iR 0 --open会随机扫描网络上的web服务器
    --exclude 排除文件


**host discovery**
也称作ping scan,探测主机是否存活,以是否可接收到主机的响应判断。
当不指定host discovery参数时Nmap sends an ICMP echo request, a TCP SYN packet to port 443, a TCP ACK packet to port 80, and an ICMP timestamp request.默认等同于使用选项 -PE -PS443 -PA80 -PP。始终会使用ARP/PR进行扫描,一般会先执行主机发现,再进行端口扫描
    -Pn     不进行主机发现,可以对每个IP地址进行高级探测。同-sn一起使用跳过ping扫描和端口扫描,以执行更高级行为
    -sL     只是列出IP地址,即根据域名解析IP地址,不会向目标主机发送任意包
    -sn     不进行端口扫描,比sL多了一步而已,通过ping探测存活的主机,也会使用ARP探测(如果不指定--send-ip)
    -PS     默认向80端口发送SYN包,可以指定端口如-PS22-25。如果端口是关闭的会收到RST,如果开放,系统底层就发送RST    -PA     TCP ACK类似于-PS,当管理员只允许同开放服务建立连接时起作用
    -PU     UDP 以接收ICMP PORT unreachable评判,
    -PY     类似PS,以ABORT , INIT-ACK确定主机是否存在
    -PE     使用标准的echo request测试,不可信赖,
    -PO     新的主机发现方式,使用IP Protocol
    -PR     ARP扫描,经常用在局域网中,
    --disable-arp-ping      当检测到处于同一局域网下时,只有该选项可以阻止ARP scan
    --traceroute        当指定-sT时不可用
    -n          不做DNS解析,以加快扫描速度,与之相反的是-R
    --system-dns        通常nmap是直接查询dns服务器,该选项指定使用本地系统dns

**端口**
端口状态:open, closed, filtered, unfiltered, open|filtered, or closed|filtered.
    closed表示端口可访问,但是没有应用程序监听该端口,可用于主机发现,OS检测等
    filtered            由于探测包被丢弃,情况不明
    unfuiltered     表示需要改用其他探测协议

端口检测:端口检测的参数为-s<C>      其中C表示端口扫描方式,默认会扫描1000个端口
    发送特别的数据包,根据响应判断端口状态
    -sS     TCP SYN扫描,默认方式,其替代品为-sT TCP connect扫描,建立完整的TCP连接
    -sU     UDP端口扫描,可以同-sS一起使用,速度很慢
    -sY     SCTP INIT 扫描,结合了ftp和udp的特色,利用“closed端口时,收到不包含RST的包时会回应RST包”有些系统不适用,比较稳定
    -sA     TCP ACK扫描,不用于检测端口的开放,而是判断防火墙的规则集(是否stateful,哪个端口被过滤)
    -sW     TCP window scan,依据tcp window field判断端口是open or filtered
    -sN,-sF,-sX与-sM     这几者类似,利用开放端口和关闭端口之间的细微差距实现扫描
    --scanflags     自定义标记位,例如:--scanflags URGACKPSHRSTSYNFIN
    -sZ     SCTP COOKIE ECHO scan
    -b          利用连接到ftp服务器后,请求文件发到其他服务器端口,从而形成扫描


    -p      指定端口范围,-p-  遗漏起始和结束端口后,扫描所有端口1-65535

**版本和服务检测**
会检测服务,程序名,版本号,主机名,设备类型,操作系统等。
    -sV             使能版本检测
    --allports      检测所有端口,默认会跳过TCP 9100
    --version-intensity     检测强度,默认为7,值越低,速度越快(--version-light),值越高,越精确(--version-all)
    --version-trace         输出探测信息

**操作系统检测:**
    -O          使能操作系统检测,-A会同时使能其他检测
    --osscan-limit          跳过不符合标准的主机
    --osscan-guess      输出可能的检测结果,即使不能完全匹配
    --max-os-tries      指定匹配失败时尝试的最大次数

**NSE   nmap scripting engine**
    -sC     使用一系列默认的脚本,等同于--script=default
    --script        指定脚本名称,类型或目录,依次被视为表达式、策略名、文件或目录,会加载目录中的每一个后缀为.nse的文件。示例:
    nmap --script “http-*”      加载所有以http-开头的数据库脚本
    nmap --script “(default or safe or intrusive) and not http-*”

    --script-help       展示某个脚本的帮助文件

**防火墙/入侵检测系统的逃避和欺骗**
    -f      采用tiny packet
    -D      欺骗防火墙有很多ip地址在进行扫描以掩盖自身
    -S,-e       指定发送接口或ip地址,-e -Pn与此同用,可以达到欺骗A公司是B公司在扫描的效果,Nmap无法接收到任何包

**输出**
    xml更容易被软件解析,interactive更容易阅读;默认为interactive mode,并被发送到标准输出,normal与此相同,即使指定了输出到文件也会打印到屏幕;grepable在一行中包含最多的主机信息。

**运行交互:**
v / V               Increase / decrease the verbosity level
d / D               Increase / decrease the debugging Level
p / P               Turn on / off packet tracing
?                   Print a runtime interaction help screen
回车展示扫描进度

简单示例:
1.扫描主机scanme.nmap.org上所有预留的TCP端口:
nmap -v scanme.nmap.org

2.对每台主机进行SYN扫描,并检测操作系统
nmap -sS -O scanme.nmap.org/24

3.对指定范围的主机进行存活检测和并对指定端口进行TCP扫描,如果发现开放的指定端口,就探测其上的服务
nmap -sV -p 22,53,110,143,4564 198.116.0-255.1-127

4.随机选择100,000个主机进行扫描,并检测80端口是否开放。因为只需要检测每个主机的一个端口,先对每台主机发送一堆探测包是浪费的
nmap -v -iR 100000 -Pn -p 80

5.不对主机进行ping扫描,探测主机的web服务并将结果以两种格式保存。
nmap -Pn -p80 -oX logs/pb-port80scan.xml -oG logs/pb-port80scan.gnmap 216.163.128.20/20

6.探测局域网内的主机,以host discovery为核心,改换不同的探测协议,以下方法快速全面,回车可以探测当前扫描进度
nmap -n -sn 192.168.192.0/24

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值