您的位置:首页 > 其它

负载均衡故障排错指南 (4)

2011-10-14 18:43 330 查看
2.4 nmap下的nping
本来,我是想给大家介绍hping,一款命令行下使用的TCP/IP数据包发送工具,经常用于安全审计、网络或防火墙测试。但是,在搜集资料的过程中,我发现了一个类似的但可能是更好的工具:nping。由于hping的开发已经基本停滞,而从nmap 5.3开始,hping大多数的功能已经陆续移植到nping,因此,从长远的发展来看,我推荐大家使用nping。
nping同样是一款开源的网络数据包发送工具,它不但能像传统的ping一样对目标主机的进行检测,而且能够产生各种各样的TCP、UDP、ICMP、ARP报文,甚至是DoS攻击数据包。通过这个工具,配合wireshark,可以让我们更加深入的了解网络协议中的细节。
目前,nping的最新版本可以通过安装最新的nmap软件包获得。Nmap的最新版本为v5.51,可以通过以下地址下载:
http://nmap.org/download.html

nping的使用很简单,其基本的命令行格式为:
nping [Probe mode] [Options] {target specification}
Target specification即探测目标,可以是主机名、域名、IP地址或一段网络地址。
Probe Mode指探测模式,nping支持以下几种探测模式:
--tcp-connect Unprivileged TCP connect probe mode.

--tcp TCP probe mode.

--udp UDP probe mode.

--icmp ICMP probe mode.

--arp ARP/RARP probe mode.

--tr, --traceroute Traceroute mode (can only be used with TCP/ UDP/ ICMP modes).

这里,比较容易迷惑的是--tcp-connect和--tcp两种探测模式的区别。简单的来讲,--tcp-connect发送的数据包是由底层系统的TCP协议栈建立的,而--tcp发送的数据包是有nping程序生成的,因此,--tcp可以对数据包进行更多的定制和控制。
至于Options,各种探测模式所支持的选项并不太相同,但是大致上,这些选项包括:指定目的端口、指定源端口、各种flag标记位设定等等。实际上,就是根据各个协议中的选项来构造数据包。甚至是生成一些有问题的数据包,比如:发送一些具有无效checksum的TCP数据包。
下面,我们将通过几个简单的例子来展示nping的强大之处。
1) 最简单的使用方式:

[root@centos ~]# nping scanme.nmap.org

Starting Nping 0.5.51 ( http://nmap.org/nping ) at 2011-10-14 17:48 CST

SENT (0.3372s) ICMP 172.16.16.32 > 74.207.244.221 Echo request (type=8/code=0) ttl=64 id=52152 iplen=28

RCVD (0.5527s) ICMP 74.207.244.221 > 172.16.16.32 Echo reply (type=0/code=0) ttl=46 id=27226 iplen=28

SENT (1.3380s) ICMP 172.16.16.32 > 74.207.244.221 Echo request (type=8/code=0) ttl=64 id=52152 iplen=28

RCVD (1.5502s) ICMP 74.207.244.221 > 172.16.16.32 Echo reply (type=0/code=0) ttl=46 id=27227 iplen=28

SENT (2.3396s) ICMP 172.16.16.32 > 74.207.244.221 Echo request (type=8/code=0) ttl=64 id=52152 iplen=28

RCVD (2.5517s) ICMP 74.207.244.221 > 172.16.16.32 Echo reply (type=0/code=0) ttl=46 id=27228 iplen=28

SENT (3.3407s) ICMP 172.16.16.32 > 74.207.244.221 Echo request (type=8/code=0) ttl=64 id=52152 iplen=28

RCVD (3.5531s) ICMP 74.207.244.221 > 172.16.16.32 Echo reply (type=0/code=0) ttl=46 id=27229 iplen=28

SENT (4.3423s) ICMP 172.16.16.32 > 74.207.244.221 Echo request (type=8/code=0) ttl=64 id=52152 iplen=28

RCVD (4.5612s) ICMP 74.207.244.221 > 172.16.16.32 Echo reply (type=0/code=0) ttl=46 id=27230 iplen=28

Max rtt: 218.368ms | Min rtt: 211.530ms | Avg rtt: 213.680ms

Raw packets sent: 5 (140B) | Rcvd: 5 (230B) | Lost: 0 (0.00%)

Tx time: 4.00576s | Tx bytes/s: 34.95 | Tx pkts/s: 1.25

Rx time: 5.00626s | Rx bytes/s: 45.94 | Rx pkts/s: 1.00

Nping done: 1 IP address pinged in 5.36 seconds

[root@centos ~]#

最简单的使用方式即忽略所有的探测模式和选项,后面指定你的探测目标。在这种方式下,nping会发送5个ICMP request到探测目标。探测结束后,会在最后列出探测的一些统计数据。
2) nping推荐的一个典型的例子(也很有趣 ! )

[root@centos ~]# nping -c 1 --tcp -p 80,433 scanme.nmap.org www.baidu.com

Starting Nping 0.5.51 ( http://nmap.org/nping ) at 2011-10-14 18:03 CST

SENT (5.0542s) TCP 172.16.16.32:41300 > 74.207.244.221:80 S ttl=64 id=17109 iplen=40 seq=2938784718 win=1480

RCVD (5.2703s) TCP 74.207.244.221:80 > 172.16.16.32:41300 SA ttl=46 id=0 iplen=44 seq=385149730 win=14600 <mss 1420>

SENT (6.0550s) TCP 172.16.16.32:41300 > 61.135.169.125:80 S ttl=64 id=17109 iplen=40 seq=2938784718 win=1480

SENT (7.0569s) TCP 172.16.16.32:41300 > 74.207.244.221:433 S ttl=64 id=17109 iplen=40 seq=2938784718 win=1480

RCVD (7.2698s) TCP 74.207.244.221:433 > 172.16.16.32:41300 RA ttl=46 id=0 iplen=40 seq=0 win=0

SENT (8.0580s) TCP 172.16.16.32:41300 > 61.135.169.125:433 S ttl=64 id=17109 iplen=40 seq=2938784718 win=1480

Statistics for host scanme.nmap.org (74.207.244.221):
| Probes Sent: 2 | Rcvd: 2 | Lost: 0 (0.00%)

|_ Max rtt: 215.424ms | Min rtt: 212.379ms | Avg rtt: 213.901ms

Statistics for host www.baidu.com (61.135.169.125):
| Probes Sent: 2 | Rcvd: 0 | Lost: 2 (100.00%)
|_ Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A

Raw packets sent: 4 (160B) | Rcvd: 2 (92B) | Lost: 2 (50.00%)

Tx time: 3.00463s | Tx bytes/s: 53.25 | Tx pkts/s: 1.33

Rx time: 4.00604s | Rx bytes/s: 22.97 | Rx pkts/s: 0.50

Nping done: 2 IP addresses pinged in 9.07 seconds

[root@centos ~]#

这是一个很有趣的例子,也是nping的官方手册中推荐的一种典型用法:

指定发送的数据包数据量: -c 1

指定探测模式: --tcp

指定探测的目标端口(多个): -p 80,443

指定探测目标(多个): scanme.nmap.org和www.baidu.com

这个例子的有趣之处在于,测试完毕之后,我发现所有对www.baidu.com的测试数据包均未收到回应。这很奇怪,因为按道理,像百度这么大的网站不应该不回应我的测试包的。因此,我仔细查看了前面的数据流,终于发现了其中的蹊跷之处:所有的数据包均是通过41300这个相同的端口发送出去的。由于我们上网的NAT设备不支持EIM (Endpoint Independent Mapping,也称作Full-cone NAT),因此,所有发往www.baidu.com的数据包都被这台NAT设备给丢弃了。具体的原因我们到后面再为大家进行详细的分析。或者,有兴趣的朋友可以自己去翻阅一下RFC5382。

3) 简单的攻击测试

利用nping强大的数据包构造功能,我们能够模拟出一些常见的网络层攻击,以验证目标对这些测试的防御情况。

[root@centos ~]# nping --tcp -p 80 --flag syn,ack,rst -c 5 --rate 10 scanme.nmap.org

Starting Nping 0.5.51 ( http://nmap.org/nping ) at 2011-10-14 18:27 CST

SENT (0.8205s) TCP 172.16.16.32:3167 > 74.207.244.221:80 SRA ttl=64 id=31756 iplen=40 seq=2249461123 win=1480

SENT (0.9215s) TCP 172.16.16.32:3167 > 74.207.244.221:80 SRA ttl=64 id=31756 iplen=40 seq=2249461123 win=1480

SENT (1.0221s) TCP 172.16.16.32:3167 > 74.207.244.221:80 SRA ttl=64 id=31756 iplen=40 seq=2249461123 win=1480

SENT (1.1227s) TCP 172.16.16.32:3167 > 74.207.244.221:80 SRA ttl=64 id=31756 iplen=40 seq=2249461123 win=1480

SENT (1.2233s) TCP 172.16.16.32:3167 > 74.207.244.221:80 SRA ttl=64 id=31756 iplen=40 seq=2249461123 win=1480

Max rtt: N/A | Min rtt: N/A | Avg rtt: N/A

Raw packets sent: 5 (200B) | Rcvd: 0 (0B) | Lost: 5 (100.00%)

Tx time: 0.40352s | Tx bytes/s: 495.64 | Tx pkts/s: 12.39

Rx time: 1.40498s | Rx bytes/s: 0.00 | Rx pkts/s: 0.00

Nping done: 1 IP address pinged in 2.24 seconds

[root@centos ~]#

在上面的例子中,我们利用nping构造出了一些具有异常flag的TCP数据包,我们可以通过这些数据包查看目标的响应情况。

指定数据包的flag: --flag syn,ack,rst

指定发送的数据包数量: -c 5

指定发送的速率: --rate 10

在这里,我只是简单介绍了nping的一些使用方式。利用nping可以帮助我们更好的了解TCP/IP协议的工作机制。我们在后面的文章中,将会经常使用这些工具。因此,能够熟练的应用这些工具,将会对理解后面的内容有很大帮助。
详细的了解nping的使用方式,最好的教材应该是官方的nping手册了,大家可以通过下面的链接来进行进一步的阅读。
http://nmap.org/book/nping-man.html

E.S.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息