Try it using Invoke-Atomic

Event Triggered Execution: Change Default File Association

Description from ATT&CK

Adversaries may establish persistence by executing malicious content triggered by a file type association. When a file is opened, the default program used to open the file (also called the file association or handler) is checked. File association selections are stored in the Windows Registry and can be edited by users, administrators, or programs that have Registry access or by administrators using the built-in assoc utility.(Citation: Microsoft Change Default Programs)(Citation: Microsoft File Handlers)(Citation: Microsoft Assoc Oct 2017) Applications can modify the file association for a given file extension to call an arbitrary program when a file with the given extension is opened.

System file associations are listed under <code>HKEY_CLASSES_ROOT.[extension]</code>, for example <code>HKEY_CLASSES_ROOT.txt</code>. The entries point to a handler for that extension located at <code>HKEY_CLASSES_ROOT\[handler]</code>. The various commands are then listed as subkeys underneath the shell key at <code>HKEY_CLASSES_ROOT\[handler]\shell\[action]\command</code>. For example:

  • <code>HKEY_CLASSES_ROOT\txtfile\shell\open\command</code>
  • <code>HKEY_CLASSES_ROOT\txtfile\shell\print\command</code>
  • <code>HKEY_CLASSES_ROOT\txtfile\shell\printto\command</code>

The values of the keys listed are commands that are executed when the handler opens the file extension. Adversaries can modify these values to continually execute arbitrary commands.(Citation: TrendMicro TROJ-FAKEAV OCT 2012) https://www.aleksandrhovhannisyan.com/blog/how-to-add-a-copy-to-clipboard-button-to-your-jekyll-blog/

Atomic Tests

Atomic Test #1 - Change Default File Association

Change Default File Association From cmd.exe of hta to notepad.

Upon successful execution, cmd.exe will change the file association of .hta to notepad.exe.

Supported Platforms: windows

auto_generated_guid: 10a08978-2045-4d62-8c42-1957bbbea102

Inputs:

Name Description Type Default Value
target_extension_handler txtfile maps to notepad.exe Path txtfile
extension_to_change File Extension To Hijack String .hta

Attack Commands: Run with command_prompt!

1
2
assoc #{extension_to_change}=#{target_extension_handler}

Cleanup Commands:

1
2
assoc .hta=htafile >nul 2>&1

source