欢迎来到 嗅灵易学

零基础也能上手的脚本技术课,一对一答疑带你入门

[原创][10] HEVD 内核漏洞之TypeConfusing

[原创][10] HEVD 内核漏洞之TypeConfusing

0x00 前言

本篇是HEVD系列的最后一篇学习文章,这段时间,通过阅读前人文章,自己分析源码,调试文件,小有收获。分享出来,希望对和我一样的初学者有所帮助。

感谢前人的付出与分享,让新手能很快的上手,握爪。

实验环境:Win10专业版+VMware Workstation 15 Pro+Win7 x86 sp1

实验工具:VS2015+Windbg+KmdManager+DbgViewer

0x01 漏洞原理

本片介绍类型混淆漏洞,类型混淆,顾名思义,通过分析代码逻辑,使得原先不可利用的类型变量或者缓冲区,修改其类型后,使其变得可以利用。

先来看看漏洞函数:

NTSTATUS TriggerTypeConfusion(

    _In_ PUSER_TYPE_CONFUSION_OBJECT UserTypeConfusionObject

)

{

    NTSTATUS Status = STATUS_UNSUCCESSFUL;

    PKERNEL_TYPE_CONFUSION_OBJECT KernelTypeConfusionObject = NULL;

    PAGED_CODE();

    __try

    {

        //

        // Verify if the buffer resides in user mode

        //

        ProbeForRead(

            UserTypeConfusionObject,

            sizeof(USER_TYPE_CONFUSION_OBJECT),

            (ULONG)__alignof(UCHAR)

        );

        //

        // Allocate Pool chunk

        //

        KernelTypeConfusionObject = (PKERNEL_TYPE_CONFUSION_OBJECT)ExAllocatePoolWithTag(

            NonPagedPool,

            sizeof(KERNEL_TYPE_CONFUSION_OBJECT),

            (ULONG)POOL_TAG

        );

        if (!KernelTypeConfusionObject)

        {

            //

            // Unable to allocate Pool chunk

            //

            DbgPrint("[-] Unable to allocate Pool chunk\n");

            Status = STATUS_NO_MEMORY;

            return Status;

        }

        else

        {

            DbgPrint("[+] Pool Tag: %s\n", STRINGIFY(POOL_TAG));

            DbgPrint("[+] Pool Type: %s\n", STRINGIFY(NonPagedPool));

            DbgPrint("[+] Pool Size: 0x%X\n", sizeof(KERNEL_TYPE_CONFUSION_OBJECT));

            DbgPrint("[+] Pool Chunk: 0x%p\n", KernelTypeConfusionObject);

        }

        DbgPrint("[+] UserTypeConfusionObject: 0x%p\n", UserTypeConfusionObject);

        DbgPrint("[+] KernelTypeConfusionObject: 0x%p\n", KernelTypeConfusionObject);

        DbgPrint("[+] KernelTypeConfusionObject Size: 0x%X\n", sizeof(KERNEL_TYPE_CONFUSION_OBJECT));

        KernelTypeConfusionObject->ObjectID = UserTypeConfusionObject->ObjectID;

        KernelTypeConfusionObject->ObjectType = UserTypeConfusionObject->ObjectType;

        DbgPrint("[+] KernelTypeConfusionObject->ObjectID: 0x%p\n", KernelTypeConfusionObject->ObjectID);

        DbgPrint("[+] KernelTypeConfusionObject->ObjectType: 0x%p\n", KernelTypeConfusionObject->ObjectType);

#ifdef SECURE

        //

        // Secure Note: This is secure because the developer is properly setting 'Callback'

        // member of the 'KERNEL_TYPE_CONFUSION_OBJECT' structure before passing the pointer

        // of 'KernelTypeConfusionObject' to 'TypeConfusionObjectInitializer()' function as

        // parameter

        //

        KernelTypeConfusionObject->Callback = &TypeConfusionObjectCallback;

        Status = TypeConfusionObjectInitializer(KernelTypeConfusionObject);

#else

        DbgPrint("[+] Triggering Type Confusion\n");

        //

        // Vulnerability Note: This is a vanilla Type Confusion vulnerability due to improper

        // use of the 'UNION' construct. The developer has not set the 'Callback' member of

        // the 'KERNEL_TYPE_CONFUSION_OBJECT' structure before passing the pointer of

        // 'KernelTypeConfusionObject' to 'TypeConfusionObjectInitializer()' function as

        // parameter

        //

        Status = TypeConfusionObjectInitializer(KernelTypeConfusionObject);

#endif

        DbgPrint("[+] Freeing KernelTypeConfusionObject Object\n");

        DbgPrint("[+] Pool Tag: %s\n", STRINGIFY(POOL_TAG));

        DbgPrint("[+] Pool Chunk: 0x%p\n", KernelTypeConfusionObject);

        //

        // Free the allocated Pool chunk

        //

        ExFreePoolWithTag((PVOID)KernelTypeConfusionObject, (ULONG)POOL_TAG);

        KernelTypeConfusionObject = NULL;

    }

    __except (EXCEPTION_EXECUTE_HANDLER)

    {

        Status = GetExceptionCode();

        DbgPrint("[-] Exception Code: 0x%X\n", Status);

    }

    return Status;

}

注意:上传附件及图片大小不得大于30M。

⚠️ 版权声明:
本博客所有内容(含教程、源码、工具)仅供个人技术学习与研究交流使用,严禁商用、倒卖、二次分发及非法用途
未经作者书面授权,任何组织或个人不得转载、复制或用于其他平台,违者将追究相关责任。

0 0 0 举报
复制成功