R
Raghu P S
Guest
DLL or EXE is not writing into the VirtualAllocEx() function allocated memory address
//Allocate new memory region inside the process's address space.
LPVOID arg = (LPVOID)VirtualAllocEx(process, NULL, strlen(buffer), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if(arg == NULL) {
printf("Error: the memory could not be allocated inside the chosen process.\n");
return 1;
}
//BOOL vRet = VirtualProtectEx(process, arg, strlen(buffer), PAGE_EXECUTE_READWRITE, );
//Get address of the LoadLibrary function.
LPVOID address = (LPVOID)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryA");
if(address == NULL) {
printf("Error: the LoadLibraryA function was not found inside kernel32.dll library.\n");
return 1;
}
//Write the argument to LoadLibraryA to the process's newly allocated memory region.
int n = WriteProcessMemory(process, arg, buffer, strlen(buffer), NULL);
if(n == 0) {
printf("Error: there was no bytes written to the process's address space.\n");
return 1;
}
//Inject our DLL into the process's address space.
HANDLE threadID = CreateRemoteThread(process, NULL, 0, (LPTHREAD_START_ROUTINE)address, arg, NULL, NULL);
if(threadID == NULL) {
printf("Error: the remote thread could not be created.\n");
return 1;
}
else {
printf("Success: the remote thread was successfully created.\n");
}
Basically I think DLL should store in the address return by VirtualAllocEx() function but DLL is storing in some other address.
Anything missing my code?
Continue reading...
//Allocate new memory region inside the process's address space.
LPVOID arg = (LPVOID)VirtualAllocEx(process, NULL, strlen(buffer), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
if(arg == NULL) {
printf("Error: the memory could not be allocated inside the chosen process.\n");
return 1;
}
//BOOL vRet = VirtualProtectEx(process, arg, strlen(buffer), PAGE_EXECUTE_READWRITE, );
//Get address of the LoadLibrary function.
LPVOID address = (LPVOID)GetProcAddress(GetModuleHandle(L"kernel32.dll"), "LoadLibraryA");
if(address == NULL) {
printf("Error: the LoadLibraryA function was not found inside kernel32.dll library.\n");
return 1;
}
//Write the argument to LoadLibraryA to the process's newly allocated memory region.
int n = WriteProcessMemory(process, arg, buffer, strlen(buffer), NULL);
if(n == 0) {
printf("Error: there was no bytes written to the process's address space.\n");
return 1;
}
//Inject our DLL into the process's address space.
HANDLE threadID = CreateRemoteThread(process, NULL, 0, (LPTHREAD_START_ROUTINE)address, arg, NULL, NULL);
if(threadID == NULL) {
printf("Error: the remote thread could not be created.\n");
return 1;
}
else {
printf("Success: the remote thread was successfully created.\n");
}
Basically I think DLL should store in the address return by VirtualAllocEx() function but DLL is storing in some other address.
Anything missing my code?
Continue reading...