special filter for iptables/netfilter tcpdump/tshark/wireshark

mostly we can use netfilter related tools' exsisted proto rules to meet our requirements.

but sometimes we may want something special but related tools may not provide the easiest way or different tools needs itsown method.

just one example, we'd like to collect GRE protocol packets.

<1>packet filter for capture(d)

--for live capture using tcpdump or filter captured packets

for live capture using tcpdump(wireshark or else), seems no existed proto support,

you may have to check the exact packets bytes to learn its data struct characturistict,

with checking one captured packets by the wireshark, its protocol is like

GRE protocol field in ip packet

















the value is at the 10th octs in the ip packet, so you can use below:

tcpdump -i any -nn -Z root 'ip[9]==0x2f'
notice: the field index start from 0, just like C array.

<2>what about iptables?

we can have similar way

iptables -m u32 --u32 "3&0x0000FF00=0x2f" -j LOG --log-prefix "PROTO-GRE"
the usage is iptables -m u32 --u32 "Start&Mask=Range", the range is like "min:max" or an exact value.

notice: remember that the mask match length is 4 bytes(u32) long and the bytes order in the packets is like [1][2][3][4]

we can also another way

iptables -m string --string "/" --algo bm --from 9 --to 10 -j LOG --log-prefix "PROTO-GRE"
the string value is just the value of ASCII.

notice: not printable values seems not easy to use by this way.


some more details references you may intrested:

http://www.tcpdump.org/manpages/pcap-filter.7.html

http://linux.die.net/man/8/iptables

http://www.watters.ws/mediawiki/index.php/Drop_packets_in_iptables_with_string_matching

http://www.stearns.org/doc/iptables-u32.current.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值