前言: 今天逆向一个非常实用的函数RtlAdjustPrivliege
Enable [In] If TRUE, then enable the privilege otherwise disable. CurrentThread [In] If TRUE, then enable in calling thread, otherwise process. Enabled [Out] Whether privilege was previously enabled or disabled.
BOOL ImproveProcPriv() 看看吧,这个提权快要累死了... 但是 如果有这个函数就不一样了,你可以只用一个函数就实现这个功能,甚至功能远多于上面的代码... 通过恰当的IDE设置和必要的Defination,上面这个函数的功能你完全可以通过一行代码来实现。
正文: 下面我们看一下这个函数是怎么运行的,顺便学习下强大的IDA
判断是调整进程权限还是线程权限, CurrentThread == FALSE 然后两个代码块同时指向这里 若 执行成功
若 OldState == 0 则 这个函数大致流程就是这样。 到这里差不多可以按一下传说中的F5了
int __stdcall RtlAdjustPrivilege(int Privilege, char Enable, char CurrentThread, int Enabled) { int result; // eax@2 signed int AdjustResult; // esi@4 char returnValue; // al@7 int v7; // [sp+2Ch] [bp-4h]@1 int IsEnabled; // [sp+4h] [bp-2Ch]@1 int TokenHandle; // [sp+8h] [bp-28h]@2 int dwPrivilege; // [sp+20h] [bp-10h]@4 signed int NewState; // [sp+1Ch] [bp-14h]@4 int v12; // [sp+24h] [bp-Ch]@4 int v13; // [sp+28h] [bp-8h]@4 int OldState; // [sp+Ch] [bp-24h]@4 char ReturnLength; // [sp+0h] [bp-30h]@4 unsigned int v16; // [sp+18h] [bp-18h]@11 v7 = dword_7C97B0C8; IsEnabled = Enabled; if ( CurrentThread == 1 ) result = ZwOpenThreadToken(-2, 40, 0, &TokenHandle); else result = NtOpenProcessToken(-1, 40, &TokenHandle); if ( result >= 0 ) { dwPrivilege = Privilege; NewState = 1; v12 = 0; v13 = -(Enable != 0) & 2; AdjustResult = NtAdjustPrivilegesToken(TokenHandle, 0, &NewState, 16, &OldState, &ReturnLength); ZwClose(TokenHandle); if ( AdjustResult == 262 ) AdjustResult = -1073741727; if ( AdjustResult >= 0 ) { if ( OldState ) returnValue = (v16 >> 1) & 1; else returnValue = Enable; *(_BYTE *)IsEnabled = returnValue; } result = AdjustResult; } return result; } 可读性好像仍然不高,看看这个...
/******************************************************************************
* RtlAdjustPrivilege [NTDLL.@] * * Enables or disables a privilege from the calling thread or process. * * PARAMS * Privilege [I] Privilege index to change. * Enable [I] If TRUE, then enable the privilege otherwise disable. * CurrentThread [I] If TRUE, then enable in calling thread, otherwise process. * Enabled [O] Whether privilege was previously enabled or disabled. * * RETURNS * Success: STATUS_SUCCESS. * Failure: NTSTATUS code. * * SEE ALSO * NtAdjustPrivilegesToken, NtOpenThreadToken, NtOpenProcessToken. * */ NTSTATUS WINAPI RtlAdjustPrivilege(ULONG Privilege, BOOLEAN Enable, BOOLEAN CurrentThread, PBOOLEAN Enabled) { TOKEN_PRIVILEGES NewState; TOKEN_PRIVILEGES OldState; ULONG ReturnLength; HANDLE TokenHandle; NTSTATUS Status; TRACE("(%d, %s, %s, %p)/n", Privilege, Enable ? "TRUE" : "FALSE", CurrentThread ? "TRUE" : "FALSE", Enabled); if (CurrentThread) { Status = NtOpenThreadToken(GetCurrentThread(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, FALSE, &TokenHandle); } else { Status = NtOpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &TokenHandle); } if (!NT_SUCCESS(Status)) { WARN("Retrieving token handle failed (Status %x)/n", Status); return Status; } OldState.PrivilegeCount = 1; NewState.PrivilegeCount = 1; NewState.Privileges[0].Luid.LowPart = Privilege; NewState.Privileges[0].Luid.HighPart = 0; NewState.Privileges[0].Attributes = (Enable) ? SE_PRIVILEGE_ENABLED : 0; Status = NtAdjustPrivilegesToken(TokenHandle, FALSE, &NewState, sizeof(TOKEN_PRIVILEGES), &OldState, &ReturnLength); NtClose (TokenHandle); if (Status == STATUS_NOT_ALL_ASSIGNED) { TRACE("Failed to assign all privileges/n"); return STATUS_PRIVILEGE_NOT_HELD; } if (!NT_SUCCESS(Status)) { WARN("NtAdjustPrivilegesToken() failed (Status %x)/n", Status); return Status; } if (OldState.PrivilegeCount == 0) *Enabled = Enable; else *Enabled = (OldState.Privileges[0].Attributes & SE_PRIVILEGE_ENABLED); return STATUS_SUCCESS; } |
不能说的秘密之RtlAdjustPrivilege
最新推荐文章于 2024-05-12 05:52:30 发布