Created
August 25, 2011 18:32
-
-
Save waffle2k/1171394 to your computer and use it in GitHub Desktop.
Perl script to become a certain user, with some verbose output to describe what's happening
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use POSIX qw(setuid getuid); | |
my $w = scalar getpwuid( $< ); | |
if( $w eq 'root' ){ | |
print "Hey, you're root... let's try to become 'abuse'\n"; | |
# become user abuse | |
my ($pwName, $pwCode, $pwUid, $pwGid, $pwQuota, $pwComment, | |
$pwGcos, $pwHome, $pwLogprog) = getpwnam( "abuse" ); | |
unless( $pwUid ){ | |
die( "That user doesn't exist\n" ); | |
} | |
print "Trying to become UID $pwUid\n"; | |
# Become abuse | |
setuid( $pwUid ); | |
} elsif ( $w ne 'abuse' ){ | |
die( "You must be abuse to run this\n" ); | |
} | |
# Test who we are | |
$w = scalar getpwuid( $< ); | |
print "Ok, now we are: " . $w . "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment