Monday, August 10, 2009

Perl check LDAP password online


#!C:\Perl\bin\perl.exe -w
use strict;

use warnings;
use IO::File;
use MIME::Base64;
use LWP::UserAgent;

my $file = 'ldap.passwd';
my $input = IO::File->new("< $file")
or die "Could't open $file for reading: $!\n";

while ( defined( my $line = $input->getline() ) ) {
chomp($line);

if ( $line =~ /\@perl/ ) {

# print $line . "\n";
my @user = split( /,/, $line );

# find username and password
my $username = $user[0];
my $password = $user[1];
my $realname = $user[2];
$password =~ s/{md5}//;
my $base64_password = decode_base64($password);
my $md5_password = unpack( "H*", $base64_password );

# get md5 reverse
my $ua = LWP::UserAgent->new;
$ua->agent("JapanApp/0.1");
my $req =
HTTP::Request->new(
GET => 'http://gdataonline.com/qkhash.php?mode=txt&hash='
. $md5_password );
my $res = $ua->request($req);
if ( $res->is_success ) {
my $content = $res->content();

print $username . "\t\t" . $1 . "\t\t" . $realname . "\n"
if $content =~ /(.+)<\/b><\/td><\/tr>/;
}
else {
print $res->status_line, "\n";
}
}

}

No comments:

Post a Comment