Office ํŒŒ์ผ ๋ถ„์„

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ

์ถ”๊ฐ€ ์ •๋ณด๋Š” https://trailofbits.github.io/ctf/forensics/๋ฅผ ํ™•์ธํ•˜์„ธ์š”. ์ด๊ฒƒ์€ ์š”์•ฝ์ž…๋‹ˆ๋‹ค:

Microsoft๋Š” ์—ฌ๋Ÿฌ ์˜คํ”ผ์Šค ๋ฌธ์„œ ํฌ๋งท์„ ๋งŒ๋“ค์—ˆ์œผ๋ฉฐ, ์ฃผ์š”ํ•œ ๋‘ ๊ฐ€์ง€ ์œ ํ˜•์€ OLE formats(์˜ˆ: RTF, DOC, XLS, PPT)์™€ Office Open XML (OOXML) formats(์˜ˆ: DOCX, XLSX, PPTX)์ž…๋‹ˆ๋‹ค. ์ด ํฌ๋งท๋“ค์€ ๋งคํฌ๋กœ๋ฅผ ํฌํ•จํ•  ์ˆ˜ ์žˆ์–ด ํ”ผ์‹ฑ ๋ฐ ๋ฉ€์›จ์–ด์˜ ํ‘œ์ ์ด ๋ฉ๋‹ˆ๋‹ค. OOXML ํŒŒ์ผ์€ zip ์ปจํ…Œ์ด๋„ˆ ๊ตฌ์กฐ๋กœ ๋˜์–ด ์žˆ์–ด ์••์ถ•์„ ํ’€์–ด ํŒŒ์ผ/ํด๋” ๊ณ„์ธต๊ณผ XML ํŒŒ์ผ ๋‚ด์šฉ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

OOXML ํŒŒ์ผ ๊ตฌ์กฐ๋ฅผ ํƒ์ƒ‰ํ•˜๊ธฐ ์œ„ํ•ด ๋ฌธ์„œ์˜ ์••์ถ•์„ ํ‘ธ๋Š” ๋ช…๋ น๊ณผ ์ถœ๋ ฅ ๊ตฌ์กฐ๊ฐ€ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ํŒŒ์ผ๋“ค์— ๋ฐ์ดํ„ฐ๋ฅผ ์ˆจ๊ธฐ๋Š” ๊ธฐ๋ฒ•๋“ค์ด ๋ฌธ์„œํ™”๋˜์–ด ์žˆ์œผ๋ฉฐ, ์ด๋Š” CTF ์ฑŒ๋ฆฐ์ง€ ๋‚ด์—์„œ ๋ฐ์ดํ„ฐ ์€๋‹‰ ๋ฐฉ๋ฒ•์˜ ์ง€์†์ ์ธ ํ˜์‹ ์„ ๋ณด์—ฌ์ค๋‹ˆ๋‹ค.

๋ถ„์„์„ ์œ„ํ•ด oletools์™€ OfficeDissector๋Š” OLE ๋ฐ OOXML ๋ฌธ์„œ๋ฅผ ๊ฒ€์‚ฌํ•˜๊ธฐ ์œ„ํ•œ ํฌ๊ด„์ ์ธ ํˆด์…‹์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ด ๋„๊ตฌ๋“ค์€ ์ž„๋ฒ ๋””๋“œ ๋งคํฌ๋กœ๋ฅผ ์‹๋ณ„ํ•˜๊ณ  ๋ถ„์„ํ•˜๋Š” ๋ฐ ๋„์›€์„ ์ฃผ๋ฉฐ, ์ž„๋ฒ ๋””๋“œ ๋งคํฌ๋กœ๋Š” ์ข…์ข… ์ถ”๊ฐ€ ์•…์„ฑ ํŽ˜์ด๋กœ๋“œ๋ฅผ ๋‹ค์šด๋กœ๋“œํ•˜๊ณ  ์‹คํ–‰ํ•˜๋Š” ๋ฉ€์›จ์–ด ์ „๋‹ฌ ๋ฒกํ„ฐ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. VBA ๋งคํฌ๋กœ์˜ ๋ถ„์„์€ Microsoft Office ์—†์ด๋„ Libre Office๋ฅผ ์‚ฌ์šฉํ•ด ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, Libre Office๋Š” ์ค‘๋‹จ์ (breakpoints)๊ณผ ์›Œ์น˜ ๋ณ€์ˆ˜(watch variables)๋ฅผ ์‚ฌ์šฉํ•œ ๋””๋ฒ„๊น…์„ ํ—ˆ์šฉํ•ฉ๋‹ˆ๋‹ค.

oletools์˜ ์„ค์น˜ ๋ฐ ์‚ฌ์šฉ์€ ๊ฐ„๋‹จํ•˜๋ฉฐ, pip๋กœ ์„ค์น˜ํ•˜๋Š” ๋ช…๋ น๊ณผ ๋ฌธ์„œ์—์„œ ๋งคํฌ๋กœ๋ฅผ ์ถ”์ถœํ•˜๋Š” ๋ช…๋ น์ด ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. ๋งคํฌ๋กœ์˜ ์ž๋™ ์‹คํ–‰์€ AutoOpen, AutoExec ๋˜๋Š” Document_Open ๊ฐ™์€ ํ•จ์ˆ˜๋“ค์— ์˜ํ•ด ํŠธ๋ฆฌ๊ฑฐ๋ฉ๋‹ˆ๋‹ค.

sudo pip3 install -U oletools
olevba -c /path/to/document #Extract macros

OLE Compound File exploitation: Autodesk Revit RFA โ€“ ECC recomputation and controlled gzip

Revit RFA models are stored as an OLE Compound File (aka CFBF). The serialized model is under storage/stream:

  • Storage: Global
  • Stream: Latest โ†’ Global\Latest

Key layout of Global\Latest (observed on Revit 2025):

  • ํ—ค๋”
  • GZIP-compressed payload (์‹ค์ œ ์ง๋ ฌํ™”๋œ ๊ฐ์ฒด ๊ทธ๋ž˜ํ”„)
  • ์ œ๋กœ ํŒจ๋”ฉ
  • Error-Correcting Code (ECC) ํŠธ๋ ˆ์ผ๋Ÿฌ

Revit๋Š” ECC ํŠธ๋ ˆ์ผ๋Ÿฌ๋ฅผ ์‚ฌ์šฉํ•ด ์ŠคํŠธ๋ฆผ์˜ ์ž‘์€ ๋ณ€ํ˜•์„ ์ž๋™ ๋ณต๊ตฌํ•˜์ง€๋งŒ, ECC์™€ ์ผ์น˜ํ•˜์ง€ ์•Š๋Š” ์ŠคํŠธ๋ฆผ์€ ๊ฑฐ๋ถ€ํ•ฉ๋‹ˆ๋‹ค. ๋”ฐ๋ผ์„œ ์••์ถ•๋œ ๋ฐ”์ดํŠธ๋ฅผ ๋‹จ์ˆœํžˆ ํŽธ์ง‘ํ•ด๋„ ๋ณ€๊ฒฝ์ด ์œ ์ง€๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค: ๋ณ€๊ฒฝ์ด ๋˜๋Œ๋ ค์ง€๊ฑฐ๋‚˜ ํŒŒ์ผ์ด ๊ฑฐ๋ถ€๋ฉ๋‹ˆ๋‹ค. ์—ญ์ง๋ ฌํ™”๊ธฐ๊ฐ€ ๋ณด๋Š” ๋‚ด์šฉ์„ ๋ฐ”์ดํŠธ ๋‹จ์œ„๋กœ ์ •ํ™•ํžˆ ์ œ์–ดํ•˜๋ ค๋ฉด ๋‹ค์Œ์„ ์ˆ˜ํ–‰ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค:

  • Revit๊ณผ ํ˜ธํ™˜๋˜๋Š” gzip ๊ตฌํ˜„์œผ๋กœ ๋‹ค์‹œ ์••์ถ•(so the compressed bytes Revit produces/accepts match what it expects).
  • ํŒจ๋”ฉ๋œ ์ŠคํŠธ๋ฆผ์— ๋Œ€ํ•ด ECC ํŠธ๋ ˆ์ผ๋Ÿฌ๋ฅผ ์žฌ๊ณ„์‚ฐํ•˜์—ฌ Revit์ด ์ž๋™ ๋ณต๊ตฌ ์—†์ด ์ˆ˜์ •๋œ ์ŠคํŠธ๋ฆผ์„ ์ˆ˜๋ฝํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

