Frage

Mit EasyHook Ich habe beide exportierten Funktionen erfolgreich angeschlossen und VTable Funktionen für verschiedene C ++ Klassen bekannt. In allen Zielen diese Fälle haben Programme verwendete DLLs.

Sofern ich die Adresse einer Funktion Einstiegspunkt kenne, ist es möglich, das gleiche zu tun, wenn eine Bibliothek in das Zielprogramm in Verbindung gebracht worden, im Gegensatz zu einer separaten Bibliothek zu sein?

War es hilfreich?

Lösung

Es erscheint mit EasyHook jedes Unterprogramm, dessen Haken kann Adresse berechenbar.

In meinem Fall Haken statisch gelinkte SSL_read und SSL_write in OpenSSL war so einfach wie die Offsets mit meinem Liebling Identifizierung Debugger und dann die Haken zu installieren.

// delegate for EasyHook:
[UnmanagedFunctionPointer(CallingConvention.Cdecl, 
    SetLastError = true, CharSet = CharSet.Ansi)]
delegate Int32 SLL_readDelegate(IntPtr SSL_ptr, IntPtr buffer, Int32 length);

// import SSL_read (I actually did it manually, but this will work in most cases)
/* proto from ssl_lib.c -> int SSL_read(SSL *s,void *buf,int num) */
[DllImport("ssleay32.dll", SetLastError = true)]
public static extern Int32 SSL_read(IntPtr ssl, IntPtr buffer, Int32 len);

// the new routine
static Int32 SSL_readCallback(IntPtr SSL_ptr, IntPtr buffer, Int32 length)
{
    /* call the imported SSL_read */
    int ret = SSL_read(SSL_ptr, buffer, length);
    /* TODO: your code here, e.g:
     * string log_me = Marshal.PtrToString(buffer, ret);
     */
    return ret;
}

Jetzt alles, was übrig bleibt, ist der Haken zu installieren:

private LocalHook sslReadHook;

public void Run(RemoteHooking.IContext InContext, String InArg1)
{
    // ... initialization code omitted for brevity

    /* the value for ssl_read_addr is made up in this example
     * you'll need to study your target and how it's loaded(?) to 
     * identify the addresses you want to hook
     */
    int ssl_read_addr = 0x12345678; /* made up for examples sake */
    sslReadHook = LocalHook.Create(new IntPtr(ssl_read_addr),
        new SSL_readDelegate(SSL_readCallback), this);

    // ...
}

Ich sollte, dass in diesem Beispiel erwähnt werden Sie brauchen libeay32.dll und ssleay32.dll als dieser auf dem ehemaligen abhängt.

Happy Einhaken!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top