private void LoadPasswordSelector(string pathToWeightedFrequencyFile) { _passwordSelector = new WeightedSelector <string>(); using (System.IO.StreamReader file = new System.IO.StreamReader(new FileStream(pathToWeightedFrequencyFile, FileMode.Open, FileAccess.Read))) { string lineWithCountFollowedBySpaceFollowedByPassword; while ((lineWithCountFollowedBySpaceFollowedByPassword = file.ReadLine()) != null) { lineWithCountFollowedBySpaceFollowedByPassword = lineWithCountFollowedBySpaceFollowedByPassword.Trim(); int indexOfFirstSpace = lineWithCountFollowedBySpaceFollowedByPassword.IndexOf(' '); if (indexOfFirstSpace < 0 || indexOfFirstSpace + 1 >= lineWithCountFollowedBySpaceFollowedByPassword.Length) { continue; } string countAsString = lineWithCountFollowedBySpaceFollowedByPassword.Substring(0, indexOfFirstSpace); ulong count; if (!ulong.TryParse(countAsString, out count)) { continue; } string password = lineWithCountFollowedBySpaceFollowedByPassword.Substring(indexOfFirstSpace + 1); _passwordSelector.AddItem(password, count); } } }
public void Generate(ExperimentalConfiguration experimentalConfiguration) { SimulatedUserAccountController simUserAccountController = new SimulatedUserAccountController(); _logger.WriteStatus("Creating accounts"); ConcurrentBag <SimulatedUserAccount> benignSimulatedAccountBag = new ConcurrentBag <SimulatedUserAccount>(); Parallel.For(0, (int)experimentalConfiguration.NumberOfBenignAccounts, (index) => { //if (index > 0 && index % 10000 == 0) // _logger.WriteStatus("Created {0:N0} benign accounts", index); SimulatedUserAccount userAccount = simUserAccountController.Create( "user_" + index.ToString(), _simPasswords.GetPasswordFromWeightedDistribution() ); userAccount.ClientAddresses.Add(_ipPool.GetNewRandomBenignIp()); string initialCookie = StrongRandomNumberGenerator.Get64Bits().ToString(); userAccount.Cookies.Add(initialCookie); userAccount.HashesOfCookiesOfClientsThatHaveSuccessfullyLoggedIntoThisAccount[initialCookie] = true; benignSimulatedAccountBag.Add(userAccount); double inverseFrequency = Distributions.GetLogNormal(0, 1); if (inverseFrequency < 0.01d) { inverseFrequency = 0.01d; } if (inverseFrequency > 50d) { inverseFrequency = 50d; } double frequency = 1 / inverseFrequency; lock (BenignAccountSelector) { BenignAccountSelector.AddItem(userAccount, frequency); } }); BenignAccounts = benignSimulatedAccountBag.ToList(); // _logger.WriteStatus("Finished creating {0:N0} benign accounts", // experimentalConfiguration.NumberOfBenignAccounts); //_logger.WriteStatus("Creating attacker IPs"); _ipPool.GenerateAttackersIps(); //_logger.WriteStatus("Creating {0:N0} attacker accounts", // experimentalConfiguration.NumberOfAttackerControlledAccounts); ConcurrentBag <SimulatedUserAccount> maliciousSimulatedAccountBag = new ConcurrentBag <SimulatedUserAccount>(); Parallel.For(0, (int)experimentalConfiguration.NumberOfAttackerControlledAccounts, (index) => { SimulatedUserAccount userAccount = simUserAccountController.Create( "attacker_" + index.ToString(), _simPasswords.GetPasswordFromWeightedDistribution()); userAccount.ClientAddresses.Add(_ipPool.GetRandomMaliciousIp()); maliciousSimulatedAccountBag.Add(userAccount); }); AttackerAccounts = maliciousSimulatedAccountBag.ToList(); _logger.WriteStatus("Finished creating accounts", experimentalConfiguration.NumberOfAttackerControlledAccounts); Parallel.ForEach(BenignAccounts.Union(AttackerAccounts), (simAccount, loopState) => { simAccount.CreditHalfLife = experimentalConfiguration.BlockingOptions.AccountCreditLimitHalfLife; simAccount.CreditLimit = experimentalConfiguration.BlockingOptions.AccountCreditLimit; foreach (string cookie in simAccount.Cookies) { simUserAccountController.HasClientWithThisHashedCookieSuccessfullyLoggedInBefore( simAccount, LoginAttempt.HashCookie(cookie)); } }); //_logger.WriteStatus("Finished creating user accounts for each simluated account record"); }