Advertisement
chino

[Sample] RtlAdjustPrivilege

Dec 3rd, 2015
659
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. #define STATUS_SUCCESS ((NTSTATUS)0x00000000L)
  5.  
  6. typedef LONG (WINAPI *RtlAdjustPrivilege)(DWORD, BOOL, INT, PBOOL);
  7.  
  8. int main()
  9. {
  10.  //RtlAdjustPrivilegeはネイティブAPIなのでNtDllより取得
  11.  HMODULE hNtDll = NULL;
  12.  hNtDll = GetModuleHandle("ntdll.dll");
  13.  if(!hNtDll){
  14.   printf("GetModuleHandle failed. ErrorCode:0x%08X\n", GetLastError());
  15.   getchar();
  16.   return 0;
  17.  }
  18.  
  19.  RtlAdjustPrivilege _RtlAdjustPrivilege = NULL;
  20.  
  21.  _RtlAdjustPrivilege = (RtlAdjustPrivilege)GetProcAddress(hNtDll, "RtlAdjustPrivilege");
  22.  if(!_RtlAdjustPrivilege){
  23.   printf("GetProcAddresss failed. ErrorCode:0x%08X\n", GetLastError());
  24.   getchar();
  25.   return 0;
  26.  }
  27.  
  28.  printf("RtlAdjustPrivilege Address:0x%08X\n\n", _RtlAdjustPrivilege);
  29.  
  30.  BOOL bRet;
  31.  NTSTATUS NtStatus = STATUS_SUCCESS;
  32.  //権限の有効、無効を切り替え
  33.  //第二引数:TRUE = 有効 , FALSE = 無効
  34.  NtStatus = _RtlAdjustPrivilege(20L /*SeDebugPrivilege*/, TRUE, 0, &bRet);
  35.  if(NtStatus != STATUS_SUCCESS){
  36.   printf("RtlAdjustPrivilege failed. NtStatus:0x%08X\n", NtStatus);
  37.   getchar();
  38.   return 0;
  39.  }
  40.  
  41.  getchar();
  42.  
  43.  return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement