4.22 HPING 使用方法

轉載至:http://cnhotfire.blog.51cto.com/2042323/698362/

HPING 使用方法

一、HPING和ping的區別:

典型ping程序使用的是ICMP回顯請求來測試,而HPING可以使用任何IP報文,包括ICMP、TCP、UDP、RAWSOCKET。

二、下載:

HTTP://WWW.HPING.ORG/

三、安裝方法與普通軟件同。

四、命令註釋:

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失效後的主機檢測:

tsinghua@tsinghua-desktop:~$ ping 192.168.2.1

PING 192.168.2.1 (192.168.2.1) 56(84) bytes of data.

--- 192.168.2.1 ping statistics ---

19 packets transmitted, 0 received, 100% packet loss, time 18009ms

------------------------------------------------

tsinghua@tsinghua-desktop:~$ sudo hping2 -c 4 -n -i 2 192.168.2.1

HPING 192.168.2.1 (eth0 192.168.2.1): NO FLAGS are set, 40 headers + 0 data bytes

len=46 ip=192.168.2.1 ttl=64 id=43489 sport=0 flags=RA seq=0 win=0 rtt=1.0 ms

len=46 ip=192.168.2.1 ttl=64 id=43490 sport=0 flags=RA seq=1 win=0 rtt=0.6 ms

len=46 ip=192.168.2.1 ttl=64 id=43491 sport=0 flags=RA seq=2 win=0 rtt=0.7 ms

len=46 ip=192.168.2.1 ttl=64 id=43498 sport=0 flags=RA seq=3 win=0 rtt=0.6 ms

--- 192.168.2.1 hping statistic ---

4 packets transmitted, 4 packets received, 0% packet loss

round-trip min/avg/max = 0.6/0.8/1.0 ms

-c 發送4個報文 -n 不進行名稱解析 -i 包發送時間間隔。

好處:即使主機阻塞了ICMP報文,也可以顯示主機是否在運行的信息,在關掉ICMP的探測有效!

顯示信息解釋: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似乎有這個設置。

2、防火牆規則測試:

hping有類似NMAP的方法來檢測並收集關於潛在的防火牆的規則和能力的信息。

如果一個主機對ping沒有任何相應,而對hping有響應,假定目標的主機爲192.168.2.234.

一旦主機對hping作出了響應,那麼下一步我們先用nmap先進行一個端口掃描,當然這個hping2也可以作.

tsinghua@tsinghua-desktop:~$ sudo nmap -sT -P0 -p 21-25 192.168.2.234

Starting Nmap 4.53 ( http://insecure.org ) at 2008-08-14 15:56 CST

Interesting ports on 192.168.2.234:

PORT STATE SERVICE

21/tcp filtered ftp

22/tcp open ssh

23/tcp filtered telnet

24/tcp filtered priv-mail

25/tcp filtered smtp

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

以上信息顯示除了ssh端口外,其他端口被阻塞.然後可以試試用hping向各個被阻塞的端口發送空的報文.用-p的開關,可以對指定的目的端口進行hping.

tsinghua@tsinghua-desktop:~$ sudo hping2 -p 21 192.168.2.234

HPING 192.168.2.234 (eth0 192.168.2.234): NO FLAGS are set, 40 headers + 0 data bytes

24: len=46 ip=192.168.2.234 ttl=128 id=2461 sport=24 flags=RA seq=7 win=0 rtt=0.7 ms

len=46 ip=192.168.2.234 ttl=128 id=2462 sport=24 flags=RA seq=8 win=0 rtt=0.7 ms

25: len=46 ip=192.168.2.234 ttl=128 id=2463 sport=25 flags=RA seq=9 win=0 rtt=0.7 ms

len=46 ip=192.168.2.234 ttl=128 id=2464 sport=24 flags=RA seq=10 win=0 rtt=0.7 ms

前三個端口沒有響應,端口 24 25 獲得了RST/ACK響應.這說明,雖然這些端口被禁止PING,但沒有工具在該端口上監聽.然而爲什麼NMAP沒有得到響應,因爲NMAP雖然使用 TCP連接,但它在TCP報頭中設置了TCP SYN標記位,而HPING 使用了空標記的報文,這就告訴我們說,在主機192.168.2.234上只阻塞進入的TCP連接.接下來使用hping創建一個SYN報文然後將其發送 到5個端口再測試.

tsinghua@tsinghua-desktop:~$ sudo hping2 -S -p 21 192.168.2.234

HPING 192.168.2.234 (eth0 192.168.2.234): S set, 40 headers + 0 data bytes

22: len=46 ip=192.168.2.234 ttl=128 id=10722 sport=22 flags=SA seq=1 win=0 rtt=1.2 ms

len=46 ip=192.168.2.234 ttl=128 id=10747 sport=22 flags=SA seq=2 win=0 rtt=0.7 ms

這次只有22端口響應,說明SSH端口是開放的,但有工具在上面監聽,該端口沒有進行過濾.

然後我們再創建一個ACK報文併發送:

tsinghua@tsinghua-desktop:~$ sudo hping2 -A -p 21 192.168.2.234

HPING 192.168.2.234 (eth0 192.168.2.234): A set, 40 headers + 0 data bytes

22: len=46 ip=192.168.2.234 ttl=128 id=12707 sport=22 flags=R seq=2 win=0 rtt=0.7 ms

len=46 ip=192.168.2.234 ttl=128 id=12708 sport=22 flags=R seq=3 win=0 rtt=0.7 ms

23: len=46 ip=192.168.2.234 ttl=128 id=12709 sport=23 flags=R seq=4 win=0 rtt=0.7 ms

len=46 ip=192.168.2.234 ttl=128 id=12710 sport=22 flags=R seq=5 win=0 rtt=0.7 ms

24: len=46 ip=192.168.2.234 ttl=128 id=12711 sport=24 flags=R seq=6 win=0 rtt=0.7 ms

len=46 ip=192.168.2.234 ttl=128 id=12712 sport=22 flags=R seq=7 win=0 rtt=0.7 ms

25: len=46 ip=192.168.2.234 ttl=128 id=12712 sport=25 flags=R seq=8 win=0 rtt=0.8 ms

len=46 ip=192.168.2.234 ttl=128 id=12713 sport=22 flags=R seq=9 win=0 rtt=0.7 ms

結果除了21端口外所有端口都響應了RST,說明了:

1.端口22是開放的,但有工具在上面監聽.

2.24 25 上面沒有工具監聽,對NULL報文回顯.

3.端口23針對ACK報文以RST進行了響應,但沒有響應NULL報文.說明該端口被過濾,但是telnet服務運行在192.168.2.234上.

4.阻塞了進入的SYN報文但允許其他TCP報文通過,說明它採用的不是基於狀態的報文防火牆.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章