網絡掃描工具nc&nmap

一、NC

1、nc安裝

# yum install nc

2、nc詳解

linux nc命令<netcat>
 
功能說明:功能強大的網絡工具
語  法:nc [-hlnruz][-g<網關...>][-G<指向器數目>][-i<延遲秒數>][-o<輸出文件>][-p<通信端口>][-s<來源位址>][-v...][-w<超時秒數>][主機名稱][通信端口...]
參  數:
  -g<網關>   設置路由器躍程通信網關,最丟哦可設置8個。
  -G<指向器數目>   設置來源路由指向器,其數值爲4的倍數。
  -h   在線幫助。
  -i<延遲秒數>   設置時間間隔,以便傳送信息及掃描通信端口。
  -l   使用監聽模式,管控傳入的資料。
  -n   直接使用IP地址,而不通過域名服務器。
  -o<輸出文件>   指定文件名稱,把往來傳輸的數據以16進制字碼傾倒成該文件保存。
  -p<通信端口>   設置本地主機使用的通信端口。
  -r   亂數指定本地與遠端主機的通信端口。
  -s<來源位址>   設置本地主機送出數據包的IP地址。
  -u   使用UDP傳輸協議。
  -v   顯示指令執行過程。
  -w<超時秒數>   設置等待連線的時間。
  -z   使用0輸入/輸出模式,只在掃描通信端口時使用。
 
擴展資料一: nc簡單使用示例
 
簡單用法舉例
1)端口掃描
# nc -v -w 2 192.168.2.34 -z 21-24
nc: connect to 192.168.2.34 port 21 (tcp) failed: Connection refused
Connection to 192.168.2.34 22 port [tcp/ssh] succeeded!
nc: connect to 192.168.2.34 port 23 (tcp) failed: Connection refused
nc: connect to 192.168.2.34 port 24 (tcp) failed: Connection refused
 
2)從192.168.2.33拷貝文件到192.168.2.34
在192.168.2.34上: nc -l 1234 > test.txt
在192.168.2.33上: nc 192.168.2.34 < test.txt
 
3)簡單聊天工具
在192.168.2.34上: nc -l 1234
在192.168.2.33上: nc 192.168.2.34 1234
這樣,雙方就可以相互交流了。使用ctrl+C(或D)退出。
 
3.用nc命令操作memcached
1)存儲數據:printf “set key 0 10 6rnresultrn” |nc 192.168.2.34 11211
2)獲取數據:printf “get keyrn” |nc 192.168.2.34 11211
3)刪除數據:printf “delete keyrn” |nc 192.168.2.34 11211
4)查看狀態:printf “statsrn” |nc 192.168.2.34 11211
5)模擬top命令查看狀態:watch “echo stats” |nc 192.168.2.34 11211
6)清空緩存:printf “flush_allrn” |nc 192.168.2.34 11211 (小心操作,清空了緩存就沒了)
 
nc -l 1234
 
nc 127.0.0.1 1234
在端口1234建立連接,互相發送輸入
 
nc -p 1234 -w 5 host.example.com 80
建立從本地1234端口到host.example.com的80端口連接,5秒超時
nc -u host.example.com 53
u爲UDP連接
 
echo -n "GET / HTTP/1.0"r"n"r"n" | nc host.example.com 80
連接到主機並執行
 
nc -v -z host.example.com 70-80
掃描端口(70到80),可指定範圍。-v輸出詳細信息。
 
擴展資料二:命令linux nc 命令傳輸文件
 
nc到底幹嘛用的我不多描述,今天主要講下用nc傳輸文件。由於公司的設備sudo後沒有ssh,scp等遠程接入命令,或host.deny裏面設置了ssh的deny,不管怎樣的原因。我今天跨過大家常用的scp,來說明下一個更有用的輕量級工具,nc的另一個強大的功---文件傳輸。
 
範例如下:
 
目的主機監聽 
nc -l 監聽端口  > 要接收的文件名
nc -l 4444 > cache.tar.gz
 
源主機發起請求
nc  目的主機ip    目的端口 
nc  192.168.0.85  4444 
 
netstat  如下
[root@localhost jiangbao]# netstat -tpln
 
tcp        0      0 0.0.0.0:4444                0.0.0.0:*                   LISTEN      18166/nc  
 
英文描述如下 
DATA TRANSFER
Start by using nc to listen on a specific port, with output captured into a file:
 $ nc -l 1234 > filename.out
