Monday, August 29, 2011

Perl script to identify Users with UID set to Zero or with Empty passwords

SCRIPT:

#!/usr/bin/perl
# Description:  Upon execution of this script, it will report the User-accounts with UID bit set to Zero and  
#                     the User-accounts with Empty passwords.
# Supported Platform:  Linux OS
# Execution method:   By root user
  
my @pass = `cat /etc/passwd`;
my @array = `cat /etc/shadow`;

foreach(@pass)
{
if ( $_ =~ m/^(\w+):\w:(\d+):\d+:/ ) {
        if( $2 == '0' ) {
                print "Username $1 has UID set to Zero\n" if ($1 ne root); }
 }
}

foreach(@array) {
if ($_ =~ m/^(\w+):([^:]*):\d+:\d:\d+/) {
        if ( length $2 == 0 ) {
                print "Username $1 has Empty password\n"; }
 }
}

SAMPLE EXECUTION:


# perl find_setuid.pl
Username ashok has UID set to Zero
Username raj1 has Empty password
#

No comments:

Post a Comment

Popular Posts

About Me

My photo
I have started this blog to share my work experience and spread some smart solutions on Linux to Internet community. I'm hoping more people will get benefited from this blog. Brief about me: I have 14+ years experience working as System Admin and currently work with VMware.