Government Security
Network Security Resources

Jump to content

Photo

Threads Won't Start From Within Injected Dll

- - - - - security
  • Please log in to reply
1 reply to this topic

#1 colinsouth

colinsouth

    Private First Class

  • Members
  • 29 posts

Posted 08 February 2012 - 03:30 PM

Hello everyone,

I have run into a little problem and was wondering if anyone knew the cause of the problem and how to solve it.

Basicly, I inject my DLL into a process (testing using firefox.exe and iexplore.exe), and the code in the DLL starts a second thread. The thread just doesnt seem to trigger for some reason.

#include "win.h"

DWORD WINAPI ThreadMain(LPVOID lpParam);

BOOL APIENTRY DllMain(HANDLE hinstance, DWORD dwReason, LPVOID lpReserved)
{
switch(dwReason)
{
  case DLL_PROCESS_ATTACH:
	DWORD ThreadID;

	HANDLE ThreadHandle = CreateThread
	(
		NULL,											//Choose default security
		0,												//Default stack size
   	 ThreadMain,							//Routine to execute
		NULL,											//Thread parameter (LPVOID)
		0,												//Immediately run the thread
		&ThreadID						   //Thread Id
	);

   MessageBox(NULL, L"From main thread", L"From main thread", MB_OK);
  while(true);
}
}

DWORD WINAPI ThreadMain(LPVOID lpParam)
{
	MessageBox(NULL, L"From new thread", L"From new thread", MB_OK);
	while(true);
}

Only the message box from the main thread is displayed.

Anyone have any ideas? I've used threads before and not had a problem, but never from a DLL so I am wondering if it is something to do with that. I've tried _beginthread, _beginthreadex, CreateThread, etc.

I'm using Win7 64 bit.

Look forward to your response Posted Image

Thanks

#2 SickO

SickO

    Private First Class

  • Members
  • 25 posts

Posted 22 July 2012 - 04:43 AM

What's with the infinite whiles?

#include "win.h"

DWORD WINAPI ThreadMain(LPVOID lpParam);

BOOL APIENTRY DllMain(HANDLE hinstance, DWORD dwReason, LPVOID lpReserved)
{
if(dwReason == DLL_PROCESS_ATTACH)
{
	CreateThread(NULL, NULL, ThreadMain, NULL, NULL, NULL)
	MessageBoxA(0,"Injected",0,0);
  }

else if(dwReason == DLL_PROCESS_DETACH)
{
   MessageBoxA(0,"Detached",0,0);
}

    return false;
}

DWORD WINAPI ThreadMain(LPVOID lpParam)
{
	MessageBoxA(0,"Threaded",0,0);
	return 1;
}






Also tagged with one or more of these keywords: security