Leaked source code of windows server 2003
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.

131 lines
3.1 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define STACKSIZE 32768
  5. typedef BOOL (* LPDEBUG_BREAK_PROCESS_ROUTINE) (
  6. HANDLE Process
  7. );
  8. VOID
  9. DebugPriv(
  10. VOID
  11. )
  12. {
  13. HANDLE Token ;
  14. UCHAR Buf[ sizeof( TOKEN_PRIVILEGES ) + sizeof( LUID_AND_ATTRIBUTES ) ];
  15. PTOKEN_PRIVILEGES Privs ;
  16. if (OpenProcessToken( GetCurrentProcess(),
  17. MAXIMUM_ALLOWED,
  18. &Token )) {
  19. Privs = (PTOKEN_PRIVILEGES) Buf ;
  20. Privs->PrivilegeCount = 1 ;
  21. Privs->Privileges[0].Luid.LowPart = 20L ;
  22. Privs->Privileges[0].Luid.HighPart = 0 ;
  23. Privs->Privileges[0].Attributes = SE_PRIVILEGE_ENABLED ;
  24. AdjustTokenPrivileges( Token,
  25. FALSE,
  26. Privs,
  27. 0,
  28. NULL,
  29. NULL );
  30. CloseHandle( Token );
  31. }
  32. }
  33. int
  34. __cdecl
  35. main(
  36. int argc,
  37. char **argv
  38. )
  39. {
  40. LPTHREAD_START_ROUTINE DbgBreakPoint;
  41. LPDEBUG_BREAK_PROCESS_ROUTINE DebugBreakProcessRoutine;
  42. HANDLE ntdll, kernel32;
  43. ULONG ProcessId;
  44. ULONG ThreadId;
  45. HANDLE Process;
  46. HANDLE Thread;
  47. if (argc != 2) {
  48. usage:
  49. fprintf(stderr, "usage: breakin <pid>\n");
  50. exit(1);
  51. }
  52. ProcessId = atoi(argv[1]);
  53. if (ProcessId == 0) {
  54. goto usage;
  55. }
  56. DebugPriv();
  57. Process = OpenProcess(
  58. PROCESS_ALL_ACCESS,
  59. FALSE,
  60. ProcessId
  61. );
  62. if (Process) {
  63. kernel32 = GetModuleHandle("kernel32.dll");
  64. if (kernel32) {
  65. DebugBreakProcessRoutine = (LPDEBUG_BREAK_PROCESS_ROUTINE)GetProcAddress(kernel32, "DebugBreakProcess");
  66. if (DebugBreakProcessRoutine) {
  67. if (!(*DebugBreakProcessRoutine)(Process)) {
  68. printf("DebugBreakProcess failed %d\n", GetLastError());
  69. }
  70. CloseHandle(Process);
  71. return 0;
  72. }
  73. }
  74. ntdll = GetModuleHandle("ntdll.dll");
  75. if (ntdll) {
  76. DbgBreakPoint = (LPTHREAD_START_ROUTINE)GetProcAddress(ntdll, "DbgBreakPoint");
  77. if (DbgBreakPoint) {
  78. Thread = CreateRemoteThread(
  79. Process,
  80. NULL,
  81. STACKSIZE,
  82. DbgBreakPoint,
  83. NULL,
  84. 0,
  85. &ThreadId
  86. );
  87. if (Thread){
  88. CloseHandle(Thread);
  89. }
  90. }
  91. }
  92. CloseHandle(Process);
  93. } else {
  94. printf("Open process failed %d\n", GetLastError());
  95. }
  96. return 0;
  97. }