From: Antony Stone <Antony@Soft-Solutions.co.uk>
To: netfilter@lists.netfilter.org
Subject: Re: Blocking source ports after REDIRECT
Date: Wed, 14 Apr 2004 18:04:57 +0100 [thread overview]
Message-ID: <200404141804.57989.Antony@Soft-Solutions.co.uk> (raw)
In-Reply-To: <407D69F3.8050105@turton.co.za>
On Wednesday 14 April 2004 5:42 pm, Trevor Turton wrote:
> I am running an untrusted web/app server and mail server on a Linux
> server, and choose to run then as non-root. The apps must therefore use
> ports other than the well-known privileged ones.
You can't start them as root, bind to a privileged port, then drop privilege
to run the remainder of the app as a standard user?
> I have set up iptables
> to redirect client requests addressed to the well-known ports to the
> ports that these apps open, e.g.
> 25 -> 8025
> 80 -> 8080
> 110 -> 8110
> This works fine.
Fair enough - an alternative way to do it.
> Out of obsessive neatness rather than for any good
> technical reason I would like to block direct access to the apps through
> their non-privileged (8xxx) ports. When I insert a filter command to do
> this, it blocks the redirected traffic as well.
> /sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 25 -j
> REDIRECT --to-ports 8025
> /sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 80 -j
> REDIRECT --to-ports 8080
> /sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 110 -j
> REDIRECT --to-ports 8110
> /sbin/iptables -t nat -A PREROUTING -p tcp -i eth0 --dport 443 -j
> REDIRECT --to-ports 8443
> #
> # accept traffic addressed to the serviced tcp ports
> #
> /sbin/iptables -A INPUT -p tcp --dport 22 -j ACCEPT
> /sbin/iptables -A INPUT -p tcp --dport 25 -j ACCEPT
> /sbin/iptables -A INPUT -p tcp --dport 80 -j ACCEPT
> /sbin/iptables -A INPUT -p tcp --dport 110 -j ACCEPT
> /sbin/iptables -A INPUT -p tcp --dport 443 -j ACCEPT
There is absolutely no reason to have the above rules, since your apps are not
listening on those ports! Port 25 just got redirected to 8025, 80 -> 8080,
110 -> 8110, and 443 -> 8443. Remember that PREROUTING happens before
INPUT, so the INPUT chain only sees the destination addresses/ports after
they've been changed.
> #
> # filter out traffic to remaining privileged tcp ports
> #
> /sbin/iptables -A INPUT -p tcp -i eth0 --dport 0:1023 -j DROP
> ## the following command blocks -eth0 --dport 25,80,110,443 as well!!
> ## /sbin/iptables -A INPUT -p tcp -i eth0 --dport 8000:8443 -j DROP
Yes, sure, because you're now blocking the packets which just got translated
from the low port numbers :)
What you need to do is either:
1. DROP the packets sent to the high port numbers in PREROUTING (not a
recommendation I would normally make, but there are always exceptions!)
or
2. DNAT the high port numbers to something you don't care about, and then DROP
those in INPUT.
eg:
1. iptables -A PREROUTING -t nat -p tcp -i eth0 --dport 8025 -j DROP
iptables -A PREROUTING -t nat -p tcp -i eth0 --dport 8080 -j DROP
etc.
or
2. iptables -A PREROUTING -t nat -p tcp -i eth0 --dport 8025 -j REDIRECT --to
65535
iptables -A PREROUTING -t nat -p tcp -i eth0 --dport 8080 -j REDIRECT --to
65535
etc.
iptables -A INPUT -p tcp -i eth0 --dport 65535 -j DROP
Regards,
Antony.
--
"There is no reason for any individual to have a computer in their home."
- Ken Olsen, President of Digital Equipment Corporation (DEC, later consumed
by Compaq, later consumed by HP)
Please reply to the list;
please don't CC me.
prev parent reply other threads:[~2004-04-14 17:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-04-14 16:42 Blocking source ports after REDIRECT Trevor Turton
2004-04-14 17:03 ` Andrew Schulman
2004-04-14 17:04 ` Antony Stone [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200404141804.57989.Antony@Soft-Solutions.co.uk \
--to=antony@soft-solutions.co.uk \
--cc=netfilter@lists.netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox