Exemplo n.º 1
0
 public byte[] CheckKey4DB(string dir, string masterPwd, bool Verbose)
 {
     try
     {
         Asn1Der asn1Der = new Asn1Der();
         byte[]  item    = new byte[0];
         byte[]  item2   = new byte[0];
         byte[]  item3   = new byte[0];
         byte[]  item4   = new byte[0];
         string  query   = "SELECT item1,item2 FROM metadata WHERE id = 'password'";
         if (Verbose)
         {
         }
         GetItemsFromQuery(dir, ref item2, ref item, query);
         Asn1DerObject asn1DerObject = asn1Der.Parse(item);
         MozillaPBE    mozillaPBE    = new MozillaPBE(item2, Encoding.ASCII.GetBytes(""), asn1DerObject.objects[0].objects[0].objects[1].objects[0].Data);
         mozillaPBE.Compute();
         string text = TripleDESHelper.DESCBCDecryptor(mozillaPBE.Key, mozillaPBE.IV, asn1DerObject.objects[0].objects[1].Data);
         if (!text.StartsWith("password-check"))
         {
             return(null);
         }
         query = "SELECT a11,a102 FROM nssPrivate";
         GetItemsFromQuery(dir, ref item3, ref item4, query);
         Asn1DerObject asn1DerObject2 = asn1Der.Parse(item3);
         byte[]        data           = asn1DerObject2.objects[0].objects[0].objects[1].objects[0].Data;
         byte[]        data2          = asn1DerObject2.objects[0].objects[1].Data;
         if (Verbose)
         {
         }
         return(decrypt3DES(item2, masterPwd, data, data2));
     }
     catch (Exception item5)
     {
         Program.Errors.Add(item5);
         return(null);
     }
 }
Exemplo n.º 2
0
        public Asn1DerObject Parse(byte[] dataToParse)
        {
            Asn1DerObject asn1DerObject = new Asn1DerObject();

            for (int i = 0; i < dataToParse.Length; i++)
            {
                int num = 0;
                switch (dataToParse[i])
                {
                case 48:
                {
                    byte[] array;
                    if (asn1DerObject.Lenght == 0)
                    {
                        asn1DerObject.Type   = Type.Sequence;
                        asn1DerObject.Lenght = dataToParse.Length - (i + 2);
                        array = new byte[asn1DerObject.Lenght];
                    }
                    else
                    {
                        asn1DerObject.objects.Add(new Asn1DerObject
                            {
                                Type   = Type.Sequence,
                                Lenght = dataToParse[i + 1]
                            });
                        array = new byte[dataToParse[i + 1]];
                    }
                    num = ((array.Length > dataToParse.Length - (i + 2)) ? (dataToParse.Length - (i + 2)) : array.Length);
                    Array.Copy(dataToParse, i + 2, array, 0, array.Length);
                    asn1DerObject.objects.Add(Parse(array));
                    i = i + 1 + dataToParse[i + 1];
                    break;
                }

                case 2:
                {
                    asn1DerObject.objects.Add(new Asn1DerObject
                        {
                            Type   = Type.Integer,
                            Lenght = dataToParse[i + 1]
                        });
                    byte[] array = new byte[dataToParse[i + 1]];
                    num = ((i + 2 + dataToParse[i + 1] > dataToParse.Length) ? (dataToParse.Length - (i + 2)) : dataToParse[i + 1]);
                    Array.Copy(dataToParse.ToArray(), i + 2, array, 0, num);
                    asn1DerObject.objects.Last().Data = array;
                    i = i + 1 + asn1DerObject.objects.Last().Lenght;
                    break;
                }

                case 4:
                {
                    asn1DerObject.objects.Add(new Asn1DerObject
                        {
                            Type   = Type.OctetString,
                            Lenght = dataToParse[i + 1]
                        });
                    byte[] array = new byte[dataToParse[i + 1]];
                    num = ((i + 2 + dataToParse[i + 1] > dataToParse.Length) ? (dataToParse.Length - (i + 2)) : dataToParse[i + 1]);
                    Array.Copy(dataToParse.ToArray(), i + 2, array, 0, num);
                    asn1DerObject.objects.Last().Data = array;
                    i = i + 1 + asn1DerObject.objects.Last().Lenght;
                    break;
                }

                case 6:
                {
                    asn1DerObject.objects.Add(new Asn1DerObject
                        {
                            Type   = Type.ObjectIdentifier,
                            Lenght = dataToParse[i + 1]
                        });
                    byte[] array = new byte[dataToParse[i + 1]];
                    num = ((i + 2 + dataToParse[i + 1] > dataToParse.Length) ? (dataToParse.Length - (i + 2)) : dataToParse[i + 1]);
                    Array.Copy(dataToParse.ToArray(), i + 2, array, 0, num);
                    asn1DerObject.objects.Last().Data = array;
                    i = i + 1 + asn1DerObject.objects.Last().Lenght;
                    break;
                }
                }
            }
            return(asn1DerObject);
        }
