Solaris 系统中的snoop命令详解(上)
参数简介:
[ -a ] # Listen to packets on audio
[ -d device ] # settable to le, ie, bf, tr
[ -s snaplen ] # Truncate packets
[ -c count ] # Quit after count packets
[ -P ] # Turn OFF promiscuous mode
[ -D ] # Report dropped packets
[ -S ] # Report packet size
[ -i file ] # Read previously captured packets
[ -o file ] # Capture packets in file
[ -n file ] # Load addr-to-name table from file
[ -N ] # Create addr-to-name table
[ -t r|a|d ] # Time: Relative, Absolute or Delta
[ -v ] # Verbose packet display
[ -V ] # Show all summary lines
[ -p first[,last] ] # Select packet(s) to display
[ -x offset[,length] ] # Hex dump from offset for length
[ -C ] # Print packet filter code
# snoop host1 host2
host1 -> host2 ICMP Echo request
host2 -> host1 ICMP Echo reply
# snoop -a dhcp
# snoop 监听所有以本机为源和目的的包并将其显示出来.
# snoop A 监听所有以主机A为源和目的的包并将其显示出来. ( A为主机名, 下同)
# snoop -o file A B 监听所有A和B之间的包并将其保存到文件file.
查看主机A和主机B之间的NFS 包(命令中的and 和or 为相应的逻辑运算)
# snoop - i file rpc nfs and A and B
1 0.0000 A -> B NFS C GETATTR FH=8E6C
2 0.0046 B -> A NFS R GETATTR OK
3 0.0080 A -> B NFS C RENAME FH=8E6C MTra00192 to .nfs08
# snoop - i file -o file2 rpc nfs A B 将这些符合条件的包保存到另一文件file2 中
# snoop A and B and (tcp or udp) and port 80 监听主机A和主机B间所有TCP 80 端口或UDP80端口的包
# snoop broadcast 监听所有的广播包
Using device /dev/hme (promiscuous mode)
10.10.10.50 -> BROADCAST UDP D=177 S=2541 LEN=35
10.10.10.50 -> BROADCAST UDP D=177 S=2541 LEN=35
10.10.10.50 -> BROADCAST UDP D=177 S=2541 LEN=35
# snoop -v multicast 监听所有的多播包, 并显示详细内容
# snoop |grep - i NTP 监听所有的NTP 协议包
Using device /dev/hme (promiscuous mode)
ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:48:50 2002)
ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:49:54 2002)
ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:50:58 2002)
ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:52:02 2002)
ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:53:06 2002)
ts1 -> 224.0.1.1 NTP broadcast (Tue Jul 23 12:54:10 2002)
这里我们也可看到NTP server 每隔约一分钟即向多播地址广播一次.
# snoop -d le0 port 123 指定网口
snoop -d pcelx0
/* Watch all network packets on device pcelx0 */
snoop -o /tmp/mylog pcelx0
/* Saves packets from device pcelx0 to a file */
snoop -i /tmp/mylog host1 host2
/* View packets from logfile between host1 & host2 */
snoop -i /tmp/mylog -v -p101
/* Show all info on packet number 101 from a logfile */
snoop -i /tmp/mylog -o /tmp/newlog host1
/* Write a new logfile with all host1 packets */
snoop -s 120
/* Return the first 120 bytes in the packet header */
snoop -v arp
/* Capture arp broadcasts on your network */
在Solaris系统下,有一个系统内置的网络数据分析和诊断工具snoop,可以抓取以太网中的数据包进行分析,功能和大名鼎鼎的Tcpdump与Sniffer Pro类似。snoop早在SunOS 4.x开始就作为SunOS系统的内置命令存在,可惜Unix世界中有优秀的Tcpdump和Ethereal存在加上Snoop本身的功能比较简单,所以Snoop只能在Solaris的世界中屈居一隅,而且大家对他也所用甚少,所幸不久前偶竟然发现一个如此强大的Snoop数据分析工具:Chaosreader,顿然发觉snoop也有了新活力。
先简单回顾一下snoop的命令参数和用法。
snoop本身能够运行在以太网环境下的solaris系统中,然后依靠网卡的混杂模式从网络中读取流过的所有数据包,当然,这依赖于网络必须是共享式以太网(使用Hub),或者在Switch上配置SPAN功能把所有流量镜像到snoop所运行的机器。如果网络是运行在除以上两者之外的交换网络上的话,那么snoop只能够获取到广播数据,以及发往主机自身的数据。
snoop本身支持以太网帧(ethernet frame),TCP|UDP/IP协议,以及之上的一些应用层协议,例如X,RPC,NFS。大家都知道,作为一个优秀的网络分析工具,必须具备良好的宏观和微观两方面的分析能力,而Sniffer类的工具,则更突出在他的微观-数据解析和分析能力方面,这就依赖于工具所能够理解和解析的网络协议(应用协议)类型数量,比如作为网络分析工具无冕之王的Ethereal就能够理解超过六百种不同的网络协议。这方面恰恰是snoop的劣势所在,所以传统的snoop仅仅是作为简单的sniffer类工具来使用的,chaosreader恰恰弥补了snoop在这方面的缺点,同时在Session分析和数据可视化重现方面大大加强了它的功能。
Chaosreader主页:
http://users.tpg.com.au/bdgcvb/chaosreader.html
下载地址:
http://users.tpg.com.au/bdgcvb/chaosreader
在Solaris系统里,只要直接运行/usr/sbin/snoop就可以启动一个监听进程:
================================
[tracy@ketty]# /usr/sbin/snoop
Using device /dev/pcn0 (promiscuous mode)
192.168.0.2 -> Katty TELNET C port=1366
Katty -> 192.168.0.2 TELNET R port=1366 Using device /dev/pc
192.168.0.2 -> Katty TELNET C port=1366
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368
.......(省略telnet协商过程)
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368 /377/376/1login:
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368 e
Katty -> 192.168.0.2 TELNET R port=1368 e
192.168.0.2 -> Katty TELNET C port=1368 l
Katty -> 192.168.0.2 TELNET R port=1368 l
192.168.0.2 -> Katty TELNET C port=1368 l
Katty -> 192.168.0.2 TELNET R port=1368 l
192.168.0.2 -> Katty TELNET C port=1368 y
Katty -> 192.168.0.2 TELNET R port=1368 y
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368 Password:
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368 e
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368 l
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368 l
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368 y
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368 Last login: Tue Feb
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368 Sun Microsystems Inc
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368 w
Katty -> 192.168.0.2 TELNET R port=1368 w
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368 e
Katty -> 192.168.0.2 TELNET R port=1368 e
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368 x
Katty -> 192.168.0.2 TELNET R port=1368 x
192.168.0.2 -> Katty TELNET C port=1368 i
Katty -> 192.168.0.2 TELNET R port=1368 i
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368 t
Katty -> 192.168.0.2 TELNET R port=1368 t
192.168.0.2 -> Katty TELNET C port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368 logout/r/n
192.168.0.2 -> Katty TELNET C port=1368
Katty -> 192.168.0.2 TELNET R port=1368
=================================
在上面这个范例中,我们用snoop监视了一个telnet会话,简要过程如下:
Client Server
1 <----------> TCP三步握手
2 <----------> Telnet协议协商
3 <----------- 发送Login:提示
4 -----------> Username: elly
5 <----------- 发送Pass:提示
6 -----------> Password: elly
7 <----------- 认证通过,返回MOTD和PS提示符
8 -----------> 发送命令,执行w
9 <----------- 返回结果
10 -----------> 发送命令,执行exit
11 <----------> 断开连接
===================================
login: elly
Password:
Last login: Tue Feb 15 18:03:14 from 192.168.0.2
Sun Microsystems Inc. SunOS 5.10 Generic January 2005
[elly@Katty]$ w
下午 6点03分 运行 49 分钟 4 用户, 平均负载:0.04, 0.02, 0.14
用户名 终端号 登入时间 闲置 JCPU PCPU 执行命令
root console 下午 5点30分 34 1 /usr/dt/bin/sdt_shell
-c ? u
root pts/2 下午 5点26分 1 1 bash
root pts/5 下午 5点35分 23 bash
elly pts/6 下午 6点02分 snoop
elly pts/7 下午 6点03分 w
[elly@Katty]$ exit
logout