Reflective Assembly Delegate Execution
Description
A .NET execution technique in which a byte array (decrypted from a resource, overlay, or network stream) is loaded into memory via Assembly.Load(byte[]) and then invoked through MethodBase.Invoke, Delegate.CreateDelegate, or DynamicMethod + ILGenerator. The payload never touches disk, leaving no file artifacts for forensic recovery.
Mechanism
- Staging: The outer binary decrypts the inner payload (AES, XOR, GZip, Base64, or raw)
- Loading:
Assembly.Load(decryptedBytes)returns anAssemblyobject - Resolution:
assembly.GetType("Namespace.Class").GetMethod("Entry")resolves the entry point - Invocation:
method.Invoke(null, args)orDelegate.CreateDelegate(...).DynamicInvoke(...)transfers control
Variants
- Simple reflection: Direct
Assembly.Load->MethodBase.Invoke - Delegate thunk:
DynamicMethod+ILGenerator+GetDelegateForFunctionPointerfor native bridging - P/Invoke bridge:
Marshal.GetDelegateForFunctionPointerto call unmanaged shellcode afterVirtualProtect
Notable Examples
931242f8...— Unobfuscated .NET 4.8 loader usingAssembly,ExecuteMethod,GetMethod,Invoke,Marshal,IntPtr, andVirtualProtectto bridge decrypted overlay into execution. ^[sample 931242f8/strings.txt]07835853...— ConfuserEx-obfuscated variant usingDynamicMethod+ILGeneratorthunks. ^[sample 07835853/strings.txt]
Detection
- ETW events for
Assembly.Loadfrom a byte array (Event ID 154 in .NET runtime) - Memory-only modules with no corresponding disk file (scanners like Hunt-Sleeping-Beacons or ETW "Image Load" events without a file path)
- Suspicious
DynamicMethodcreation withILGeneratoremittingcalliorldftnopcodes