This page looks best with JavaScript enabled

Running a Service with a Regular User under a Privileged Port

 ·  🎃 kr0m

This is a little trick for a regular user to have their own service on a privileged port. The trick is that root will configure an iptables rule that will redirect traffic to the non-privileged port.

We start the service on a non-privileged port with a regular user:

nc -l -p 7777

Now, as root, we configure the following iptables rule so that when connecting to port 80, it ends up on port 7777:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 7777

When someone connects to port 80, they will end up communicating with the nc on port 7777:

telnet 192.168.20.27 80

Trying 192.168.20.27...
Connected to 192.168.20.27.
Escape character is '^]'.
If you liked the article, you can treat me to a RedBull here