Nmap学习笔记

Nmap学习笔记

作用:

  1. 查看存活主机
  2. 扫描目标主机开放的端口
  3. 鉴别安全过滤机制
  4. 识别目标主机的操作系统
  5. 查看目标主机服务的版本信息
  6. 利用脚本扫描漏洞

适用系统:

Windows

Linux

Mac

使用方式:

命令行

图形化GUI

功能参数:

目标说明

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
  • -iL: 从主机地址列表文件中导入扫描地址
  • -iR: 随机选择目标进行扫描,num hosts表示数目,设置为0则无休止扫描
  • –exclude: 排除某个主机地址
  • –excludefile: 排除主机地址列表中的地址

主机发现

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
  • -sL: 列表扫描 ,简单列出要扫描的目标,不进行主机发现
  • -sn: 与-sP一样Ping 扫描,只进行主机发现,不扫描目标主机端口
  • -Pn: 不进行主机发现,将所有指定主机视为已开启状态
  • -PS/PA/PU/PY: 发送一个设置SYN/ACK/UDP标志位的空TCP报文,默认80端口,可以指定端口可 -PU可以穿透只过滤的防火墙
  • -PE/PP/PM: ICMP 回显、时间戳和网络掩码请求发现探测
  • -P0: 使用IP协议进行Ping操作
  • -n/-R: -n不用域名解析,加速扫描;-R为目标IP做反向域名解析,扫描速度较慢
  • –dns-servers: 自定义域名解析服务器地址
  • –traceroute: 目标主机路由追踪

端口扫描

Nmap将目标端口分为6个状态:

  • opne: 开放的
  • closed: 关闭的
  • filtered: 被过滤的
  • unfiltered: (未被过滤的)可访问但是不确定开放情况
  • open|filtered: (开放或者被过滤)无法确定端口是开放的还是被过滤的
  • closed|filtered: (关闭或者被过滤)无法确定端口是关闭的还是被过滤的
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
  • -sS: TCP SYN扫描,半开放扫描,速度快(不完成TCP连接),能明确区分端口状态
  • -sT: TCP连接扫描,容易产生记录,效率低
  • -sA: TCP ACK扫描,只扫描ACK标志位,区别被过滤与未被过滤的
  • -sU: UDP服务扫描,效率低
  • -sN/sF/sX: TCP Null,Fin,Xmas扫描,从RFC挖掘的微妙方法来区分开放端口和关闭端口
  • -sI: 利用僵尸主机上已知IP分段ID序列生成算法来探测目标上开放端口的信息,极端隐蔽
  • -sO: IP协议扫描,可以确定目标主机支持哪些IP协议

端口说明和扫描顺序

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>
  • -p: 指定扫描端口,可以是单个端口,也可以是端口范围可以指定UDP或者TCP协议扫描特定端口
  • –exclude-ports: 指定端口不扫描
  • -F: 快速模式,仅扫描100个常用端口

服务与版本探测==(不是绝对正确)==

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)
  • -sV: 进行服务版本探测
  • –version-trace: 设定版本扫描强度,范围0~9,默认为7,强度越高,扫描时间越长,服务越可能被正确识别

脚本扫描

Nmap允许用户自己编写脚本来执行自动化操作或者拓展Nmap功能,使用Lua脚本语言.

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.
  • -sC: 使用默认类别脚本进行扫描
  • –script=: 使用某个或者某类脚本进行扫描支持通配符描述

操作系统探测

Nmap使用TCP/IP协议栈fingerprinting进行探测,Nmap发送一系列TCP/UDP报文到远程主机,检查响应中的每一个比特.测试后Nmap把结果和数据库中的已知fingerprints比较,输出结果

OS DETECTION:
  -O: Enable OS detection
  --osscan-limit: Limit OS detection to promising targets
  --osscan-guess: Guess OS more aggressively
  • -O: 启用操作系统探测
  • -A: 万能开关同时启用操作系统探测和服务版本探测
  • –osscan-limit: 针对指定目标进行操纵系统检测
  • –osscan-guess: 当Nmap无法确定所检测的操作系统时,会尽可能地提供最相近的匹配

时间和性能

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
  • -T<0-5>: 设置时间模板级数,到0~5中选择;T0,T1:用于IDS规避;T2:降低扫描速度可以使用更少的带宽和资源;默认为T3:未作任何优化;T4:假设具有合适及可靠的网络从而加速扫描;T5:假设具有特别快的网络或者愿意为速度牺牲准确性
  • –host-timeout

防火墙/IDS规避和欺骗

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
  • -f; --mtu : -f(报文分段);–mtu(使用指定的MTU)将TCP头分段在几个包中,使得包过滤器,IDS以及其他工具的检测更加困难
  • -D: 隐蔽扫描;使用逗号分隔每个诱饵主机,用自己真实的IP作为诱饵使用ME选项.如在6号或更后的位置使用ME选项,一些检测器就不报告真实IP;如果不使用ME,真实IP将随机放置.
  • -S <IP_Address>: 伪造数据包的源地址
  • g/–source-port : 伪造源端口

输出选项

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
  --noninteractive: Disable runtime interactions via keyboard
  --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
  • -oN: 标准输出
  • -oX: XML输出写入指定的文件
  • -oS: 脚本小子输出,类似于交互工具输出
  • -oG: Grep输出
  • -oA: 输出到所有格式
  • -v: 提高输出信息的详细度
  • –resume : 继续中断的扫描

Nmap常用扫描技巧

扫描单一主机

#默认发送一个ARP包扫描1-1000范围内开放的端口
nmap + 目标主机域名
nmap + 目标主机IP地址
例:
nmap baidu.com
nmap 192.168.xx.xx

扫描整个子网

#Nmap默认不扫描本机
nmap + 需要扫描的网段地址
例:
nmap 192.168.xx.xx/24

扫描多个目标

nmap + 多个目标主机IP地址或者域名
例:
nmap baidu.com 192.168.xx.xx google.com

扫描一个范围内的目标

nmap + 目标IP地址范围
例:
nmap 192.168.xx.xx-200

导入IP列表进行扫描

nmap -sL + IP列表
例:
nmap -sL ip.txt #ip.txt在Nmap的目录下

列举目标地址,但不进行扫描

nmap -sL + 需要扫描的网段地址
例:
nmap -sL 192.168.xx.xx/24

排除IP进行扫描

nmap + 网段地址 -exclude + 排除的IP地址
例:
nmap 192.168.xx.xx/24 -exclude 192.168.xx.xx
nmap + 网段地址 -exclude file + 排除的IP列表
例:
nmap 192.168.xx.xx -exclude file ip.txt #ip.txt要在Nmap目录下

扫描特定主机的特定端口

nmap -p + 端口 + 目标主机/域名
例:
nmap -p 80,21,22,8080 192.168.xx.xx
nmap -p 50-900 192.168.xx.xx

简单扫描,详细输出返回结果

nmap -vv + 目标主机IP地址/域名
例:
nmap -vv 192.168.xx.xx

简单扫描并进行路由跟踪

nmap -traceroute + IP地址/域名
例:
nmap -traceroute 192.168.xx.xx

ping扫描,不扫描端口Linux系统需要root权限

namp -sP + IP地址/域名
nmap -sn + IP地址/域名
例:
namp -sP 192.168.xx.xx
nmap -sn 192.168.xx.xx

探测操作系统类型

nmap -O + 目标主机的IP地址/域名
例:
nmap -O 192.168.xx.xx

Nmap万能开关-A参数

nmap -A + 目标主机的IP地址/域名
nmap -A 192.168.xx.xx

混合命令扫描

#按个人需求组合命令扫描
例:
namp -vv -p1-500 -O 192.168.xx.xx/24 -exclude 192.168.xx.x
#扫描192.168.xx.xx/24这个范围内除了192.168.xx.x这个IP地址的主机的1-500端口,识别目标操作系统然后详细输出

半开放TCP SYN端口扫描

namp -sS + 目标主机的IP地址/域名
例:
namp -sS 192.168.xx.xx

扫描UDP服务端口

nmap -sU + 目标主机的IP地址/域名
例:
nmap -sU 192.168.xx.xx

TCP连接扫描端口

nmap -sT + 目标主机的IP地址/域名
例:
nmap -sT 192.168.xx.xx

当目标主机存在IDS/IPS系统时,防火墙拦截SYN数据包时,可以发送设置FIN标志的数据包,无需完成TCP握手不产生日志

nmap -sF + 目标主机的IP地址/域名
例:
nmap -sF 192.168.xx.xx

Nmap的脚本扫描功能

Nmap允许用户自己编写脚本来执行自动化操作或者拓展Nmap功能,使用Lua脚本语言.

*脚本的默认路径为:/nmap/scripts/ *

脚本以==.nse==格式保存

-sC => -sC=default使用默认脚本进行扫描;

脚本分类:

  1. auth: 负责处理鉴权证书(绕开鉴权)的脚本
  2. broadcast: 在局域网内探查更多服务开启状况
  3. brute: 针对常见应用提供暴力破解方式;如http/sqlserver
  4. default: 使用-sC或-A选项扫描时默认的脚本,提供基本的脚本扫描能力
  5. discovery: 对网络进行更多的信息,如SMB\SNMP查询等
  6. dos: 用于进行拒绝服务器攻击DDOS攻击
  7. exploit: 利用已知的漏洞入侵系统
  8. external: 利用第三方的数据库或者资源,例如进行whois解析
  9. fuzzer: 模糊测试的脚本,发送异常的包到目标主机,探测潜在漏洞
  10. instrusive: 入侵性的脚本,此类脚本可以引发对方的IDS/IPS的记录或者屏蔽
  11. malware: 探测目标主机是否感染了病毒,开启了后门等信息
  12. safe: 此类与instrusive相反,属于安全性的脚本
  13. version: 负责增强服务与版本扫描(Version Detection)功能的脚本
  14. vuln: 负责检查目标主机是否有常见的漏洞(Vulnerability),比如MS08_067
例:
nmap --<script>= + 脚本 + 目标主机的IP/域名地址
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

how223366

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值