CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Threaded View

  1. #1
    Join Date
    Jul 2002
    Posts
    788

    Code injection with CreateRemoteThread

    I am trying to do code injection into one of my dialog application exe.
    Code:
    #define cbInjectFunc	192
    HANDLE	hProcess = 0; 
    HANDLE	hThread	   = 0;	// The handle and ID of the thread executing
    DWORD	dwThreadId = 0;	// the remote InjectFunc.
    
    DWORD dwNumBytesXferred = 0; // Number of bytes written to the remote process.
    
    static DWORD WINAPI InjectFunc () 
    {
    
    //How to invoke the following function in the remote process once InjectFunc is copied into the remote process?	
    //GetModuleHandle(__TEXT("kernel32"));
    
    return 0;
    }
    
    //hWnd is the handle to the dialog application exe
    ::GetWindowThreadProcessId( hWnd, (DWORD*)&PID );
    
    hProcess = ::OpenProcess(	PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,FALSE, PID);
    
    DWORD	*pCodeRemote;
    pCodeRemote = (PDWORD) VirtualAllocEx( hProcess, 0, cbInjectFunc, MEM_COMMIT, PAGE_EXECUTE_READWRITE );	
    
    WriteProcessMemory( hProcess, pCodeRemote, &InjectFunc, cbInjectFunc, &dwNumBytesXferred );
    
    hThread = CreateRemoteThread(hProcess, NULL, 0, 
    (LPTHREAD_START_ROUTINE)pCodeRemote,
    0, 0 , &dwThreadId);
    The remote application crashed when CreateRemoteThread is called. I couldn't find the reason..

    What went wrong?
    Last edited by mce; September 25th, 2007 at 12:29 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured