Process Running Dll Injection C++ menu

User Tag List

Results 1 to 15 of 15
  1. #1
    BitHacker's Avatar Master Sergeant
    Reputation
    13
    Join Date
    May 2012
    Posts
    114
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Process Running Dll Injection C++

    I'm not sure why this isn't letting me inject this testdll3.dll into the process. Everything is correct all my variables are getting the correct data. All memory regions are getting the proper flags. I'm fed up with it. My output is below.

    Can anyone tell me what I'm doing wrong?

    You can drop a test dll into the diablo III.exe folder.... This could will read it and try to inject it into a running process.


    Code:
    #undef UNICODE
    #include <vector>
    #include <string>
    #include <windows.h>
    #include <Tlhelp32.h>
    #include <iostream>
    #include <Psapi.h>
    
    using namespace std;
    
    int main(void)
    {
        vector<string>processNames;
        PROCESSENTRY32 pe32;
        pe32.dwSize = sizeof(PROCESSENTRY32);
        HANDLE hTool32 = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
        BOOL bProcess = Process32First(hTool32, &pe32);
        if(bProcess == TRUE)
        {
            while((Process32Next(hTool32, &pe32)) == TRUE)
    		{
                processNames.push_back(pe32.szExeFile);
    
    			if(strcmp(pe32.szExeFile, "Diablo III.exe") == 0)
    			{
    				string dllPathMod;
    				char DirPath[MAX_PATH];
    				char* FullPath = new char[MAX_PATH];
    				
    				//Grab handle 
    				HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
    
    				//Grab File location
    				GetProcessImageFileName(hProcess, DirPath, sizeof(DirPath));
    
    				//Save Path into string
    				dllPathMod = DirPath;
    				dllPathMod.erase( dllPathMod.size() - 14 );
    
    				//Convert back to char[]
    				char* dllPath = new char[dllPathMod.size() + 1];
    				dllPath[dllPathMod.size()] = 0;
    				memcpy(dllPath, dllPathMod.c_str(), dllPathMod.size());
    				
    				//Copy Path
    				sprintf_s(FullPath, MAX_PATH, "%s\\testdll3.dll", dllPath);
    
    				//Finding LoadLibraryAddr
    				LPVOID LoadLibraryAddr = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
    
    				//Allocate memory inside diablo III.exe
    				LPVOID LLParam = (LPVOID)VirtualAllocEx(hProcess, NULL, strlen(FullPath), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
    
    				//Write to memory
    				WriteProcessMemory(hProcess, LLParam, FullPath, strlen(FullPath), NULL);
    
    				//Create a thread inside virtual address space of diablo III.exe
    				CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryAddr, LLParam, NULL, NULL);
    
    
    				CloseHandle(hProcess);
    				delete [] FullPath;
    				delete [] dllPath;				
    			}
    		}
        }
        CloseHandle(hTool32);
        return 0;
    }

    My Output:
    Process Running Dll Injection C++-captureoutput-jpg

    -Bit_Hacker

    Process Running Dll Injection C++
  2. #2
    DrGonzo's Avatar Contributor
    Reputation
    144
    Join Date
    Jun 2009
    Posts
    132
    Thanks G/R
    0/59
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *Prepares for shit storm*

    This is a no question section. If you have programming questions take it to stack overflow.

    Didn't bother reading code but try running as admin and setting debug privilege. If that doesn't work find better copypasta.

  3. #3
    BitHacker's Avatar Master Sergeant
    Reputation
    13
    Join Date
    May 2012
    Posts
    114
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    FearAndLawyering,

    Thanks for your input but I wrote all of it

    -Bit_Hacker

  4. #4
    Valtharak's Avatar Master Sergeant
    Reputation
    51
    Join Date
    Feb 2011
    Posts
    105
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    or in the programming section

  5. #5
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Knowing the win32 API would help And so would checking GetLastError when LoadLibrary fails.
    Hint: Fix your namespace.
    Last edited by _Mike; 05-31-2012 at 03:17 PM.

  6. #6
    Yazuak's Avatar Active Member
    Reputation
    123
    Join Date
    Mar 2007
    Posts
    86
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'd imagine it's failing because your paths are in device format. Try using something other than
    GetProcessImageFileName to retrieve the path. (You want something that begins with "C:\\" or similar.)

  7. #7
    _Mike's Avatar Contributor
    Reputation
    310
    Join Date
    Apr 2008
    Posts
    531
    Thanks G/R
    0/2
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by Yazuak View Post
    (You want something that begins with "C:\\" or similar.)
    No need. LoadLibrary is fully capable of handling device paths. All you need is the right namespace prefix.
    Doesn't anyone know the windows apis these days? I blame C# for that

  8. #8
    bossfong's Avatar Private
    Reputation
    2
    Join Date
    Jun 2012
    Posts
    4
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looking at your FullPath variable it seems to be screwed. From what I see you're trying to load your DLL from a noname folder inside Diablo3 folder.
    Also:
    Why have it simple when you can do it complicated:


    Code:
            HWND hWindow;
    
    	while (!(hWindow = ::FindWindow(NULL, "Diablo III")))
    	{
    		Sleep(100);
    	}
    
    	std::cout << "Found Diablo3" << std::endl;
    
    	DWORD procid;
    
    	::GetWindowThreadProcessId(hWindow, &procid); // NO ERROR CHECKING
    No ProcessAPI, loops and shit involved. l2msdn

  9. #9
    BitHacker's Avatar Master Sergeant
    Reputation
    13
    Join Date
    May 2012
    Posts
    114
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    bossfong,

    I got it working:
    Code:
    #undef UNICODE
    #include <vector>
    #include <string>
    #include <windows.h>
    #include <Tlhelp32.h>
    #include <iostream>
    #include <Psapi.h>
    
    using namespace std;
    
    int main(void)
    {
        vector<string>processNames;
        PROCESSENTRY32 pe32;
        pe32.dwSize = sizeof(PROCESSENTRY32);
        HANDLE hTool32 = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
        BOOL bProcess = Process32First(hTool32, &pe32);
        if(bProcess == TRUE)
        {
            while((Process32Next(hTool32, &pe32)) == TRUE)
    		{
                processNames.push_back(pe32.szExeFile);
    
    			if(strcmp(pe32.szExeFile, "Diablo III.exe") == 0)
    			{								
    				char* FullPath = new char[MAX_PATH];
    				HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);
    				sprintf(FullPath, "testdll3.dll");
    				LPVOID LoadLibraryAddr = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");
    				LPVOID LLParam = (LPVOID)VirtualAllocEx(hProcess, NULL, strlen(FullPath), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
    				WriteProcessMemory(hProcess, LLParam, FullPath, strlen(FullPath), NULL);
    				CreateRemoteThread(hProcess, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibraryAddr, LLParam, NULL, NULL);
    				CloseHandle(hProcess);
    				delete [] FullPath;
    			}
    			
    			// Add break for while loop
    		}
        }
        CloseHandle(hTool32);
        return 0;
    }

    i got it working by changing this line of code:

    sprintf_s(FullPath, MAX_PATH, "%s\\testdll3.dll", dllPath);

    to:

    sprintf(FullPath, "testdll3.dll");




    Process Running Dll Injection C++-diablo3capture-jpg

  10. #10
    Yazuak's Avatar Active Member
    Reputation
    123
    Join Date
    Mar 2007
    Posts
    86
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by _Mike View Post
    No need. LoadLibrary is fully capable of handling device paths. All you need is the right namespace prefix.
    Doesn't anyone know the windows apis these days? I blame C# for that
    I know more about them now than I did a second ago.

  11. #11
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by _Mike View Post
    Knowing the win32 API would help And so would checking GetLastError when LoadLibrary fails.
    Hint: Fix your namespace.
    I think he's too busy worrying about this being a "C# only forum" to actually learn C++ and the Win32 API.

  12. #12
    BitHacker's Avatar Master Sergeant
    Reputation
    13
    Join Date
    May 2012
    Posts
    114
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cypher,

    Ya, thats why I got it to work without any help from this forum right? Piss off....

    -Bit_hacker

  13. #13
    Cypher's Avatar Kynox's Sister's Pimp
    Reputation
    1356
    Join Date
    Apr 2006
    Posts
    5,368
    Thanks G/R
    0/4
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally Posted by BitHacker View Post
    Cypher,

    Ya, thats why I got it to work without any help from this forum right? Piss off....

    -Bit_hacker

    Anyone can fiddle around with code until it seems to work. If you actually understood what you are doing though you'd notice the numerous bugs and corner cases in your code.

    Not to mention the fact that your 'fix' doesn't actually fix the issue you were having, you've simply reverted to using a relative path now instead of an absolute one (which introduces more potential issues).

    EDIT:

    I forgot to mention, if you actually did error checking in your code, you could easily pinpoint what was failing and why.

    1. Check return value of function. If function returns an error code, go to step 3. If it returns a boolean (or a pointer) continue to step 2.
    2. Call GetLastError to retrieve the error code.
    3. Look up what the error code means on MSDN/Google.
    4. Fix the problem.

    The same applies to functions you call in the remote process (i.e. LoadLibraryA <-- Protip: This is one of the potential problems with your code, but I digress...).

    If you (understandably) don't want to use a dynamic code generation library (like AsmJit), or write a 'wrapper' for your LoadLibrary call in assembly then copy it over to the remote process, you can just fire up a debugger on your target, set a breakpoint for your call to LoadLibrary, then inspect the LastError value in the TEB (most debuggers have a command/window to show this automagically). Then you just MSDN/Google the error code as normal (or at least provide such information in your post so we don't have to try and mentally debug your program for you).
    Last edited by Cypher; 06-02-2012 at 08:25 AM.

  14. #14
    BitHacker's Avatar Master Sergeant
    Reputation
    13
    Join Date
    May 2012
    Posts
    114
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cypher,

    Thank you for not flaming and making constructive criticism. I will take what you said under my wing bro.

    -Bit_Hacker

  15. #15
    zewt's Avatar Member
    Reputation
    13
    Join Date
    Nov 2008
    Posts
    127
    Thanks G/R
    0/0
    Trade Feedback
    0 (0%)
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wrong thread post :x sorry
    Last edited by zewt; 06-02-2012 at 11:04 AM.

Similar Threads

  1. Replies: 1
    Last Post: 01-19-2012, 03:14 AM
  2. [WoW] [C++] Hack Loader (DLL Injection Example)
    By Cypher in forum WoW Memory Editing
    Replies: 28
    Last Post: 07-06-2010, 11:41 PM
  3. [Tutorial] DLL Injection
    By jagged software in forum Programming
    Replies: 22
    Last Post: 04-21-2009, 03:27 AM
  4. DLL injection with windows SP3
    By Therrm in forum World of Warcraft Bots and Programs
    Replies: 3
    Last Post: 12-06-2008, 03:03 PM
  5. What are the risks with DLL injection?
    By object in forum WoW Memory Editing
    Replies: 14
    Last Post: 08-22-2008, 09:23 PM
All times are GMT -5. The time now is 03:09 AM. Powered by vBulletin® Version 4.2.3
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved. User Alert System provided by Advanced User Tagging (Pro) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
Digital Point modules: Sphinx-based search