Anonymous
Доступ запрещен для удаленного создания потоков с помощью Windows API
Сообщение
Anonymous » 10 май 2024, 02:36
Я пытаюсь аварийно завершить работу своих процессов в блокноте. Я написал следующий код:
Код: Выделить всё
#include
#include
int main(int argc, char *argv[])
{
if (argc < 2) {
printf("mssing argument \n");
return EXIT_FAILURE;
}
HANDLE hProcess, hThread = NULL;
BOOL bWrite;
LPVOID lValloc;
LPCVOID lpBuffer = "\x41\x41\x41\x41\x41";
DWORD PID = atoi(argv[1]), TID = atoi(argv[1]);
printf("pid is %ld\n", PID);
hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
if (hProcess == NULL) {
printf("Impossible to access process, error code :%ld\n", GetLastError());
return EXIT_FAILURE;
}
lValloc = VirtualAllocEx(hProcess, NULL, sizeof(lpBuffer), (MEM_COMMIT | MEM_RESERVE), PAGE_EXECUTE_READWRITE);
if (lValloc == NULL) {
printf("Impossible to allocate memory, error code : %ld", GetLastError());
return EXIT_FAILURE;
}
bWrite = WriteProcessMemory(hProcess, lValloc, lpBuffer, sizeof(lpBuffer), NULL);
if(bWrite == 0){
printf("Impossible to write in memory, error code : %ld\n", GetLastError());
return EXIT_FAILURE;
}
hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)lValloc, NULL, 0, &TID);
if(hThread == NULL) {
printf("CreateRemoteThread failed, error code: %ld\n", GetLastError());
CloseHandle(hProcess);
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Когда я выполняю код с pid, у меня возникает следующая ошибка:
Код: Выделить всё
C:\Users\vbrain\source\repos\malware>a.exe 19236
pid is 19236
CreateRemoteThread failed, error code: 5
Я действительно проверил, с чем связана эта ошибка 5. Кажется, это ERROR_ACCESS_DENIED
Однако я указал правильный доступ: PAGE_EXECUTE_READWRITE
Что мне не хватает?
Подробнее здесь:
https://stackoverflow.com/questions/784 ... indows-api
1715297763
Anonymous
Я пытаюсь аварийно завершить работу своих процессов в блокноте. Я написал следующий код: [code]#include #include int main(int argc, char *argv[]) { if (argc < 2) { printf("mssing argument \n"); return EXIT_FAILURE; } HANDLE hProcess, hThread = NULL; BOOL bWrite; LPVOID lValloc; LPCVOID lpBuffer = "\x41\x41\x41\x41\x41"; DWORD PID = atoi(argv[1]), TID = atoi(argv[1]); printf("pid is %ld\n", PID); hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID); if (hProcess == NULL) { printf("Impossible to access process, error code :%ld\n", GetLastError()); return EXIT_FAILURE; } lValloc = VirtualAllocEx(hProcess, NULL, sizeof(lpBuffer), (MEM_COMMIT | MEM_RESERVE), PAGE_EXECUTE_READWRITE); if (lValloc == NULL) { printf("Impossible to allocate memory, error code : %ld", GetLastError()); return EXIT_FAILURE; } bWrite = WriteProcessMemory(hProcess, lValloc, lpBuffer, sizeof(lpBuffer), NULL); if(bWrite == 0){ printf("Impossible to write in memory, error code : %ld\n", GetLastError()); return EXIT_FAILURE; } hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)lValloc, NULL, 0, &TID); if(hThread == NULL) { printf("CreateRemoteThread failed, error code: %ld\n", GetLastError()); CloseHandle(hProcess); return EXIT_FAILURE; } return EXIT_SUCCESS; } [/code] Когда я выполняю код с pid, у меня возникает следующая ошибка: [code]C:\Users\vbrain\source\repos\malware>a.exe 19236 pid is 19236 CreateRemoteThread failed, error code: 5 [/code] Я действительно проверил, с чем связана эта ошибка 5. Кажется, это ERROR_ACCESS_DENIED Однако я указал правильный доступ: PAGE_EXECUTE_READWRITE Что мне не хватает? Подробнее здесь: [url]https://stackoverflow.com/questions/78457356/access-denied-for-remote-thread-creation-with-windows-api[/url]