...

View Full Version : hook problem



abcdefgqwerty
08-23-2009, 05:25 AM
I have some code I copied from some places like code project and the visual studio 2005 debugger shows all the addresses and that as being valid but its never showing anything in the dll I made that gets injected. My dll to be injected is here C:\\test\\testdll.dll but for some reason I never see the "in dll main" message so something isnt working right. Any ideas?

Code to make thread in target process:


typedef void (*EntryPointfuncPtr)(int argc, const char * argv );

FARPROC GetAddress(HMODULE &hmod);
FARPROC fp=NULL;
char buf[MAX_PATH];

int _tmain(int argc, _TCHAR* argv[])
{
int num=0;
char c;
LUID pl;
TOKEN_PRIVILEGES tp;
HANDLE p=NULL;
HANDLE h;
HMODULE hmod;

fp=GetAddress(hmod);
if(fp==NULL)
{printf("Getaddress didnt work ");}
//printf("address of loadlibrary is: %Xd",fp);

strcpy(buf,"C:\\test\\testdll.dll");

DWORD processid=2276;//GetProcessId((HANDLE)3664);
h=OpenProcess(PROCESS_ALL_ACCESS,false,processid);


if(OpenProcessToken(h,TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&p)==0)
{
printf("Open token failed\n");
}
LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &pl );
DWORD d=GetLastError();
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid.HighPart = pl.HighPart;
tp.Privileges[0].Luid.LowPart= pl.LowPart;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if(!(AdjustTokenPrivileges(p,FALSE,&tp,sizeof(tp),NULL,NULL)))
{
//fail
}


int b=1+strlen(buf);

void *mem=VirtualAllocEx(h,NULL,sizeof(buf),MEM_COMMIT,PAGE_READWRITE);
if(mem==NULL)
{
printf("virtual alloc failed\n");
}

if(!(WriteProcessMemory(h,mem,(void*)buf,sizeof(buf),NULL)))
{
printf("write memory failed\n");
//error
}

HANDLE threadh=CreateRemoteThread(h,NULL,0,(LPTHREAD_START_ROUTINE)fp,mem,0,NULL);
if(threadh==NULL)
{
printf("createthread fail\n");
}

WaitForSingleObject(threadh,INFINITE);

//VirtualFreeEx(h,mem,sizeof(mem),);
CloseHandle(threadh);
CloseHandle(h);

cin>>c;
cin>>c;

return 0;
}

FARPROC GetAddress(HMODULE &hmod)
{
hmod=GetModuleHandle(L"C:\\WINDOWS\\system32\\kernel32.dll");
if(hmod==NULL){printf("getmodulehandle failed");}
return GetProcAddress(hmod,"LoadLibraryA");
}


My dll I am trying to inject:


#include "stdafx.h"
#include <iostream.h>

BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
char c;
cout<<"In dll main\n";

cin>>c;

return TRUE;
}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum