Skip to content

Instantly share code, notes, and snippets.

@Akagi201
Last active January 10, 2018 05:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Akagi201/10230435 to your computer and use it in GitHub Desktop.
Save Akagi201/10230435 to your computer and use it in GitHub Desktop.

Capture Filter(抓包过滤)

  • BPF? - 在Capture Options中的Capture FIlter中

Expression(查看过滤)

  • wireshark特有? - 在wireshark主界面的Filter框右边的Expression...

BPF语法

expression

expression = qualifier + id

qualifier

  • type: host(不写的话默认为host), net, port, protrange
  • dir: src, dst, src or dst(不写的话默认为src or dst), src and dst, inbound, outbound
  • proto: ether, fddi, tr(Token Ring), wlan, ip, ip6, arp, rarp, decnet, tcp, udp.(fddi, tr, wlan是ether的别名, 包结构很类似)

其他一些特殊的primitive关键字, 不遵循上面的pattern

  • gateway
  • broadcast
  • less
  • greater
  • 算数表达式

连接primitives

  • and
  • or
  • not

ok的表达式

  • dst host

  • src host

  • host

  • 以上的表达式可以在前面增加一个关键字: ip, arp, rarp, ip6; 如: ip host == ether proto ip and host

  • ether dst - ehost既可以是/etc/ethers里面的名字也可以是一个数字.

  • ether src

  • ether host

  • gateway - 如果这个包使用作为gateway, ethernet的源或者目的地址是, 但是IP的源和目的地址都不是. 必须是一个名字, 并且必须同时被机器的hostname-to-ip和hostname-to-ethernet-address解析/etc/ethers. 等价表达式: ether host <ehost> and not host <host> 名字和数字都可以用在和, 这个语法目前在IPV6-enabled configuration不工作.

  • dst net 真如果IPV4/V6的包的目的地址有一个network number . 可以是一个来自/etc/networks中的名字或者一个network number. IPV4地址可以是点4格式dotted quad(192.168.1.0) - netmask 255.255.255.255, 或者点3格式dottd triple(192.168.1) - netmask 255.255.255.0, 或者点2格式dotted pair(172.16) - netmask 255.255.0.0, 或者单独数字格式single number(10) - netmask 255.0.0.0. IPV6地址必须写完整, netmask是 ff:ff:ff:ff:ff:ff:ff:ff, 掩码可以用长度来限制.见下面

  • src net IPV4/V6源地址

  • net IPV4/V6源或者目的

  • net mask 真如果IPV4地址满足掩码满足, 可以是源或者目的. 不适用IPV6

  • net / 真如果IPV4/V6地址匹配, 并且子网掩码满足长度. 可以是源或者目的.

  • dst port 真如果包是 ip/tcp, ip/udp, ip6/tcp, ip6/udp有一个目的端口. 可以是一个数字或者名字使用在 /etc/services.

  • src port

  • port

  • dst portrange 真如果包是ip/tcp, ip/udp, ip6/tcp, ip6/udp并且有一个目的端口值在和之间

  • src portrange

  • portrange

  • tcp或udp前缀可以放在前面的端口限制前面, 如 tcp src port <port>

  • less 真如果包的大小满足小于等于, 等价表达式: len <= <length>

  • greater , 等价于: len >= <length>

  • ip proto 真如果IPV4包的类型是, 可以是数字或者以下名字, icmp, icmp6, igmp, igrp, pim, ah, esp, vrrp, udp, 或者tcp. 注意标示符tcp, udp, icmp也是关键字, 必须使用\转义, 在c-shell中用\\.Note that this primitive does not chase the protocol header chain.

  • ip6 proto , 用于IPV6, Note that this primitive does not chase the protocol header chain.

  • ip6 protochain 真如果包是IPV6包, 并且contains protocol header with type protocol in its protocol header chain.

ip6 protochain 6

Ref

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment