Skip to content

Commit

Permalink
add debug privileges
Browse files Browse the repository at this point in the history
  • Loading branch information
dumbasPL committed Sep 29, 2023
1 parent bb3009c commit b068bfc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/stage1/fumo_preloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define ERR_STAGE1_SUCCESS 0
#define ERR_STAGE1_INVALID_ARGS 1
#define ERR_STAGE1_FAILED_TO_OPEN_FILE 2
#define ERR_STAGE1_FAILED_TO_GET_DEBUG_PRIVILEGES 3
#define ERR_STAGE1_UNSUPPORTED_OS 50
#define ERR_STAGE1_HVCI_ENABLED 51
#define ERR_STAGE1_FAILED_TO_MAP_DRIVER 100
Expand Down
28 changes: 28 additions & 0 deletions src/stage1/stage1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@
#include <filesystem>
#include <fstream>

bool get_debug_privileges() {
HANDLE token;
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
return false;

LUID luid;
if (!LookupPrivilegeValue(NULL, SE_DEBUG_NAME, &luid)) {
CloseHandle(token);
return false;
}

TOKEN_PRIVILEGES privileges;
privileges.PrivilegeCount = 1;
privileges.Privileges[0].Luid = luid;
privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

if (!AdjustTokenPrivileges(token, FALSE, &privileges, sizeof(privileges), NULL, NULL)) {
CloseHandle(token);
return false;
}

CloseHandle(token);
return true;
}

int main(PFUMO_EMBEDDED_DATA embedded_data) {
std::vector<BYTE> fumo_data;
std::wstring fumo_file_path;
Expand Down Expand Up @@ -56,6 +81,9 @@ int main(PFUMO_EMBEDDED_DATA embedded_data) {
if (isHvciEnabled())
return fumo::error(ERR_STAGE1_HVCI_ENABLED, L"HyperVisor Code Integrity (HVCI) is enabled, please disable it and try again");

if(!get_debug_privileges())
return fumo::error(ERR_STAGE1_FAILED_TO_GET_DEBUG_PRIVILEGES, L"Failed to get debug privileges");

auto error = init_driver(osv.dwBuildNumber);
if (error != ERR_STAGE1_SUCCESS)
return error;
Expand Down

0 comments on commit b068bfc

Please sign in to comment.