1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| #!/usr/bin/perl
# bindstress.pl - free software by Matt Richard
# edit the variables below to reflect your LDAP server
use strict; use warnings;
my $server = 'ldapserver';
my $uid_base = 'cn=users,dc=example,dc=org';
my @bind_pass = ('abc123',
'bcd456',
#...
);
my $filter = '(!(|(uid=admin)(uid=root)(uid=*admin)(uid=vpn*)))';
my $success = 0;
my $failure = 0;
# initialize random number generator
srand;
# search for users in the database
my @search = `ldapsearch -x -LLL -A -b "$uid_base" -s one -h "$server" "$filter" dn | grep "dn"`;
my @users;
# convert search results into a list of users
for my $searchline (@search)
{
($junk, $junk, $dn, $junk) = split(/[=,\ ]/,$searchline);
push (@users, $dn);
}
# keep attempting to bind forever
while (1)
{
#pick a random user
my $dn = @users [ rand @users ];
# get the current time
chomp ($date = substr(`date \"+%H:%M:%S\"`,0,-1));
my $result;
# perform the ldap bind
for my $bind_pass (@bind_pass) {
$result = `ldapwhoami -x -h $server -D \"uid=$dn,$uid_base\" -w \"$bind_pass\" 2>&1`;
last if $result =~ /dn:uid=/;
}
# if we noticed a success
if ($result =~ /dn:uid=/ )
{
# increment the success coun and don't hilight the output
print "\033[0m$date \{" . ++$success . "\/" . $failure . "\} $dn -> $result";
}
else
{
# otherwise increment the failure count and hilight the output
print "\033[1m$date \{" . $success . " " . ++$failure . "\} $dn -> $result";
}
# uncomment to slow things down a bit
#sleep 1;
} |
Partager