# Ray Espinoza # ChAdminPass.pl # This is the completed script that will change the local admin password on a list of machines # that you specify. It will ask for a password, encrypt it and copy over with a compiled exe of this # perl script. The script will then be decrypted locally on the machine and change the password and # delete the encryted text file along with the executable. ##################################################################################################### #!D:\perl\bin use strict; use Crypt::Blowfish_PP; use Win32::AdminMisc; ############################################################################################### # This will prompt user for the list of machines to read in and the password to assign ############################################################################################### print "Enter in the name of the text file that you would like to read in:\n"; chomp(my $List = ); print "Enter in the password that you would like to assign the local admin account:\n"; chomp(my $Password = ); ################################################################################################ # Calling on subRoutine to Encrypt the password and adding it to text file. ################################################################################################ Create_Password(); ################################################################################################ # This will open the list file for reading or error if it can't find it. ################################################################################################ open(LIST,$List) || die "Can't read $List: $!"; ################################################################################################ # This will read in the text file line by line and execute the copy of files over to the local # machine and execute ChPass.exe ################################################################################################ while () { my $Server = $_; my $source1 = "C:/ChPass/phrase.txt"; my $dest1 = "//$Server/c\$/temp/phrase.txt"; my $command = qq(copy "$source1" "$dest1") || die "Couldn't copy $source1: $!"; $command =~ s#/#\\#g; system $command; my $source2 = "C:/ChPass/ChPass.exe"; my $dest2 = "//$Server/c\$/temp/ChPass.exe"; my $command2 = qq(copy "$source2" "$dest2") || die "Couldn't copy $source2: $!"; $command2 =~ s#/#\\#g; system $command2; system("//$Server/c\$/temp/ChPass.exe $Server); } ################################################################################################# # This is the subroutine that encrypts the password. ################################################################################################# sub Create_Password { open(OUT,">phrase.txt") #|| die "Can't create phrase.txt: $!"; my $key = "abcdefghijklmnopqrstuvwxyz123456789"; my $bf = Crypt::Blowfish_PP->new($key); print my $encrypted_Password = $bf->encrypt($Password); print OUT $encrypted_Password; } ################################################################################################ # Closes any open files gracefully. ################################################################################################ close(OUT); close(LIST); # Here is the next script (ChPass.pl before it is ChPass.exe) # Ray Espinoza # ChPass.pl # This script calls in the encrypted password file and decrypts it and uses # its value as $Password to change the account password to $Password. ################################################################################################# #!D:\perl\bin -w use strict; use Win32::AdminMisc; #use Win32::AdminMisc qw(SetPassword); chomp(my $Server = ); my $User = "Administrator"; my $Password = &getPassword; my $Result = Win32::AdminMisc::SetPassword( $Server, $User, $Password) || die "Couldn't change password on $Server: $^E"; print $Password . "\n"; print $Result; sub getPassword { use Crypt::Blowfish_PP; my $key="abcdefghijklmnopqrstuvwxyz123456789"; my $bf = Crypt::Blowfish_PP->new($key); open (IN,"phrase.txt") || die "Can't read phrase.txt: $!"; my $encrypted_password = ; my $decrypted_password = $bf->decrypt($encrypted_password); return $decrypted_password; close(IN); } # Here are the errors that i am getting: String found where operator expected at C:\scripts\perl\ChAdminPass.pl line 65, near "txt") #|| die "" Bareword found where operator expected at C:\scripts\perl\ChAdminPass.pl line 65 , near "") #|| die "Can't" (Missing operator before Can't?) String found where operator expected at C:\scripts\perl\ChAdminPass.pl line 67, near "$key = "" (Might be a runaway multi-line "" string starting on line 65) (Missing semicolon on previous line?) Bareword found where operator expected at C:\scripts\perl\ChAdminPass.pl line 67 , near "$key = "abcdefghijklmnopqrstuvwxyz123456789" (Missing operator before abcdefghijklmnopqrstuvwxyz123456789?) String found where operator expected at C:\scripts\perl\ChAdminPass.pl line 67, at end of line (Missing semicolon on previous line?) syntax error at C:\scripts\perl\ChAdminPass.pl line 65, near "txt") #|| die "" Global symbol "$key" requires explicit package name at C:\scripts\perl\ChAdminPa ss.pl line 65. Can't find string terminator '"' anywhere before EOF at C:\scripts\perl\ChAdminP ass.pl line 67.