chino icon

[Sample] RtlAdjustPrivilege

chino | PRO | 12/03/15 04:50:21 PM UTC | 0 ⭐ | 10703 👁️ | Never ⏰ | []
C++ (WinAPI) |

0 B

|

None

|

0 👍

/

0 👎

#include <windows.h>
#include <stdio.h>
 
#define STATUS_SUCCESS ((NTSTATUS)0x00000000L) 
 
typedef LONG (WINAPI *RtlAdjustPrivilege)(DWORD, BOOL, INT, PBOOL);
 
int main()
{
 //RtlAdjustPrivilegeはネイティブAPIなのでNtDllより取得
 HMODULE hNtDll = NULL;
 hNtDll = GetModuleHandle("ntdll.dll");
 if(!hNtDll){
  printf("GetModuleHandle failed. ErrorCode:0x%08X\n", GetLastError());
  getchar();
  return 0;
 }
 
 RtlAdjustPrivilege _RtlAdjustPrivilege = NULL;
 
 _RtlAdjustPrivilege = (RtlAdjustPrivilege)GetProcAddress(hNtDll, "RtlAdjustPrivilege");
 if(!_RtlAdjustPrivilege){
  printf("GetProcAddresss failed. ErrorCode:0x%08X\n", GetLastError());
  getchar();
  return 0;
 }
 
 printf("RtlAdjustPrivilege Address:0x%08X\n\n", _RtlAdjustPrivilege);
 
 BOOL bRet;
 NTSTATUS NtStatus = STATUS_SUCCESS;
 //権限の有効、無効を切り替え
 //第二引数:TRUE = 有効 , FALSE = 無効
 NtStatus = _RtlAdjustPrivilege(20L /*SeDebugPrivilege*/, TRUE, 0, &bRet);
 if(NtStatus != STATUS_SUCCESS){
  printf("RtlAdjustPrivilege failed. NtStatus:0x%08X\n", NtStatus);
  getchar();
  return 0;
 }
  
 getchar();
 
 return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