Using a second machine, connect to the listening nc process, feeding it the file which is to be transferred:
 $ nc host.example.com 1234 
 
擴展資料三: linux nc (NetCat) 命令詳解,這篇文章對nc的介紹非常詳細,和以上資料有部分重複.
 
一、版本
 
通常的Linux發行版中都帶有NetCat(簡稱nc),甚至在拯救模式光盤中也由busybox提供了簡版的nc工具。但不同的版本,其參數的使用略有差異。
 
[root@hatest1 ~]# cat /etc/asianux-release
Asianux release 2.0 (Trinity SP2)
[root@hatest1 ~]# cat /etc/redflag-release
Red Flag DC Server release 5.0 (Trinity SP2)
[root@hatest1 ~]# type -a nc
nc is /usr/bin/nc
[root@hatest1 ~]# rpm -q nc
nc-1.10-22
建議在使用前,先用man nc看看幫助。這裏以紅旗DC Server 5.0上的1.10版本進行簡單說明。
假設兩服務器信息:
 
引用
 
server1: 192.168.228.221
server2: 192.168.228.222
 
二、常見使用
 
1、遠程拷貝文件
 
從server1拷貝文件到server2上。需要先在server2上,用nc激活監聽,server2上運行:
 
[root@hatest2 tmp]# nc -lp 1234 > install.log
server1上運行:
 
引用
 
[root@hatest1 ~]# ll install.log
-rw-r–r–   1 root root 39693 12月 20   2007 install.log
[root@hatest1 ~]# nc -w 1 192.168.228.222 1234 < install.log
 
2、克隆硬盤或分區
 
操作與上面的拷貝是雷同的,只需要由dd獲得硬盤或分區的數據,然後傳輸即可。
克隆硬盤或分區的操作,不應在已經mount的的系統上進行。所以,需要使用安裝光盤引導後,進入拯救模式(或使用Knoppix工具光盤)啓動系統後,在server2上進行類似的監聽動作:
 
# nc -l -p 1234 | dd of=/dev/sda
 
server1上執行傳輸,即可完成從server1克隆sda硬盤到server2的任務:
 
# dd if=/dev/sda | nc 192.168.228.222 1234
 
※完成上述工作的前提,是需要落實光盤的拯救模式支持服務器上的網卡,並正確配置IP。
 
3、端口掃描
 
可以執行:
 
引用
 
# nc -v -w 1 192.168.228.222 -z 1-1000
hatest2 [192.168.228.222] 22 (ssh) open
 
4、保存Web頁面
 
# while true; do nc -l -p 80 -q 1 < somepage.html; done
 
5、模擬HTTP Headers
 
引用
 
[root@hatest1 ~]# nc www.linuxso.com 80
GET / HTTP/1.1
Host: ispconfig.org
Referrer: mypage.com
User-Agent: my-browser
 
HTTP/1.1 200 OK
Date: Tue, 16 Dec 2008 07:23:24 GMT
Server: Apache/2.2.6 (Unix) DAV/2 mod_mono/1.2.1 mod_python/3.2.8 Python/2.4.3 mod_perl/2.0.2 Perl/v5.8.8
Set-Cookie: PHPSESSID=bbadorbvie1gn037iih6lrdg50; path=/
Expires: 0
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Cache-Control: private, post-check=0, pre-check=0, max-age=0
Set-Cookie: oWn_sid=xRutAY; expires=Tue, 23-Dec-2008 07:23:24 GMT; path=/
Vary: Accept-Encoding
Transfer-Encoding: chunked
Content-Type: text/html
[......]
在nc命令後,輸入紅色部分的內容,然後按兩次回車,即可從對方獲得HTTP Headers內容。
 
6、聊天
 
nc還可以作爲簡單的字符下聊天工具使用,同樣的,server2上需要啓動監聽:
 
[root@hatest2 tmp]# nc -lp 1234
 
server1上傳輸:
 
[root@hatest1 ~]# nc 192.168.228.222 1234
 
這樣,雙方就可以相互交流了。使用Ctrl+D正常退出。
 
7、傳輸目錄
 
從server1拷貝nginx-0.6.34目錄內容到server2上。需要先在server2上,用nc激活監聽,server2上運行:
 
引用
 
[root@hatest2 tmp]# nc -l 1234 |tar xzvf -
server1上運行:
 
引用
 
