zoukankan      html  css  js  c++  java
  • centos 6.5下安装nmap工具及简单用法

      Nmap是一款针对大型网络的端口扫描工具,被广泛应用于黑客领域做漏洞探测以及安全扫描,其主要功能有主机发现(Host Discovery)、 端口扫描(Port Scanning)、 版本侦测(Version Detection) 、操作系统侦测(Operating System Detection),可以适用于winodws,linux,mac等操作系统。

    1、yum安装nmap

    yum install nmap

    nmap 命令参数:nmap -h

    [root@lamp01 scripts]# nmap -h
    Nmap 5.51 ( http://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
      -PR: ARP ping - does not need HW address -> IP translation
      -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
      -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
      -sR: Check what service uses opened ports using RPC scan
      --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-trace: Show all data sent and received
      --script-updatedb: Update the script database.
    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
      --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)
      --log-errors: Log errors/warnings to the normal-format output file
      --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 (http://nmap.org/book/man.html) FOR MORE OPTIONS AND EXAMPLES

    2、nmap 常用命令介绍:

    扫描单个主机:

    nmap 192.168.43.118

    扫描单个子网主机:

    nmap 192.168.43.0/24

    扫描多个主机:

    nmap 192.168.43.117 192.168.43.43.99

    扫描一个范围内的主机:

    nmap 192.168.43.1-254

    若你有一个ip地址表,将ip地址存在ip.log文件中,命令如下:

    nmap -iL ip.log

    若你想查看扫描的所有主机列表命令如下:

    nmap -sL 192.168.43.1/24

    扫描一子网主机且排除某一个ip命令:

    nmap 192.168.43.1/24 -exclude 192.168.43.118

    扫描一子网主机且排除某一个ip地址表命令:

    nmap 192.168.43.1/24 -exclude ip.log

    扫描主机路由跟踪信息:

    nmap --traceroute 192.168.43.118

    扫描主机信息结果详细输出:

    nmap -vv --traceroute 192.168.43.118

    扫描某主机上指定的端口或协议,例如80,21,22

    nmap -p U:53,T:80,21,22,S:9 192.168.43.118 (其中T代表TCP协议、U代表UDP协议、S代表SCTP协议)

    快速扫描端口模式,扫描100个最有可能开放的端口   -v 获取扫描的信息 

     nmap -F -v 192.168.43.118

    Tcp SYN Scan (sS)  隐蔽扫描

    这是一个不完整的扫描方式,它被称为半开放扫描,Nmap发送SYN包到远程主机,但是它不会产生任何会话,在syn扫描中不需要通过完整3次的握手,因此不会在目标主机上产生任何日志记录,这个就是SYN扫描的优势,但是这种扫描是需要root权限(对于windows用户来说,是没有root权限这个概念的,root权限是linux的最高权限,对应windows的管理员权限)

     nmap -sS 192.168.43.118

    Tcp connect() scan(sT) 最常用

    如果不选择SYN扫描,TCP connect()扫描就是默认的扫描模式,不同于Tcp SYN扫描,Tcp connect()扫描需要完成三次握手,并且要求调用系统的connect(),Tcp connect()扫描技术只适用于找出TCP和UDP端口,但是这种方式扫描的速度快,准确性高,对操作者没有权限上的要求,但是容易被防火墙和IDS(防入侵系统)发现。

    nmap -sT 192.168.43.118

    UDP scan(sU)  

    顾名思义,这种扫描技术用来寻找目标主机打开的UDP端口,它不需要发送任何的SYN包,因为这种技术是针对UDP端口的。UDP扫描发送UDP数据包到目标主机,并等待响应,如果返回ICMP不可达的错误消息,说明端口是关闭的,如果得到正确的适当的回应,说明端口是开放的。

    nmap -sU 192.168.43.118

    FIN scan (sF)  

    有时候Tcp SYN扫描不是最佳的扫描模式,因为有防火墙的存在,目标主机有时候可能有IDS和IPS系统的存在,防火墙会阻止掉SYN数据包。发送一个设置了FIN标志的数据包并不需要完成TCP的握手,收到RST回复说明该端口关闭,否则说明是open或filtered状态

    nmap -sF 192.168.43.118

    PING Scan (sP) 扫描在线主机

    PING扫描它只用于找出主机是否是存在在网络中的,它不是用来发现是否开放端口的,PING扫描需要ROOT权限,如果用户没有ROOT权限,PING扫描将会使用connect()调用。

    nmap -sP 192.168.43.118

    版本检测(sV)  

    版本检测是用来扫描目标主机和端口上运行的软件的版本,它不同于其它的扫描技术,它不是用来扫描目标主机上开放的端口,不过它需要从开放的端口获取信息来判断软件的版本,使用版本检测扫描之前需要先用TCP SYN扫描开放了哪些端口。

    nmap -sV 192.168.43.118

    Idle scan (sL)  

    Idle scan是一种先进的匿名扫描技术,它不是用你真实的主机Ip发送数据包,而是使用另外一个目标网络的主机发送数据包,例如:通过目标网络中的192.168.43.118向主机192.168.43.4发送数据,来获取192.168.1.1开放的端口。

    nmap -sL 192.168.43.118 192.168.43.4 

    有需要其它的扫描技术,如 FTP bounce(FTP反弹), fragmentation scan(碎片扫描),IP protocol scan(IP协议扫描),以上讨论的是几种最主要的扫描方式。

    Nmap的OS检测(O)

    Nmap最重要的特点之一是能够远程检测操作系统,Nmap的OS检测技术在渗透测试中用来了解远程主机的操作系统是非常有用的,通过获取的信息你可以知道已知的漏洞

    nmap -O 192.168.43.17

     ACK扫描:

    利用ACK扫描判断端口是否被过滤。针对ACK探测包,为被过滤的端口(无论打开或关闭)会回复RST包

    nmap -sA -T4 p1521,80 192.168.43.17

    使用TCP ACK (PA)和TCP Syn (PS)扫描远程主机

    nmap -pA -T4 p1521,80 192.168.43.17

    nmap -pA -T4 p1521,80 192.168.43.17

    扫描前不进行Ping扫描测试:

    nmap -Pn  p1521,80 192.168.43.17

    通过tcp空扫描以绕过防火墙检测:

    nmap -sN 192.168.43.17

    打印主机接口和路由

    nmap --iflist

    按顺序扫描端口:

    nmap -r 192.168.43.118

    扫描主机检测是否有防火墙过滤:

    nmap -PN -p 1521 192.168.43.17

    扫描操作系统信息和路由跟踪

    使用Nmap,你可以检测远程主机上运行的操作系统和版本。为了启用操作系统和版本检测,脚本扫描和路由跟踪功能,我们可以使用NMAP的“-A“选项。

    nmap -A 192.168.43.17

    扫描端口时状态介绍:

    Open  端口开启,数据有到达主机,有程序在端口上监控

    Closed  端口关闭,数据有到达主机,没有程序在端口上监控  

    Filtered  数据没有到达主机,返回的结果为空,数据被防火墙或者是IDS过滤  

    UnFiltered  数据有到达主机,但是不能识别端口的当前状态  

    Open|Filtered  端口没有返回值,主要发生在UDP、IP、FIN、NULL和Xmas扫描中

    Closed|Filtered   只发生在IP ID idle扫描

    以上总结来源于网络。

  • 相关阅读:
    [NOI 2011][BZOJ 2434] 阿狸的打字机
    列出cocos2dx运行场景所有节点信息
    png 转 eps (电脑已安装latex环境前提下)
    latex小记
    第二篇
    博客第一篇
    百度动态规划
    百度约瑟夫算环
    转~最大连续子序列求和
    Oracle学习笔记——一对多的关系关联查询时只关联查找最新的第一条数据
  • 原文地址:https://www.cnblogs.com/su-root/p/10428547.html
Copyright © 2011-2022 走看看