Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a mud server in perl and I am worried about securety on the machine that will be running this app. It binds to port 23 (telnet) which requires root privilages which makes the potential dammage caused by malicious parties great. I do not trust my programming enough to risk my network.

I have seen non perl applications, such as apache and bind actually change the executing user in mid execution. (Although apache does this by running more processes, I would still like to know if it is an easy viable solution).

The script I am writing is based around POE::Component::Server::TCP to dispatch jobs from multiple clients which may complicate the matter.

Is is possible to do this in perl?

Replies are listed 'Best First'.
Re: Change UID of executing POE TCP server
by Zaxo (Archbishop) on Jun 25, 2003 at 02:06 UTC
    $< = $runuid;

    Also see POSIX::setuid

    After Compline,
    Zaxo

Re: Change UID of executing POE TCP server
by Abigail-II (Bishop) on Jun 25, 2003 at 02:10 UTC
    You can drop privilidges by assigning to $<, $>, $( and $), which stand for the UID, EUID, GID and EGID of the program. You could also use POSIX::setuid and POSIX::setgid.

    You may want to check out the perlsec and perlvar manual pages, the POSIX module, Stevens' Advanced Programming in the UNIX environment, and the relevant manuals on your system.

    Abigail

      Thanks both, I'll look into doing this. (forgot to login before i posted)
        Or you could just use a higher port like say... 8080 or was it 8008, and that way you wouldn't even need to launch your server task as root. Any one here remember what port EOTL mud used? My fav back in the day.
Re: Change UID of executing POE TCP server
by sgifford (Prior) on Jun 25, 2003 at 05:59 UTC
    I would recommend writing a very short application to open port 23, switch UIDs, then exec your real server. That means your only root security risks are in the listener program; once the other program has started, there's no way to get back root status. Plus, it's easy to give a thorough security audit to a 56-line program.

    Speaking of 56-line programs,

    The other thing I would strongly recommend is that you write your server with perl's taint-checking (-T) switch. It's no substitute for a secure mindset, but it catches many types of silly errors and many more subtle errors. It makes sure any data coming from the user is sanitized before it's used for anything dangerous.