[root@hatest1 ~]# ll -d nginx-0.6.34
drwxr-xr-x 8 1000 1000 4096 12-23 17:25 nginx-0.6.34
[root@hatest1 ~]# tar czvf – nginx-0.6.34|nc 192.168.228.222 1234
 
 
8、參數簡介
 
 
這僅是一個1.10版本的簡單說明,詳細的參數使用還是需要看man:
 
引用
 
想要連接到某處: nc [-options] hostname port[s] [ports] …
綁定端口等待連接: nc -l -p port [-options] [hostname] [port]
參數:
-g gateway source-routing hop point[s], up to 8
-G num source-routing pointer: 4, 8, 12, …
-h 幫助信息
-i secs 延時的間隔
-l 監聽模式,用於入站連接
-n 指定數字的IP地址,不能用hostname
-o file 記錄16進制的傳輸
-p port 本地端口號
-r 任意指定本地及遠程端口
-s addr 本地源地址
-u UDP模式
-v 詳細輸出——用兩個-v可得到更詳細的內容
-w secs timeout的時間
-z 將輸入輸出關掉——用於掃描時,其中端口號可以指定一個或者用lo-hi式的指定範圍。
 
 
三、版本差異
 
不用系統上提供的nc版本會有說不同,其提供的參數使用方法也略有差異。
例如,紅旗Asianux 3.0 SP1拯救光盤上的版本是供使用的參數僅有一部分:
 
引用
 
# nc -h
BusyBox v1.2.0 (2008.04.14-01:35+0000) multi-call binary
 
Usage: nc [OPTIONS] [IP] [port]
 
Netcat opens a pipe to IP:port
 
Options:
         -l               listen mode, for inbound connects
         -p PORT         local port number
         -i SECS         delay interval for lines sent
         -e PROG         program to exec after connect (dangerous!)
         -w SECS         timeout for connects and final net reads
而在Asianux 3.0 SP1系統中提供的nc版本則是1.84的,按上面的參數用法寫會執行不了:
 
引用
 
[root@ftpserver ~]# rpm -q nc
nc-1.84-10
[root@ftpserver ~]# nc -lp 1234
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-p source_port]
           [-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_version]
           [-x proxy_address[:port]] [hostname] [port[s]]
講查看man文檔,可見在這個版本中,-l是不能與-s、-p、-z一起使用的,-w參數也會被忽略,所以,正確的用法是:
 
[root@ftpserver tmp]# nc -l 1234
 
四、用在腳本中
 
nc每次啓動監聽後,都會在客戶端連接完成並退出的同時,服務端一同退出。所以,如果需要不斷的使用nc進行數據傳輸,需要在腳本中使用循環。利用nc實現更多的功能,可參考其rpm提供的參考腳本:
 
引用
 
# rpm -qd nc
/usr/share/doc/nc-1.10/Changelog
/usr/share/doc/nc-1.10/README
/usr/share/doc/nc-1.10/scripts/README
/usr/share/doc/nc-1.10/scripts/alta
/usr/share/doc/nc-1.10/scripts/bsh
/usr/share/doc/nc-1.10/scripts/dist.sh
/usr/share/doc/nc-1.10/scripts/irc
 
/usr/share/doc/nc-1.10/scripts/iscan
/usr/share/doc/nc-1.10/scripts/ncp
/usr/share/doc/nc-1.10/scripts/probe
/usr/share/doc/nc-1.10/scripts/web
/usr/share/doc/nc-1.10/scripts/webproxy
/usr/share/doc/nc-1.10/scripts/webrelay
/usr/share/doc/nc-1.10/scripts/websearch
/usr/share/man/man1/nc.1.gz

二、NMAP

1、安裝

# yum install nmap

2、詳解

Nmap即Network Mapper,它是在免費軟件基金會的GNU General Public License (GPL)下發布的。其基本功能有:探測一組主機是否在線;掃描主機端口,嗅探提供的網絡服務;判斷主機的操作系統。軟件下載後,執行configure、make和make install三個命令,將nmap二進制碼安裝到系統上,就可以執行nmap了。

官網下載:http://nmap.org/download.html

或下載包

rpm -vhU http://nmap.org/dist/nmap-5.21-1.i386.rpm
rpm -vhU http://nmap.org/dist/zenmap-5.21-1.noarch.rpm

