tcpdump cheat sheet

tcpdump

tcpdump/libpcap的包过滤规则也支持更多通用分组表达式,在这些表达式中,包中的任意字节范围都可以使用关系或二进制操作符进行检查。
对于字节范围表达,你可以使用以下格式:

proto [ expr : size ]

“proto”可以是熟知的协议之一(如ip,arp,tcp,udp,icmp,ipv6),
“expr”表示与指定的协议头开头相关的字节偏移量。有我们熟知的直接偏移量如tcpflags,也有取值常量如tcp-syn,tcp-ack或者tcp-fin。
“size”是可选的,表示从字节偏移量开始检查的字节数量。

一般

# 关闭解释
tcpdump -nn

# 显示 mac 地址。需要指定网口
tcpdump -E 

# 显示 报文内容 
tcpdump -X

# Print absolute, rather than relative, TCP sequence numbers.
tcpdump -S

# Don't print a timestamp on each dump line.
tcpdump -t 
    
# Print an unformatted timestamp on each dump line.
tcpdump -tt    

# Print a delta (micro-second resolution) between current and previous line on each dump line.
tcpdump -ttt   

# Print a timestamp in default format proceeded by date on each dump line.
tcpdump -tttt  

# Print a delta (micro-second resolution) between current and first line on each dump line.
tcpdump -ttttt 

# read from file
tcpdump -r <file_read>

# write to file
tcpdump -w <file_writed>

网口

# 任意网口
tcpdump -i any

# 多个网口
tcpdump -i <interface_1> -i <interface_2>

ip

# ip
host <ip_address>

# 源ip
src <ip_address>

# 目的ip
dst <ip_address>

网段

# 网段
net <net_address>/<net_mask>

# 源网段
src net <net_address>/<net_mask>

# 目的网段
dst net <net_address>/<net_mask>

端口

# 端口
port <port>

# 源端口
src port <port>

# 目的端口
dst port <port>

# 端口范围
tcpdump -i <interface_1> portrange <port_lower>-<port_upper>

# 表达式

```bash
"<expression>" := "<expression>" && "<expression>"
"<expression>" := "<expression>" || "<expression>"
"<expression>" := !"<expression>"

TCP FLAGS

显示只有`SYN`的报文:
tcpdump -i <interface> "tcp[tcpflags]==tcp-syn)"

显示只有`SYN+ACK`的报文:
tcpdump -i <interface> "tcp[tcpflags]==(tcp-syn|tcp-ack)"

显示只有`ACK`的报文:
tcpdump -i <interface> "tcp[tcpflags]==tcp-ack)"

显示只有`FIN`的报文:
tcpdump -i <interface> "tcp[tcpflags]==tcp-fin)"

显示只有`FIN+ACK`的报文:
tcpdump -i <interface> "tcp[tcpflags]==(tcp-fin|tcp-ack)"

显示只有`RST`的报文:
tcpdump -i <interface> "tcp[tcpflags]==(tcp-rst)"

显示包含`SYN`的报文:
tcpdump -i <interface> "tcp[tcpflags] & (tcp-syn) !=0"

显示包含有`FIN`的报文:
tcpdump -i <interface> "tcp[tcpflags] & (tcp-fin) !=0"

显示包含有`PUSH`的报文:
tcpdump -i <interface> "tcp[tcpflags] & (tcp-push) !=0"

显示包含有`ACK`的报文:
tcpdump -i <interface> "tcp[tcpflags] & (tcp-ack) !=0"

ref:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值