mirror of
https://github.com/3xpl01tc0d3r/ProcessInjection
synced 2026-06-06 15:14:27 +00:00
59 lines
1.8 KiB
C#
59 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Security.Cryptography;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ProcessInjection.Utils
|
|
{
|
|
public class Crypto
|
|
{
|
|
//https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab4/1.cs#L10
|
|
public static byte[] xor(byte[] cipher, byte[] key)
|
|
{
|
|
|
|
byte[] xored = new byte[cipher.Length];
|
|
|
|
for (int i = 0; i < cipher.Length; i++)
|
|
{
|
|
xored[i] = (byte)(cipher[i] ^ key[i % key.Length]);
|
|
}
|
|
|
|
return xored;
|
|
}
|
|
|
|
// https://github.com/mvelazc0/defcon27_csharp_workshop/blob/master/Labs/lab4/3.cs#L95
|
|
public static byte[] AES_Decrypt(byte[] bytesToBeDecrypted, byte[] passwordBytes)
|
|
{
|
|
byte[] decryptedBytes = null;
|
|
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
|
|
|
|
using (MemoryStream ms = new MemoryStream())
|
|
{
|
|
using (RijndaelManaged AES = new RijndaelManaged())
|
|
{
|
|
AES.KeySize = 256;
|
|
AES.BlockSize = 128;
|
|
|
|
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
|
|
AES.Key = key.GetBytes(AES.KeySize / 8);
|
|
AES.IV = key.GetBytes(AES.BlockSize / 8);
|
|
|
|
AES.Mode = CipherMode.CBC;
|
|
|
|
using (var cs = new CryptoStream(ms, AES.CreateDecryptor(), CryptoStreamMode.Write))
|
|
{
|
|
cs.Write(bytesToBeDecrypted, 0, bytesToBeDecrypted.Length);
|
|
cs.Close();
|
|
}
|
|
decryptedBytes = ms.ToArray();
|
|
}
|
|
}
|
|
|
|
return decryptedBytes;
|
|
}
|
|
}
|
|
}
|