扫描工具nmap安装和使用

请输入图片描述

访问nmap官网或者中文网找到相应的安装包:
官网:https://nmap.org
中文网:http://www.nmap.com.cn

解压压缩包并进入目录

tar -xjvf nmap-7.31.tar.bz2
cd nmap-7.31/

编译

./configure
make
make install

执行 nmap 会给出使用参数,执行 nmap -v 会输出当前版本号

执行一下扫描看下

[root@battlerhenry test ~]# nmap XXX.XXX.XXX.XXX

Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-03 10:59 CST
Nmap scan report for XXX.XXX.XXX.XXX
Host is up (0.026s latency).
Not shown: 994 filtered ports
PORT      STATE  SERVICE
21/tcp    open   ftp
22/tcp    open   ssh
53/tcp    open   domain
80/tcp    open   http
443/tcp   open   https
35500/tcp closed unknown

Nmap done: 1 IP address (1 host up) scanned in 10.57 seconds

filtered表示端口可能开着,状态未知

检查主机系统:

[root@battlerhenry-test ~]# nmap -O 121.42.122.226

Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-03 11:16 CST
Nmap scan report for 121.42.122.226
Host is up (0.021s latency).
Not shown: 996 filtered ports
PORT     STATE  SERVICE
21/tcp   open   ftp
80/tcp   open   http
1433/tcp closed ms-sql-s
3306/tcp closed mysql
Device type: general purpose
Running: Microsoft Windows Vista|7|2008
OS CPE: cpe:/o:microsoft:windows_vista::sp1:home_premium cpe:/o:microsoft:windows_7 cpe:/o:microsoft:windows_server_2008
OS details: Microsoft Windows Vista Home Premium SP1, Windows 7, or Windows Server 2008

OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.25 seconds

192.168.0.1-100达到局域网网段扫描的效果
192.168.0.1/24来实现整个局域网扫描

使用-vv输出详细结果

[root@battlerhenry-test ~]# nmap -vv 121.42.122.226

Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-03 11:22 CST
Initiating Ping Scan at 11:22
Scanning 121.42.122.226 [4 ports]
Completed Ping Scan at 11:22, 0.03s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 11:22
Completed Parallel DNS resolution of 1 host. at 11:22, 0.35s elapsed
Initiating SYN Stealth Scan at 11:22
Scanning 121.42.122.226 [1000 ports]
Discovered open port 80/tcp on 121.42.122.226
Discovered open port 21/tcp on 121.42.122.226
Completed SYN Stealth Scan at 11:22, 4.85s elapsed (1000 total ports)
Nmap scan report for 121.42.122.226
Host is up (0.023s latency).
Scanned at 2017-11-03 11:22:44 CST for 6s
Not shown: 996 filtered ports
PORT     STATE  SERVICE
21/tcp   open   ftp
80/tcp   open   http
1433/tcp closed ms-sql-s
3306/tcp closed mysql

Read data files from: /usr/bin/../share/nmap
Nmap done: 1 IP address (1 host up) scanned in 5.25 seconds
           Raw packets sent: 2002 (88.064KB) | Rcvd: 7 (276B)

指定端口扫描范围

[root@battlerhenry-test ~]# nmap -p1-998 121.42.122.226

Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-03 11:25 CST
Nmap scan report for 121.42.122.226
Host is up (0.020s latency).
Not shown: 996 filtered ports
PORT   STATE SERVICE
21/tcp open  ftp
80/tcp open  http

Nmap done: 1 IP address (1 host up) scanned in 5.02 seconds

指定特定的一些端口号进行扫描

[root@battlerhenry-test ~]# nmap -p80,512,22,80,8080,21,443 121.42.122.226

Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-03 11:28 CST
WARNING: Duplicate port number(s) specified.  Are you alert enough to be using Nmap?  Have some coffee or Jolt(tm).
Nmap scan report for 121.42.122.226
Host is up (0.021s latency).
PORT     STATE    SERVICE
21/tcp   open     ftp
22/tcp   filtered ssh
80/tcp   open     http
443/tcp  filtered https
512/tcp  filtered exec
8080/tcp filtered http-proxy

Nmap done: 1 IP address (1 host up) scanned in 1.32 seconds

进行ping扫描

[root@battlerhenry-test ~]# nmap -sP 121.42.122.226

Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-03 11:30 CST
Nmap scan report for 121.42.122.226
Host is up (0.020s latency).
Nmap done: 1 IP address (1 host up) scanned in 0.24 seconds

跑traceroute

[root@battlerhenry-test ~]# nmap -traceroute 121.42.122.226

Starting Nmap 6.40 ( http://nmap.org ) at 2017-11-03 14:00 CST
Nmap scan report for 121.42.122.226
Host is up (0.021s latency).
Not shown: 996 filtered ports
PORT     STATE  SERVICE
21/tcp   open   ftp
80/tcp   open   http
1433/tcp closed ms-sql-s
3306/tcp closed mysql

TRACEROUTE (using port 3306/tcp)
HOP RTT      ADDRESS
1   ...
2   1.48 ms  10.254.2.252
3   7.80 ms  100.127.202.17
4   2.18 ms  58.241.243.101
5   3.46 ms  221.6.248.65
6   23.24 ms 219.158.10.253
7   20.53 ms 219.158.10.253
8   20.91 ms 27.221.80.250
9   19.99 ms 116.251.113.34
10  19.79 ms 119.38.215.21
11  20.45 ms 116.251.114.125
12  ...
13  20.18 ms 121.42.122.226

Nmap done: 1 IP address (1 host up) scanned in 8.31 seconds

显示帮助文档

[root@battlerhenry-test ~]# nmap -help
Nmap 6.40 ( 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
  -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
  --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 separted 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
  --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

总体来说还是很好用的。

————————————————————————————————————-
猫箱内の六轩岛原创文章,转载请保留出处:http://blog.ushiromiyabatora.com

Last modification:November 10th, 2017 at 10:35 am
If you think my article is useful to you, please feel free to appreciate

Leave a Comment