Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.0 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define STACKSIZE 32768
  5. void DebugPriv(void)
  6. {
  7. PTOKEN_PRIVILEGES pp;
  8. PTOKEN_PRIVILEGES ppNew;
  9. HANDLE hToken;
  10. UCHAR ucPriv[sizeof(TOKEN_PRIVILEGES) + sizeof(LUID_AND_ATTRIBUTES)];
  11. UCHAR ucPrivNew[sizeof(ucPriv)];
  12. DWORD cb;
  13. if (OpenProcessToken(GetCurrentProcess(), MAXIMUM_ALLOWED, &hToken))
  14. {
  15. pp = (PTOKEN_PRIVILEGES)ucPriv;
  16. pp->PrivilegeCount = 1;
  17. pp->Privileges[0].Luid.LowPart = 20L;
  18. pp->Privileges[0].Luid.HighPart = 0;
  19. pp->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
  20. ppNew = (PTOKEN_PRIVILEGES)ucPrivNew ;
  21. AdjustTokenPrivileges(hToken, FALSE, pp, sizeof(ucPrivNew), ppNew, &cb);
  22. CloseHandle(hToken);
  23. }
  24. }
  25. int __cdecl main(int argc, char **argv)
  26. {
  27. LPTHREAD_START_ROUTINE pfnDBP = NULL;
  28. HMODULE hmodntdll;
  29. HANDLE hProcess;
  30. HANDLE hThread;
  31. ULONG ProcessId;
  32. ULONG ThreadId;
  33. if (argc < 2 || argc > 3)
  34. {
  35. fprintf(stderr, "usage: nukeapp <pid> [-breakin]\n");
  36. return 1;
  37. }
  38. ProcessId = atoi(argv[1]);
  39. if (ProcessId == 0)
  40. {
  41. fprintf(stderr, "usage: nukeapp <pid> [-breakin]\n");
  42. return 1;
  43. }
  44. DebugPriv();
  45. hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ProcessId);
  46. if (hProcess != NULL)
  47. {
  48. hmodntdll = GetModuleHandle("ntdll.dll");
  49. if (hmodntdll != NULL)
  50. {
  51. if (argc == 3 && _strcmpi(argv[2], "-breakin") == 0)
  52. pfnDBP = (LPTHREAD_START_ROUTINE)GetProcAddress(hmodntdll, "DbgBreakPoint");
  53. hThread = CreateRemoteThread(hProcess, NULL, STACKSIZE, pfnDBP, NULL, 0, &ThreadId);
  54. if (hThread == NULL)
  55. fprintf(stderr, "Unable to create remote thread.\n");
  56. }
  57. }
  58. else
  59. {
  60. fprintf(stderr, "Unable to open process.\n");
  61. }
  62. return 0;
  63. }