Monday, October 31, 2016

LDAP crypt password extraction

 but.  
   
 if your passwords are crypt...  
   
 ldapsearch -x -D "cn=admin,dc=my,dc=pants,dc=com" -w badpassword \  
 -h ldap.my.pants.com -b "dc=my,dc=pants,dc=com" \  
 -LLL -v "" uid userPassword \  
 | ldap2pw > ldap.pw  
   
 ....  
   
 #! /usr/bin/perl -w  
   
 use strict;  
 use MIME::Base64;  
   
 while( <> && ! eof) {  # need eof since we will hit eof on the other <> chomp;  
    my( $uid, $passw, $cn, $dn );  
    $cn = $uid = '';  
    while( <> ) {  # get an object  
     chomp;  
     last if /^\s*$/;   # object have blank lines between then  
     if( /^cn: (.+)/ ) {  
       $cn = $1;  
     }  elsif( /^dn: (.+)/ ) {  
       $dn = $1;  
     }  elsif( /^userP\w+:: (.+)/) {  
       $passw = substr( decode_base64($1), 7);  # assuming {crypt}  
     }  elsif( /^uid: (.+)/) {  
       $uid = $1;  
     }  
    }  
    print "$uid\:$passw\n" if defined $passw; # only output if object has password  
 }  
   
 ...  
   
 fun.  
Post a Comment