klezVirus / CVE-2021-40444
- воскресенье, 19 сентября 2021 г. в 00:29:42
CVE-2021-40444 - Fully Weaponized Microsoft Office Word RCE Exploit
Malicious docx generator to exploit CVE-2021-40444 (Microsoft Office Word Remote Code Execution), works with arbitrary DLL files.
Although many PoC are already around the internet, I guessed to give myself a run to weaponizing this vulnerability, as what I found available lacked valuable information that it's worth sharing, also considering Microsoft already released a patch for this vulnerability.
So far, the only valuable resources I've seen to create a fully working generator are:
The above resources outline a lot of the requirements needed to create a full chain. To avoid repeating too much unnecessary information, I'll just summarize the relevant details.
There are quite a bit of overlooked requirements for this exploit to work, which caused even good PoCs, like the one by lockedbyte, to fail working properly.
Maybe nobody explicitly "released" them to avoid the vulnerability to be exploited more. But now it's patched, so it should not cause a lot of troubles to release the details.
The CAB file needs to be byte-patched to avoid extraction errors and to achieve the ZipSlip:
filename.inf
should become ../filename.inf
filename.inf
should be exactly <12-char>.inf
CFFOLDER.typeCompress
should be 0 (not compressed)CFFOLDER.coffCabStart
should be increased by 3CFFOLDER.cCfData
should be 2CFFILE.cbFile
should be greater than the whole CFHEADER.cbCabinet
CFDATA.csum
should be recalculated (or zeroed out)The reason for these constraints are many, and I didn't spend enough time to deeply understand all of them, but let's see the most important:
NOTE1: Defender now detects if the CAB file contains a PE by using the _IMAGE_DOS_HEADER.e_magic
value as a
signature, potentially avoiding PE files to be embedded in the CAB. Can this signature be bypassed?
I'm not sure but, as observed before, this is a patched vulnerability, so I'm not planning to invest much more time
on this. Up to the curious reader to develop this further.
NOTE2: Microsoft Patch blocks arbitrary URI schemes, apparently using a blacklist approach (this is just a supposition)
The utility cab_parser.py
can be used to see the headers of the exploit file, but don't consider this a full
parser. It's a very quick and dirty CAB header viewer I developed to understand what was going on.
The generator is designed to work on Windows, as it uses the makecab
utility. Before usage, be sure to install required dependencies:
git clone https://github.com/klezVirus/CVE-2021-40444
cd CVE-2021-40444
pip install virtualenv
python -m virtualenv venv
venv\Scripts\activate.bat
pip install -r requirements
git clone https://github.com/klezVirus/CVE-2021-40444
cd CVE-2021-40444
pip install -r requirements
The generator is trivial to use, and has been tested with a number of different DLL payloads.
usage: generator.py [-h] -P PAYLOAD -u URL [-o OUTPUT] [--host] [-p LPORT] [-c COPY_TO]
[%] CVE-2021-40444 - MS Office Word RCE Exploit [%]
optional arguments:
-h, --help show this help message and exit
-P PAYLOAD, --payload PAYLOAD
DLL payload to use for the exploit
-u URL, --url URL Server URL for malicious references (CAB->INF)
-o OUTPUT, --output OUTPUT
Output files basename (no extension)
--host If set, will host the payload after creation
-p LPORT, --lport LPORT
Port to use when hosting malicious payload
-c COPY_TO, --copy-to COPY_TO
Copy payload to an alternate path