Practical workflow for patching/fuzzing RFA contents:

  1. Expand the OLE compound document
# Expand RFA into a folder tree (storages โ†’ folders, streams โ†’ files)
CompoundFileTool /e model.rfa /o rfa_out
# rfa_out/Global/Latest is the serialized stream of interest
  1. gzip/ECC ๊ทœ์น™์— ๋”ฐ๋ผ Global\Latest ํŽธ์ง‘
  • Global/Latest ๋ถ„ํ•ด: ํ—ค๋”๋ฅผ ์œ ์ง€ํ•˜๊ณ , payload๋ฅผ gunzip์œผ๋กœ ์••์ถ• ํ•ด์ œํ•œ ๋‹ค์Œ ๋ฐ”์ดํŠธ๋ฅผ ๋ณ€ํ˜•ํ•˜๊ณ  Revit-compatible deflate parameters๋ฅผ ์‚ฌ์šฉํ•ด ๋‹ค์‹œ gzipํ•ฉ๋‹ˆ๋‹ค.
  • zero-padding์„ ๋ณด์กดํ•˜๊ณ  ECC ํŠธ๋ ˆ์ผ๋Ÿฌ๋ฅผ ์žฌ๊ณ„์‚ฐํ•˜์—ฌ ์ƒˆ๋กœ์šด ๋ฐ”์ดํŠธ๊ฐ€ Revit์— ์˜ํ•ด ๋ฐ›์•„๋“ค์—ฌ์ง€๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
  • ๊ฒฐ์ •๋ก ์  ๋ฐ”์ดํŠธ-๋‹จ์œ„ ์žฌํ˜„์ด ํ•„์š”ํ•˜๋ฉด, Revitโ€™s DLLs ์ฃผ์œ„์— ์ตœ์†Œ ๋ž˜ํผ๋ฅผ ๋งŒ๋“ค์–ด ๊ทธ gzip/gunzip ๊ฒฝ๋กœ์™€ ECC ๊ณ„์‚ฐ์„ ํ˜ธ์ถœํ•˜๊ฑฐ๋‚˜(์—ฐ๊ตฌ์—์„œ ์‹œ์—ฐ๋œ ๊ฒƒ์ฒ˜๋Ÿผ), ์ด๋Ÿฌํ•œ ์˜๋ฏธ๋ก ์„ ๋ณต์ œํ•˜๋Š” ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ํ—ฌํผ๋ฅผ ์žฌ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค.
  1. OLE compound document ์žฌ๊ตฌ์„ฑ
# Repack the folder tree back into an OLE file
CompoundFileTool /c rfa_out /o model_patched.rfa

