Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created August 25, 2011 18:32
Show Gist options
  • Save waffle2k/1171394 to your computer and use it in GitHub Desktop.
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
#!/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