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

Please help filter iptables DNAT traffic with netfilter-ndpi module #2308

Open
gentoosys opened this issue Feb 7, 2024 · 1 comment
Open
Labels

Comments

@gentoosys
Copy link

Hi. I am using ndpi netfilter module.
I have multiple DNAT rules, forwarding ports to external socks proxy servers, like this
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 13069 -j DNAT --to-destination 5.5.5.5:31029

I want to filter smtp traffic. I added such rules

iptables -A INPUT -m ndpi --proto smtp -j REJECT
iptables -A FORWARD -m ndpi --proto smtp -j REJECT
iptables -A OUTPUT -m ndpi --proto smtp -j REJECT #works for outgoing smtp connections from that server
iptables -t mangle -I PREROUTING -m ndpi --proto smtp -j DROP
iptables -t mangle -I OUTPUT -m ndpi --proto smtp -j DROP
iptables -t nat -I PREROUTING -p tcp -m ndpi --proto smtp -j REDIRECT --to-ports 666 #inexistent port, coz drop is not allowed in nat
iptables -t nat -I OUTPUT -p tcp -m ndpi --proto smtp -j REDIRECT --to-ports 666

but smtp connections are still going through socks proxy servers. Can you please advice me how to filter smtp traffic?
the scheme is: socks client -> my server -> dnat -> external server socks port

@vel21ripn
Copy link
Contributor

You cannot change NAT after a connection has been established.
DPI determines the protocol based on the contents of the packets. This means that the protocol will be determined after the connection is established.

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

No branches or pull requests

2 participants