Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > General Coding
You last visited: Today at 22:49

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Problem mit dll injection

Discussion on Problem mit dll injection within the General Coding forum part of the Coders Den category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Mar 2008
Posts: 96
Received Thanks: 3
Problem mit dll injection

Hallo ich versuche n programm zu schreiben, dass beliebige dlls in beliebige prozesse injected. Die theorie ist mir klar und so weiter aber beim injecten der dll stürzt der betreffenden Prozess ab. Ich weiß auch an welcher Stelle das passiert, habe das im quellcode mal markiert. Die dll enthält nichts besonderes, lediglich eine message box.

Quellcode:

Code:
#include <windows.h>
#include <cstdio>
#include <tlhelp32.h>
#include <iostream>

using namespace std;


typedef HINSTANCE (*fpLoadLibrary)(char*);
typedef LPVOID (*fpGetProcAddress)(HINSTANCE, char*);
typedef void (*fpFunktion)(void);

struct INJECTSTRUCT
{
      fpLoadLibrary LoadLibrary;
      fpGetProcAddress GetProcAddress;
      char path[255];
      char func[255];
};


DWORD WINAPI threadstart(LPVOID addr)
{
	HINSTANCE hDll;
	fpFunktion funktion;
	INJECTSTRUCT * is = (INJECTSTRUCT*)addr;       
	hDll = is->LoadLibrary(is->path);
	funktion = (fpFunktion)is->GetProcAddress(hDll, is->func);
	funktion();
	return 0;
}
void threadend()
{
}

bool EnableDebugPrivilege()
{
	TOKEN_PRIVILEGES priv;
	HANDLE hThis, hToken;
	LUID luid;

	hThis = GetCurrentProcess();

	OpenProcessToken(hThis, TOKEN_ADJUST_PRIVILEGES, &hToken);

	LookupPrivilegeValue(0, "seDebugPrivilege", &luid);

	priv.PrivilegeCount = 1;
	priv.Privileges[0].Luid = luid;
	priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

	AdjustTokenPrivileges(hToken, false, &priv, 0, 0, 0);

	CloseHandle(hToken);
	CloseHandle(hThis);
	return true;
}

void listproc()
{
		HANDLE hSnap, hTemp;
	PROCESSENTRY32 pe;
	pe.dwSize = sizeof(PROCESSENTRY32);

	//EnableDebugPrivilege();
	hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	
	if(Process32First(hSnap, &pe))
	{
		do
		{
			hTemp = OpenProcess(PROCESS_ALL_ACCESS, 0, pe.th32ProcessID);
			if(hTemp)
			{
				printf("%4d\t%s\n", pe.th32ProcessID, pe.szExeFile);
				CloseHandle(hTemp);
			}
		}
		while(Process32Next(hSnap, &pe));
	}
}




int main()
{

   HANDLE hProc;
   LPVOID start, thread;
   DWORD funcsize, written;
   HINSTANCE hDll;
   INJECTSTRUCT is;
   DWORD id;
   bool suc;

   EnableDebugPrivilege();
   listproc();

   printf("\n\nThe dll that shall be injected needs to be in the same directory as \nDLL_Injector.exe and has to be called DLL.dll\n\n");


   hDll = LoadLibrary("KERNEL32");
   is.LoadLibrary = (fpLoadLibrary)GetProcAddress(hDll, "LoadLibraryA");
   is.GetProcAddress = (fpGetProcAddress)GetProcAddress(hDll, "GetProcAddress");
   strcpy(is.path, "DLL.dll");
   strcpy(is.func, "Funktion");

   funcsize = (DWORD)threadend-(DWORD)threadstart;

   printf("Process ID: ");
   scanf("%d", &id);

   hProc = OpenProcess(PROCESS_ALL_ACCESS, false, id);

   printf("Prozess Handle:       %x", hProc);

   start = VirtualAllocEx(hProc, 0, funcsize+sizeof(INJECTSTRUCT), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
   printf("Memory:               %x\n", start);

   suc = WriteProcessMemory(hProc, start, (LPVOID)&is, sizeof(INJECTSTRUCT), NULL);
   if(!suc)
   MessageBox ( NULL, "WriteProcessMemory(hProc, start, (LPVOID)&is, sizeof(INJECTSTRUCT), NULL) failed", "DLL Injector", MB_OK);

   thread = (LPVOID)((DWORD)start+sizeof(INJECTSTRUCT));

   suc = WriteProcessMemory(hProc, thread, (LPVOID)threadstart, funcsize, NULL);//Hier ist wohl das Problem
   if(!suc)
   MessageBox ( NULL, "WriteProcessMemory(hProc, thread, (LPVOID)threadstart, funcsize, NULL) failed", "DLL Injector", MB_OK);

   CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)thread, start, 0, 0);

    CloseHandle(hProc);
	return 0;
}
Grabgewalt is offline  
Old 11/10/2008, 21:06   #2
 
elite*gold: 0
Join Date: Aug 2005
Posts: 443
Received Thanks: 72
Du musst aufpassen was du in der Hook DLL machst, wenn du vor hast, sie in NT system- oder service prozesse zu injizieren. Dort darf man keine GUI Befehle in nicht-interaktiven Systemprozessen nutzen (z.b. FindWindow, PostMessage, MessageBox, etc.). Tust du es trotzdem kann es zu systemabstürzen oder ähnlichem kommen (Bluescreen etc.)


Tritt der Fehler auch auf, wenn du nichts ausführst, sondern die dll nur injectest?
neji is offline  
Old 11/10/2008, 21:31   #3
 
elite*gold: 0
Join Date: Mar 2008
Posts: 96
Received Thanks: 3
Ich habe nur versucht die dll in prozesse wie minesweeper oder selbst geschriebene programme/prozesse zu injecten.
Quote:
Tritt der Fehler auch auf, wenn du nichts ausführst, sondern die dll nur injectest?

Wie meinst du das? Ich versuche ja eben nen dll injector zu schreiben und das ist ja eben ne exe die ne dll injected.

EDIT: Mit Absturz meine ich, dass das jeweilige Programm abstürzt, nicht das ganze System. Es kommt die Fehlermeldung ...exe hat ein Problem festgestellt und muss beendet werden.
Grabgewalt is offline  
Old 11/10/2008, 22:30   #4
 
elite*gold: 0
Join Date: Mar 2008
Posts: 96
Received Thanks: 3
problem gelöst. falls es wen interessiert:

start = VirtualAllocEx(hProc, 0, funcsize+sizeof(INJECTSTRUCT), MEM_COMMIT, PAGE_EXECUTE_READWRITE);

PAGE_EXECUTE_READWRITE ist scheinbar das Problem. Mit PAGE_READWRITE klappts.

EDIT: ok leider doch noch nicht ganz gelöst, es wird zwar das gemacht was in der dll steht aber danach stürzt der prozess in den injected wird immernoch ab. Was in der dll steht macht wohl keinen unterschied. Gleicher effekt bei ner "leeren" dll wie auch bei einer die irgendwas macht.

Noch jemand nen Rat für mich?^^
Grabgewalt is offline  
Reply


Similar Threads Similar Threads
Win7 Injection Problem
03/24/2010 - GW Bots - 10 Replies
Hi Im running Win7 32-bit and im having no problems what so ever with bots that auto-inject - but when i have to inject manually nothing kinda happends :/ I've even tried to run both gw the injector and the bot as admin, but still nothing works. I can see that the bots start but my char just dont move or do anything. Im using the Inizio injection - but also tried other injectors, without luck.
[ Wolfteam ] Injection via Import Table [ Problem ]
04/06/2009 - General Coding - 0 Replies
Hi, im currently trying to inject smth into Wolfteam, since it detects normal methods like a wrapper, rewriting the name in the hex file to a slightly different one or other ones i tried to use the import table of an loaded DLL, but whenever i edit it with LORD PE and add just once entry to it it will result in a programm crash. Now why i ask is because i know this method can work ( wolf lite uses it ). Some advices for me? ( The way i do it, 1. open dll with pe builder of Lord Pe 2. G to...
Injection problem.
02/27/2009 - Kal Online - 2 Replies
Always when i try to inject .dll file in Chilla kal or Kalvision private server, i got message that there is problem with anti-hacking. I using OMFGZ injector. Should I try with other injector or is problem anywhere else?
Code Injection Problem
01/03/2009 - General Coding - 4 Replies
Der Original Code im Assembler ist "mov esi, "(read) und müsste auf die Adresse der Aktuell aktivierten Waffe zeigen. Der Wert esi hat für jede Waffe einen festgelegten Wert während ecx eine Adresse(verändert sich bei waffenwechsel nicht) beinhaltet. Mir geht es darum den Wert während die Schleife durchläuft wieder um 1 zu erhöhen wobei ich ein kleines Problem mit dem Syntax habe. Wie ändere ich den Code so um das er den Wert an der Adresse (esi, ) um 1(oder mehr) erhöht? Der Interpreter in...
problem mit dem injection hack
12/09/2008 - Metin2 - 0 Replies
hey, habe grad ein kleines problem im code! #include "dll.h" #include "windows.h" #ifdef _MANAGED #pragma managed(push, off) #endif HMODULE lib = 0; BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved



All times are GMT +2. The time now is 22:49.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.