使用tcpdump拦截linux服务端网络数据

Posted blog of asml

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用tcpdump拦截linux服务端网络数据相关的知识,希望对你有一定的参考价值。

语法范例:

tcpdump -vv -i ens3 \'((tcp)&&(host 183.239.240.48)&&(port 3001))\'  -c 100 -w 12.cap

-i表示指定网络设备

后面的字串是规则,规则通常这么拼接:

非 : ! or "not"
且 : && or "and"  
或 : || or "or"

规则语句有这些:

协议类:

arp,ip,tcp,udp,icmp

地址类:

host:源或目标ip

dst host:目标ip

src host:源ip

 

port:源或目标端口.(有dst host  , src host,含义同上)

net:指定网络.(也有dst net ,src net)

按照包长:

less 100 表示少于100

greater 100 表示大于100

 

高级过滤:

根据ip包头:

ip[0]>5

从IP包头取包大小(2bytes),判断:

ip[2:2]>600

 

tcp包头也能取大小:

tcp[0:2]

 

拦截HTTP(并不一定能成功,因为头长度不固定):

0x4745 为"GET"前两个字母"GE"

0x4854 为"HTTP"前两个字母"HT"

 tcp[20:2]=0x4745 or tcp[20:2]=0x4854

==============================================

可以通过-c参数指定抓多少个包,然后用"-w"放到文本文件

参考文章:

https://www.wains.be/pub/networking/tcpdump_advanced_filters.txt (中文翻译:http://www.veryarm.com/1751.html#12)

http://packetpushers.net/masterclass-tcpdump-expressions/

https://www.hugeserver.com/kb/install-use-tcpdump-capture-packets/

https://www.cnblogs.com/ggjucheng/archive/2012/01/14/2322659.html

以上是关于使用tcpdump拦截linux服务端网络数据的主要内容,如果未能解决你的问题,请参考以下文章

tcpdump命令

tcpdump命令

(转) tcpdump参数解析及使用详解

Linux tcpdump 命令详解与示例

Linux 基础教程 29-tcpdump命令-1

Linux命令—tcpdump