目标 我正在尝试一个简单的shellcode练习-使用CreateRemoteThread在远程进程上调用“ OutputDebugStringA”,它将激活一个shellcode-此练习没有dll注入!
问题 我不知道“ OutputDebugStringA”在远程进程中的地址,仅在本地进程中。
到目前为止我一直在尝试什么
int main() {
char ShellCode[] = "\x48\x8d\x0c\x25\x10\x9c\x8c\x4c\xff\x14\x25\x00\x01\x8d\x4c";
/*
* Get process handle passing in the process ID.
*/
int32_t nProcID = 21440;
const HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, nProcID);
if (NULL == hProcess) {
printf("Error: the specified process couldn't be found.\n");
}
const LPVOID arg = (LPVOID)VirtualAllocEx(hProcess, NULL, sizeof(ShellCode), MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (NULL == arg) {
int32_t nLastErrorCode = GetLastError();
printf("Error: the memory could not be allocated inside the chosen process. Error code - %d.\n", nLastErrorCode);
}
const int32_t nBytesWritten = WriteProcessMemory(hProcess, arg, ShellCode, sizeof(ShellCode), NULL);
if (0 == nBytesWritten) {
int32_t nLastErrorCode = GetLastError();
printf("Error: there was no bytes written to the process's address space. Error code - %d.\n", nLastErrorCode);
}
const HANDLE hThreadID = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)arg , NULL, NULL, NULL);
if (NULL == hThreadID) {
int32_t nLastErrorCode = GetLastError();
printf("Error: the remote thread could not be created. Error code - %d.\n", nLastErrorCode);
}
else {
printf("Success: the remote thread was successfully created.\n");
}
/*
* Close the handle to the process, because we've already injected the DLL.
*/
CloseHandle(hProcess);
getchar();
return 0;
}
我尝试过的事情 分解OutputDebugStringA picture1 然后将其在线转换为shellcode,然后使用新的shellcode调用我的代码。但是远程过程并不熟悉这些地址。
答案 0 :(得分:-1)
如果您唯一想知道的是OutputDebugStringA
的地址(假设您的shellcode确实有效),则该地址与当前进程相同。因此,您可以通过执行LPVOID function_addr = reinterpret_cast<LPVOID>(GetProcAddress(GetModuleHandleA("kernel32.dll"), "OutputDebugStringA"));
来获得它,然后根据需要使用function_addr
。
由于kernel32.dll
在每个进程中都有相同的基地址,因此相对虚拟地址将相同,因此该地址也将相同。