Microsoft micros

Bypass Technique for Mark Of The Web (MOTW)

  • Container Formats (ISO, IMG, VHD): Do not support NTFS Alternate Data Streams (ADS), preventing files inside from inheriting the Mark-of-the-Web (MOTW).

  • Security Bypass: Inner files execute without MOTW-based security prompts, allowing malware delivery.

  • Compressed Archives (ZIP, 7z): Can support ADS but may bypass MOTW due to extraction tool behavior (e.g., 7-Zip previously did not honor MOTW by default).

  • Threat Actor Exploitation: Used to evade MOTW-based security measures and content scanners.

  • Key Takeaway: Encapsulation in certain formats helps malware evade detection and execute without warnings.

Making Macros in MS Word

Microsoft Office applications like Word and Excel allow users to embed macros, which are a series of commands and instructions grouped to accomplish a task programmatically.

The newer .docx file type cannot save macros without attaching a containing template. This means that we can run macros within .docx files but we can't embed or save the macro in the document. In other words, the macro is not persistent. Alternatively, we could also use the .docm file type for our embedded macro.

You need to open a Word file and save it in .docm file type.

Something like this

To make macros, Goto View tab > macros.

Let's enter MyMacro as the name in the Macro Name section, then select the mymacro document from the Macros in drop-down menu. This document is where the macro will be saved. Finally, click Create to insert a simple macro framework into the document.

We will be presented with the below windows.

General structute of micro is presented to us.

Since Office macros are not executed automatically, we must use the predefined AutoOpen macro and Document_Open event. These procedures can call a custom procedure to run code when a Word document is opened. They differ slightly depending on how Microsoft Word or the document is opened. Each covers specific cases that the other does not, which is why both are used.

Above code Macro automatically executes powershell.exe after opening the Document.

Reverse shell

We can get the reverse shell from a macro using powershell and Powercat.ps1.

Encode the above command to base64 using the below method.

In many scripting or macro environments—especially VBA macros—there are limits on how long a single string literal can be or how many characters are allowed per line. Splitting a large base64-encoded command into smaller chunks ensures that you can work around those line-length or character-count restrictions, making the code valid and easier to handle within the macro environment. Additionally, splitting it into chunks can sometimes improve readability and maintainability of the script. So, We will split it using python code below.

Final macro for a reverse shell.

CreateObject("Wscript.Shell").Run Str: This opens powershell and runs content stored in str variable.

Save this macro and start the listener.

Now When the victim opens the file and enables macros. You will get the shell.

If you are performing this on Lab then you need to run it manually.

Last updated