【原理基礎】
Hping是一個命令行下使用的TCP/IP數據包組裝/分析工具,其命令模式很像Unix下的ping命令,但是它不是只能發送ICMP回應請求,它還可以支持TCP、UDP、ICMP和RAW-IP協議,它有一個路由跟蹤模式,能夠在兩個相互包含的通道之間傳送文件。Hping常被用於檢測網絡和主機,其功能非常強大,可在多種操作系統下運行,如Linux,FreeBSD,NetBSD,OpenBSD,Solaris,MacOs X,Windows。
Hping的主要功能有:
防火牆測試
實用的端口掃描
網絡檢測,可以用不同的協議、服務類型(TOS)、IP分片
手工探測MTU(最大傳輸單元)路徑
先進的路由跟蹤,支持所有的協議
遠程操作系統探測
遠程的運行時間探測
TCP/IP堆棧審計
Hping的詳細參數
-h --help 顯示幫助信息
-v --version 顯示Hping的版本信息
-c --count 指定數據包的次數
-i --interval 指定發包間隔為多少毫秒,如-i m10:表示發包間隔為10毫秒
附秒、毫秒、微秒進率
--fast 與 -i m100等同,即每秒鍾發送10個數據包
-n --numeric 指定以數字形式輸出
-q --quiet 退出Hping
-I --interface 指定IP,如本機有兩塊網卡,可通過此參數指定發送數據包的IP地址。如果不指定則默認使用網關IP
-V --verbose 冗余模式
-D --debug 調試信息
-z --bind 將ctrl+z 綁定到ttl,默認使用DST端口
-Z --unbind 解除ctrl+z的綁定
指定所用的模式:
默認模式 TCP模式
-0 --rawip RAW IP 模式
-1 --icmp ICMP 模式
-2 --udp UDP 模式
-8 --scan 掃描模式.
例: hping --scan 1-30,70-90 -S www.target.host
-9 --listen 監聽模式
IP選項:
-a --spoof 源地址欺騙
--rand-dest 隨機目的地址模式
--rand-source 隨機源目的地址模式
-t --ttl ttl值,默認為64
-N --id 指定id,默認是隨機的
-W --winid 使用win*的id 字節順序
-r --rel 相對的id區域
-f --frag 將數據包分片后傳輸(可以通過薄弱的acl(訪問控制
列表))
-x --morefrag 設置更多的分片標記
-y --dontfrag 設置不加分片標記
-g --fragoff 設置分片偏移
-m --mtu 設置虛擬MTU, 當數據包>MTU時要使用--frag 進行分片
-o --tos 指定服務類型,默認是0x00,,可以使用--tos help查看幫助
-G --rroute 包含RECORD_ROUTE選項並且顯示路由緩存
--lsrr 釋放源路記錄
--ssrr 嚴格的源路由記錄
-H --ipproto 設置協議范圍,僅在RAW IP模式下使用
ICMP選項
-C --icmptype 指定icmp類型(默認類型為回顯請求)
-K --icmpcode 指定icmp編碼(默認為0)
--force-icmp 發送所有ICMP數據包類型(默認只發送可以支持的類型) --icmp-gw 針對ICMP數據包重定向設定網關地址(默認是0.0.0.0)
--icmp-ts 相當於--icmp --icmptype 13(ICMP時間戳)
--icmp-addr 相當於--icmp --icmptype 17(ICMP地址掩碼)
--icmp-help 顯示ICMP的其它幫助選項
UDP/TCP選項
-s --baseport 基本源端口(默認是隨機的)
-p --destport 目的端口(默認為0),可同時指定多個端口
-k --keep 仍然保持源端口
-w --win 指定數據包大小,默認為64
-O --tcpoff 設置假的TCP數據偏移
-Q --seqnum 僅顯示TCP序列號
-b --badcksum 嘗試發送不正確IP校驗和的數據包
許多系統在發送數據包時使用固定的IP校驗和,因此你會得到不正確的UDP/TCP校驗和.
-M --setseq 設置TCP序列號
-L --setack 使用TCP的ACK(訪問控制列表)
-F --fin 使用FIN標記set FIN flag
-S --syn 使用SNY標記
-R --rst 使用RST標記
-P --push 使用PUSH標記
-A --ack 使用 ACK 標記
-U --urg 使用URG標記
-X --xmas 使用 X 未用標記 (0x40)
-Y --ymas 使用 Y 未用標記 (0x80)
--tcpexitcode 最后使用 tcp->th_flags 作為退出代碼
--tcp-timestamp 啟動TCP時間戳選項來猜測運行時間
常規選項
-d --data 數據大小,默認為0
-E --file 從指定文件中讀取數據
-e --sign 增加簽名
-j --dump 以十六進行形式轉存數據包
-J --print 轉存可輸出的字符
-B --safe 啟用安全協議
-u --end 當通過- -file指定的文件結束時停止並顯示,防止文件再從頭開始
-T --traceroute 路由跟蹤模式
--tr-stop 在路由跟蹤模式下當收到第一個非ICMP數據包時退出
--tr-keep-ttl 保持源TTL,對監測一個hop有用
--tr-no-rtt 使用路由跟蹤模式時不計算或顯示RTT信息
ARS 數據包描述(新增加的內容,暫時還不穩定)
--apd-send 發送用描述APD的數據包
=============================================================
HPING 使用方法
一、HPING和ping的區別:
典型ping程序使用的是ICMP回顯請求來測試,而HPING可以使用任何IP報文,包括ICMP、TCP、UDP、RAWSOCKET。
二、下載:
HTTP://WWW.HPING.ORG/
三、安裝(CentOS 5.5 64)
安裝過程沒有想象中的順利,測試了好長時間才成功!!!
1、安裝基礎庫
[root@localhost ~]# yum -y install gcc libpcap-devel tcl-devel
注意:此環境必須安裝tcl-devel包才可以,不然一直出錯,所表現的錯誤在下面已一一列出,請參閱下面提示
2、下載源碼包
[root@localhost ~]# wget http://www.hping.org/hping3-20051105.tar.gz
3、編譯安裝
[root@localhost ~]# tar -zxvf hping3-20051105.tar.gz
[root@localhost ~]# cd hping3-20051105
[root@localhost hping3-20051105]# ./configure
。。。。。。。。。。。。
creating Makefile...
creating dependences...
In file included from ars.h:20,
from apd.c:19:
bytesex.h:22:3: error: #error can not find the byte order for this architecture, fix bytesex.h
In file included from apd.c:19:
ars.h:190:2: error: #error "Please, edit Makefile and add -DBYTE_ORDER_(BIG|LITTLE)_ENDIAN"
ars.h:254:2: error: #error "Please, edit Makefile and add -DBYTE_ORDER_(BIG|LITTLE)_ENDIAN"
ars.h:323:2: error: #error "Please, edit Makefile and add -DBYTE_ORDER_(BIG|LITTLE)_ENDIAN"
。。。。。。。。。。。。。。。。。。。
解決方法:
從錯誤提示上看,又是什么高位前低位后到問題,打開Makefile,找了好久也找不到去哪兒添加這個環境變量,遂Google之,原來是因為64位機到緣故,遂修改上面說到的 bytesex.h (添加紅色區域部分)
[root@localhost hping3-20051105]# vi bytesex.h
/* Original code from the Linux C library */
/* Copyright (C) 2000,2001 Salvatore Sanfilippo <antirez@invece.org>
* This code is under the original GNU C library license (GPL) */
/* $Id: bytesex.h,v 1.1.1.1 2003/08/31 17:23:48 antirez Exp $ */
#ifndef ARS_BYTESEX_H
#define ARS_BYTESEX_H
#if defined(__i386__) \
|| defined(__x86_64__) \
|| defined(__alpha__) \
|| (defined(__mips__) && (defined(MIPSEL) || defined (__MIPSEL__)))
#define BYTE_ORDER_LITTLE_ENDIAN
#elif defined(__mc68000__) \
|| defined (__sparc__) \
|| defined (__sparc) \
|| defined (__PPC__) \
|| defined (__BIG_ENDIAN__) \
|| (defined(__mips__) && (defined(MIPSEB) || defined (__MIPSEB__)))
#define BYTE_ORDER_BIG_ENDIAN
#else
# error can not find the byte order for this architecture, fix bytesex.h
#endif
#endif /* ARS_BYTESEX_H */
繼續安裝。。。
[root@localhost hping3-20051105]# make
gcc -c -O2 -Wall -g main.c
gcc -c -O2 -Wall -g getifname.c
getifname.c: In function ‘get_output_if’:
getifname.c:343: warning: pointer targets in passing argument 3 of ‘getsockname’ differ in signedness
。。。。。。。。。。
gcc -c -O2 -Wall -g libpcap_stuff.c
libpcap_stuff.c:20:21: error: net/bpf.h: No such file or directory
libpcap_stuff.c: In function ‘pcap_recv’:
libpcap_stuff.c:61: warning: pointer targets in assignment differ in signedness
make: *** [libpcap_stuff.o] Error 1
提示我bpf.h文件未找到,印象中這個文件應該是libpcap的一部分才是阿~~~
按如下提示作個鏈接
[root@localhost hping3-20051105]# ln -s /usr/include/pcap.h /usr/include/net/bpf.h
繼續make
[root@localhost hping3-20051105]# make
又出現了如下錯誤
。。。。。。。。。。
/usr/bin/ld: cannot find -ltcl
collect2: ld returned 1 exit status
make: *** [hping3] Error 1
這個錯誤排除了鏈接原因外就是沒有安裝tcp-devel包(上面第一步使用yum搭建基礎環境中的紅色字體部分是我后添加上去的,走了很多彎路測試了好多次才找到原因啊~~)
安裝tcl-devel包(如果第一步已安裝,此外不用再重提安裝!!)
[root@localhost yum.repos.d]# yum install tcl-devel
再次make
[root@localhost hping3-20051105]# make
gcc -o hping3 -O2 -Wall -g main.o getifname.o getlhs.o parseoptions.o datafiller.o datahandler.o gethostname.o binding.o getusec.o opensockraw.o logicmp.o waitpacket.o resolve.o sendip.o sendicmp.o sendudp.o sendtcp.o cksum.o statistics.o usage.o version.o antigetopt.o sockopt.o listen.o sendhcmp.o memstr.o rtt.o relid.o sendip_handler.o libpcap_stuff.o memlockall.o memunlockall.o memlock.o memunlock.o ip_opt_build.o display_ipopt.o sendrawip.o signal.o send.o strlcpy.o arsglue.o random.o scan.o hstring.o script.o interface.o adbuf.o hex.o apdutils.o sbignum.o sbignum-tables.o ars.o apd.o split.o rapd.o -L/usr/local/lib -lpcap -ltcl -lm -lpthread
./hping3 -v
hping version 3.0.0-alpha-1 ($Id: release.h,v 1.4 2004/04/09 23:38:56 antirez Exp $)
NO TCL scripting support compiled in
use `make strip' to strip hping3 binary
use `make install' to install hping3
又出錯。。。暈了。。
按上面紅色字體提示部分進行安裝
[root@localhost hping3-20051105]# make strip
-rwxr-xr-x 1 root root 436351 Jun 13 11:03 ./hping3
strip hping3
-rwxr-xr-x 1 root root 117368 Jun 13 11:03 ./hping3
[root@localhost hping3-20051105]# make strip
-rwxr-xr-x 1 root root 436351 Jun 13 11:03 ./hping3
strip hping3
-rwxr-xr-x 1 root root 117368 Jun 13 11:03 ./hping3
[root@localhost hping3-20051105]# make install
cp -f hping3 /usr/sbin/
chmod 755 /usr/sbin/hping3
ln -s /usr/sbin/hping3 /usr/sbin/hping
ln -s /usr/sbin/hping3 /usr/sbin/hping2
@@@@@@ WARNING @@@@@@
Can't install the man page: /usr/local/man/man8 does not exist
這應試安裝成功了吧。。。。。
測試是否可用
[root@localhost hping3-20051105]# hping2 -c 4 -n -i 2 192.168.18.118
HPING 192.168.18.118 (eth0 192.168.18.118): NO FLAGS are set, 40 headers + 0 data bytes
len=46 ip=192.168.18.118 ttl=64 DF id=4638 sport=0 flags=RA seq=0 win=0 rtt=1.7 ms
len=46 ip=192.168.18.118 ttl=64 DF id=4796 sport=0 flags=RA seq=1 win=0 rtt=0.3 ms
len=46 ip=192.168.18.118 ttl=64 DF id=4966 sport=0 flags=RA seq=2 win=0 rtt=0.3 ms
len=46 ip=192.168.18.118 ttl=64 DF id=5069 sport=0 flags=RA seq=3 win=0 rtt=0.3 ms
--- 192.168.18.118 hping statistic ---
4 packets tramitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.6/1.7 ms
[root@localhost hping3-20051105]#
附此類問題解決思路:http://blog.itechol.com/space.php?uid=33&do=blog&id=5773
四、命令注釋:
tsinghua@tsinghua-desktop:~$ hping2 --help
usage: hping host [options]
-h --help show this help //help
-v --version show version //版本
-c --count packet count //hping的包數量 和ping相同。
-i --interval wait (uX for X microseconds, for example -i u1000) //hping的間隔 u表示微妙,--fast表示快速模式,一秒10個包。
--fast alias for -i u10000 (10 packets for second)
-n --numeric numeric output //表示不進行名稱解析。
-q --quiet quiet //安靜模式 只輸出開始結束信息。
-I --interface interface name (otherwise default routing interface) //-使用網卡端口,缺省按路由表進行。
-V --verbose verbose mode //詳細模式 一般顯示很多包信息。
-D --debug debugging info //debug模式,定義hping2使用模式。
-z --bind bind ctrl+z to ttl (default to dst port)//幫定快捷鍵
-Z --unbind unbind ctrl+z //撤銷快捷鍵。
Mode //模式選擇。
default mode TCP (缺省使用TCP進行PING處理)
-0 --rawip RAW IP mode //裸IP方式。使用RAWSOCKET方式。
-1 --icmp ICMP mode //ICMP模式。
-2 --udp UDP mode //UDP模式
-8 --scan SCAN mode. //掃描模式 指定掃描對應的端口。
Example: hping --scan 1-30,70-90 -S http://www.target.host
-9 --listen listen mode //偵聽模式,會接受指定的信息。偵聽指定的信息內容。
IP //IP模式選擇。
-a --spoof spoof source address //源地址欺騙。
--rand-dest random destionation address mode. see the man.隨機目的地址模式。
--rand-source random source address mode. see the man. 隨機源地址模式,具體信息看MAN。
-t --ttl ttl (default 64) //修改TTL值。
-N --id id (default random) --hping中的ID值,缺省為隨機值。
-W --winid use win* id byte ordering 使用winid的模式,針對不同的操作系統。
-r --rel relativize id field (to estimate host traffic) //遞減id區域模式。
-f --frag split packets in more frag. (may pass weak acl)//分段,可以測試對方或者交換機碎片處理能力,缺省16字節。
-x --morefrag set more fragments flag //大量碎片,淚滴攻擊。
-y --dontfrag set dont fragment flag //不可恢復的IP碎片。
-g --fragoff set the fragment offset //設置斷偏移。
-m --mtu set virtual mtu, implies --frag if packet size > mtu //設置虛擬MTU值,當大於mtu的時候分段。
-o --tos type of service (default 0x00), try --tos help //tos字段,缺省0x00,盡力而為?
-G --rroute includes RECORD_ROUTE option and display the route buffer //記錄IP路由,並顯示路由緩沖。
--lsrr loose source routing and record route //松散源路由
--ssrr strict source routing and record route //嚴格源路由。
-H --ipproto set the IP protocol field, only in RAW IP mode //設置ip協議域,僅在RAW ip模式使用。
ICMP //ICMP模式。
-C --icmptype icmp type (default echo request) //ICMP類型,缺省回顯請求。
-K --icmpcode icmp code (default 0) //ICMP代碼。
--force-icmp send all icmp types (default send only supported types) //強制ICMP類型。
--icmp-gw set gateway address for ICMP redirect (default 0.0.0.0) //ICMP重定向
--icmp-ts Alias for --icmp --icmptype 13 (ICMP timestamp) //icmp時間戳
--icmp-addr Alias for --icmp --icmptype 17 (ICMP address subnet mask) //icmp子網地址。
--icmp-help display help for others icmp options //ICMP幫助。
UDP/TCP //UDP/TCP模式。
-s --baseport base source port (default random) //缺省隨機源端口
-p --destport [+][+]<port> destination port(default 0) ctrl+z inc/dec //缺省目的端口為0,連接后端口+1。
-k --keep keep still source port //保持源端口
-w --win winsize (default 64) //win的滑動窗口。
-O --tcpoff set fake tcp data offset (instead of tcphdrlen / 4)//設置偽造的數據偏移。
-Q --seqnum shows only tcp sequence number //tcp 連接序列號
-b --badcksum (try to) send packets with a bad IP checksum //IP包校驗。
many systems will fix the IP checksum sending the packet
so you'll get bad UDP/TCP checksum instead.
-M --setseq set TCP sequence number //設置TCP序列號
-L --setack set TCP ack
-F --fin set FIN flag
-S --syn set SYN flag
-R --rst set RST flag
-P --push set PUSH flag
-A --ack set ACK flag
-U --urg set URG flag //一大堆IP抱頭的設置。
-X --xmas set X unused flag (0x40)
-Y --ymas set Y unused flag (0x80)
--tcpexitcode use last tcp->th_flags as exit code
--tcp-timestamp enable the TCP timestamp option to guess the HZ/uptime //tcp的時間戳。
Common //通用設置
-d --data data size (default is 0) 發送數據包大小,缺省是0。
-E --file data from file //從文件中發送
-e --sign add 'signature' //標注簽名
-j --dump dump packets in hex //以16進制顯示包格式
-J --print dump printable characters //打印
-B --safe enable 'safe' protocol //開啟安全模式,確保數據發送。
-u --end tell you when --file reached EOF and prevent rewind //到達報尾后提示。
-T --traceroute traceroute mode (implies --bind and --ttl 1)
--tr-stop Exit when receive the first not ICMP in traceroute mode
--tr-keep-ttl Keep the source TTL fixed, useful to monitor just one hop
--tr-no-rtt Don't calculate/show RTT information in traceroute mode
ARS packet description (new, unstable)
--apd-send Send the packet described with APD (see docs/APD.txt)
五、具體應用:
1、PING失效后的主機檢測:
[root@localhost hping3-20051105]# hping2 192.168.18.188
HPING 192.168.18.188 (eth0 192.168.18.188): NO FLAGS are set, 40 headers + 0 data bytes
--- 192.168.18.188 hping statistic ---
9 packets tramitted, 0 packets received, 100% packet loss
round-trip min/avg/max = 0.0/0.0/0.0 ms
[root@localhost hping3-20051105]# hping2 -c 4 -n -i 2 192.168.18.251
HPING 192.168.18.251 (eth0 192.168.18.251): NO FLAGS are set, 40 headers + 0 data bytes
len=46 ip=192.168.18.251 ttl=64 DF id=0 sport=0 flags=RA seq=0 win=0 rtt=0.7 ms
len=46 ip=192.168.18.251 ttl=64 DF id=0 sport=0 flags=RA seq=1 win=0 rtt=0.3 ms
len=46 ip=192.168.18.251 ttl=64 DF id=0 sport=0 flags=RA seq=2 win=0 rtt=0.3 ms
len=46 ip=192.168.18.251 ttl=64 DF id=0 sport=0 flags=RA seq=3 win=0 rtt=0.2 ms
--- 192.168.18.251 hping statistic ---
4 packets tramitted, 4 packets received, 0% packet loss
round-trip min/avg/max = 0.2/0.4/0.7 ms
-c 發送4個報文 -n 不進行名稱解析 -i 包發送時間間隔。
顯示信息解釋:len,返 回ip報文大小;ttl; id,IP的ID域;sport,源端口,flags,返回的IP報設置的TCP標志 (R:RESET,A:ACK;S:SYN;F:FIN;P:PUSH;U:URGENT);seq:序列號;win:tcp窗口大小;rtt:往返 時,EIGRP似乎有這個設置。
好處:
即使主機阻塞了ICMP報文,也可以顯示主機是否在運行的信息,在關掉ICMP的探測有效!
如下示:
主機192.168.18.117上我設置了 iptables阻止icmp包響應。
[root@localhost ~]# iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
DROP icmp -- anywhere anywhere
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
使用ping測試是否能通
[root@localhost hping3-20051105]# ping 192.168.18.117
PING 192.168.18.117 (192.168.18.117) 56(84) bytes of data.
--- 192.168.18.117 ping statistics ---
3 packets transmitted, 0 received, 100% packet loss, time 2000ms
[root@localhost hping3-20051105]#
使用hping2測試是否有響應包
[root@localhost hping3-20051105]# hping2 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): NO FLAGS are set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=0 flags=RA seq=0 win=0 rtt=0.4 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=0 flags=RA seq=1 win=0 rtt=0.3 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=0 flags=RA seq=2 win=0 rtt=0.3 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=0 flags=RA seq=3 win=0 rtt=0.3 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=0 flags=RA seq=4 win=0 rtt=0.3 ms
--- 192.168.18.117 hping statistic ---
5 packets tramitted, 5 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.3/0.4 ms
[root@localhost hping3-20051105]#
2、防火牆規則測試:
hping有類似NMAP的方法來檢測並收集關於潛在的防火牆的規則和能力的信息。
如果一個主機對ping沒有任何相應,而對hping有響應,假定目標的主機為192.168.2.234.
一旦主機對hping作出了響應,那么下一步我們先用nmap先進行一個端口掃描,
當然這個hping2也可以作掃描
如下示:
[root@localhost hping3-20051105]# hping2 --scan 1-100 -S 192.168.18.251
Scanning 192.168.18.251 (192.168.18.251), port 1-100
100 ports to scan, use -V to see all the replies
+----+-----------+---------+---+-----+-----+-----+
|port| serv name | flags |ttl| id | win | len |
+----+-----------+---------+---+-----+-----+-----+
21 ftp : .S..A... 64 0 5840 46
22 ssh : .S..A... 64 0 5840 46
23 telnet : .S..A... 64 0 5840 46
80 http : .S..A... 64 0 5840 46
All replies received. Done.
Not responding ports:
[root@localhost hping3-20051105]# nmap -sT -P0 -p 21-25 192.168.18.251
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2012-06-13 15:44 CST
Interesting ports on bogon (192.168.18.251):
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
23/tcp open telnet
24/tcp closed priv-mail
25/tcp closed smtp
Nmap finished: 1 IP address (1 host up) scanned in 1.110 seconds
請看下面一個示例分析:
[root@localhost hping3-20051105]# nmap -sT -P0 -p 21-25 192.168.18.117
Starting Nmap 4.11 ( http://www.insecure.org/nmap/ ) at 2012-06-13 15:55 CST
Interesting ports on bogon (192.168.18.117):
PORT STATE SERVICE
21/tcp closed ftp
22/tcp open ssh
23/tcp closed telnet
24/tcp closed priv-mail
25/tcp closed smtp
Nmap finished: 1 IP address (1 host up) scanned in 0.008 seconds
以上信息顯示除了ssh端口外,其他端口被阻塞.
然后可以試試用hping向各個被阻塞的端口發送空的報文.用-p的開關,可以對指定的目的端口進行hping.
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -p 21 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): NO FLAGS are set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=21 flags=RA seq=0 win=0 rtt=0.3 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=21 flags=RA seq=1 win=0 rtt=0.3 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.3/0.3 ms
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -p 23 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): NO FLAGS are set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=23 flags=RA seq=0 win=0 rtt=0.4 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=23 flags=RA seq=1 win=0 rtt=0.2 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.2/0.3/0.4 ms
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -p 24 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): NO FLAGS are set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=24 flags=RA seq=0 win=0 rtt=0.5 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=24 flags=RA seq=1 win=0 rtt=0.4 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.4/0.4/0.5 ms
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -p 25 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): NO FLAGS are set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=25 flags=RA seq=0 win=0 rtt=0.6 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=25 flags=RA seq=1 win=0 rtt=0.2 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.2/0.4/0.6 ms
端口21 23 24 25 獲得了RST/ACK響應.這說明,雖然這些端口被禁止PING,但沒有工具在該端口上監聽.
然而為什么NMAP沒有得到響應,因為NMAP雖然使用 TCP連接,但它在TCP報頭中設置了TCP SYN標記位,而HPING 使用了空標記的報文,這就告訴我們說,在主機192.168.18.117上只阻塞進入的TCP連接.
接下來使用hping創建一個SYN報文然后將其發送到5個端口再測試.
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -S -p 21 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): S set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=21 flags=RA seq=0 win=0 rtt=0.3 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=21 flags=RA seq=1 win=0 rtt=0.3 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.3/0.3 ms
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -S -p 22 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): S set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=22 flags=SA seq=0 win=5840 rtt=0.4 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=22 flags=SA seq=1 win=5840 rtt=0.3 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.3/0.4 ms
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -S -p 23 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): S set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=23 flags=RA seq=0 win=0 rtt=0.2 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=23 flags=RA seq=1 win=0 rtt=0.3 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.2/0.3/0.3 ms
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -S -p 24 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): S set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=24 flags=RA seq=0 win=0 rtt=0.3 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=24 flags=RA seq=1 win=0 rtt=0.3 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.3/0.3 ms
[root@localhost hping3-20051105]# hping2 -c 2 -n -i 2 -S -p 25 192.168.18.117
HPING 192.168.18.117 (eth0 192.168.18.117): S set, 40 headers + 0 data bytes
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=25 flags=RA seq=0 win=0 rtt=0.4 ms
len=46 ip=192.168.18.117 ttl=64 DF id=0 sport=25 flags=RA seq=1 win=0 rtt=0.3 ms
--- 192.168.18.117 hping statistic ---
2 packets tramitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 0.3/0.4/0.4 ms
這次只有22端口響應,說明SSH端口是開放的,但有工具在上面監聽,該端口沒有進行過濾.