Created
March 23, 2023 18:36
-
-
Save khr0x40sh/4c2744e8679a2d98c45a34347cf79b5f to your computer and use it in GitHub Desktop.
HTB:CA2023 Forensics Interstellar Encryption C2 Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static string Encryption(string key, string un, bool comp = false, byte[] unByte = null) | |
{ | |
byte[] array = null; | |
if (unByte != null) | |
{ | |
array = unByte; | |
} | |
else | |
{ | |
array = Encoding.UTF8.GetBytes(un); | |
} | |
if (comp) | |
{ | |
array = Program.Compress(array); | |
} | |
string result; | |
try | |
{ | |
SymmetricAlgorithm symmetricAlgorithm = Program.CreateCam(key, null, true); | |
byte[] second = symmetricAlgorithm.CreateEncryptor().TransformFinalBlock(array, 0, array.Length); | |
result = Convert.ToBase64String(Program.Combine(symmetricAlgorithm.IV, second)); | |
} | |
catch | |
{ | |
SymmetricAlgorithm symmetricAlgorithm2 = Program.CreateCam(key, null, false); | |
byte[] second2 = symmetricAlgorithm2.CreateEncryptor().TransformFinalBlock(array, 0, array.Length); | |
result = Convert.ToBase64String(Program.Combine(symmetricAlgorithm2.IV, second2)); | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment