[Source] InjectDLL function (ripped from my old MSBot src)

C / C++ Discuss, [Source] InjectDLL function (ripped from my old MSBot src) at Programmers Lounge forum; So I was going through my GMail and I found the source to an old build of MSBot (0.1.4) that ...


Go Back   Gamerz Needs - For All Your Gaming Needs! > Technology Zone > Programmers Lounge > C / C++
Forgot Password? | Sign Up!

Notices

Advertisement
   

Reply
 
Bookmark this Thread Tools Display Modes
  #1  
Old 08-08-2008, 07:06 AM
dveloper's Avatar
T3H Team Pro Coder
 
Last Online: 10-22-2008 06:57 PM
Join Date: Mar 2006
Location: Florida, USA
Age: 22
Posts: 211
Thanks: 0
Thanked 83 Times in 27 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6
dveloper is on a distinguished road
Points: 7,440.46
Bank: 1,497.16
Total Points: 8,937.62
[Source] InjectDLL function (ripped from my old MSBot src)

So I was going through my GMail and I found the source to an old build of MSBot (0.1.4) that I sent to TiMBuS. So here's some useful code from the injector, to get all you DLL injection kiddies going.

Code:
bool InjectDLL(DWORD dwPID, const char *szDLL)
{
	HANDLE hProcess, hThread, hFile;
	void* pLibRemote;
	DWORD dwOldProtect;
	DWORD dwExitCode;

	hFile = CreateFile(szDLL, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);

	if (hFile == INVALID_HANDLE_VALUE)
		return false;

	hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPID);

	pLibRemote = VirtualAllocEx(hProcess, NULL, strlen(szDLL), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

	if (!VirtualProtectEx(hProcess, pLibRemote, strlen(szDLL), PAGE_EXECUTE_READWRITE, &dwOldProtect))
		return false;

	if (!WriteProcessMemory(hProcess, pLibRemote, (void*)szDLL, strlen(szDLL), 0))
		return false;

	VirtualProtectEx(hProcess, pLibRemote, strlen(szDLL), dwOldProtect, &dwOldProtect);

	hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandle("Kernel32"), "LoadLibraryA"), pLibRemote, 0, NULL);

	if (hThread == NULL)
		return false;

	WaitForSingleObject(hThread, INFINITE);
	GetExitCodeThread(hThread, &dwExitCode);

	VirtualFreeEx(hProcess, pLibRemote, strlen(szDLL), MEM_RELEASE);

	CloseHandle(hProcess);
	CloseHandle(hThread);

	return true;
}
Usage:
Code:
InjectDLL(dwProcessIDOfTargetProcess, "C:\mycode\mydll.dll");
Enjoy.

-d

Last edited by dveloper; 08-08-2008 at 07:22 AM.. Reason: Fixed a small typo.
The Following 4 Users Say Thank You to dveloper For This Useful Post:
ItsGreg (08-08-2008), kaswar (08-08-2008), Slugsnack (09-10-2008), wassssup34579 (08-08-2008)
  #2  
Old 08-08-2008, 07:08 AM
ItsGreg's Avatar
<span style="color: red;">&lt;span style=&quot;color: red;&quot;&gt;Mustache Mucho&lt;/span&gt;</span>
 
Last Online: Today 12:35 PM
Join Date: Sep 2007
Location: 46°21′50.14″N, 15°3′28.69″E
Age: 14
Posts: 1,385
Donation Award 
Blog Entries: 5
Thanks: 123
Thanked 397 Times in 150 Posts
Nominated 8 Times in 6 Posts
TOTW/F/M Award(s): 0
Latest Blog: My info
Rep Power: 7
ItsGreg is on a distinguished road
Points: 10,365.10
Bank: 510,492.30
Total Points: 520,857.40
Send a message via MSN to ItsGreg
Wow! Nice! i'll try to make something outta that!
__________________
  #3  
Old 08-08-2008, 07:14 AM
dveloper's Avatar
T3H Team Pro Coder
 
Last Online: 10-22-2008 06:57 PM
Join Date: Mar 2006
Location: Florida, USA
Age: 22
Posts: 211
Thanks: 0
Thanked 83 Times in 27 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6
dveloper is on a distinguished road
Points: 7,440.46
Bank: 1,497.16
Total Points: 8,937.62
No problem, I'm looking through the source for some other gems. Stay tuned.
  #4  
