使用tcpdump抓包,并用Wireshark和Fiddler工具分析

        我们在排查问题的时候,进程要遇到抓包,如果是在windows环境,可以使用wireshark直接抓包,如果是在linux环境下,可以使用tcpdump命令进行抓包,然后取下来用wireshark或者Fiddler进行分析。

tcpdump命令介绍

命令格式:

tcpdump [-adeflnNOpqStvx] [-c 数量] [-F 文件名] [-i 网络接口]

               [-r文件名] [-s snaplen] [-T 类型] [-w 文件名] [表达式]

选项介绍:[-adeflnNOpqStvx]

-a    将网络地址和广播地址转变为名字

-d    将匹配信息包的代码以能够理解的汇编格式给出

-e    在输出行打印出数据链路层的头部信息

-f     将外部的网络地址以数字的形式打印出来

-l     使标准输出变为缓存行形式

-n    不把网络地址转换成名字

-t     在输出的每一行不打印时间戳

-i     指定监听的网络接口

-w    直接将包写入文件中,并不分析和打印出来

常用命令:

 tcpdump -i eth0 -w dump.pcap
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
^C418 packets captured
419 packets received by filter
0 packets dropped by kernel

-i 指定要抓取的网卡

-w 指定抓取后放到哪个文件

tcpdump -i eth0 -w dump.pcap -v
tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
Got 152

-v 可以实时查看到抓取了多少包

[root@izbp14wmlq6ajvhexzq3q0z ~]# tcpdump -D
1.eth0
2.nflog (Linux netfilter log (NFLOG) interface)
3.nfqueue (Linux netfilter queue (NFQUEUE) interface)
4.usbmon1 (USB bus number 1)
5.any (Pseudo-device that captures on all interfaces)
6.lo [Loopback]

获取全部的网卡列表

也可以指定源ip和端口进行过滤

tcpdump -i eth0 -w abc.pcap src net ip and port port

也可以指定目的ip和端口进行过滤

tcpdump -i eth0 -w abc.pcap dst net ip and port port

也可以指定源和目的的ip和端口进行过滤

tcpdump -i eth0 -w abc.pcap s0 net ip and port port

tcpdump -i eth0 -w abc.pcap s0 host ip and port port

使用Wireshark进行分析

使用Fiddler进行分析

 


wireshark 条件过滤

关键字有:

eq,== 等于
ne,!= 不等于
gt,> 比…大
lt,< 比…小 ge,>= 大于等于
le,<= 小于等于 and,|| 且 or,&& 或 not,! 取反

另外还有containsmatches两个不常用的关键字,过滤效果不错。

“contains”过滤包含指定字符串的数据包。例如:

http.request.uri contains “/dll/test.htm?”
//过滤http请求的uri中含有/dll/test.htm?字段的请求信息

udp contains 81:60:03
//过滤包含81:60:03的udp数据包

http.request.uri matches “V4=..1″
//matches 匹配过滤条件中给定的正则表达式,支持与Perl兼容的正则表达式(PCRE)。

http.host==baidu.com
http.host contains baidu.com
//过滤经过指定域名的http数据包,这里的host值不一定是请求中的域名

http.response.code==302
//过滤http响应状态码为302的数据包

http.response==1
//过滤所有的http响应包

http.request==1
//过滤所有的http请求,貌似也可以使用http.request

http.request.method==POST
//wireshark过滤所有请求方式为POST的http请求包,注意POST为大写

http.cookie contains guid
//过滤含有指定cookie的http数据包

http.request.uri==”/online/setpoint”
//过滤请求的uri,取值是域名后的部分

http.request.full_uri==” http://task.browser.360.cn/online/setpoint”
//过滤含域名的整个url则需要使用http.request.full_uri

http.server contains “nginx”
//过滤http头中server字段含有nginx字符的数据包

http.content_type == “text/html”
//过滤content_type是text/html的http响应、post包,即根据文件类型过滤http数据包

http.content_encoding == “gzip”
//过滤content_encoding是gzip的http包

http.transfer_encoding == “chunked”
//根据transfer_encoding过滤

http.content_length == 279
http.content_length_header == “279″
//根据content_length的数值过滤

http.server
//过滤所有含有http头中含有server字段的数据包

http.request.version == “HTTP/1.1″
//过滤HTTP/1.1版本的http包,包括请求和响应

http.response.phrase == “OK”

//过滤http响应中的phrase

 

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值