当前位置: 移动技术网 > 网络运营>服务器>Linux > linux系统下使用tcpdump进行抓包方法

linux系统下使用tcpdump进行抓包方法

2019年07月18日  | 移动技术网网络运营  | 我要评论

我先看下实例代码:

1.常见参数

tcpdump -i eth0 -nn -s0 -v port 80

-i 选择监控的网卡

-nn 不解析主机名和端口号,捕获大量数据,名称解析会降低解析速度

-s0 捕获长度无限制

-v 增加输出中显示的详细信息量

port 80 端口过滤器,只捕获80端口的流量,通常是http

2.

tcpdump -a -s0 port 80

-a 输出ascii数据

-x 输出十六进制数据和ascii数据

3.

tcpdump -i eth0 udp

udp 过滤器,只捕获udp数据

proto 17 协议17等效于udp

proto 6 等效于tcp

4.

tcpdump -i eth0 host 10.10.1.1

host 过滤器,基于ip地址过滤

5.

tcpdump -i eth0 dst 10.105.38.204

dst 过滤器,根据目的ip过滤

src 过滤器,根据来源ip过滤

6.

tcpdump -i eth0 -s0 -w test.pcap

-w 写入一个文件,可以在wireshark中分析

7.

tcpdump -i eth0 -s0 -l port 80 | grep 'server:'

-l 配合一些管道命令的时候例如grep

8.

组合过滤

and or &&

or or ||

not or !

9.

快速提取http ua

tcpdump -nn -a -s1500 -l | grep "user-agent:"

使用egrep 匹配 ua和host

tcpdump -nn -a -s1500 -l | egrep -i 'user-agent:|host:'

10.

匹配get的数据包

tcpdump -s 0 -a -vv 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x47455420'

匹配post包,post的数据可能不在包里

tcpdump -s 0 -a -vv 'tcp[((tcp[12:1] & 0xf0) >> 2):4] = 0x504f5354'

11.

匹配http请求头

tcpdump -s 0 -v -n -l | egrep -i "post /|get /|host:"

匹配一些post的数据

tcpdump -s 0 -a -n -l | egrep -i "post /|pwd=|passwd=|password=|host:"

匹配一些cookie信息

tcpdump -nn -a -s0 -l | egrep -i 'set-cookie|host:|cookie:'

12.

捕获dns请求和响应

tcpdump -i eth0 -s0 port 53

13.

使用tcpdump捕获并在wireshark中查看

使用ssh远程连接服务器执行tcpdump命令,并在本地的wireshark分析

ssh root@remotesystem 'tcpdump -s0 -c 1000 -nn -w - not port 22' | wireshark -k -i -

ssh ubuntu@115.159.28.111 'sudo tcpdump -s0 -c 1000 -nn -w - not port 22' | wireshark -k -i -

14.

配合shell获取最高的ip数

tcpdump -nnn -t -c 200 | cut -f 1,2,3,4 -d '.' | sort | uniq -c | sort -nr | head -n 20

15.捕获dhcp的请求和响应

tcpdump -v -n port 67 or 68

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网