Exemplo n.º 3
0
 public byte[] CheckKey3DB(string filePath, string MasterPwd, bool Verbose)
 {
     try
     {
         Converts   converts   = new Converts();
         Asn1Der    asn1Der    = new Asn1Der();
         BerkeleyDB berkeleyDB = new BerkeleyDB(Path.Combine(filePath, "key3.db"));
         if (Verbose)
         {
         }
         PasswordCheck passwordCheck = new PasswordCheck(berkeleyDB.Keys.Where(delegate(KeyValuePair <string, string> p)
         {
             KeyValuePair <string, string> keyValuePair6 = p;
             return(keyValuePair6.Key.Equals("password-check"));
         }).Select(delegate(KeyValuePair <string, string> p)
         {
             KeyValuePair <string, string> keyValuePair5 = p;
             return(keyValuePair5.Value);
         }).FirstOrDefault()
                                                         .Replace("-", ""));
         string hexString = berkeleyDB.Keys.Where(delegate(KeyValuePair <string, string> p)
         {
             KeyValuePair <string, string> keyValuePair4 = p;
             return(keyValuePair4.Key.Equals("global-salt"));
         }).Select(delegate(KeyValuePair <string, string> p)
         {
             KeyValuePair <string, string> keyValuePair3 = p;
             return(keyValuePair3.Value);
         }).FirstOrDefault()
                            .Replace("-", "");
         if (Verbose)
         {
         }
         MozillaPBE mozillaPBE = new MozillaPBE(converts.ConvertHexStringToByteArray(hexString), Encoding.ASCII.GetBytes(MasterPwd), converts.ConvertHexStringToByteArray(passwordCheck.EntrySalt));
         mozillaPBE.Compute();
         string text = TripleDESHelper.DESCBCDecryptor(mozillaPBE.Key, mozillaPBE.IV, converts.ConvertHexStringToByteArray(passwordCheck.Passwordcheck));
         if (!text.StartsWith("password-check"))
         {
             return(null);
         }
         string hexString2 = berkeleyDB.Keys.Where(delegate(KeyValuePair <string, string> p)
         {
             KeyValuePair <string, string> keyValuePair2 = p;
             int result;
             if (!keyValuePair2.Key.Equals("global-salt"))
             {
                 keyValuePair2 = p;
                 if (!keyValuePair2.Key.Equals("Version"))
                 {
                     keyValuePair2 = p;
                     result        = ((!keyValuePair2.Key.Equals("password-check")) ? 1 : 0);
                     goto IL_0043;
                 }
             }
             result = 0;
             goto IL_0043;
             IL_0043:
             return((byte)result != 0);
         }).Select(delegate(KeyValuePair <string, string> p)
         {
             KeyValuePair <string, string> keyValuePair = p;
             return(keyValuePair.Value);
         }).FirstOrDefault()
                             .Replace("-", "");
         Asn1DerObject asn1DerObject = asn1Der.Parse(converts.ConvertHexStringToByteArray(hexString2));
         MozillaPBE    mozillaPBE2   = new MozillaPBE(converts.ConvertHexStringToByteArray(hexString), Encoding.ASCII.GetBytes(MasterPwd), asn1DerObject.objects[0].objects[0].objects[1].objects[0].Data);
         mozillaPBE2.Compute();
         byte[]        dataToParse    = TripleDESHelper.DESCBCDecryptorByte(mozillaPBE2.Key, mozillaPBE2.IV, asn1DerObject.objects[0].objects[1].Data);
         Asn1DerObject asn1DerObject2 = asn1Der.Parse(dataToParse);
         Asn1DerObject asn1DerObject3 = asn1Der.Parse(asn1DerObject2.objects[0].objects[2].Data);
         byte[]        array          = new byte[24];
         if (asn1DerObject3.objects[0].objects[3].Data.Length > 24)
         {
             Array.Copy(asn1DerObject3.objects[0].objects[3].Data, asn1DerObject3.objects[0].objects[3].Data.Length - 24, array, 0, 24);
         }
         else
         {
             array = asn1DerObject3.objects[0].objects[3].Data;
         }
         return(array);
     }
     catch (Exception item)
     {
         Program.Errors.Add(item);
         return(null);
     }
 }