C# run byte array without dumping to temp file

321 views Asked by At

I'm here to ask if anyone here can help me. I have been doing the following:

  1. Copy bytes from file
  2. Encrypt and convert bytes to string by using base64
  3. Write the string to a program with a binary writer
  4. The program will pick up on the string and store it in a variable
  5. The program will now convert it back to a byte array and decrypt it
  6. Now I tried to get the program to run the bytes with assembly.load (where it goes wrong)

System.BadImageFormatException: Could not load file or assembly

If you need any other details please ask.

NOTE: I want to be able to do this with any program (so any architecture, native or not), I don't want to write the bytes to a file and run the new file, I want everything to be done within memory and not on the storage device after execution.

Thanks to everyone in advance.

Example of running the byte array:

Assembly exeAssembly = Assembly.Load(decryptedBuffer);

object[] parameters = new object[1];
exeAssembly.EntryPoint.Invoke(null, parameters);

[SOLUTION] I used RunPE to self inject the bytes into the stub. Works fine, thanks to everyone who helped!

0

There are 0 answers