Windows Search远程代码执行漏洞简单分析及流量侧检测防御思路
本文为看雪论坛精华文章
看雪论坛作者ID:有毒
Windows Search是一个桌面搜索平台,具备对大多数常见文件类型和数据类型的即时搜索功能。 其主要组件是WSearch Windows服务,它负责索引、组织和提取有关本地文件系统的信息。此外,它还实现了Generic Search Service(GSS),可以为搜索查询提供结果所需的后端功能。客户端使用Windows Search Protocol(WSP)向托管GSS的服务器发出查询。WSP依赖于服务器消息块(SMB)命名管道协议进行消息传输和身份验证。
漏洞文件:tquery.dll
漏洞函数:CRegXpr::CRegXpr()
数据对象:一个CPropertyRestriction结构
背景知识:Windows Search、MS-CIFS、MS-SMB
因为是Windows Search的一个漏洞,需要对Windows Search具备一定的了解,此漏洞使用的SMB的途径,所以也要对SMB有一定的了解。
Windows Search Protocol
[ Client ] --------------------> [ Server ] - CPMConnectIn
[ Client ] <-------------------- [ Server ] - CPMConnectOut
[ Client ] --------------------> [ Server ] - CPMCreateQueryIn
[ Client ] <-------------------- [ Server ] - CPMCreateQueryOut
[ Client ] --------------------> [ Server ] - CPMSetBindingsIn request
[ Client ] <-------------------- [ Server ] - CPMSetBindingsIn response
[ Client ] --------------------> [ Server ] - CPMGetRowsIn
[ Client ] <-------------------- [ Server ] - CPMGetRowsOut
[ Client ] --------------------> [ Server ] - CPMGetFreeCursorIn
[ Client ] <-------------------- [ Server ] - CPMGetFreeCursorOut
[ Client ] --------------------> [ Server ] - CPMDisconnect
Offset Size (bytes) Field
--------------------------------------------
0x00 0x4 _msg
0x04 0x4 _status
0x08 0x4 _ulChecksum
0x0c 0x4 _ulReserved2
Offset Size (bytes) Field
--------------------------------------------------------------------
0x00 0x4 Size
0x04 0x1 CColumnSetPresent
0x05 0x3 paddingCColumnSet
0x08 var (w) ColumnSet
0x08 + w 0x1 CRestrictionPresent
0x09 + w var (x) RestrictionArray
0x09 + w + x 0x1 CSortSetPresent
0x0a + w + x 0x3 paddingCCortSet
0x0d + w + x var (y) SortSet
0x0d + w + x + y 0x1 CCategorizationSetPresent
0x0e + w + x + y 0x3 paddingCCategorizationSet
0x11 + w + x + y var (z) CCategorizationSet
0x11 + w + x + y + z 0x14 RowSetProperties
0x25 + w + x + y + z var (m) PidMapper
0x25 + w + x + y + z + m var (n) GroupArray
0x25 + w + x + y + z + m + n 0x4 Lcid
Offset Size(bytes) Field
-------------------------------------------
0x00 0x1 count
0x01 0x1 isPresent
0x02 0x3 padding
0x05 var Restriction
Offset Size(bytes) Field
------------------------------------------
0x00 0x4 ulType
0x04 0x4 Weight
0x08 var Restriction
RTAnd (0x1), Restriction contains a CNodeRestriction structure
RTOr (0x2), Restriction contains a CNodeRestriction structure
RTNot (0x3), Restriction contains a CRestriction structure
RTProximity (0x6), Restriction contains a CNodeRestriction structure
RTVector (0x7), Restriction contains a CVectorRestriction structure
RTCoerce_Add (0xA), Restriction contains a CCoercionRestriction structure
RTCoerce_Multiply (0xB), Restriction contains a CCoercionRestriction structure
RTCoerce_Absolute (0xC), Restriction contains a CCoercionRestriction structure
RTPhrase (0x00FFFFFD), Restriction contains a CNodeRestriction structure
CNodeRestriction:
Offset Size(bytes) Field
----------------------------------------------------------------
0x00 0x4 cNode (number of structures in paNode)
0x04 var paNode (array of CRestriction structures)
CVectorRestriction:
Offset Size (bytes) Field
------------------------------------------------------------
0x00 var (n) pres (CNodeRestriction structure)
0x00 + n 0x3 padding
0x03 0x4 ulRankMethod
CCoercionRestriction:
Offset Size (bytes) Field
-------------------------------------------------------
0x00 0x4 flValue
0x04 var childRes (CRestriction structure)
Offset Size (bytes) Field
------------------------------------------
0x00 0x4 relop
0x04 var (m) Property
0x04 + m var (n) prval
0x04 + m + n 0x3 padding
0x07 + m + n 0x4 lcid
Offset Size (bytes) Field
------------------------------------------
0x00 0x2 vType
0x02 0x1 vData1
0x03 0x1 vData2
0x04 var vValue
但是,在解析正则表达式之前,服务无法验证CBaseStorageVariant对象的类型是否为VT_LPWSTR,这是一个以null结尾的Unicode字符串。如果类型不是VT_LPWSTR,则会发生类型混淆。
远程未经身份验证的攻击者可以通过向目标服务器发送恶意CPMCreateQueryIn消息来利用这些漏洞。成功利用可能会导致在SYSTEM上下文中的目标服务器上执行远程代码。
漏洞触发代码
使用的dll版本为7.0.7601.23861
.text:6EC88B61 push ebx ; struct PDeSerStream *
.text:6EC88B62 lea ecx, [ebp+var_20]
.text:6EC88B65 call ??0CStorageVariant... ; unmarshall prval
.text:6EC88B6A push eax
.text:6EC88B6B mov ecx, edi
.text:6EC88B6D mov byte ptr [ebp+var_4], 3
.text:6EC88B71 call ??4CStorageVariant... ; CStorageVariant::operator=
.text:6ED350B3 cmp eax, 6 ; eax contains relop, check if relop indicates regexp
.text:6ED350B6 jnz short loc_6ED350DE
.text:6ED350B8 push 40h ; unsigned int
.text:6ED350BA call ?ciNew@@YGPAXI@Z ; ciNew(uint)
.text:6ED350BF mov [ebp+arg_0], eax
.text:6ED350C2 mov ecx, [esi+14h]
.text:6ED350C5 mov edx, [esi+10h]
.text:6ED350C8 push ecx
.text:6ED350C9 push edx
.text:6ED350CA push [ebp+arg_4]
.text:6ED350CD mov ecx, eax
.text:6ED350CF push esi
.text:6ED350D0 mov byte ptr [ebp+var_4], 7
.text:6ED350D4 call ??0CRegXpr@@QA... ; CRegXpr(), 解析正则表达式
.text:6ED37ABC push 0A8h ; unsigned int
.text:6ED37AC1 call ?ciNew@@YGPAXI@Z ; ciNew(uint)
.text:6ED37AC6 mov [ebp+var_7C], eax
.text:6ED37AC9 push [ebp+var_78] ; int
.text:6ED37ACC mov ecx, [esi+20h]
.text:6ED37ACF push 0 ; int
.text:6ED37AD1 push [ebp+arg_4] ; int
.text:6ED37AD4 mov byte ptr [ebp+var_4], 6
.text:6ED37AD8 push ecx ; unsigned __int16 *
.text:6ED37AD9 mov ecx, eax
.text:6ED37ADB call ??0CDFA@@Q... ; CDFA::CDFA(), 不检测类型就直接解析vValue
.text:6AF2781E mov dx, [eax] ; eax指向VT_LPWSTR data
.text:6AF27821 inc eax
.text:6AF27822 inc eax
.text:6AF27823 cmp dx, di
.text:6AF27826 jnz short loc_6AF2781E
漏洞触发流
The attacker sends a NEGOTIATE request to the target server:
[ Attacker ] --------------------> [ Target ]
The server responds:
[ Attacker ] <-------------------- [ Target ]
The attacker sends a SESSION_SETUP (NTLMSSP_NEGOTIATE) request to the target server:
[ Attacker ] --------------------> [ Target ]
The server responds:
[ Attacker ] <-------------------- [ Target ]
The attacker sends a SESSION_SETUP (NTLMSSP_AUTH) request to the target server:
[ Attacker ] --------------------> [ Target ]
The server responds:
[ Attacker ] <-------------------- [ Target ]
The attacker sends a TREE_CONNECT request to the target server:
[ Attacker ] --------------------> [ Target ]
The server responds:
[ Attacker ] <-------------------- [ Target ]
The attacker sends a CREATE request to the target server:
[ Attacker ] --------------------> [ Target ]
The server responds:
[ Attacker ] <-------------------- [ Target ]
The attacker sends a CPMConnectIn message to the target server:
[ Attacker ] --------------------> [ Target ]
The server responds with a CPMConnectOut message:
[ Attacker ] <-------------------- [ Target ]
The attacker sends a CPMCreateQueryIn message to the target server:
[ Attacker ] --------------------> [ Target ]
The server responds with a CPMCreateQueryOut message:
[ Attacker ] <-------------------- [ Target ]
Offset Size (bytes) Field
-----------------------------------------------------------
0x00 0x1 WordCount
0x01 0x1 AndXCommand
0x02 0x1 AndXReserved
0x03 0x2 AndXOffset
0x04 0x1 Reserved
0x05 0x2 NameLength
0x07 0x4 Flags
0x0b 0x4 RootDirectoryFID
0x0f 0x4 DesiredAccess
0x13 0x8 AllocationSize
0x1b 0x4 ExtFileAttributesMicrosoft Research Service 20
0x1f 0x4 ShareAccess
0x23 0x4 CreateDisposition
0x27 0x4 CreateOptions
0x2b 0x4 ImpersonationLevel
0x2f 0x1 SecurityFlags
0x30 0x2 ByteCount
0x32 var FileName
• SMB_COM_NT_TRANSACT with NT_TRANSACT_CREATE subcommand
• SMB_COM_TRANSACTION2 with TRANS2_OPEN2 subcommand
• SMB_COM_OPEN (deprecated)
• SMB_COM_OPEN_ANDX (deprecated)
• SMB_COM_TRANSACTION with TRANS_CALL_NMPIPE subcommand (obsolescent)
• SMB_COM_WRITE
• SMB_COM_WRITE_AND_UNLOCK
• SMB_COM_WRITE_RAW
• SMB_COM_WRITE_MPX
• SMB_COM_WRITE_AND_CLOSE
• SMB_COM_WRITE_ANDX
• SMB_COM_WRITE_PRINT_FILE
• SMB_COM_TRANSACTION (TRANS_RAW_WRITE_NMPIPE)
• SMB_COM_TRANSACTION (TRANS_WRITE_NMPIPE)
Offset Size (bytes) Field
-------------------------------------------
0x00 0x1 count
0x01 0x1 isPresent
0x02 0x3 padding
0x05 var Restriction
Offset Size (bytes) Field
------------------------------------------
0x00 0x4 ulType
0x04 0x4 Weight
0x08 var Restriction
• RTAnd (0x1), Restriction contains a CNodeRestriction structure
• RTOr (0x2), Restriction contains a CNodeRestriction structure
• RTNot (0x3), Restriction contains a CRestriction structure
• RTVector (0x7), Restriction contains a CVectorRestriction structure
• RTCoerce_Add (0xA), Restriction contains a CCoercionRestriction structure
• RTCoerce_Multiply (0xB), Restriction contains a CCoercionRestriction structure
• RTCoerce_Absolute (0xC), Restriction contains a CCoercionRestriction structure
如果设备找到嵌套的CRestriction,则它必须递归检查ulType for RTProperty(0x5)或任何可能的递归类型。
- End -
看雪ID:有毒
https://bbs.pediy.com/user-779730.htm
进阶安全圈,不得不读的一本书
推荐文章++++
* Linux Kernel Exploit 内核漏洞学习(3)-Bypass-Smep
﹀
﹀
﹀
官方微博:看雪安全
商务合作请发邮件至:wsc@kanxue.com