(1)-sP :進行ping掃描css
nmap -sP 10.0.3.0/24
這個命令能夠用於探測局域網有哪些機器html
[root@B ~]# nmap -sP 10.0.3.0/24
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 11:24 CST
Nmap scan report for 10.0.3.1
Host is up (0.0079s latency).
Nmap scan report for 10.0.3.2
Host is up (0.0046s latency).
Nmap scan report for 10.0.3.3
Host is up (0.0037s latency).
Nmap done: 256 IP addresses (3 hosts up) scanned in 10.01 seconds
[root@B ~]#
(2) -sn:mysql
-sn: Ping Scan - disable port scan #ping探測掃描主機, 不進行端口掃描 (測試過對方主機把icmp包都丟棄掉,依然能檢測到對方開機狀態)web
[root@B ~]# nmap -sn 10.0.1.161-166
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 11:25 CST
Nmap scan report for 10.0.1.161
Host is up (0.00076s latency).
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap scan report for 10.0.1.162
Host is up.
Nmap done: 6 IP addresses (2 hosts up) scanned in 0.76 seconds
[root@B ~]#
[root@B ~]# nmap 10.0.1.161 -sA Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 13:55 CST Nmap scan report for 10.0.1.161 Host is up (0.00030s latency). All 1000 scanned ports on 10.0.1.161 are unfiltered MAC Address: 00:0C:29:56:DE:46 (VMware) Nmap done: 1 IP address (1 host up) scanned in 1.53 seconds [root@B ~]# nmap 10.0.1.166 -sA Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 13:55 CST Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn Nmap done: 1 IP address (0 hosts up) scanned in 0.51 seconds [root@B ~]#
使用頻率最高的掃描選項:SYN掃描,又稱爲半開放掃描,它不打開一個徹底的TCP鏈接,執行得很快,效率高 (一個完整的tcp鏈接須要3次握手,而-sS選項不須要3次握手) Tcp SYN Scan (sS) 它被稱爲半開放掃描 優勢:Nmap發送SYN包到遠程主機,可是它不會產生任何會話,目標主機幾乎不會把鏈接記入系統日誌。(防止對方判斷爲掃描攻擊),掃描速度快,效率高,在工做中使用頻率最高 缺點:它須要root/administrator權限執行
命令以下sql
nmap -sS 10.0.1.161
[root@B ~]# nmap -sS 10.0.1.161 Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 11:38 CST Nmap scan report for 10.0.1.161 Host is up (0.00028s latency). Not shown: 995 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind 873/tcp open rsync 7777/tcp open cbt 8888/tcp open sun-answerbook MAC Address: 00:0C:29:56:DE:46 (VMware) Nmap done: 1 IP address (1 host up) scanned in 1.31 seconds [root@B ~]#
Tcp connect() scan (sT)和上面的Tcp SYN 對應,TCP connect()掃描就是默認的掃描模式. 不一樣於Tcp SYN掃描,Tcp connect()掃描須要完成三次握手,而且要求調用系統的connect(). 優勢:你勿需root權限。普通用戶也可使用。 缺點:這種掃描很容易被檢測到,在目標主機的日誌中會記錄大批的鏈接請求以及錯誤信息,因爲它要完成3次握手,效率低,速度慢,建議使用-sS
[root@B ~]# nmap -sT 10.0.1.161 Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 11:40 CST Nmap scan report for 10.0.1.161 Host is up (0.00048s latency). Not shown: 995 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind 873/tcp open rsync 7777/tcp open cbt 8888/tcp open sun-answerbook MAC Address: 00:0C:29:56:DE:46 (VMware) Nmap done: 1 IP address (1 host up) scanned in 0.27 seconds [root@B ~]#
(3)sU:udp端口的掃描windows
nmap -sU 10.0.1.161
[root@B ~]# nmap -sF 10.0.1.161
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 11:46 CST
Nmap scan report for 10.0.1.161
Host is up (0.00050s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open|filtered ssh
111/tcp open|filtered rpcbind
873/tcp open|filtered rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 2.59 seconds
[root@B ~]#
-sF、-sX、-sN安全
祕密FIN數據包掃描、聖誕樹(XmasTree)、空(Null)掃描模式 有的防火牆可能專門阻止-sS掃描。使用這些掃描能夠發送特殊標記位的數據包 好比,-sF發送一個設置了FIN標誌的數據包 它們和-sS同樣也須要完成TCP的握手. 和sS掃描效果差很少,都比sT速度快 除了探測報文的標誌位不一樣,三種掃描在行爲上一致 優點:能躲過一些無狀態防火牆和報文過濾路由器,比SYN還要隱祕 劣勢:現代的IDS產品能夠發現,並不是全部的系統嚴格遵循RFC 793 即便SYN掃描都沒法肯定的狀況下使用:一些防火牆和包過濾軟件可以對發送到被限制端口的SYN數據包進行監視, 並且有些程序好比synlogger和courtney可以檢測那些掃描。使用-sF、-sX、-sN能夠逃過這些干擾。 這些掃描方式的理論依據是:關閉的端口須要對你的探測包迴應RST包,而打開的端口必需忽略有問題的包。 FIN掃描使用暴露的FIN數據包來探測,而聖誕樹掃描打開數據包的FIN、URG和PUSH標誌。 因爲微軟決定徹底忽略這個標準,另起爐竈。因此這種掃描方式對Windows無效。 不過,從另外的角度講,可使用這種方式來分別兩種不一樣的平臺。 若是使用這種掃描方式能夠發現打開的端口,你就能夠肯定目標註意運行的不是Windows系統。 若是使用-sF、-sX或者-sN掃描顯示全部的端口都是關閉的,而使用-sS(SYN)掃描顯示有打開的端口,你能夠肯定目標主機可能運行的是Windwos系統。 如今這種方式沒有什麼太大的用處,由於nmap有內嵌的操做系統檢測功能。還有其它幾個系統使用和windows一樣的處理方式,包括Cisco、BSDI、HP/UX、MYS、IRIX。 在應該拋棄數據包時,以上這些系統都會從打開的端口發出復位數據包。
[root@B ~]# nmap -sW 10.0.1.161 -p22
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 13:17 CST
Nmap scan report for 10.0.1.161
Host is up (0.0027s latency).
PORT STATE SERVICE
22/tcp closed ssh
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.34 seconds
[root@B ~]#
[root@B ~]# nmap -sV 10.0.1.161
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 13:18 CST
Nmap scan report for 10.0.1.161
Host is up (0.00017s latency).
Not shown: 997 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 5.3 (protocol 2.0)
111/tcp open rpcbind
873/tcp open rsync (protocol version 30)
MAC Address: 00:0C:29:56:DE:46 (VMware)
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.60 seconds
[root@B ~]#
[root@B ~]# nmap -iR 2 -Pn -p22 Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 13:51 CST Nmap scan report for LFbn-1-4041-19.w86-233.abo.wanadoo.fr (86.233.49.19) Host is up. PORT STATE SERVICE 22/tcp filtered ssh Nmap scan report for 209.236.30.216 Host is up. PORT STATE SERVICE 22/tcp filtered ssh Nmap done: 2 IP addresses (2 hosts up) scanned in 15.28 seconds [root@B ~]#
[root@B ~]# nmap --top-ports 5 10.0.1.161
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 13:58 CST
Nmap scan report for 10.0.1.161
Host is up (0.00074s latency).
PORT STATE SERVICE
21/tcp closed ftp
22/tcp open ssh
23/tcp closed telnet
80/tcp closed http
443/tcp closed https
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.40 seconds
[root@B ~]#
[root@B ~]# nmap --port-ratio 0.1 10.0.1.161 Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 13:59 CST Nmap scan report for 10.0.1.161 Host is up (0.0011s latency). PORT STATE SERVICE 21/tcp closed ftp 22/tcp open ssh 23/tcp closed telnet 25/tcp closed smtp 80/tcp closed http 443/tcp closed https MAC Address: 00:0C:29:56:DE:46 (VMware) Nmap done: 1 IP address (1 host up) scanned in 0.35 seconds [root@B ~]#
[root@B ~]# nmap -sO 10.0.1.161 Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 14:00 CST Stats: 0:04:10 elapsed; 0 hosts completed (1 up), 1 undergoing IPProto Scan IPProto Scan Timing: About 91.69% done; ETC: 14:05 (0:00:23 remaining) Nmap scan report for 10.0.1.161 Host is up (0.00082s latency). Not shown: 249 closed protocols PROTOCOL STATE SERVICE 1 open icmp 2 open|filtered igmp 6 open tcp 17 open udp 47 open|filtered gre 103 open|filtered pim 136 open|filtered udplite MAC Address: 00:0C:29:56:DE:46 (VMware) Nmap done: 1 IP address (1 host up) scanned in 289.19 seconds [root@B ~]#
[root@A ~]# netstat -lntp --inet | grep -v 127.0.0.1 Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:45654 0.0.0.0:* LISTEN 22257/nc tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2157/sshd tcp 0 0 0.0.0.0:13306 0.0.0.0:* LISTEN 21699/mysqld tcp 0 0 0.0.0.0:873 0.0.0.0:* LISTEN 2640/rsync tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 21505/rpcbind [root@A ~]#
以下,對於一些端口號仍然沒檢測出bash
[root@B ~]# nmap 10.0.1.161 --allports
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 14:07 CST
Nmap scan report for 10.0.1.161
Host is up (0.000098s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.20 seconds
[root@B ~]#
其他不多使用的參數服務器
-P0 在掃描以前,沒必要ping主機。有些網絡的防火牆不容許ICMPecho請求穿過,使用這個選項能夠對這些網絡進行掃描。microsoft.com就是一個例子,所以在掃描這個站點時,你應該一直使用-P0或者-PT80選項。 -PT 掃描以前,使用TCPping肯定哪些主機正在運行。nmap不是經過發送ICMPecho請求包而後等待響應來實現這種功能,而是向目標網絡(或者單一主機)發出TCPACK包而後等待迴應。
[root@B ~]# nmap -A www.baidu.com
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 14:10 CST
Nmap scan report for www.baidu.com (115.239.210.27)
Host is up (0.0046s latency).
Other addresses for www.baidu.com (not scanned): 115.239.211.112
Not shown: 998 filtered ports
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd
|_http-methods: No Allow or Public header in OPTIONS response (status code 302)
| http-robots.txt: 8 disallowed entries
|_/baidu /s? /ulink? /link? /shifen/ /homepage/ /cpro /
|_http-title: \xE7\x99\xBE\xE5\xBA\xA6\xE4\xB8\x80\xE4\xB8\x8B\xEF\xBC\x8C\xE4\xBD\xA0\xE5\xB0\xB1\xE7\x9F\xA5\xE9\x81\x93
|_http-favicon:
443/tcp open ssl/https?
|_http-title: 405 Not Allowed
|_http-methods: No Allow or Public header in OPTIONS response (status code 405)
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at http://www.insecure.org/cgi-bin/servicefp-submit.cgi :
SF-Port443-TCP:V=5.51%T=SSL%I=7%D=12/29%Time=5864A904%P=x86_64-redhat-linu
SF:x-gnu%r(RTSPRequest,1000,"<html>\r\n<head>\r\n<meta\x20http-equiv=\"con
SF:tent-type\"\x20content=\"text/html;charset=utf-8\">\r\n<style\x20data-f
SF:or=\"result\"\x20id=\"css_result\">\r\nbody{color:#333;background:#fff;
SF:padding:6px\x200\x200;margin:0;position:relative;min-width:900px}body,t
SF:h,td,\.p1,\.p2{font-family:arial}p,form,ol,ul,li,dl,dt,dd,h3{margin:0;p
SF:adding:0;list-style:none}input{padding-top:0;padding-bottom:0;-moz-box-
SF:sizing:border-box;-webkit-box-sizing:border-box;box-sizing:border-box}t
SF:able,img{border:0}td{font-size:9pt;line-height:18px}\r\n\r\n\r\n\r\n#fo
SF:ot{font-size:12px}\.logo{width:117px;height:38px;cursor:pointer}\r\n\r\
SF:n#u,#head,#tool,#search,\.p1{line-height:120%;margin-left:-12pt}\.p2{wi
SF:dth:100%;line-height:120%;margin-left:-12pt}#wrapper{_zoom:1}#container
SF:{word-break:break-all;word-wrap:break-word}\.container_s{width:1002px}\
SF:.container_l{width:1222px}#content_left{width:636px;float:left;padding-
SF:left:35px}#content_right{border-left:1px\x20solid\x20#e1e1e1;f")%r(RPCC
SF:heck,1000,"HTTP/1\.1\x20302\x20Moved\x20Temporarily\r\nServer:\x20bfe/1
SF:\.0\.8\.18\r\nDate:\x20Thu,\x2029\x20Dec\x202016\x2006:11:16\x20GMT\r\n
SF:Content-Type:\x20text/html\r\nContent-Length:\x2017931\r\nConnection:\x
SF:20close\r\nETag:\x20\"54d9748e-460b\"\r\nSet-Cookie:\x20__bsi=168002475
SF:26252574989_00_4_R_N_0_0303_C02F_N_I_I_0;\x20expires=Thu,\x2029-Dec-16\
SF:x2006:11:21\x20GMT;\x20domain=www\.baidu\.com;\x20path=/\r\n\r\n<html>\
SF:r\n<head>\r\n<meta\x20http-equiv=\"content-type\"\x20content=\"text/htm
SF:l;charset=utf-8\">\r\n<style\x20data-for=\"result\"\x20id=\"css_result\
SF:">\r\nbody{color:#333;background:#fff;padding:6px\x200\x200;margin:0;po
SF:sition:relative;min-width:900px}body,th,td,\.p1,\.p2{font-family:arial}
SF:p,form,ol,ul,li,dl,dt,dd,h3{margin:0;padding:0;list-style:none}input{pa
SF:dding-top:0;padding-bottom:0;-moz-box-sizing:border-box;-webkit-box-siz
SF:ing:border-box;box-sizing:border-box}table,img{border:0}td{font-size:9p
SF:t;line-height:18px}\r\n\r\n\r\n\r\n#foot{font-size:12px}\.logo{width:11
SF:7px;height:38px;cursor:pointer}\r\n\r\n#u,#head,#tool,#");
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: switch
Running (JUST GUESSING): HP embedded (86%)
Aggressive OS guesses: HP 4000M ProCurve switch (J4121A) (86%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 10 hops
TRACEROUTE (using port 443/tcp)
HOP RTT ADDRESS
1 ...
2 2.75 ms 192.168.19.2
3 2.09 ms 192.168.0.1
4 ... 9
10 3.60 ms 115.239.210.27
OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 30.58 seconds
[root@B ~]#
-e:指定網絡接口,掃描時使用哪一個網卡網絡
[root@B ~]# nmap 10.0.1.161 -e eth0 Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 14:25 CST Nmap scan report for 10.0.1.161 Host is up (0.00020s latency). Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind 873/tcp open rsync MAC Address: 00:0C:29:56:DE:46 (VMware) Nmap done: 1 IP address (1 host up) scanned in 1.28 seconds [root@B ~]#
-S:能夠假裝源地址進行掃描。這樣好處在於不會被對方發現本身的真實IP
接下來咱們來驗證一下
A機器添加一條規則,好比,拒絕源地址爲10.0.1.162的任何訪問請求
[root@A ~]# iptables -I INPUT -s 10.0.1.162 -j DROP [root@A ~]# iptables -L -n Chain INPUT (policy ACCEPT) target prot opt source destination DROP all -- 10.0.1.162 0.0.0.0/0 Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination [root@A ~]#
而後咱們使用B機器假裝成10.0.1.167去掃描A機器,是能夠掃描成功的
[root@B ~]# nmap -e eth0 10.0.1.161 -S 10.0.1.167 -Pn
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 14:30 CST
Nmap scan report for 10.0.1.161
Host is up (0.0016s latency).
Not shown: 997 closed ports
PORT STATE SERVICE
22/tcp open ssh
111/tcp open rpcbind
873/tcp open rsync
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 0.47 seconds
[root@B ~]#
假如咱們在A機器上禁止源地址爲10.0.1.167的訪問請求,那麼B機器就應該沒法掃描A的端口了。咱們來驗證下
A機器禁止源地址爲10.0.1.167的機器訪問
[root@A ~]# iptables -I INPUT -s 10.0.1.167 -j DROP
[root@A ~]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP all -- 10.0.1.167 0.0.0.0/0
DROP all -- 10.0.1.162 0.0.0.0/0
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@A ~]#
B機器假裝成10.0.1.167掃描A機器,掃描不到對方端口
[root@B ~]# nmap -e eth0 10.0.1.161 -S 10.0.1.167 -Pn
Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 14:33 CST
Nmap scan report for 10.0.1.161
Host is up (0.0012s latency).
All 1000 scanned ports on 10.0.1.161 are filtered
MAC Address: 00:0C:29:56:DE:46 (VMware)
Nmap done: 1 IP address (1 host up) scanned in 22.95 seconds
[root@B ~]#
若是咱們假裝成別的地址就應該能繼續掃描到端口
咱們假裝成了10.0.1.168,掃描成功
[root@B ~]# nmap -e eth0 10.0.1.161 -S 10.0.1.168 -Pn Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 14:34 CST Nmap scan report for 10.0.1.161 Host is up (0.00026s latency). Not shown: 997 closed ports PORT STATE SERVICE 22/tcp open ssh 111/tcp open rpcbind 873/tcp open rsync MAC Address: 00:0C:29:56:DE:46 (VMware) Nmap done: 1 IP address (1 host up) scanned in 0.50 seconds [root@B ~]#
[root@B ~]# nmap -iflist Starting Nmap 5.51 ( http://nmap.org ) at 2016-12-29 14:37 CST ************************INTERFACES************************ DEV (SHORT) IP/MASK TYPE UP MTU MAC lo (lo) 127.0.0.1/8 loopback up 65536 eth0 (eth0) 10.0.1.162/24 ethernet up 1500 00:0C:29:11:64:A1 **************************ROUTES************************** DST/MASK DEV GATEWAY 10.0.1.0/24 eth0 169.254.0.0/16 eth0 0.0.0.0/0 eth0 10.0.1.1 [root@B ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 10.0.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0 0.0.0.0 10.0.1.1 0.0.0.0 UG 0 0 0 eth0 [root@B ~]#
nmap功能參數還有不少,我的以爲以上功能能應付工做中99%的須要了。沒特殊必要,不用花太多時間在上面。
小結:
nmap工具很強大。建議先用Nmap掃描一個熟悉的系統,感受一下Nmap的基本運行模式,熟悉以後,再將掃描範圍擴大到其餘系統。
首先掃描內部網絡看看Nmap報告的結果,而後從一個外部IP地址掃描,注意防火牆、入侵檢測系統(IDS)以及其餘工具對掃描操做的反應。 一般,TCP connect()會引發IDS系統的反應(默認的nmap掃描就是sT的方式,也就是3次握手的方式掃描) 但IDS不必定會記錄俗稱「半鏈接」的TCP SYN掃描(-sS方式的)。 若是你打算熟悉和使用Nmap,下面幾點經驗可能對你有幫助: 一、 避免誤解。不要隨意選擇測試Nmap的掃描目標。許多單位把端口掃描視爲惡意行爲,因此測試Nmap最好在內部網絡進行。若有必要,應該告訴同事你正在試驗端口掃描,由於掃描可能引起IDS警報以及其餘網絡問題。 二、 關閉沒必要要的服務。根據Nmap提供的報告(同時考慮網絡的安全要求),關閉沒必要要的服務,或者調整路由器的訪問控制規則(ACL),禁用網絡開放給外界的某些端口。 三、 創建安全基準。在Nmap的幫助下加固網絡、搞清楚哪些系統和服務可能受到攻擊以後,下一步是從這些已知的系統和服務出發創建一個安全基準,之後若是要啓用新的服務或者服務器,就能夠方便地根據這個安全基準執行。
一些nmap相關的連接,有時間能夠參照下,這兩篇筆記總結的比較全了
http://www.91ri.org/4105.html
http://www.91ri.org/3870.html
http://blog.163.com/jianshitianxia_ao/blog/static/1765693842012731114821230/
https://nmap.org/download.html#windows
http://www.91ri.org/8516.html
http://blog.csdn.net/huangwwu11/article/details/20230795
http://blog.csdn.net/tan6600/article/details/45340511