Old 08-08-2008, 08:05 AM
kaswar's Avatar
Registered Users +
 
Last Online: Today 12:03 PM
Join Date: Nov 2006
Location: Location:
Posts: 2,064
Thanks: 230
Thanked 221 Times in 145 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 11
kaswar will become famous soon enough
Points: 1,091.40
Bank: 110,398.61
Total Points: 111,490.01
Here ya go. Don't get drunk! O.O - joriannn Marked as kashin's property. (One of the four Mighty Titans led by sir SpaceCake) - kashin Merry christmas and seriously i couldnt find any other gift - ItsmYarD Merry Christmas N Happy New Years!!! - BiGbAnG to karwas. Bang - stormer320 
gotcha RPKMHFTAGUITALABPC - ROVE ure not drunk enough yet - swordmas754 
Gold - Wizxon Green - swordmas754 Green - swordmas754 
Send a message via MSN to kaswar
what does Alloc mean?

btw nice source, very useful! I might make it a DLL in C++ and use it for my Delphi thanks
__________________
Ha I'm back whatever
  #5  
Old 08-08-2008, 08:25 AM
dveloper's Avatar
T3H Team Pro Coder
 
Last Online: 10-22-2008 06:57 PM
Join Date: Mar 2006
Location: Florida, USA
Age: 22
Posts: 211
Thanks: 0
Thanked 83 Times in 27 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6
dveloper is on a distinguished road
Points: 7,440.46
Bank: 1,497.16
Total Points: 8,937.62
Allocate. That line allocates memory in the target process to hold the DLL's filename.
  #6  
Old 08-08-2008, 09:46 AM
kaswar's Avatar
Registered Users +
 
Last Online: Today 12:03 PM
Join Date: Nov 2006
Location: Location:
Posts: 2,064
Thanks: 230
Thanked 221 Times in 145 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 11
kaswar will become famous soon enough
Points: 1,091.40
Bank: 110,398.61
Total Points: 111,490.01
Here ya go. Don't get drunk! O.O - joriannn Marked as kashin's property. (One of the four Mighty Titans led by sir SpaceCake) - kashin Merry christmas and seriously i couldnt find any other gift - ItsmYarD Merry Christmas N Happy New Years!!! - BiGbAnG to karwas. Bang - stormer320 
gotcha RPKMHFTAGUITALABPC - ROVE ure not drunk enough yet - swordmas754 
Gold - Wizxon Green - swordmas754 Green - swordmas754 
Send a message via MSN to kaswar
lul can you try to explain a word without it in the explaination xD

anyway, I'll go search it up
__________________
Ha I'm back whatever
  #7  
Old 08-08-2008, 10:52 AM
wassssup34579's Avatar
Diamond Hole
 
Last Online: Today 04:40 PM
Join Date: Jan 2007
Location: California
Posts: 756
Blog Entries: 1
Thanks: 144
Thanked 99 Times in 50 Posts
Nominated 6 Times in 3 Posts
TOTW/F/M Award(s): 0
Latest Blog: blahh!!!
Rep Power: 6
wassssup34579 will become famous soon enough
Points: 1,600.90
Bank: 95,830.04
Total Points: 97,430.94
No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 
No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 
No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 
No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 No Message - wassssup34579 
Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 
Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 
Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 
Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 Black - wassssup34579 
Send a message via AIM to wassssup34579 Send a message via MSN to wassssup34579
would it still work if we took this out?
Code:
	WaitForSingleObject(hThread, INFINITE);
	GetExitCodeThread(hThread, &dwExitCode);
does that code make the program wait until the thread finished?
  #8  
Old 08-08-2008, 04:37 PM
Sean's Avatar
Gunbound UnderGround Level 3
 
Last Online: Today 02:00 AM
Join Date: Aug 2005
Age: 20
Posts: 4,402
Thanks: 2
Thanked 8,568 Times in 794 Posts
Nominated 33 Times in 17 Posts
Nominated TOTW/F/M Award(s): 1
Latest Blog:
Rep Power: 23
Sean has a spectacular aura aboutSean has a spectacular aura aboutSean has a spectacular aura about
Points: 41,574.96
Bank: 259,569.03
Total Points: 301,143.99
meat vomit - Ken I like people that are switched on up there. - Slugsnack I need no cells hack - huseyin No Message - goblin4u No Message - ahmedangel 
after all those bans, you still get POTM - pilotcs I love how you release only 1 new item to a hack, and get 250 more thanks. gay. =) - pilotcs Hmm. Banana. - Goku Thanks for the great MH ^^ - Adamaniac AwsOme HaCkEr - rebelife56 
I wonder if yours is longer. :) - Crumpeteer_ You Are a Cool friend so good luck and dont forget to eat my burger :)) - humam1992 A nice cold one on me! - kronikill421 best haxor - Plazma No Message - Yokerr 
GregP123 Ownz + Sean Ownz - GregP123 Cheers Sean! - chaosnite192 A beer for awesomeness! - Roguez Keep up the great works on the hacks. - Kyle No Message - jordandll 
Green - JMT420 Gold - Andrex2x Burgundy - Adamaniac Black - gogo_salem Black - shaolin786 
Dark Blue - aaronchanhongsen Gold - bmwm4 Green - hyperzuz Black - gogo_salem Gold - Roguez 
Burgundy - Torai Gold - Denipie 
Quote:
Originally Posted by kaswar View Post
lul can you try to explain a word without it in the explaination xD

anyway, I'll go search it up
...how can you not know what allocation means >.>

ok look, when a process is created, it takes up a certain amount of space in the memory of your computer. by allocating, you can "make" space within the space of that process for you to use for yourself. In this case, we are making space in that process so that we can write the path for the dll there. Next we are making more space which will be a thread that calls loadlibrary when it's created.

create remote thread is a very public injection method and doesn't work for all games - on rakion, gameguard hooks it and thus detects if its used.
__________________


Hacks of mine that you can get if you buy premium:
  • Gunz Multi Hack (IJJI)
  • Wolfteam Multi Hack (WIS, WLS)
  • Gunbound Multi Hack (GBNA, GIS, GBEU)
  • Rakion Legit Hack (RIS, RLS, RSS)
So support GzN, buy premium, and start hacking today!
The Following User Says Thank You to Sean For This Useful Post:
kaswar (08-08-2008)
  #9  
Old 08-08-2008, 11:38 PM
dveloper's Avatar
T3H Team Pro Coder
 
Last Online: 10-22-2008 06:57 PM
Join Date: Mar 2006
Location: Florida, USA
Age: 22
Posts: 211
Thanks: 0
Thanked 83 Times in 27 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 6
dveloper is on a distinguished road
Points: 7,440.46
Bank: 1,497.16
Total Points: 8,937.62
It all depends on when you inject, which is why I posted just the bare injection function. You can CreateProcess with CREATE_SUSPENDED if you like, inject, and then resume the process. I know there are multiple injection methods, this being the simplest.
  #10  
Old 08-21-2008, 07:07 PM
kaswar's Avatar
Registered Users +
 
Last Online: Today 12:03 PM
Join Date: Nov 2006
Location: Location:
Posts: 2,064
Thanks: 230
Thanked 221 Times in 145 Posts
Nominated 0 Times in 0 Posts
TOTW/F/M Award(s): 0
Latest Blog:
Rep Power: 11
kaswar will become famous soon enough
Points: 1,091.40
Bank: 110,398.61
Total Points: 111,490.01
Here ya go. Don't get drunk! O.O - joriannn Marked as kashin's property. (One of the four Mighty Titans led by sir SpaceCake) - kashin Merry christmas and seriously i couldnt find any other gift - ItsmYarD Merry Christmas N Happy New Years!!! - BiGbAnG to karwas. Bang - stormer320 
gotcha RPKMHFTAGUITALABPC - ROVE ure not drunk enough yet - swordmas754 
Gold - Wizxon Green - swordmas754 Green - swordmas754 
Send a message via MSN to kaswar
Can you create this in a DLL so i can call it with my Dephi?
__________________
Ha I'm back whatever

Last edited by kaswar; 08-23-2008 at 11:21 AM..
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump