2010-11-17 4 views
1

je me suis un (ancien) application qui appelle à la fonction WinSocket:crochetage Application (winsock) de C++/C#

struct hostent* FAR gethostbyname(
    __in const char *name 
); 

Il n'importe actuellement ws32_dll # 52 place l'appel du nom normal.. Mon intention est juste de pouvoir faire quelque chose comme ouvrir une boîte de message quand une recherche d'hôte arrive (ce qui devrait être au début de l'application). J'ai essayé de créer un fichier C++ dll avec les commentaires pragma pointant vers # 52 et le mettant dans l'application dir (y compris les fichiers "exe.local" et "exe.manifest" pour essayer de le rediriger) mais il a chargé le c: \ windows \ system32 à la place. Après cela, j'ai créé un projet C# lançant le processus lui-même (obtenant ainsi le PID de l'objet Process), en lui ajoutant la DLL easyhook.

j'ai vérifié l'exemple à: http://www.codeproject.com/KB/DLL/EasyHook64.aspx

Modification des appels à:

FileMon.FileMonInterface Interface; 
    LocalHook CreateFileHook; 
    Stack<String> Queue = new Stack<String>(); 

    public Main(
     RemoteHooking.IContext InContext, 
     String InChannelName) 
    { 
     // connect to host... 

     Interface = 
      RemoteHooking.IpcConnectClient<FileMon.FileMonInterface>(InChannelName); 
    } 

    public void Run(
     RemoteHooking.IContext InContext, 
     String InChannelName) 
    { 
     // install hook... 
     try 
     { 
      CreateFileHook = LocalHook.Create(
       LocalHook.GetProcAddress("ws2_32.dll", "gethostbyname"), 
       new DCreateFile(GetHostByName_Hooked), 
       this); 

      CreateFileHook.ThreadACL.SetExclusiveACL(new Int32[] { 0 }); 
     } 
     catch (Exception ExtInfo) 
     { 
      Interface.ReportException(ExtInfo); 

      return; 
     } 

     Interface.IsInstalled(RemoteHooking.GetCurrentProcessId()); 

     // wait for host process termination... 
     try 
     { 
      while (true) 
      { 
       Thread.Sleep(500); 

       // transmit newly monitored file accesses... 
       if (Queue.Count > 0) 
       { 
        String[] Package = null; 

        lock (Queue) 
        { 
         Package = Queue.ToArray(); 

         Queue.Clear(); 
        } 

        Interface.OnCreateFile(RemoteHooking.GetCurrentProcessId(), Package); 
       } 
       else 
        Interface.Ping(); 
      } 
     } 
     catch 
     { 
      // NET Remoting will raise an exception if host is unreachable 
     } 
    } 


    [UnmanagedFunctionPointer(CallingConvention.StdCall, 
     CharSet = CharSet.Auto, 
     SetLastError = true)] 
    delegate IntPtr DGetHostByName(
     String name); 

    // just use a P-Invoke implementation to get native API access 
    // from C# (this step is not necessary for C++.NET) 
    [DllImport("ws2_32.dll", 
     CharSet = CharSet.Auto, 
     SetLastError = true, 
     CallingConvention = CallingConvention.StdCall)] 
    static extern IntPtr gethostbyname(
     String name); 

    // this is where we are intercepting all file accesses! 
    static IntPtr GetHostByName_Hooked(
     String name) 
    { 
     try 
     { 
      Main This = (Main)HookRuntimeInfo.Callback; 
      MessageBox.Show("hi!"); 


     } 
     catch 
     { 
     } 

     // call original API... 
     return GetHostByName(
      name); 
    } 
} 

}

(peut avoir fait des fautes de frappe écrire ici, mais le projet est compilé avec succès @ home).

La chose est que je ne sais pas ce que je dois faire l'accrochage de ces méthodes < -> l'application elle-même.

Je veux dire .. ce qui gauches juste faire l'accrochage avec C# easyhook (en supposant que l'application est "foo.exe")? Ai-je besoin de créer un DLL personnalisé pour easyhook? (Dans ce cas, quel contenu dois-je définir à l'intérieur?)

Je l'ai trouvé un peu ... "complexe" pour un hook helloworld, hehe.

Merci à l'avance;)

Répondre

0

En fin de compte, en utilisant le livre « python gris pirater » taugh-moi comment faire tout cela avec moins de lignes, et la même chose que je voulais.

Pas encore d'exe mais ... c'est tout.

Utilisation de pydbg + crochets.