packet.proxy

A module that relies on NFQUEUEs in order to actively filter packets, using Go native plugins (plugins for this module can be found in this repository).

This module is only supported on GNU/Linux.

Commands

packet.proxy on

Start the NFQUEUE based packet proxy.

packet.proxy off

Stop the NFQUEUE based packet proxy.

Parameters

parameterdefaultdescription
packet.proxy.queue.num0NFQUEUE number to create and bind to.
packet.proxy.chainOUTPUTChain name of the iptables rule.
packet.proxy.ruleAny additional iptables rule to make the queue more selective (ex. —destination 8.8.8.8).
packet.proxy.pluginGo plugin file to load and call for every packet.

Plugins

Instead of using Javascript extensions like the HTTP and HTTPS proxies, this module requires the plugins to be natively written in Go in order to avoid adding too much overhead for each incoming packet. The packet.proxy.plugin parameter is mandatory and needs to be filled with the path of a shared object built as a Go plugin and exporting an OnPacket callback like the following:

  1. package main
  2. import (
  3. "github.com/bettercap/bettercap/log"
  4. "github.com/chifflier/nfqueue-go/nfqueue"
  5. )
  6. func OnPacket(payload *nfqueue.Payload) int {
  7. log.Info("We got a packet: %v", payload)
  8. // this will accept the packet, use NF_DROP to
  9. // drop the packet instead.
  10. payload.SetVerdict(nfqueue.NF_ACCEPT)
  11. return 0
  12. }

A more complex example using the gopacket library to parse and dump all the layers of the packet:

  1. package main
  2. import (
  3. "github.com/bettercap/bettercap/log"
  4. "github.com/chifflier/nfqueue-go/nfqueue"
  5. "github.com/google/gopacket"
  6. "github.com/google/gopacket/layers"
  7. )
  8. func OnPacket(payload *nfqueue.Payload) int {
  9. packet := gopacket.NewPacket(payload.Data, layers.LayerTypeIPv4, gopacket.Default)
  10. log.Info("%s", packet.Dump())
  11. payload.SetVerdict(nfqueue.NF_ACCEPT)
  12. return 0
  13. }

This test.go file can be compiled like so:

  1. go build -buildmode=plugin test.go

Once the test.so file is generated, it can be used for the packet.proxy.plugin parameter.

In order to be compiled correctly, plugin .go files need to be copied inside bettercap’s source folder and compiled from there, otherwise you might have issues compiling due to dependency conflicts with the vendor folder.