์ฐธ๊ณ :

  • CompoundFileTool๋Š” NTFS ์ด๋ฆ„์—์„œ ์œ ํšจํ•˜์ง€ ์•Š์€ ๋ฌธ์ž๋ฅผ ์ด์Šค์ผ€์ดํ”„ ์ฒ˜๋ฆฌํ•˜์—ฌ storages/streams๋ฅผ ํŒŒ์ผ ์‹œ์Šคํ…œ์— ๊ธฐ๋กํ•ฉ๋‹ˆ๋‹ค; ์ถœ๋ ฅ ํŠธ๋ฆฌ์—์„œ ์›ํ•˜๋Š” ์ŠคํŠธ๋ฆผ ๊ฒฝ๋กœ๋Š” ์ •ํ™•ํžˆ Global/Latest์ž…๋‹ˆ๋‹ค.
  • cloud storage์—์„œ RFA๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ecosystem plugins๋ฅผ ํ†ตํ•ด ๋Œ€๊ทœ๋ชจ ๊ณต๊ฒฉ์„ ์ „๋‹ฌํ•  ๋•Œ๋Š”, ๋„คํŠธ์›Œํฌ ์ฃผ์ž…์„ ์‹œ๋„ํ•˜๊ธฐ ์ „์— ํŒจ์น˜ํ•œ RFA๊ฐ€ ๋กœ์ปฌ์—์„œ Revit์˜ ๋ฌด๊ฒฐ์„ฑ ๊ฒ€์‚ฌ(์˜ˆ: gzip/ECC correct)๋ฅผ ๋จผ์ € ํ†ต๊ณผํ•˜๋Š”์ง€ ํ™•์ธํ•˜์„ธ์š”.

Exploitation insight (to guide what bytes to place in the gzip payload):

  • The Revit deserializer reads a 16-bit class index and constructs an object. Certain types are nonโ€‘polymorphic and lack vtables; abusing destructor handling yields a type confusion where the engine executes an indirect call through an attacker-controlled pointer.
  • Picking AString (class index 0x1F) places an attacker-controlled heap pointer at object offset 0. During the destructor loop, Revit effectively executes:
rcx = [rbx]              ; object pointer (e.g., AString*)
rax = [rcx]              ; attacker-controlled pointer to AString buffer
call qword ptr [rax]     ; one attacker-chosen gadget per object
  • ์—ฌ๋Ÿฌ ๊ฐœ์˜ ๊ทธ๋Ÿฐ ๊ฐ์ฒด๋ฅผ ์ง๋ ฌํ™”๋œ ๊ทธ๋ž˜ํ”„์— ๋ฐฐ์น˜ํ•˜์—ฌ ๊ฐ destructor loop ๋ฐ˜๋ณต์ด ํ•˜๋‚˜์˜ gadget(โ€œweird machineโ€)์„ ์‹คํ–‰ํ•˜๋„๋ก ํ•˜๊ณ , stack pivot์„ ์ „ํ˜•์ ์ธ x64 ROP chain์œผ๋กœ ๊ตฌ์„ฑํ•œ๋‹ค.

See Windows x64 pivot/gadget building details here:

Stack Pivoting - EBP2Ret - EBP chaining

and general ROP guidance here:

ROP & JOP

๋„๊ตฌ:

  • CompoundFileTool (OSS) to expand/rebuild OLE compound files: https://github.com/thezdi/CompoundFileTool
  • IDA Pro + WinDBG TTD for reverse/taint; disable page heap with TTD to keep traces compact.
  • ๋กœ์ปฌ ํ”„๋ก์‹œ(์˜ˆ: Fiddler)๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ ํŠธ๋ž˜ํ”ฝ์—์„œ RFAs๋ฅผ ๊ต์ฒดํ•˜์—ฌ ๊ณต๊ธ‰๋ง ์ „๋‹ฌ์„ ์‹œ๋ฎฌ๋ ˆ์ด์…˜ํ•˜๋Š” ๋ฐ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

์ฐธ๊ณ ์ž๋ฃŒ

Tip

AWS ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ:HackTricks Training AWS Red Team Expert (ARTE)
GCP ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training GCP Red Team Expert (GRTE) Azure ํ•ดํ‚น ๋ฐฐ์šฐ๊ธฐ ๋ฐ ์—ฐ์Šตํ•˜๊ธฐ: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks ์ง€์›ํ•˜๊ธฐ