项目作者: tgogos

项目描述 :
Packet inspection with gopacket and nfqueue...
高级语言: Go
项目地址: git://github.com/tgogos/gopacket_nfqueue.git
创建时间: 2016-09-21T13:35:27Z
项目社区:https://github.com/tgogos/gopacket_nfqueue

开源协议:

下载


gopacket_nfqueue

Packet inspection with golang, gopacket and nfqueue…

  1. # prerequisites
  2. go get github.com/google/gopacket
  3. apt-get install libpcap-dev
  4. apt-get install libnetfilter-queue-dev
  5. # how to run...
  6. cd /[golang path]/src/github.com/tgogos/gopacket_nfqueue
  7. go install .
  8. sudo $GOPATH/bin/gopacket_nfqueue

Test environment

Virtualbox with three Ubuntu VMs set up like this:

  1. +-----------+ +-------------------+ +-----------+
  2. | client VM |-------| pkt inspection VM |-------| server VM |
  3. +-----------+ +-------------------+ +-----------+
  4. eth1 eth1 eth2 eth1
  5. client VM eth1 (host-only): 192.168.4.2
  6. server VM eth1 (host-only): 192.168.5.2
  7. pkt inspection VM eth1 (host-only): 192.168.4.3
  8. pkt inspection VM eth2 (host-only): 192.168.5.3

Client VM configuration:

The client must forward traffic to the pkt inspection VM eth1 so a route must be added:

  1. route add -net 192.168.5.0 netmask 255.255.255.0 gw 192.168.4.3 dev eth1

Server VM configuration:

The server must forward traffic to the pkt inspection VM eth2 so a route must be added:

  1. route add -net 192.168.4.0 netmask 255.255.255.0 gw 192.168.5.3 dev eth1

Packet inspection VM configuration:

The following commands set up the packet forwarding and the routing rules in order to use NFQUEUE:

  1. sysctl -w net.ipv4.ip_forward=1
  2. iptables -t raw -A PREROUTING -i eth1 -j NFQUEUE --queue-num 0
  3. iptables -t raw -A PREROUTING -i eth2 -j NFQUEUE --queue-num 0

To list or flush the above iptables rules:

  1. sudo iptables -t raw -S # list
  2. sudo iptables -t raw -F # flush