#!/usr/bin/perl -wT # # -T to set taint mode use strict; # # setup ENV for taint mode # delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; $ENV{PATH}="/bin:/usr/bin"; # # die unless the process is running with # an effective uid of 0 (root) # die "Must run as root" unless ($> == 0); # # explicitly set real uid to 0 (root), # so that we can switch effective uid at will # $<=0; if ($< != 0) { die "Couldn't set real uid to 0: $!\n"; } if( my $id =getpwnam("http")) { # set the effective uid to http's uid $>=$id; if ($> != $id) {die "seteuid failed: $!\n"} # run the id shell command that lists uid,euid,etc system("id"); } if( my $otherid =getpwnam("nobody")) { # reset the effective uid to 0, or you won't be able to # set it to nobody's uid $>=0; $>=$otherid; if ($> != $otherid) {die "seteuid failed: $!\n"} system("id"); }