安全工具-Nmap


前言

本篇文章为端口扫描工具Nmap常用选项和命令的记录。


常用选项摘要

  • 命令:nmap 。不带参数,可参看常用的命令信息。
Nmap 7.91 ( 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

TARGET SPECIFICATION(目标规范)

可以传递主机名、IP地址、网络等。
例:scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
-iL:从主机/网络列表输入
-iR:选择随机目标
–exclude <host1[,host2][,host3],…>:排除主机/网络
–excludefile <exclude_file>:从文件中排除列表


HOST DISCOVERY(主机发现)

-sL:列表扫描-只需列出要扫描的目标
-sn:Ping扫描-禁用端口扫描
-Pn:将所有主机视为联机–跳过主机发现
-PS/PA/PU/PY[portlist]:对给定端口的TCP SYN/ACK、UDP或SCTP发现
-PE/PP/PM:ICMP回显、时间戳和网络掩码请求发现探测
-PO[协议列表]:IP协议Ping
-n/-R:从不进行DNS解析/始终解析[默认值:有时]
–dns-servers <serv1[,serv2],…>:指定自定义DNS服务器
–system-dns:使用操作系统的dns解析程序
–traceroute:跟踪到每个主机的跃点路径


SCAN TECHNIQUES(扫描技术)

-sS/sT/sA/sW/sM:TCP-SYN/Connect()/ACK/Window/Maimon扫描
-su:UDP扫描
-sN/sF/sX:TCP Null、FIN和Xmas扫描
–scanflags :自定义TCP扫描标志
-sI <zombie host[:probeport]>:空闲扫描
-sY/sZ:SCTP初始化/COOKIE-ECHO扫描
-sO:IP协议扫描
-b <FTP中继主机>:FTP跳转扫描


PORT SPECIFICATION AND SCAN ORDER(端口规格和扫描顺序)

-p :仅扫描指定的端口
Ex:-p22;-p1-65535;-p U:53,111,137,T:21-25,80,139,8080,S:9
–exclude-ports <端口范围>:从扫描中排除指定的端口
-F:快速模式-扫描的端口数少于默认扫描
-r:连续扫描端口-不要随机化
–top-ports <编号>:扫描<编号>最常见的端口
–port-ratio <比率>:扫描比<比率>更常见的端口


SERVICE/VERSION DETECTION(服务/版本检测)

-sV:探测打开的端口以确定服务/版本信息
–version-intensity:从0(少量的)设置为9(尝试所有探头)
–version-light:限制最可能的探测器(强度2)
–version-all:尝试每一个探头(强度9)
–version-trace:显示详细的版本扫描活动(用于调试)


SCRIPT SCAN(脚本扫描)

-sC:相当于–script=default
–script <Lua 脚本>:是一个用逗号分隔的脚本列表目录、脚本文件或脚本类别
–script-args=<n1=v1,[n2=v2,…]>:为脚本提供参数
–script args file=filename:在文件中提供NSE脚本args
–script-trace:显示发送和接收的所有数据
–script-updatedb:更新脚本数据库。
–script-help=:显示关于脚本的帮助。是以逗号分隔的脚本文件或脚本类别。


OS DETECTION(操作系统检测)

-O:启用操作系统检测
–osscan limit:将OS检测限制在有希望的目标上
–osscan-guess:更积极地猜测操作系统


TIMING AND PERFORMANCE(时机和表现)


FIREWALL/IDS EVASION AND SPOOFING(防火墙/IDS规避和欺骗)

-f;–mtu:片段数据包(可选带给定mtu)
-D <decoy1,decoy2[,ME],…>:用诱饵掩盖扫描
-S <IP地址>:欺骗源地址
-e :使用指定的接口
-g/–source-port :使用给定的端口号
–proxies <url1[url2],…>:通过HTTP/SOCKS4代理中继连接
–data :向发送的数据包附加自定义负载
–data-string <字符串>:将自定义ASCII字符串附加到发送的数据包中
–data-length :将随机数据附加到发送的数据包中
–ip-options <选项>:使用指定的ip选项发送数据包
–ttl:设置IP生存时间字段
–spoof-mac <mac地址/前缀/供应商名称>:欺骗你的mac地址
–badsum:使用伪TCP/UDP/SCTP校验和发送数据包


OUTPUT(输出)

-oN/-oX/-oS/-oG :正常、XML、s |<cript kIddi3和Grepable格式,分别设置为给定的文件名。
-oA :同时以三种主要格式输出
-v:增加详细程度(使用-vv或更高级别以获得更大效果)
-d:提高调试级别(使用-dd或更多以获得更大的效果)
–reason:显示端口处于特定状态的原因`
–open:仅显示打开(或可能打开)的端口
–packet-trace:显示发送和接收的所有数据包
–iflist:打印主机接口和路由(用于调试)
–append-output:追加到指定的输出文件,而不是删除指定的输出文件
–resume:恢复中止的扫描
–stylesheet <path/URL>:将XML输出转换为HTML的XSL样式表
–webxml:来自Nmap的参考样式表。Org获取更具可移植性的XML
–no-stylesheet:防止XSL样式表与XML输出关联


MISC(杂项)

-6:启用IPv6扫描
-A:启用操作系统检测、版本检测、脚本扫描和跟踪路由
–datadir:指定自定义Nmap数据文件位置
–send-eth/–send-ip:使用原始以太网帧或ip数据包发送
–privileged:假设用户拥有完全特权
–unprivileged:假设用户缺乏原始套接字权限
-V:打印版本号
-h:打印此帮助摘要页面。

常用命令

主机发现

  • nmap -sn ip
    -sn:Ping扫描-禁用端口扫描

端口及版本扫描

  • namp -p 80-445 ip
    -p:扫描主机的80-445端口的开放情况

  • nmap -sS -sU -p T:80,U:445 ip
    以半连接的TCP SYN方式扫描主机的80端口,又以UDP方式扫描主机的445端口

  • nmap -sV ip
    -sV:进行详细版本扫描


操作系统探测

  • nmap -O ip
    -O:操作系统探测

脚本漏洞扫描

  • nmap -T4 -A -V ip
    -A:用于使用攻击性方式扫描
    -T4:指定扫描过程使用的时序,总共有6个级别(0-5)级别越高扫描速度越快,但是也容易被防火墙检测并屏蔽掉,在网络情况较好的是可以使用T4
    -v:显示冗余信息,在扫描的过程中显示扫描的细节

  • nmap --script=vuln 192.168.229.128
    –script=vuln:指定漏洞脚本进行扫描

Nmap脚本目录:/usr/share/nmap/scripts
更多脚本的高级用法可参考链接Nmap的高级扫描(脚本)


总结

  • namp命令选项较多,更高级的用法请多百度搜索。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Windows系统下使用Python-nmap可以进行网络扫描和端口扫描。Python-nmap是一个Python库,它封装了Nmap安全扫描工具的功能,可以通过Python代码来调用Nmap进行扫描操作。 要在Windows系统中使用Python-nmap,首先需要确保已经安装了Python和Nmap。以下是使用Python-nmap的基本步骤: 1. 安装Python:从Python官方网站下载并安装适合您系统的Python版本。 2. 安装Nmap:从Nmap官方网站下载并安装适合您系统的Nmap版本。 3. 安装Python-nmap库:打开命令提示符或者PowerShell,并执行以下命令来安装Python-nmap库: ``` pip install python-nmap ``` 4. 编写Python代码:创建一个Python脚本文件,例如`scan.py`,并在其中编写扫描代码。以下是一个简单的示例: ```python import nmap nm = nmap.PortScanner() result = nm.scan('127.0.0.1', '22-443') for host in result['scan']: print('Host: %s' % host) for port in result['scan'][host]['tcp']: print('Port: %s\tState: %s' % (port, result['scan'][host]['tcp'][port]['state'])) ``` 上述代码使用了`nmap.PortScanner()`创建了一个扫描器对象,然后使用`scan()`方法对指定IP地址和端口范围进行扫描。扫描结果存储在`result`变量中,可以根据需要进行处理和输出。 5. 运行Python脚本:在命令提示符或者PowerShell中执行以下命令来运行Python脚本: ``` python scan.py ``` 执行后,您将看到扫描结果输出在命令行中。 希望以上介绍对您有帮助!如果您有任何进一步的问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值