コード例 #1
0
ファイル: EncryptDecrypt.cs プロジェクト: sry309/Blacklist3r
        public static byte[] DecryptData(byte[] protectedData, string strMachineKeysFilePath, string strValidationAlgorithm, string strDecryptionAlgorithm)
        {
            byte[] clearData = null;
            if (File.Exists(strMachineKeysFilePath))
            {
                byte[] byteEncryptionIV = new byte[16];
                Buffer.BlockCopy(protectedData, 0, byteEncryptionIV, 0, byteEncryptionIV.Length);

                Console.Write("\n\nDecryption process start!!\n\n");

                string[] machineKeys = File.ReadAllLines(strMachineKeysFilePath);
                int      nIndex      = 0;
                foreach (string strLine in machineKeys)
                {
                    try
                    {
                        Console.ForegroundColor = ConsoleColor.Blue;
                        Console.Write("\rPocessing machinekeys : {0}/{1}....", nIndex++, machineKeys.Length);

                        string[] values           = strLine.Split(',');
                        string   strValidationKey = values[0];
                        string   strDecryptionKey = values[1];

                        AspNetCryptoServiceProvider obj = new AspNetCryptoServiceProvider(strValidationKey, strValidationAlgorithm, strDecryptionKey, strDecryptionAlgorithm);
                        ICryptoService cryptoService    = obj.GetCryptoService(DefinePurpose.GetPurpose(), CryptoServiceOptions.CacheableOutput);

                        clearData = cryptoService.Unprotect(protectedData);
                        if (clearData != null)
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\n\nKeys found!!");
                            Console.WriteLine("------------");
                            Console.ForegroundColor = ConsoleColor.Blue;
                            Console.WriteLine("DecryptionKey:" + strDecryptionKey);
                            Console.WriteLine("ValidationKey:" + strValidationKey);
                            DataWriter.WriteKeysToFile(strValidationKey, strDecryptionKey, strValidationAlgorithm, strDecryptionAlgorithm, byteEncryptionIV);
                            Console.ResetColor();
                            break;
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("Null data found for following keys!!");
                            Console.WriteLine("\n\nDecryptionKey:" + strDecryptionKey);
                            Console.WriteLine("ValidationKey:" + strValidationKey + "\n\n");
                            Console.ResetColor();
                        }
                    }
                    catch (Exception e)
                    {
                    }
                }
            }
            return(clearData);
        }
コード例 #2
0
ファイル: EncryptDecrypt.cs プロジェクト: sry309/Blacklist3r
        public static string EncryptData(string strDecryptDataFilePath)
        {
            ReadObject objData = new ReadObject(strDecryptDataFilePath);
            AspNetCryptoServiceProvider obj = new AspNetCryptoServiceProvider(
                objData.ValidationKey,
                objData.ValidationAlgo, objData.DecryptionKey, objData.DecryptionAlgo);

            obj.SetEncryptionIV(objData.EncryptionIV);
            DefinePurpose.SetPurposeString(objData.Purpose);

            Purpose objPurpose = null;

            byte[] byteClearData = null;
            DefinePurpose.GetPurposeAndClearData(objData, out objPurpose, out byteClearData);
            ICryptoService cryptoService = obj.GetCryptoService(objPurpose);

            return(PrintData(cryptoService.Protect(byteClearData)));
        }
コード例 #3
0
        static void Main(string[] args)
        {
            string strKeysFilePath        = null,
                   strCookieValue         = null,
                   strDecryptDataFilePath = null,
                   strPurpose             = null,
                   strValidationAlgorithm = null,
                   strDecryptionAlgorithm = null;
            bool bDecrypt = false;

            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(options =>
            {
                strKeysFilePath        = options.strKeysFilePath;
                strCookieValue         = options.strCookieValue;
                strValidationAlgorithm = options.strValidationAlgorithm;
                strDecryptionAlgorithm = options.strDecryptionAlgorithm;
                strPurpose             = options.strPurpose;
                strDecryptDataFilePath = options.strDecryptDataFilePath;
                bDecrypt = options.bDecrypt;
                if (!String.IsNullOrEmpty(options.strOutputFilePath))
                {
                    strDecryptedTxtFilePath = options.strOutputFilePath;
                }
            });

            if (strValidationAlgorithm != null)
            {
                strValidationAlgorithm = strValidationAlgorithm.ToUpper();
            }
            if (strDecryptionAlgorithm != null)
            {
                strDecryptionAlgorithm = strDecryptionAlgorithm.ToUpper();
            }
            if (strPurpose != null)
            {
                DefinePurpose.SetPurposeString(strPurpose);
            }

            if (bDecrypt)
            {
                if (strKeysFilePath == null || strCookieValue == null || strValidationAlgorithm == null ||
                    strDecryptionAlgorithm == null || strPurpose == null)
                {
                    Options.GetUsage(true);
                }
                else
                {
                    if (File.Exists(strKeysFilePath))
                    {
                        byte[] protectedData = DefinePurpose.GetProtectedData(strCookieValue);
                        if (protectedData != null)
                        {
                            byte[] clearData = EncryptDecrypt.DecryptData(protectedData, strKeysFilePath, strValidationAlgorithm, strDecryptionAlgorithm);
                            if (clearData != null)
                            {
                                DataWriter.WritePurposeToFile(strPurpose);
                                DataWriter.WriteOtherDataToFile(DefinePurpose.enumPurpose, clearData);
                            }
                        }
                        else
                        {
                            Console.Write("Failed to get protected data!!");
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("\n\nKey path file {0} not found!!\n", strKeysFilePath);
                        Console.ResetColor();
                    }
                }
            }
            else
            {
                if (strDecryptDataFilePath == null)
                {
                    Options.GetUsage(false);
                }
                else
                {
                    if (File.Exists(strDecryptDataFilePath))
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("\nEncryptedData");
                        Console.WriteLine("-------------");
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(EncryptDecrypt.EncryptData(strDecryptDataFilePath));
                        Console.ResetColor();
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("\n\nDecryptedText.txt File not found!!\n");
                        Console.ResetColor();
                    }
                }
            }
        }
