Code Injection - VirtualAllocEx,WriteProcessMemory,CreateRemoteThread - Teil 3 von 3 PDF Print E-mail
User Rating: / 0
PoorBest 

Den dritten un letzten Teil widme ich der DLL, welche den auszuführenden Code beinhaltet. Dieser Teil ist recht einfach zu
implementieren. Im Grunde wird bei LoadLibrary einfach ein weiteren Thread gestartet, welcher dann die Arbeit übernimmt.

Der Einstiegspunkt - LoadLibrary:

Wird die Dll von einem Prozess geladen wird einfach ein weiteren Thread gestartet.

BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /* lpvReserved */)
{
   if (dwReason == DLL_PROCESS_ATTACH )
   {
        DoAction();
   }

   return TRUE;
}

Die DoAction Funktion erzeugt einen neuen Thread, welcher über alle Fenster mittels EnumWindows iteriert.

 void DoAction()
{
    CreateThread( NULL,
                  0,
                  ThreadProc,
                  0,
                  0,
                  0);    
}

DWORD WINAPI ThreadProc(  LPVOID lpParameter )
{

   EnumWindows( EnumWindowsProc, 0 );
 
   while( 1 )
   {
       Sleep( 100 );
   }

    return 0;
}

BOOL CALLBACK EnumWindowsProc( HWND hwnd, LPARAM lParam )
{
    const DWORD currentID = GetCurrentProcessId();
    DWORD procid = 0;
    GetWindowThreadProcessId (hwnd, &procid);

    if( currentID == procid )
    {
        SetWindowsHookEx( WH_KEYBOARD, KeyboardProc, NULL,  );
    }
    return TRUE;
}

LRESULT CALLBACK KeyboardProc( int nCode, WPARAM wParam, LPARAM lParam )
{

   // implementation

}

Weiterführende Links:

Last Updated on Monday, 14 December 2009 21:00