11-linux抓包

tshark安装:

1、yum istall -y tshark

发现没有可用的安装包

2、yum whatprovides *tshark*

查看 wireshark 包里面存在 tshark 命令

安装: yum install -y wireshark

tshark使用:

tshark -i ens3 -f ' host www.ly.com ' -F pcapng -w 1.pcapng

筛选规则:https://gitlab.com/wireshark/wireshark/-/wikis/CaptureFilters

tcpdump -i bond0 host 10.98.21.4 -w /data/logs/ssl.pcapng

下面的例子全是以抓取eth0接口为例,如果不加”-i eth0”是表示抓取所有的接口包括lo。  

首先安装tcpdump包:yum install -y tcpdump  

  

 1、抓取包含172.16.1.122的数据包  

# tcpdump -i bond0 -vnn host 172.18.63.14

   

2、抓取包含172.16.1.0/24网段的数据包  

# tcpdump -i eth0 -vnn net 172.16.1.0/24  

   

3、抓取包含端口22的数据包  

# tcpdump -i eth0 -vnn port 22  

   

4、抓取udp协议的数据包  

# tcpdump -i eth0 -vnn  udp  

   

5、抓取icmp协议的数据包  

# tcpdump -i eth0 -vnn icmp  

  

6、抓取arp协议的数据包  

# tcpdump -i eth0 -vnn arp  

   

7、抓取ip协议的数据包  

# tcpdump -i eth0 -vnn ip  

   

8、抓取源ip是172.16.1.122数据包。  

# tcpdump -i eth0 -vnn src host 172.16.1.122  

   

9、抓取目的ip是172.16.1.122数据包  

# tcpdump -i eth0 -vnn dst host 172.16.1.122  

   

10、抓取源端口是22的数据包  

# tcpdump -i eth0 -vnn src port 22  

   

11、抓取源ip是172.16.1.253且目的ip是22的数据包  

# tcpdump -i eth0 -vnn src host 172.16.1.253 and dst port 22 && clear  

                 

12、抓取源ip是172.16.1.122或者包含端口是22的数据包  

# tcpdump -i eth0 -vnn src host 172.16.1.122 or port 22  

   

13、抓取源ip是172.16.1.122且端口不是22的数据包  

[root@ ftp]# tcpdump -i eth0 -vnn src host 172.16.1.122 and not port 22  

  

14、抓取源ip是172.16.1.2且目的端口是22,或源ip是172.16.1.65且目的端口是80的数据包。  

# tcpdump -i eth0 -vnn src host 172.16.1.2 and dst port 22 or src host 172.16.1.65 and dst port 80  

   

15、抓取源ip是172.16.1.59且目的端口是22,或源ip是172.16.1.68且目的端口是80的数据包。  

# tcpdump -i  eth0 -vnn 'src host 172.16.1.59 and dst port 22' or  ' src host 172.16.1.68 and dst port 80 '  

   

16、把抓取的数据包记录存到/tmp/fill文件中,当抓取100个数据包后就退出程序。  

# tcpdump –i eth0 -vnn -w  /tmp/fil1 -c 100  

   

17、从/tmp/fill记录中读取tcp协议的数据包  

# tcpdump –i eth0 -vnn -r  /tmp/fil1 tcp  

   

18、从/tmp/fill记录中读取包含172.16.1.58的数据包  

# tcpdump –i eth0 -vnn -r  /tmp/fil1 host  172.16.1.58  

19、通过过滤统计TCP通讯的单方向的平局窗口大小最大窗口最小窗口

#tshark -r vmx.cap -q -n -t ad -z io,stat,1,"AVG(tcp.window_size)tcp.window_size && tcp.srcport==446","MAX(tcp.window_size)tcp.window_size && tcp.srcport==446","MIN(tcp.window_size)tcp.window_size && tcp.srcport==446" | more

tshark -i bond0 -n -t a -R 'http.request and http.host==www.ly.com and http.request.uri=="/huochepiao"' -T fields -e frame.time -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e http.request.version -e http.host -e http.request.uri -e http.response.code -e http.request.method -e http.content_length -l

tshark -i ens16 -w packet.pcap

/usr/local/bin/tshark -R "http.response or http.request" \

                -T fields -E separator="|" \

                -e frame.time_epoch \

                -e ip.src \

                -e tcp.srcport \

                -e ip.dst \

                -e tcp.dstport \

                -e http.request.version \

                -e http.request.method \

                -e http.host \

                -e http.request.uri \

                -e http.user_agent \

                -e http.response.code \

                -e http.content_type \

                -e http.content_length \

                -e http.location \

                -e http.referer \

                -r input.pcap

实时打印当前http请求的url(包括域名)

tshark -s 512 -i eth1 -n -f 'tcp dst port 80' -R 'ip.src and http.host and http.request.uri' -T fields -e ip.src -e http.host -e http.request.uri -l | tr -d '\t'

tshark -s 512 -i eth1 -n -f 'tcp dst port 80' -R 'ip.src and http.host and http.request.uri' -T fields -e ip.src -e http.host -e http.request.uri -l | tr -d '\t'

tshark -i eth1 -n -t a -f "host 61.155.159.81" -R http.request -T fields -e "frame.time" -e "ip.src" -e "http.host" -e "http.request.method" -e "http.request.uri"

tshark -i eth1 -n -t a -f "host 61.155.159.81" -R 'http.request and http.host==tcopenapi1.17usoft.com' -T fields -e frame.time -e ip.src -e http.host -e http.request.uri -l

tshark 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' -R'http.request.method == "GET" || http.request.method == "HEAD"'

下面介绍参数含义:

-s 512 :只抓取前512个字节数据

-i eth0 :捕获eth0网卡

-n :禁止网络对象名称解析

-f 'tcp dst port 80' :只捕捉协议为tcp,目的端口为80的数据包

-R 'http.host and http.request.uri' :过滤出http.host和http.request.uri

-T fields -e http.host -e http.request.uri :打印http.host和http.request.uri

-l :输出到标准输出

实时打印当前mysql查询语句

tshark -s 512 -i eth0 -n -f 'tcp dst port 3306' -R 'mysql.query' -T fields -e mysql.query

下面介绍参数含义:

-s 512 :只抓取前512个字节数据

-i eth0 :捕获eth0网卡

-n :禁止网络对象名称解析

-f 'tcp dst port 3306' :只捕捉协议为tcp,目的端口为3306的数据包

-R 'mysql.query' :过滤出mysql.query

-T fields -e mysql.query :打印mysql查询语句

tshark使用-f来指定捕捉包过滤规则,规则与tcpdump一样,可以通过命令man pcap-filter来查得。

tshark使用-R来过滤已捕捉到的包,与界面板wireshark的左上角Filter一致。

tcpdump -i bond0 host IP -w /data/logs/101.6.pcapng

mapi.alipaydns.com.     11      IN      A       110.75.244.40

mapi.alipaydns.com.     11      IN      A       110.75.236.40

mapi.alipaydns.com.     11      IN      A       110.75.244.17

mapi.alipaydns.com.     11      IN      A       110.76.18.40

mapi.alipaydns.com.     11      IN      A       110.75.231.40

tcpdump -i bond0 host IP  or  host IP or  host IP or  host IP or  host IP -w /data/logs/101.6.pcapng

tcpdump -i bond0 host IP -w /data/logs/ssl.pcapng

tcpdump -i eth0 -vnn host IP -w /data/logs/1.pcapng

tcpdump -i eth0 -w /data/logs/1.pcapng

参考:

https://blog.csdn.net/weixin_44288604/article/details/123807294

https://www.lmlphp.com/user/57799/article/item/663849/

https://gitlab.com/wireshark/wireshark/-/wikis/CaptureFilters


版权声明:本文为jfjiangfeng820原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。