測試系統:CentOS5.3

      Nmap的語法很簡單,但功能十分強大。比如:Ping-scan命令就是“-sP”,在確定了目標主機和網絡之後,即可進行掃描。如果以root來運行Nmap,Nmap的功能會更加增強,因爲超級用戶可以創建便於Nmap利用的定製數據包。使用Nmap進行單機掃描或是整個網絡的掃描很簡單,只要將帶有“/mask”的目標地址指定給Nmap即可。另外,Nmap允許使用各類指定的網絡地址,比如192.168.1.*,是對所選子網下的主機進行掃描。

nmap的使用方法

下面是Nmap支持的四種最基本的掃描方式:

    * TCP connect()端口掃描(-sT參數)。

    * TCP同步(SYN)端口掃描(-sS參數)。

    * UDP端口掃描(-sU參數)。

    * Ping掃描(-sP參數)

如果要勾畫一個網絡的整體情況,Ping掃描和TCP SYN掃描最爲實用。

    * Ping掃描通過發送ICMP(Internet Control Message Protocol,Internet控制消息協議)迴應請求數據包和TCP應答(Acknowledge,簡寫ACK)數據包,確定主機的狀態,非常適合於檢測指定網段內正在運行的主機數量。

    * TCP SYN掃描一下子不太好理解,但如果將它與TCP connect()掃描比較,就很容易看出這種掃描方式的特點。在TCP connect()掃描中,掃描器利用操作系統本身的系統調用打開一個完整的TCP連接也就是說,掃描器打開了兩個主機之間的完整握手過程(SYN, SYN-ACK,和ACK)。一次完整執行的握手過程表明遠程主機端口是打開的。

    * TCP SYN掃描創建的是半打開的連接,它與TCP connect()掃描的不同之處在於,TCP SYN掃描發送的是復位(RST)標記而不是結束ACK標記(即,SYN,SYN-ACK,或RST):如果遠程主機正在監聽且端口是打開的,遠程主機用 SYN-ACK應答,Nmap發送一個RST;如果遠程主機的端口是關閉的,它的應答將是RST,此時Nmap轉入下一個端口。

-sS 使用SYN+ACK的方法,使用TCP SYN,

-sT 使用TCP的方法, 3次握手全做

-sU 使用UDP的方法

-sP ICMP ECHO Request 送信,有反應的端口進行調查

-sF FIN SCAN

-sX

-sN 全部FLAG OFF的無效的TCP包送信,根據錯誤代碼判斷端口情況

-P0 無視ICMP ECHO request的結果,SCAN

-p scan port range 指定SCAN的目端口的範圍

   1-100, 或者使用25,100的方式

-O 偵測OS的種類

-oN 文件名 通常格式文件輸出

-oX 文件名 通過DTD,使用XML格式輸出結果

-oG 文件名,grep容易的格式輸出

-sV 服務的程序名和版本SCAN

Ping掃描:入侵者使用Nmap掃描整個網絡尋找目標。通過使用“-sP”命令,缺省情況下,Nmap給每個掃描到的主機發送一個ICMP echo和一個TCP ACK,主機對任何一種的響應都會被Nmap得到。如下所示。

[root@coremail ~]# nmap -sP 192.168.1.60

