private byte[] CheckKey4DB(string dir, string masterPwd) { try { ErrorHandle eh = new ErrorHandle(); Asn1Der asn = new Asn1Der(); byte[] item2 = new byte[] { }; byte[] item1 = new byte[] { }; byte[] a11 = new byte[] { }; byte[] a102 = new byte[] { }; string query = "SELECT item1,item2 FROM metadata WHERE id = 'password'"; GetItemsFromQuery(dir, ref item1, ref item2, query); Asn1DerObject f800001 = asn.Parse(item2); MozillaPBE CheckPwd = new MozillaPBE(item1, Encoding.ASCII.GetBytes(""), f800001.objects[0].objects[0].objects[1].objects[0].Data); CheckPwd.Compute(); string decryptedPwdChk = TripleDESHelper.DESCBCDecryptor(CheckPwd.Key, CheckPwd.IV, f800001.objects[0].objects[1].Data); if (!decryptedPwdChk.StartsWith("password-check")) { eh.ErrorFunc("Master password is wrong !"); return(null); } query = "SELECT a11,a102 FROM nssPrivate"; GetItemsFromQuery(dir, ref a11, ref a102, query); var decodedA11 = asn.Parse(a11); var entrySalt = decodedA11.objects[0].objects[0].objects[1].objects[0].Data; var cipherT = decodedA11.objects[0].objects[1].Data; return(decrypt3DES(item1, masterPwd, entrySalt, cipherT)); } catch (Exception ex) { return(null); } }
private byte[] CheckKey3DB(string filePath, string MasterPwd) { try { Converts conv = new Converts(); ErrorHandle eh = new ErrorHandle(); Asn1Der asn = new Asn1Der(); BerkeleyDB db = new BerkeleyDB(Path.Combine(filePath, "key3.db")); // Verify MasterPassword PasswordCheck pwdCheck = new PasswordCheck((from p in db.Keys where p.Key.Equals("password-check") select p.Value).FirstOrDefault().Replace("-", "")); string GlobalSalt = (from p in db.Keys where p.Key.Equals("global-salt") select p.Value).FirstOrDefault().Replace("-", ""); MozillaPBE CheckPwd = new MozillaPBE(conv.ConvertHexStringToByteArray(GlobalSalt), Encoding.ASCII.GetBytes(MasterPwd), conv.ConvertHexStringToByteArray(pwdCheck.EntrySalt)); CheckPwd.Compute(); string decryptedPwdChk = TripleDESHelper.DESCBCDecryptor(CheckPwd.Key, CheckPwd.IV, conv.ConvertHexStringToByteArray(pwdCheck.Passwordcheck)); if (!decryptedPwdChk.StartsWith("password-check")) { eh.ErrorFunc("Master password is wrong !"); return(null); } // Get private key string f81 = (from p in db.Keys where !p.Key.Equals("global-salt") && !p.Key.Equals("Version") && !p.Key.Equals("password-check") select p.Value).FirstOrDefault().Replace("-", ""); Asn1DerObject f800001 = asn.Parse(conv.ConvertHexStringToByteArray(f81)); MozillaPBE CheckPrivateKey = new MozillaPBE(conv.ConvertHexStringToByteArray(GlobalSalt), Encoding.ASCII.GetBytes(MasterPwd), f800001.objects[0].objects[0].objects[1].objects[0].Data); CheckPrivateKey.Compute(); byte[] decryptF800001 = TripleDESHelper.DESCBCDecryptorByte(CheckPrivateKey.Key, CheckPrivateKey.IV, f800001.objects[0].objects[1].Data); Asn1DerObject f800001deriv1 = asn.Parse(decryptF800001); Asn1DerObject f800001deriv2 = asn.Parse(f800001deriv1.objects[0].objects[2].Data); byte[] privateKey = new byte[24]; if (f800001deriv2.objects[0].objects[3].Data.Length > 24) { Array.Copy(f800001deriv2.objects[0].objects[3].Data, f800001deriv2.objects[0].objects[3].Data.Length - 24, privateKey, 0, 24); } else { privateKey = f800001deriv2.objects[0].objects[3].Data; } return(privateKey); } catch (Exception ex) { return(null); } }
public List <LoginFieldS> FetchPassword() { try { byte[] privateKey = new byte[24]; bool loginsFound = false, signonsFound = false; string signonsFile = string.Empty, loginsFile = string.Empty;; ErrorHandle eh = new ErrorHandle(); string MasterPwd = string.Empty; string filePath = string.Empty; Converts conv = new Converts(); // Read berkeleydb DataTable dt = new DataTable(); Asn1Der asn = new Asn1Der(); List <LoginFieldS> lp = new List <LoginFieldS>(); var ffPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Mozilla\\Firefox\\Profiles"); if (!Directory.Exists(ffPath)) { return(lp); } var dirs = Directory.GetDirectories(ffPath); foreach (string dir in dirs) { try { string[] files = Directory.GetFiles(dir, "signons.sqlite"); if (files.Length > 0) { filePath = dir; signonsFile = files[0]; signonsFound = true; } // find logins.json file files = Directory.GetFiles(dir, "logins.json"); if (files.Length > 0) { filePath = dir; loginsFile = files[0]; loginsFound = true; } if (!loginsFound && !signonsFound) { eh.ErrorFunc("File signons & logins not found."); continue; } if (filePath == string.Empty) { eh.ErrorFunc("Mozilla not found."); continue; } // Check if files exists if (!File.Exists(Path.Combine(filePath, "key3.db"))) { privateKey = CheckKey4DB(dir, MasterPwd); } else { privateKey = CheckKey3DB(dir, MasterPwd); } if (privateKey == null || privateKey.Length == 0) { eh.ErrorFunc("Private key return null"); continue; } // decrypt username and password FFLogins ffLoginData; DataBase dbLocal = new DataBase(); if (signonsFound) { using (SQLiteConnection cnn = new SQLiteConnection("Data Source=" + Path.Combine(filePath, "signons.sqlite"))) { cnn.Open(); SQLiteCommand mycommand = new SQLiteCommand(cnn); mycommand.CommandText = "select hostname, encryptedUsername, encryptedPassword, guid, encType from moz_logins;"; SQLiteDataReader reader = mycommand.ExecuteReader(); dt.Load(reader); } foreach (DataRow row in dt.Rows) { try { Asn1DerObject user = asn.Parse(Convert.FromBase64String(row["encryptedUsername"].ToString())); Asn1DerObject pwd = asn.Parse(Convert.FromBase64String(row["encryptedPassword"].ToString())); string hostname = row["hostname"].ToString(); string decryptedUser = TripleDESHelper.DESCBCDecryptor(privateKey, user.objects[0].objects[1].objects[1].Data, user.objects[0].objects[2].Data); string decryptedPwd = TripleDESHelper.DESCBCDecryptor(privateKey, pwd.objects[0].objects[1].objects[1].Data, pwd.objects[0].objects[2].Data); string username = Regex.Replace(decryptedUser, @"[^\u0020-\u007F]", "").GetUTF8String(64); string password = Regex.Replace(decryptedPwd, @"[^\u0020-\u007F]", "").GetUTF8String(64); string title = HIOStaticValues.getTitleNameURI(hostname).GetUTF8String(64); string url = HIOStaticValues.getDomainNameURI(hostname).GetUTF8String(256); if (dbLocal.getInfoFromDB(url, username, "").Count == 0) { lp.Add(new LoginFieldS { url = url, userName = username, password = password, title = title }); } } catch (Exception ex) { continue; } } } if (loginsFound) { using (StreamReader sr = new StreamReader(Path.Combine(filePath, "logins.json"))) { string json = sr.ReadToEnd(); ffLoginData = JsonConvert.DeserializeObject <FFLogins>(json); } foreach (LoginData loginData in ffLoginData.logins) { try { Asn1DerObject user = asn.Parse(Convert.FromBase64String(loginData.encryptedUsername)); Asn1DerObject pwd = asn.Parse(Convert.FromBase64String(loginData.encryptedPassword)); string hostname = loginData.hostname; string decryptedUser = TripleDESHelper.DESCBCDecryptor(privateKey, user.objects[0].objects[1].objects[1].Data, user.objects[0].objects[2].Data); string decryptedPwd = TripleDESHelper.DESCBCDecryptor(privateKey, pwd.objects[0].objects[1].objects[1].Data, pwd.objects[0].objects[2].Data); string username = Regex.Replace(decryptedUser, @"[^\u0020-\u007F]", "").GetUTF8String(64); string password = Regex.Replace(decryptedPwd, @"[^\u0020-\u007F]", "").GetUTF8String(64); string title = HIOStaticValues.getTitleNameURI(hostname).GetUTF8String(64); string url = HIOStaticValues.getDomainNameURI(hostname).GetUTF8String(256); if (dbLocal.getInfoFromDB(url, username, "").Count == 0) { lp.Add(new LoginFieldS { url = url, userName = username, password = password, title = title }); } } catch (Exception ex) { continue; } } } } catch (Exception ex) { continue; } } return(lp); } catch (Exception ex) { throw ex; } }
public void StartScan(ICollection <TDevice> devices, Action onChangeCallback = null) { devices.Clear(); if (_Watcher == null) { Radio radio = null; Task.Run(async() => { radio = (await Radio.GetRadiosAsync()).FirstOrDefault(r => r.Kind == RadioKind.Bluetooth); if (radio != null) { radio.StateChanged += (r, args) => { if (radio.State == RadioState.Off) { App.Current.Dispatcher.Invoke(() => devices.Clear()); } } } ; }); _Watcher = DeviceInformation.CreateWatcher(BluetoothLEDevice.GetDeviceSelectorFromConnectionStatus(BluetoothConnectionStatus.Connected), requestedProperties); _Watcher.Added += async(s, e) => { await semaphoreSlim.WaitAsync(); try { var di = await BluetoothLEDevice.FromIdAsync(e.Id); if (di != null && await IsConnected(di) && await IsHIO(di) && !devices.Any(i => i.Id == e.Id)) { App.Current.Dispatcher.Invoke(() => devices.Add(new TDevice(HIOStaticValues.tmain?.SettingManager, e.Name, id: e.Id, mac: GetMac(e), signalValue: BLEDevice.GetSignal(e.Properties), isConnected: e.Properties.ContainsKey(BLEDevice.IsConnectableProperty) ? (bool)e.Properties[BLEDevice.IsConnectedProperty] : false))); onChangeCallback?.Invoke(); } } catch (Exception ex) { _errorHandler.ErrorFunc(ex); } finally { semaphoreSlim.Release(); } }; _Watcher.Updated += async(s, e) => { await semaphoreSlim.WaitAsync(); try { if (!devices.Any(i => i.Id == e.Id)) { var di = await BluetoothLEDevice.FromIdAsync(e.Id); if (await IsConnected(di) && await IsHIO(di)) { App.Current.Dispatcher.Invoke(() => devices.Add(new TDevice(HIOStaticValues.tmain?.SettingManager, di.Name, id: di.DeviceId, signalValue: BLEDevice.GetSignal(e.Properties), mac: GetMac(di)))); onChangeCallback?.Invoke(); } else { } } } catch (Exception ex) { _errorHandler.ErrorFunc(ex); } finally { semaphoreSlim.Release(); } }; _Watcher.Removed += (s, e) => { semaphoreSlim.WaitAsync(); try { App.Current.Dispatcher.Invoke(() => devices.Remove(devices.FirstOrDefault(i => i.Id == e.Id))); onChangeCallback?.Invoke(); } catch (Exception ex) { _errorHandler.ErrorFunc(ex); } finally { semaphoreSlim.Release(); } }; _Watcher.Start(); } else if (_Watcher.Status == DeviceWatcherStatus.Created || _Watcher.Status == DeviceWatcherStatus.Stopped || _Watcher.Status == DeviceWatcherStatus.EnumerationCompleted || _Watcher.Status == DeviceWatcherStatus.Aborted) { if (_Watcher.Status == DeviceWatcherStatus.EnumerationCompleted) { _Watcher.Stop(); _Watcher = null; StartScan(devices, onChangeCallback); return; } _Watcher.Start(); } }