• Stars
    star
    124
  • Rank 278,760 (Top 6 %)
  • Language VBA
  • Created over 1 year ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Running .NET from VBA

TLDR:

Just experimenting with different ways to load CLR (.NET) assemblies on VBA locally and remotely by using AppDomain.ExecuteAssembly or any other handy method after getting arround AccessVBOM (programmatic access to visual basic project is not trusted) from VBA.

  • vba2clr.*.vba:
    • Sets AccessVBOM regkey to 1
    • Instantiate a Word.Application COM object. (could be Excel.Application MS PowerPoint, Access ..etc).
    • Add Macro From String (Macro corresponds to b64/hex encoded ExecuteAssembly.vba)
    • Run ExecuteAssembly.vba Macro using wordObj.Application.Run...

.NET from VBA:

  • ExecuteAssembly.clr.2.0.vba: Up to .NET 3.5

    • Adds the required mscordlib references
    • Instantiates the required objects (IDomain, ICRHost)
    • Pack the required AppDomain.ExecuteAssembly arguments into two separate arrays (variables, types).
    • Use DispCallFunc to call AppDomain.ExecuteAssembly(Arg1, Arg2) (VFTable offset 51) where Arg1 is the ".NET Assembly URL" or "Local Path" and Arg2 is the return value.
    • AppDomain methods VFTable offsets can be checked on the AppDomain IDL _AppDomain.idl, just keep in mind that the AppDomain interface inherits from the IUnknown interface, so functions/methods VTable offsets start from the third offset onwards, this is because interfaces inheriting from IUnknown have the first 3 entries in their vtable set to QueryInterface, AddRef, Release methods.
    • WinDbg or IDA can be also used as alternatives for extracting functions/methods VTable offsets.
  • ExecuteAssembly.clr.x.vba: supports .NET 2, 3.5 and 4.x

OPSEC Notes:

  • Creating a COM object for Word.Application (or Excel.Application ..etc), will result spawning an additional WinWord.exe as a child process of svchost.exe instead of the main WinWord.exe process.
  • AccessVBOM Registry key is modified/restored via COM using WScript.Shell , using win32 APIs could be a better alternative.
  • Hosting the CLR using win32 APIs on VBA is obviously safer than updating the AccessVBOM registry key, will leave this for an other day...
  • Other .NET APIs such as System.CodeDom.Compiler can be used to compile/execute c# code from VBA, check reference below;

References:

More Repositories

1

SigFlip

SigFlip is a tool for patching authenticode signed PE files (exe, dll, sys ..etc) without invalidating or breaking the existing signature.
C#
934
star
2

GadgetToJScript

A tool for generating .NET serialized gadgets that can trigger .NET assembly load/execution when deserialized using BinaryFormatter from JS/VBS/VBA based scripts.
C#
814
star
3

ExecuteAssembly

Load/Inject .NET assemblies by; reusing the host (spawnto) process loaded CLR AppDomainManager, Stomping Loader/.NET assembly PE DOS headers, Unlinking .NET related modules, bypassing ETW+AMSI, avoiding EDR hooks via NT static syscalls (x64) and hiding imports by dynamically resolving APIs (hash).
C++
518
star
4

NTLMRelay2Self

An other No-Fix LPE, NTLMRelay2Self over HTTP (Webdav).
C
363
star
5

NoAmci

Using DInvoke to patch AMSI.dll in order to bypass AMSI detections triggered when loading .NET tradecraft via Assembly.Load().
C#
211
star
6

NET-Assembly-Inject-Remote

.NET assembly local/remote loading/injection into memory.
C#
117
star
7

genxlm

A simple script to generate JScript code for calling Win32 API functions using XLM/Excel 4.0 macros via Excel.Application "ExecuteExcel4Macro"
Go
87
star
8

RT-EWS

A Powershell module including a couple of cmdlets for EWS Enum/Exploitation.
PowerShell
17
star
9

Scrncat

A script using OCR (pytesseract) and PIL to rename/order/group Screenshots into PR/RT phases based on which RT/PT stage executed commands correspond to & Redact passwords based on common password patterns (Regex) or a passwords/hashes list of choice.
Python
1
star