Starting Nmap 5.21 ( http://nmap.org ) at 2010-06-08 12:46 CST
Nmap scan report for 192.168.1.60
Host is up (0.00085s latency).
Nmap done: 1 IP address (1 host up) scanned in 0.49 seconds

Nmap支持不同類別的端口掃描,TCP連接掃描可以使用“-sT”命令,TCP connect()端口掃描(-sT參數)。具體如下所示:
[root@coremail ~]# nmap -sT 192.168.92.129

Starting Nmap 5.21 ( http://nmap.org ) at 2010-06-08 12:51 CST
Nmap scan report for 192.168.92.129
Host is up (0.0017s latency).
Not shown: 997 closed ports
PORT      STATE SERVICE
22/tcp    open  ssh
111/tcp   open  rpcbind
11111/tcp open  unknown

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



隱蔽掃描(Stealth Scanning) 。在掃描時,如果攻擊者不想使其信息被記錄在目標系統日誌上,TCP SYN掃描可幫你的忙。使用“-sS”命令,就可以發送一個SYN掃描探測主機或網絡。如下所示。

[root@coremail ~]# nmap -sS www.baidu.com

Starting Nmap 5.21 ( http://nmap.org ) at 2010-06-08 12:51 CST
Nmap scan report for www.baidu.com (220.181.6.175)
Host is up (0.0094s latency).
Not shown: 998 filtered ports
PORT   STATE SERVICE
21/tcp open  ftp
80/tcp open  http

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

如果一個攻擊者想進行UDP掃描,即可知哪些端口對UDP是開放的。Nmap將發送一個O字節的UDP包到每個端口。如果主機返回端口不可達,則表示端口是關閉的。UDP端口掃描(-sU參數)。如下所示。

[root@coremail ~]# nmap -sU 192.168.92.129

Starting Nmap 5.21 ( http://nmap.org ) at 2010-06-08 12:53 CST
Nmap scan report for 192.168.92.129
Host is up (0.000019s latency).
Not shown: 996 closed ports
PORT    STATE         SERVICE
68/udp  open|filtered dhcpc
111/udp open          rpcbind
123/udp open|filtered ntp
631/udp open|filtered ipp

Nmap done: 1 IP address (1 host up) scanned in 1.93 secon


操作系統識別。通過使用“-O”選項,就可以探測遠程操作系統的類型。Nmap通過向主機發送不同類型的探測信號,縮小查找的操作系統系統的範圍。如圖6所示。

[root@coremail ~]# nmap -sS -O 192.168.92.129

Starting Nmap 5.21 ( http://nmap.org ) at 2010-06-08 12:56 CST
Nmap scan report for 192.168.92.129
Host is up (0.00024s latency).
Not shown: 997 closed ports
PORT      STATE SERVICE
22/tcp    open  ssh
111/tcp   open  rpcbind
11111/tcp open  unknown
Device type: general purpose
Running: Linux 2.6.X
OS details: Linux 2.6.15 - 2.6.30
Network Distance: 0 hops

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



Ident掃描。攻擊者都喜歡尋找一臺對於某些進程存在漏洞的電腦,比如一個以root運行的WEB服務器。如果目標機運行了identd,攻擊者就可以通過“-I”選項的TCP連接發現哪個用戶擁有http守護進程。我們以掃描一個Linux WEB服務器爲例,使用如下命令即可:

[root@coremail ~]# nmap -sT -p 80  -O  www.baidu.com

Starting Nmap 5.21 ( http://nmap.org ) at 2010-06-08 12:58 CST
Nmap scan report for www.baidu.com (220.181.6.175)
Host is up (0.0069s latency).
PORT   STATE    SERVICE
80/tcp filtered http
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose|storage-misc|WAP|game console
Running (JUST GUESSING) : Apple Mac OS X 10.5.X (96%), BlueArc embedded (87%), KCorp embedded (86%), Nintendo embedded (86%)
Aggressive OS guesses: Apple Mac OS X 10.5.5 (Leopard) (96%), BlueArc Titan 2100 NAS device (87%), KCorp KLG-575 WAP (86%), Nintendo DS game console (86%)
No exact OS matches for host (test conditions non-ideal).

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

[root@coremail ~]# nmap -sT -p 80  -O  192.168.92.129

Starting Nmap 5.21 ( http://nmap.org ) at 2010-06-08 13:00 CST
Nmap scan report for 192.168.92.129
Host is up (0.00014s latency).
PORT   STATE SERVICE
80/tcp open  http
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose
Running: Linux 2.6.X
OS details: Linux 2.6.15 - 2.6.30
Network Distance: 0 hops

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



隱藏掃描的源地址:

      假設你的系統IP是192.168.1.20,但是你希望你的系統發出的所有NMAP包都被標註爲IP地址20.20.20.20,那你可以用下面的命令來對名爲sandi德系統發出數據包:

          nmap  -S 20.20.20.20 -e eth0 -P0 -sS -v sandi

    -P0(不PING)和-sS(TCP SYN隱藏端口掃描)使得Nmap執行基於 TCP掃描但不首先發ping 數據包。-sS選項能幫助進行的掃描通過過濾初始SYN數據包的防火牆。

       要讓系統使用端口53來發送數據包執行和上面相似的掃描,可發出下面的命令

      nmap -g 53 -S 20.20.20.20  -e eth0 -P0 -sS -v sandi

     除了以上這些掃描,Nmap還提供了很多選項,這是很多Linux攻擊者的必備法寶之一,通過這個軟件,我們就可以對系統瞭如指掌,從而爲下面的攻擊打下良好的基礎。



發佈了59 篇原創文章 · 獲贊 7 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章