Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Redirecting to another port #13

Open
glaslos opened this issue Oct 17, 2021 · 1 comment
Open

Redirecting to another port #13

glaslos opened this issue Oct 17, 2021 · 1 comment
Assignees

Comments

@glaslos
Copy link
Contributor

glaslos commented Oct 17, 2021

Hi, first of all, thanks for this very interesting library!
I am trying to receive frames, change the destination port and send it on again. Is this generally possible? E.g. frame has destination port 8080, I change it to 80 and let me web server handle it. Ideally on the way out I'd also change the source port back to the original destination port. If this sounds mad, I basically want to replace a solution based on nfqueue were I accept any destination port and send all the traffic to a single server (honeypot research).

I took the dumpframes example and added a xsk.Transmit(rxDescs) but I have the suspicion this send the packet out of the interface instead letting it continue to reach my service.

@slavc slavc self-assigned this Oct 26, 2021
@slavc
Copy link
Collaborator

slavc commented Nov 1, 2021

Thanks Lukas and sorry for late reply,

Check out this diagram: https://upload.wikimedia.org/wikipedia/commons/3/37/Netfilter-packet-flow.svg

An XDP BPF program gets executed only on the receive path, very early on, e.g. before an SKB gets allocated, it does not get executed on the transmit path (e.g. when a locally running application sends something).

Theoretically, you can modify the port in XDP BPF, but then you'd also probably need to fix up the checksums - I'm not sure this is possible, there are bpf-helpers(8) to do that, but they assume an SKB and so cannot be used in XDP BPF.

Perhaps what you're looking for are the tc-bpf(8). They can be hooked on both receive and transmit paths, and you could track the state of IP+port translations with BPF maps. On the diagram above, the ingress/egress qdisc is where tc-bpf(8) can be attached. The manpage actually has an example of port redirection.

Hope this helps, best of luck with the project!

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

No branches or pull requests

2 participants