inux下tcpdump命令的使用

tcpdump | grep 120.241.0.223

tcpdump | grep 106.39.153.237

tcpdump host 172.31.140.147 and 120.241.0.223
 
抓包写入文件:
tcpdump tcp -s 65535 and host 120.241.0.223 -w tcppack/snap004.cap
 
 
 
 
 

linux上抓包及分析

1.抓取tcp包数据

tcpdump tcp -s 0 and host 10.10.10.10 -w /tmp/20180604-full.cap
  • 1

简便解释一下:抓取10.10.10.10服务器上的tcp数据包,并存储到/tmp/20180604-full.cap文件里。 
-s snaplen 
设置tcpdump的数据包抓取长度为snaplen

-w 将抓包数据写入到本地文件

2.使用wireshark软件打开包数据文件,然后使用 追踪流-》TCP流,即可 查看客户端与服务端的通信数据

 
 
 
 
 

一般情况下linux系统会自带tcpdump工具,如果系统没有安装,直接用命令安装就行了。

安装命令:yum install -y tcpdump

查看安装版本命令:tcpdump --help

查看网卡命令:

知道了网卡,就可以使用tcpdump工具针对服务器上的网卡监控、过滤网络数据。

tcpdump常用命令:

#抓取所有经过 eth0,目的或源地址是 192.168.29.162 的网络数据
命令:tcpdump -n -i eth0 host 192.168.29.162

# 源地址
命令:tcpdump -i eth1 src host 192.168.29.162
# 目的地址
命令:tcpdump -i eth1 dst host 192.168.29.162

#抓取当前服务器eth0网卡端口8080的网络数据
命令:tcpdump -n -i eth0 port 8080

#抓取mysql执行的sql语句
命令:tcpdump -i eth1 -s 0 -l -w - dst port 3306 | strings

#抓取mysql通讯的网络包(cap用wireshark打开)
命令tcpdump -n -nn -tttt -i eth0 -s 65535 'port 3306' -w 20160505mysql.cap

#抓取SMTP 数据
命令:tcpdump -i eth1 'tcp[tcpflags] & tcp-syn != 0 and tcp[tcpflags] & tcp-ack != 0'

#抓取HTTP GET数据,"GET "的十六进制是 47455420
命令:tcpdump -i eth1 'tcp[(tcp[12]>>2):4] = 0x47455420'

#抓取SSH返回,"SSH-"的十六进制是 0x5353482D
命令:tcpdump -i eth1 'tcp[(tcp[12]>>2):4] = 0x5353482D'

#实时抓取端口号8080的GET包,然后写入GET.log
命令:tcpdump -i eth0 '((port 8080) and (tcp[(tcp[12]>>2):4]=0x47455420))' -nnAl -w /tmp/GET.log

#抓取指定SYN个数,-c 参数指定抓多少个包。
命令:time tcpdump -nn -i eth0 'tcp[tcpflags] = tcp-syn' -c 10

posted @ 2019-01-23 14:47  会飞的斧头  阅读(313)  评论(0编辑  收藏  举报