Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect package to a different IP #13

Open
bonifaido opened this issue Dec 14, 2022 · 1 comment
Open

redirect package to a different IP #13

bonifaido opened this issue Dec 14, 2022 · 1 comment

Comments

@bonifaido
Copy link

I have the following example, which tries to redirect my pings to 8.8.8.8 address instead of the original request:

package main

import (
	"fmt"
	"net"
	"os"

	"github.com/AkihiroSuda/go-netfilter-queue"
	"github.com/google/gopacket/layers"
)

func main() {
	var err error

	nfq, err := netfilter.NewNFQueue(0, 100, netfilter.NF_DEFAULT_PACKET_SIZE)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer nfq.Close()
	packets := nfq.GetPackets()

	for true {
		select {
		case p := <-packets:
			fmt.Println(p.Packet)

			p.Packet.NetworkLayer().(*layers.IPv4).DstIP = net.IPv4(8, 8, 8, 8)

			fmt.Println("new ->", p.Packet)

			p.SetVerdictWithPacket(netfilter.NF_ACCEPT, p.Packet.Data())
		}
	}
}

I think from the logs, that it doesn't work, since even if I change the IP to a bad address instead I still get a response in ping CLI, where am I doing it wrong?

I used sudo iptables -A OUTPUT -p icmp -j NFQUEUE to setup the queue.

@terrbear
Copy link

You'll want to re-serialize the packet after changing the dest that way. See https://pkg.go.dev/github.com/google/gopacket#SerializePacket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants