当前位置: 移动技术网 > 科技>操作系统>Linux > centos 6.5下安装nmap工具及简单用法

centos 6.5下安装nmap工具及简单用法

2019年02月25日  | 移动技术网科技  | 我要评论
Nmap是一款针对大型网络的端口扫描工具,被广泛应用于黑客领域做漏洞探测以及安全扫描,其主要功能有主机发现(Host Discovery)、 端口扫描(Port Scanning)、 版本侦测(Version Detection) 、操作系统侦测(Operating System Detection ...

  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扫描

以上总结来源于网络。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网