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
The intent of this blog is to share my work experience and spread some smart solutions on Linux to System Administrators. I'm hoping the solutions shared in this Blog would be helpful and come as a handy for Viewers. Brief about me: I have 18+ years work experience in System and Cloud Administration domain, primarily works on VMware Cloud Products (vSphere, vCloud Director, vRealize Automation, NSX Adv. Load Balancer, vROps).