14..tcpdump wireshark
tcpdump抓包:
抓10.191.19.35與123.58.33.158之間的包
tcpdump -n -i eth0 host 192.168.31.147 and 114.114.114.114
截获主机210.27.48.1 和主机210.27.48.2 或210.27.48.3的通信
tcpdump host 210.27.48.1 and \ (210.27.48.2 or 210.27.48.3 \)
监听指定的主机
$ tcpdump -i eth0 -nn 'host 192.168.1.231'
这样的话,192.168.1.231这台主机接收到的包和发送的包都会被抓取。
$ tcpdump -i eth0 -nn 'src host 192.168.1.231'
这样只有192.168.1.231这台主机发送的包才会被抓取。
$ tcpdump -i eth0 -nn 'dst host 192.168.1.231'
这样只有192.168.1.231这台主机接收到的包才会被抓取。
监听指定端口
$ tcpdump -i eth0 -nnA 'port 80'
上例是用来监听主机的80端口收到和发送的所有数据包,结合-A参数,在web开发中,真是非常有用。
监听指定主机和端口
$ tcpdump -i eth0 -nnA 'port 80 and src host 192.168.1.231'
多个条件可以用and,or连接。上例表示监听192.168.1.231主机通过80端口发送的数据包。
监听除某个端口外的其它端口
$ tcpdump -i eth0 -nnA '!port 22'
如果需要排除某个端口或者主机,可以使用“!”符号,上例表示监听非22端口的数据包。
抓eth1的包
tcpdump -i eth1 -w /tmp/xxx.cap
抓 192.168.1.123的包
tcpdump -i eth1 host 192.168.1.123 -w /tmp/xxx.cap
本機(192.168.31.147)和主機114.114.114.114之間所有包
tcpdump -n -i eth0 src host 192.168.1.123 and port 80 -w /tmp/xxx.cap
進入本機所有包(兩個IP都是本機的)
tcpdump -n -i eth0 dst 192.168.31.147 or 192.168.31.157
tcpdump -n -i eth0 dst 192.168.31.147 or 192.168.31.157 and port 80
離開本機所有包(兩個IP都是本機的)
tcpdump -n -i eth0 src 192.168.31.147 or 192.168.31.157 and port ! 22 and tcp
抓取源IP192.168.1.123及端口包
tcpdump -nn -i eth0 host 192.168.1.123 and 114.114.114.114 -w /tmp/xxx.cap
抓192.168.1.123的80端口的包
tcpdump -n -i eth1 host 192.168.1.123 and port 80 -w /tmp/xxx.cap
抓192.168.1.123的icmp的包
tcpdump -i eth1 host 192.168.1.123 and icmp -w /tmp/xxx.cap
抓192.168.1.123的80端口和110和25以外的其他端口的包
tcpdump -i eth1 host 192.168.1.123 and ! port 80 and ! port 25 and ! port 110 -w /tmp/xxx.cap
抓vlan 1的包
tcpdump -i eth1 port 80 and vlan 1 -w /tmp/xxx.cap
抓pppoe的密码
tcpdump -i eth1 pppoes -w /tmp/xxx.cap
以100m大小分割保存文件, 超过100m另开一个文件 -C 100m
抓10000个包后退出 -c 10000
后台抓包, 控制台退出也不会影响:
nohup tcpdump -i eth1 port 110 -w /tmp/xxx.cap &
tcpdump tcp -i eth1 -t -s 0 -c 100 and dst port ! 22 and src net 192.168.1.0/24 -w ./target.cap
(1)tcp: ip icmp arp rarp 和 tcp、udp、icmp这些选项等都要放到第一个参数的位置,用来过滤数据报的类型
(2)-i eth1 : 只抓经过接口eth1的包
(3)-t : 不显示时间戳
(4)-s 0 : 抓取数据包时默认抓取长度为68字节。加上-S 0 后可以抓到完整的数据包
(5)-c 100 : 只抓取100个数据包
(6)dst port ! 22 : 不抓取目标端口是22的数据包
(7)src net 192.168.1.0/24 : 数据包的源网络地址为192.168.1.0/24
(8)-w ./target.cap : 保存成cap文件,方便用ethereal(即wireshark)分析
(1) 想要截获所有210.27.48.1 的主机收到的和发出的所有的分组:
#tcpdump host 210.27.48.1
(2) 想要截获主机210.27.48.1 和主机210.27.48.2或210.27.48.3的通信,使用命令(注意:括号前的反斜杠是必须的):
#tcpdump host 210.27.48.1 and 210.27.48.2or210.27.48.3
(3) 如果想要获取主机210.27.48.1除了和主机210.27.48.2之外所有主机通信的ip包,使用命令:
#tcpdump ip host 210.27.48.1 and ! 210.27.48.2
(4) 如果想要获取主机192.168.228.246接收或发出的ssh包,并且不转换主机名使用如下命令:
#tcpdump -nn -n src host 192.168.228.246 and port 22 and tcp
(5) 获取主机192.168.228.246接收或发出的ssh包,并把mac地址也一同显示:
# tcpdump -e src host 192.168.228.246 and port 22 and tcp -n -nn
(6) 过滤的是源主机为192.168.0.1与目的网络为192.168.0.0的报头:
tcpdump src host 192.168.0.1 and dst net 192.168.0.0/24
(7) 过滤源主机物理地址为XXX的报头:
tcpdump ether src 00:50:04:BA:9B and dst……
(为什么ether src后面没有host或者net?物理地址当然不可能有网络喽)。
(8) 过滤源主机192.168.0.1和目的端口不是telnet的报头,并导入到tes.t.txt文件中:
Tcpdump src host 192.168.0.1 and dst port not telnet -l > test.txt
ip icmp arp rarp 和 tcp、udp、icmp这些选项等都要放到第一个参数的位置,用来过滤数据报的类型。
例如我截取本机(192.168.31.147)和主机114.114.114.114之间的数据
tcpdump -n -i eth0 host 192.168.31.147 and 114.114.114.114
还有截取全部进入服务器的数据可以使用以下的格式
tcpdump -n -i eth0 dst 192.168.31.147
或者服务器有多个IP 可以使用参数
tcpdump -n -i eth0 dst 192.168.31.147 or 192.168.31.157
我们抓取全部进入服务器的TCP数据包使用以下的格式,大家可以参考下
tcpdump -n -i eth0 dst 192.168.31.147 or 192.168.31.157 and tcp
从本机出去的数据包
tcpdump -n -i eth0 src 192.168.31.147 or 192.168.31.157
tcpdump -n -i eth0 src 192.168.31.147 or 192.168.31.157 and port ! 22 and tcp
或者可以条件可以是or 和 and 配合使用即可筛选出更好的结果。
解析數據包
tcpdump -c 2 -q -XX -vvv -nn -i eth0 tcp dst port 22

浙公网安备 33010602011771号