コード例 #4
0
        public static byte[] DecryptData(byte[] protectedData, string strMachineKeysFilePath, string strTargetPagePath, string strIISAppPath, string strAntiCSRFToken)
        {
            byte[] clearData = null;
            if (File.Exists(strMachineKeysFilePath))
            {
                byte[] byteEncryptionIV = new byte[16];
                Buffer.BlockCopy(protectedData, 0, byteEncryptionIV, 0, byteEncryptionIV.Length);

                Console.Write("\n\nDecryption process start!!\n\n");

                string[] machineKeys = File.ReadAllLines(strMachineKeysFilePath);
                bool     bFound      = false;
                foreach (string strDecryptionAlgorithm in ContantValue.arrayDecryptionAlgo)
                {
                    foreach (string strValidationAlgorithm in ContantValue.arrayValidationAlgo)
                    {
                        int nIndex = 1;
                        foreach (string strLine in machineKeys)
                        {
                            try
                            {
                                Console.ForegroundColor = ConsoleColor.Blue;
                                Console.Write("\rPocessing machinekeys {0},{1}: {2}/{3}..............", strDecryptionAlgorithm, strValidationAlgorithm, nIndex++, machineKeys.Length);

                                string[] values           = strLine.Split(',');
                                string   strValidationKey = values[0];
                                string   strDecryptionKey = values[1];
                                Purpose  objPurpose       = null;
                                if (DefinePurpose.enumPurpose == EnumPurpose.VIEWSTATE)
                                {
                                    objPurpose = DefinePurpose.GetViewStatePurpose(strTargetPagePath, strIISAppPath, strAntiCSRFToken);
                                }
                                else
                                {
                                    objPurpose = DefinePurpose.GetPurpose();
                                }
                                AspNetCryptoServiceProvider obj = new AspNetCryptoServiceProvider(strValidationKey, strValidationAlgorithm, strDecryptionKey, strDecryptionAlgorithm);
                                ICryptoService cryptoService    = obj.GetCryptoService(objPurpose, CryptoServiceOptions.CacheableOutput);

                                clearData = cryptoService.Unprotect(protectedData);
                                if (clearData != null)
                                {
                                    Console.ForegroundColor = ConsoleColor.Green;
                                    Console.WriteLine("\n\nKeys found!!");
                                    Console.WriteLine("------------");
                                    Console.ForegroundColor = ConsoleColor.Blue;
                                    Console.WriteLine("DecryptionKey:" + strDecryptionKey);
                                    Console.WriteLine("ValidationKey:" + strValidationKey);
                                    DataWriter.WriteKeysToFile(strValidationKey, strDecryptionKey, strValidationAlgorithm, strDecryptionAlgorithm, byteEncryptionIV);
                                    Console.ResetColor();
                                    bFound = true;
                                    break;
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine("Null data found for following keys!!");
                                    Console.WriteLine("\n\nDecryptionKey:" + strDecryptionKey);
                                    Console.WriteLine("ValidationKey:" + strValidationKey + "\n\n");
                                    Console.ResetColor();
                                }
                            }
                            catch (Exception e)
                            {
                            }
                        }
                        if (bFound)
                        {
                            break;
                        }
                    }
                    if (bFound)
                    {
                        break;
                    }
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.Write("\n\nKey path file {0} not found!!\n\n", strMachineKeysFilePath);
                Console.ResetColor();
            }
            return(clearData);
        }
コード例 #5
0
        static void Main(string[] args)
        {
            string strKeysFilePath = null,
                   strEncryptedData = null,
                   strDecryptDataFilePath = null,
                   strPurpose = null,
                   strValidationAlgorithm = null,
                   strDecryptionAlgorithm = null,
                   strModifier = null,
                   strIISAppPath = null,
                   strTargetPagePath = null,
                   strAntiCSRFToken = null;
            bool bDecrypt = false, bDecode = false, bLegacy = false;

            Parser.Default.ParseArguments <Options>(args)
            .WithParsed <Options>(options =>
            {
                strKeysFilePath        = options.strKeysFilePath;
                strEncryptedData       = options.strEncryptedData;
                strValidationAlgorithm = options.strValidationAlgorithm;
                strDecryptionAlgorithm = options.strDecryptionAlgorithm;
                strPurpose             = options.strPurpose;
                strDecryptDataFilePath = options.strDecryptDataFilePath;
                strModifier            = options.strModifier;
                strIISAppPath          = options.strIISDirPath;
                strTargetPagePath      = options.strTargetPagePath;
                strAntiCSRFToken       = options.strAntiCSRFToken;
                bDecrypt = options.bDecrypt;
                bLegacy  = options.bLegacy;
                bDecode  = options.bDecode;
                if (!String.IsNullOrEmpty(options.strOutputFilePath))
                {
                    strDecryptedTxtFilePath = options.strOutputFilePath;
                }
            });
            if (strValidationAlgorithm != null)
            {
                strValidationAlgorithm = strValidationAlgorithm.ToUpper();
            }
            if (strDecryptionAlgorithm != null)
            {
                strDecryptionAlgorithm = strDecryptionAlgorithm.ToUpper();
            }
            if (strPurpose != null)
            {
                DefinePurpose.SetPurposeString(strPurpose);
            }
            else
            {
                if (bDecrypt)
                {
                    Options.GetUsage(true);
                    return;
                }
            }
            if (DefinePurpose.enumPurpose == EnumPurpose.VIEWSTATE && bLegacy && bDecode)
            {
                if (strKeysFilePath == null || strEncryptedData == null || strValidationAlgorithm == null ||
                    strDecryptionAlgorithm == null || strPurpose == null || strModifier == null)
                {
                    Options.GetViewStateLegacyUsage();
                }
                else
                {
                    if (File.Exists(strKeysFilePath))
                    {
                        byte[] protectedData = DefinePurpose.GetProtectedData(strEncryptedData);
                        if (protectedData != null)
                        {
                            EncryptDecrypt.DecodeViewState(protectedData, strKeysFilePath, strValidationAlgorithm, strDecryptionAlgorithm, strModifier, strPurpose);
                        }
                    }
                }
            }
            else
            {
                if (bDecrypt)
                {
                    if (DefinePurpose.enumPurpose == EnumPurpose.VIEWSTATE)
                    {
                        if (strKeysFilePath == null || strEncryptedData == null || strValidationAlgorithm == null ||
                            strDecryptionAlgorithm == null || strPurpose == null || strIISAppPath == null || strTargetPagePath == null)
                        {
                            Options.GetViewStateUsage();
                            return;
                        }
                    }
                    else
                    {
                        if (strKeysFilePath == null || strEncryptedData == null || strValidationAlgorithm == null ||
                            strDecryptionAlgorithm == null || strPurpose == null)
                        {
                            Options.GetUsage(true);
                            return;
                        }
                    }
                    if (File.Exists(strKeysFilePath))
                    {
                        byte[] protectedData = DefinePurpose.GetProtectedData(strEncryptedData);
                        if (protectedData != null)
                        {
                            byte[] clearData = EncryptDecrypt.DecryptData(protectedData, strKeysFilePath, strValidationAlgorithm, strDecryptionAlgorithm, strTargetPagePath, strIISAppPath, strAntiCSRFToken);
                            if (clearData != null)
                            {
                                DataWriter.WritePurposeToFile(strPurpose);
                                DataWriter.WriteOtherDataToFile(DefinePurpose.enumPurpose, clearData);
                            }
                        }
                        else
                        {
                            Console.Write("Failed to get protected data!!");
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Write("\n\nKey path file {0} not found!!\n", strKeysFilePath);
                        Console.ResetColor();
                    }
                }
                else
                {
                    if (strDecryptDataFilePath == null)
                    {
                        Options.GetUsage(false);
                    }
                    else
                    {
                        if (File.Exists(strDecryptDataFilePath))
                        {
                            Console.ForegroundColor = ConsoleColor.Green;
                            Console.WriteLine("\nEncryptedData");
                            Console.WriteLine("-------------");
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine(EncryptDecrypt.EncryptData(strDecryptDataFilePath));
                            Console.ResetColor();
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write("\n\nDecryptedText.txt File not found!!\n");
                            Console.ResetColor();
                        }
                    }
                }
            }
        }