예제 #1
0
        //static IGenomeDecoder<NeatGenome, MarkovChain> _genomeDecoder;
        //static PasswordCrackingEvaluator _passwordCrackingEvaluator;



        public static void Evaluate(IGenomeDecoder<NeatGenome, MarkovChain> genomeDecoder, PasswordCrackingEvaluator passwordCrackingEvaluator, PasswordEvolutionExperiment experiment)
        {

            string[] genomeFiles = Directory.GetFiles(@"..\..\..\experiments\genomes\", "*.xml");

            XmlDocument doc = new XmlDocument();
            int genomeNumber;


            foreach (string genomeFile in genomeFiles)
            {
                // Read in genome
                doc.Load(genomeFile);

                //NeatGenome genome = NeatGenomeXmlIO.LoadGenome(doc, false);
                //NeatGenomeFactory genomeFactory = (NeatGenomeFactory)CreateGenomeFactory();

                NeatGenome genome = experiment.LoadPopulation(XmlReader.Create(genomeFile))[0];
                MarkovChain phenome = experiment.CreateGenomeDecoder().Decode(genome);//genomeDecoder.Decode(genome);

                string[] filePath = genomeFile.Split('\\');
                string[] fileName = (filePath[filePath.Length - 1]).Split('-');


                String fileNumber = (fileName[1]).Split('.')[0];

                genomeNumber = Convert.ToInt32(fileNumber);


                //FileStream fs = File.Open(@"..\..\..\experiments\genomes\genome-results\genome-"+genomeNumber+"-results.txt", FileMode.CreateNew, FileAccess.Write);
                TextWriter tw = new StreamWriter(@"..\..\..\experiments\genomes\genome-results\genome-" + genomeNumber + "-results.txt");

                // Evaluate
                if (null == phenome)
                {   // Non-viable genome.
                    tw.WriteLine("0.0 0.0");
                }
                else
                {
                    FitnessInfo fitnessInfo = passwordCrackingEvaluator.Evaluate(phenome);
                    double val = fitnessInfo._fitness;
                    double val2 = fitnessInfo._alternativeFitness;
                    tw.WriteLine(fitnessInfo._fitness + " " + fitnessInfo._alternativeFitness);
                }
                tw.Close();
                File.Create(@"..\..\..\experiments\genomes\genome-finished\genome-" + genomeNumber + "-finished.txt");
            }

            // Write results?? -> genome_#_results
            // Write finished flag -> genome_#_finished

        }
예제 #2
0
        // Loads all the passwords and the configuration file.
        static void PrepareMarkovModelRuns(string results_file)
        {
            const string PASSWORD_OFFSET = @"../../../passwords/";

            _datasetFilenames = new PasswordDatasetInfo[]
            {
                new PasswordDatasetInfo()
                {
                    Filename = "faithwriters-withcount.txt", Name = "faithwriters"
                },
                new PasswordDatasetInfo()
                {
                    Filename = "myspace-filtered-withcount.txt", Name = "myspace"
                },
                new PasswordDatasetInfo()
                {
                    Filename = "phpbb-withcount.txt", Name = "phpbb"
                },
                new PasswordDatasetInfo()
                {
                    Filename = "rockyou-withcount.txt", Name = "rockyou"
                },
                new PasswordDatasetInfo()
                {
                    Filename = "singles.org-withcount.txt", Name = "singles.org"
                },
//                new PasswordDatasetInfo() { Filename = "morphed_english.txt", Name = "training" },
//                new PasswordDatasetInfo() { Filename = "forced_morphed_english.txt", Name = "testing" }
            };

            Console.WriteLine("Loading all {0} password datasets...", _datasetFilenames.Length);
            _passwords = new Dictionary <string, PasswordInfo> [_datasetFilenames.Length];
            for (int i = 0; i < _passwords.Length; i++)
            {
                Console.WriteLine(_datasetFilenames[i].Name);
                _passwords[i] = PasswordUtil.LoadPasswords(PASSWORD_OFFSET + _datasetFilenames[i].Filename);
            }
            Console.WriteLine("Done.");

            _experiment = new PasswordEvolutionExperiment();

            XmlDocument xmlConfig = new XmlDocument();

            xmlConfig.Load(CONFIG_FILE);
            _experiment.Passwords = _passwords[0];
            _experiment.Initialize("PasswordEvolution", xmlConfig.DocumentElement);

            using (TextWriter writer = new StreamWriter(results_file))
                writer.WriteLine("TrainingSet,TestingSet,Accounts Cracked,Passwords Cracked,% Accounts,% Passwords");
        }
예제 #3
0
        // Loads all the passwords and the configuration file.
        static void PrepareMarkovModelRuns()
        {
            const string PASSWORD_OFFSET = @"..\..\..\passwords\";
            _datasetFilenames = new PasswordDatasetInfo[]
            {
                //new PasswordDataset(){ Filename = "faithwriters-withcount.txt", Name = "faithwriters" },
                //new PasswordDataset(){ Filename = "myspace-filtered-withcount.txt", Name = "myspace" },
                //new PasswordDataset(){ Filename = "phpbb-withcount.txt", Name = "phpbb" },
                //new PasswordDataset(){ Filename = "rockyou-withcount.txt", Name = "rockyou" },
                //new PasswordDataset(){ Filename = "singles.org-withcount.txt", Name = "singles.org" },
                new PasswordDatasetInfo() { Filename = "morphed_english.txt", Name = "training" },
                new PasswordDatasetInfo() { Filename = "forced_morphed_english.txt", Name = "testing" }
            };

            Console.WriteLine("Loading all {0} password datasets...", _datasetFilenames.Length);
            _passwords = new Dictionary<string, double>[_datasetFilenames.Length];
            for (int i = 0; i < _passwords.Length; i++)
            {
                Console.WriteLine(_datasetFilenames[i].Name);
                _passwords[i] = PasswordUtil.LoadPasswords(PASSWORD_OFFSET + _datasetFilenames[i].Filename);
            }
            Console.WriteLine("Done.");

            _experiment = new PasswordEvolutionExperiment();

            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(CONFIG_FILE);
            _experiment.Passwords = _passwords[0];
            _experiment.Initialize("PasswordEvolution", xmlConfig.DocumentElement);

            using (TextWriter writer = new StreamWriter(@"..\..\..\experiments\summary_results.csv"))
                writer.WriteLine("TrainingSet,TestingSet,Accounts Cracked,Passwords Cracked,% Accounts,% Passwords");
        }
예제 #4
0
        /// <summary>
        /// Trains a Markov model on a the training set of passwords, then evolves it against the target password database
        /// specified in the config file. At the end of the evolution, the champion model is evaluated for a larger number
        /// of guesses.
        /// </summary>
        /// <param name="trainingSetFile">The file containing the passwords from which to build the initial Markov model.</param>
        /// <param name="seedFile">The file to which the initial Markov model will be saved.</param>
        /// <param name="configFile">The file containing all the configuration parameters of the evolution.</param>
        /// <param name="resultsFile">The file to which the results will be saved at each generation.</param>
        /// <param name="validateSeed">If true, the seed model will first be validated against a large number of guesses.</param>
        //private static void RunExperiment(string trainingSetFile, string seedFile, string configFile, string resultsFile, bool validateSeed = false)
        private static void RunExperiment(string configFile, bool validateSeed = false)
        {
            Console.Write("Building Markov model...");
            
            // Load the XML configuration file
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(configFile);
            XmlElement xmlConfigElement = xmlConfig.DocumentElement;

            // Set Training File
            string trainingSetFile = XmlUtils.GetValueAsString(xmlConfigElement, "TrainingFile");

            // Create seedFile
            string seedFile = XmlUtils.GetValueAsString(xmlConfigElement, "SeedFile");

            // Create results file.
            string resultsFile = XmlUtils.GetValueAsString(xmlConfigElement, "ResultsFile");

            Console.WriteLine("\nTraining File: {0}\nSeed File: {1}\nResults File: {2}", trainingSetFile, seedFile, resultsFile);
            

            // Load the training set passwords from file
            var passwords = PasswordUtil.LoadPasswords(trainingSetFile, 8); 
            
            // Create a Markov model from the passwords. This model will be used
            // as our seed for the evolution.
            int outputs = MarkovFilterCreator.GenerateFirstOrderMarkovFilter(seedFile, passwords);

            // Free up the memory used by the passwords
            passwords = null;

            Console.WriteLine("Done! Outputs: {0}", outputs);

            _experiment = new PasswordEvolutionExperiment();
            _experiment.OutputCount = outputs;
            
            // Initialize the experiment with the specifications in the config file.
            _experiment.Initialize("PasswordEvolution", xmlConfig.DocumentElement);

            // Set the passwords to be used by the fitness evaluator.
            // These are the passwords our models will try to guess.
            // PasswordsWithAccounts is the file used for validation. Its account values won't be changed.
            PasswordCrackingEvaluator.Passwords = _experiment.Passwords;
            PasswordCrackingEvaluator.PasswordsWithAccounts = new Dictionary<string,double>(_experiment.Passwords); // Makes a deep copy

            Console.WriteLine("Loading seed...");
            
            // Load the seed model that we created at the start of this function
            var seed = _experiment.LoadPopulation(XmlReader.Create(seedFile))[0];

            // Validates the seed model by running it for a large number of guesses 
            if (validateSeed)
            {
                Console.WriteLine("Validating seed model...");
                var seedModel = _experiment.CreateGenomeDecoder().Decode(seed);
                ValidateModel(seedModel, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
            }

            // Create evolution algorithm using the seed model to initialize the population
            Console.WriteLine("Creating population...");
            _ea = _experiment.CreateEvolutionAlgorithm(seed);

            // Attach an update event handler. This will be called at the end of every generation
            // to log the progress of the evolution (see function logEvolutionProgress below).
            _ea.UpdateEvent += new EventHandler(logEvolutionProgress);
            //_ea.UpdateScheme = new UpdateScheme(1);//.UpdateMode.
            
            // Setup results file
            using (TextWriter writer = new StreamWriter(resultsFile))
                writer.WriteLine("Generation,Champion Accounts,Champion Uniques,Average Accounts,Average Uniques,Total Accounts,Total Uniques");
            _generationalResultsFile = resultsFile;

            // Start algorithm (it will run on a background thread).
            Console.WriteLine("Starting evolution. Pop size: {0} Guesses: {1}", _experiment.DefaultPopulationSize, _experiment.GuessesPerIndividual);
            _ea.StartContinue();

            // Wait until the evolution is finished.
            while (_ea.RunState == RunState.Running) { Thread.Sleep(1000); }

            // Validate the resulting model.
            var decoder = _experiment.CreateGenomeDecoder();
            var champ = decoder.Decode(_ea.CurrentChampGenome);
            ValidateModel(champ, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
        }
예제 #5
0
        /// <summary>
        /// Trains a Markov model on a the training set of passwords, then evolves it against the target password database
        /// specified in the config file. At the end of the evolution, the champion model is evaluated for a larger number
        /// of guesses.
        /// </summary>
        /// <param name="trainingSetFile">The file containing the passwords from which to build the initial Markov model.</param>
        /// <param name="seedFile">The file to which the initial Markov model will be saved.</param>
        /// <param name="configFile">The file containing all the configuration parameters of the evolution.</param>
        /// <param name="resultsFile">The file to which the results will be saved at each generation.</param>
        /// <param name="validateSeed">If true, the seed model will first be validated against a large number of guesses.</param>
        //private static void RunExperiment(string trainingSetFile, string seedFile, string configFile, string resultsFile, bool validateSeed = false)
        private static void RunExperiment(string configFile, bool validateSeed = false)
        {
            Console.Write("Building Markov model...");

            // Load the XML configuration file
            XmlDocument xmlConfig = new XmlDocument();

            xmlConfig.Load(configFile);
            XmlElement xmlConfigElement = xmlConfig.DocumentElement;

            // Set Training File
            string trainingSetFile = XmlUtils.GetValueAsString(xmlConfigElement, "TrainingFile");

            // Create seedFile
            string seedFile = XmlUtils.GetValueAsString(xmlConfigElement, "SeedFile");

            // Create results file.
            string resultsFile = XmlUtils.GetValueAsString(xmlConfigElement, "ResultsFile");

            Console.WriteLine("\nTraining File: {0}\nSeed File: {1}\nResults File: {2}", trainingSetFile, seedFile, resultsFile);


            // Load the training set passwords from file
            var passwords = PasswordUtil.LoadPasswords(trainingSetFile, 8);

            // Create a Markov model from the passwords. This model will be used
            // as our seed for the evolution.
            int outputs = MarkovFilterCreator.GenerateFirstOrderMarkovFilter(seedFile, passwords);

            // Free up the memory used by the passwords
            passwords = null;

            Console.WriteLine("Done! Outputs: {0}", outputs);

            _experiment             = new PasswordEvolutionExperiment();
            _experiment.OutputCount = outputs;

            // Initialize the experiment with the specifications in the config file.
            _experiment.Initialize("PasswordEvolution", xmlConfig.DocumentElement);

            // Set the passwords to be used by the fitness evaluator.
            // These are the passwords our models will try to guess.
            // PasswordsWithAccounts is the file used for validation. Its account values won't be changed.
            PasswordCrackingEvaluator.Passwords             = _experiment.Passwords;
            PasswordCrackingEvaluator.PasswordsWithAccounts = new Dictionary <string, double>(_experiment.Passwords); // Makes a deep copy

            Console.WriteLine("Loading seed...");

            // Load the seed model that we created at the start of this function
            var seed = _experiment.LoadPopulation(XmlReader.Create(seedFile))[0];

            // Validates the seed model by running it for a large number of guesses
            if (validateSeed)
            {
                Console.WriteLine("Validating seed model...");
                var seedModel = _experiment.CreateGenomeDecoder().Decode(seed);
                ValidateModel(seedModel, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
            }

            // Create evolution algorithm using the seed model to initialize the population
            Console.WriteLine("Creating population...");
            _ea = _experiment.CreateEvolutionAlgorithm(seed);

            // Attach an update event handler. This will be called at the end of every generation
            // to log the progress of the evolution (see function logEvolutionProgress below).
            _ea.UpdateEvent += new EventHandler(logEvolutionProgress);
            //_ea.UpdateScheme = new UpdateScheme(1);//.UpdateMode.

            // Setup results file
            using (TextWriter writer = new StreamWriter(resultsFile))
                writer.WriteLine("Generation,Champion Accounts,Champion Uniques,Average Accounts,Average Uniques,Total Accounts,Total Uniques");
            _generationalResultsFile = resultsFile;

            // Start algorithm (it will run on a background thread).
            Console.WriteLine("Starting evolution. Pop size: {0} Guesses: {1}", _experiment.DefaultPopulationSize, _experiment.GuessesPerIndividual);
            _ea.StartContinue();

            // Wait until the evolution is finished.
            while (_ea.RunState == RunState.Running)
            {
                Thread.Sleep(1000);
            }

            // Validate the resulting model.
            var decoder = _experiment.CreateGenomeDecoder();
            var champ   = decoder.Decode(_ea.CurrentChampGenome);

            ValidateModel(champ, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
        }
예제 #6
0
        private static void RunExperiment()
        {
            // Create evolution algorithm using the seed model to initialize the population
            Console.WriteLine("Creating population...");
            Console.Write("Building Markov model...");

            // Load the XML configuration file
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(cp.ConfigFile);
            
            // Set Training File
            string trainingSetFile = cp.TrainingDb;

            // Create seedFile
            string seedFile = cp.SeedFile;

            // Create results file.
            string resultsFile = cp.ResultsFile;
            Console.WriteLine();
            Console.WriteLine("Training File: {0}", trainingSetFile);
            Console.WriteLine("Seed File: {0}", seedFile);
            Console.WriteLine("Results File: {0}", resultsFile);

            // Load the training set passwords from file
            var passwords = PasswordUtil.LoadPasswords(trainingSetFile, cp.PasswordLength);


            // Create a Markov model from the passwords. This model will be used
            // as our seed for the evolution.
            int outputs = MarkovFilterCreator.GenerateFirstOrderMarkovFilter(seedFile, passwords);

            // Free up the memory used by the passwords
            passwords = null;

            Console.WriteLine("Done! Outputs: {0}", outputs);

            _experiment = new PasswordEvolutionExperiment();
            _experiment.OutputCount = outputs;

            // Initialize the experiment with the specifications in the config file.
            _experiment.Initialize("PasswordEvolution", xmlConfig.DocumentElement); //cmd arguments

            if(cp.EvolutionDb != null)
			{
				Console.WriteLine("Using command-line password file for evolution: {0}", cp.EvolutionDb);
				Console.WriteLine("Password length: {0}", cp.PasswordLength);
				PasswordCrackingEvaluator.Passwords = PasswordUtil.LoadPasswords(cp.EvolutionDb, cp.PasswordLength);
				Console.WriteLine("PasswordCrackingEvaluator.Passwords = {0}", PasswordCrackingEvaluator.Passwords == null ? "NULL" : "NOT NULL");
			}
			else
			{
				// Set the passwords to be used by the fitness evaluator.
				// These are the passwords our models will try to guess.
				PasswordCrackingEvaluator.Passwords = _experiment.Passwords;
				Console.WriteLine("Using config file passwords for evolution.");
			}
			Accounts = PasswordCrackingEvaluator.Passwords;

            Console.WriteLine("Loading seed...");

            // Load the seed model that we created at the start of this function
            var seed = _experiment.LoadPopulation(XmlReader.Create(seedFile))[0];

            // Create evolution algorithm using the seed model to initialize the population
            Console.WriteLine("Creating population...");

            ce = new CondorEvaluator(cp.ExperimentDir, cp.ConfigFile, cp.ResultsFile, CondorGroup.Grad, outputs, PasswordCrackingEvaluator.Passwords, cp.PasswordLength);
            _ea = _experiment.CreateEvolutionAlgorithm(seed, ce);


            // Attach an update event handler. This will be called at the end of every generation
            // to log the progress of the evolution (see function logEvolutionProgress below).
			_ea.UpdateScheme = new UpdateScheme(1);
			_ea.UpdateEvent += new EventHandler(logEvolutionProgress);
            
            // Setup results file
            using (TextWriter writer = new StreamWriter(resultsFile))
                writer.WriteLine("Generation,Champion Accounts,Champion Uniques,Average Accounts,Average Uniques,Total Accounts,Total Uniques");
            //_generationalResultsFile = resultsFile;

            // Start algorithm (it will run on a background thread).
            Console.WriteLine("Starting evolution. Pop size: {0} Guesses: {1}", _experiment.DefaultPopulationSize, _experiment.GuessesPerIndividual);
            _ea.StartContinue();

            // Wait until the evolution is finished.
            while (_ea.RunState == RunState.Running) { Thread.Sleep(1000); }


        }
예제 #7
0
        /// <summary>
        /// Trains a Markov model on a the training set of passwords, then evolves it against the target password database
        /// specified in the config file. At the end of the evolution, the champion model is evaluated for a larger number
        /// of guesses.
        /// </summary>
        /// <param name="trainingSetFile">The file containing the passwords from which to build the initial Markov model.</param>
        /// <param name="seedFile">The file to which the initial Markov model will be saved.</param>
        /// <param name="configFile">The file containing all the configuration parameters of the evolution.</param>
        /// <param name="resultsFile">The file to which the results will be saved at each generation.</param>
        /// <param name="validateSeed">If true, the seed model will first be validated against a large number of guesses.</param>
        //private static void RunExperiment(string trainingSetFile, string seedFile, string configFile, string resultsFile, bool validateSeed = false)
        private static void RunExperiment(string configFile, bool validateSeed = false)
        {
            Console.WriteLine("Removing previous champions...");
            string[] oldChampionFiles = Directory.GetFiles(@"../../../experiments/champions/", "*.xml");
            foreach (string oldChampion in oldChampionFiles)
                File.Delete(oldChampion);

            Console.Write("Building Markov model...");
            
            // Load the XML configuration file
            XmlDocument xmlConfig = new XmlDocument();
            xmlConfig.Load(configFile);
            XmlElement xmlConfigElement = xmlConfig.DocumentElement;

            // Set Training File
            string trainingSetFile = XmlUtils.GetValueAsString(xmlConfigElement, "TrainingFile");

            // Create seedFile
            string seedFile = XmlUtils.GetValueAsString(xmlConfigElement, "SeedFile");

            // Create results file.
            string resultsFile = XmlUtils.GetValueAsString(xmlConfigElement, "ResultsFile");

            Console.WriteLine();
            Console.WriteLine("Training File: {0}", trainingSetFile);
            Console.WriteLine("Seed File: {0}", seedFile);
            Console.WriteLine("Results File: {0}", resultsFile);
            

            // Load the training set passwords from file
            var passwords = PasswordUtil.LoadPasswords(trainingSetFile, 8); 
            
            // Create a Markov model from the passwords. This model will be used
            // as our seed for the evolution.
            int outputs = MarkovFilterCreator.GenerateFirstOrderMarkovFilter(seedFile, passwords);

            // Free up the memory used by the passwords
            passwords = null;

            Console.WriteLine("Done! Outputs: {0}", outputs);

            _experiment = new PasswordEvolutionExperiment();
            _experiment.OutputCount = outputs;
            
            // Initialize the experiment with the specifications in the config file.
            _experiment.Initialize("PasswordEvolution", xmlConfig.DocumentElement);

            // Set the passwords to be used by the fitness evaluator.
            // These are the passwords our models will try to guess.
            // PasswordsWithAccounts is the file used for validation. Its account values won't be changed.
            PasswordCrackingEvaluator.Passwords = _experiment.Passwords;

            Console.WriteLine("Loading seed...");
            
            // Load the seed model that we created at the start of this function
            var seed = _experiment.LoadPopulation(XmlReader.Create(seedFile))[0];

            // Validates the seed model by running it for a large number of guesses 
            if (validateSeed)
            {
                Console.WriteLine("Validating seed model...");
                var seedModel = _experiment.CreateGenomeDecoder().Decode(seed);
                ValidateModel(seedModel, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
            }

            // Create evolution algorithm using the seed model to initialize the population
            Console.WriteLine("Creating population...");
            _ea = _experiment.CreateEvolutionAlgorithm(seed);

            // Attach an update event handler. This will be called at the end of every generation
            // to log the progress of the evolution (see function logEvolutionProgress below).
            _ea.UpdateEvent += new EventHandler(logEvolutionProgress);
            //_ea.UpdateScheme = new UpdateScheme(1);//.UpdateMode.
            
            // Setup results file
            using (TextWriter writer = new StreamWriter(resultsFile))
                writer.WriteLine("Generation,Champion Accounts,Champion Uniques,Average Accounts,Average Uniques,Total Accounts,Total Uniques");
            _generationalResultsFile = resultsFile;

            // Start algorithm (it will run on a background thread).
            Console.WriteLine("Starting evolution. Pop size: {0} Guesses: {1}", _experiment.DefaultPopulationSize, _experiment.GuessesPerIndividual);
            _ea.StartContinue();

            // Wait until the evolution is finished.
            while (_ea.RunState == RunState.Running) { Thread.Sleep(1000); }

            if (VALIDATE_ALL_STAR)
            {
                // Validate the champions of each generation.
                List<MarkovChain> championModels = new List<MarkovChain>();
                string[] championFiles = Directory.GetFiles(@"../../../experiments/champions/", "*.xml");
                foreach (string championFile in championFiles)
                {
                    var currentChamp = _experiment.LoadPopulation(XmlReader.Create(championFile))[0];
                    var champModel = _experiment.CreateGenomeDecoder().Decode(currentChamp);
                    championModels.Add(champModel);
                }
                ValidateForest(championModels, _experiment.Passwords, VALIDATION_GUESSES/championFiles.Length, _experiment.Hashed);

                // Validate a population made up of copies of the final champion.
            /*    List<MarkovChain> championCopyPop = new List<MarkovChain>();

                Console.WriteLine();
                Console.WriteLine("Validating the final champion population");
                for (int i = 0; i < MAX_GENERATIONS; i++)
                {
                    var decoder = _experiment.CreateGenomeDecoder();
                    var champ = decoder.Decode(_ea.CurrentChampGenome);
                    championCopyPop.Add(champ);
                }
                ValidateAllstarTeam(championCopyPop, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
            */
            }
            else
            {
                // Validate the resulting model.
                var decoder = _experiment.CreateGenomeDecoder();
                var champ = decoder.Decode(_ea.CurrentChampGenome);
                ValidateModel(champ, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
            }

        }
예제 #8
0
        static void Main(string[] args)
        {
            if (args.Length < 7)
            {
				Console.WriteLine("Usage: ModelEvaluator.exe <results_file> <model_id> <model_file> <finished_flag> <passwords_found_file> <config_file> <outputs> [passwords] [pw_length]");
                return;
            }
			Console.WriteLine("Starting");
            PasswordEvolutionExperiment experiment = new PasswordEvolutionExperiment();

            int curArg = 0;
			string resultsFile = args[curArg++];
            int modelId = int.Parse(args[curArg++]);
			string modelFile = args[curArg++];
			string finishedFlag = args[curArg++];
			string passwordsFoundFile = args[curArg++];
			string configFile = args[curArg++];
			int outputs = int.Parse(args[curArg++]);
			experiment.OutputCount = outputs;

			// Load the XML configuration file
			XmlDocument xmlConfig = new XmlDocument();
			xmlConfig.Load(configFile);

			experiment.Initialize("evaluation", xmlConfig.DocumentElement);

            // Optionally load the passwords from somewhere besides the file specified
            // in the experiment config file.
            if (args.Length > curArg)
            {
				Console.WriteLine("Passwords file: {0}", args[curArg]);
				string passwordFile = args[curArg++];

                int? pwLength = null;
                if (args.Length > curArg)
				{
					Console.WriteLine("Password Length: {0}", args[curArg]);
					pwLength = int.Parse(args[curArg++]);
				}
                // Load the passwords to evaluate with
                experiment.Passwords = PasswordUtil.LoadPasswords(passwordFile, pwLength);
				Console.WriteLine("Passwords loaded");
            }
			PasswordCrackingEvaluator.Passwords = experiment.Passwords;

            PasswordCrackingEvaluator eval = new PasswordCrackingEvaluator(experiment.GuessesPerIndividual, experiment.Hashed);

            var modelGenome = experiment.LoadPopulation(XmlReader.Create(modelFile))[0];
            var model = experiment.CreateGenomeDecoder().Decode(modelGenome);

            using (TextWriter tw = new StreamWriter(resultsFile))
            {
                // Evaluate
                if (model == null)
                {   // Non-viable genome.
                    tw.WriteLine("0.0 0.0");
                }
                else
                {
                    FitnessInfo fitnessInfo = eval.Evaluate(model);
                    tw.WriteLine(fitnessInfo._fitness + " " + fitnessInfo._alternativeFitness);
                }
            }

			using(TextWriter writer = new StreamWriter(passwordsFoundFile))
				foreach(var pw in eval.FoundPasswords)
					writer.WriteLine(pw);

            File.Create(finishedFlag);
        }
예제 #9
0
        //static IGenomeDecoder<NeatGenome, MarkovChain> _genomeDecoder;
        //static PasswordCrackingEvaluator _passwordCrackingEvaluator;



        public static void Evaluate(IGenomeDecoder <NeatGenome, MarkovChain> genomeDecoder, PasswordCrackingEvaluator passwordCrackingEvaluator, PasswordEvolutionExperiment experiment)
        {
            string[] genomeFiles = Directory.GetFiles(@"..\..\..\experiments\genomes\", "*.xml");

            XmlDocument doc = new XmlDocument();
            int         genomeNumber;


            foreach (string genomeFile in genomeFiles)
            {
                // Read in genome
                doc.Load(genomeFile);

                //NeatGenome genome = NeatGenomeXmlIO.LoadGenome(doc, false);
                //NeatGenomeFactory genomeFactory = (NeatGenomeFactory)CreateGenomeFactory();

                NeatGenome  genome  = experiment.LoadPopulation(XmlReader.Create(genomeFile))[0];
                MarkovChain phenome = experiment.CreateGenomeDecoder().Decode(genome);//genomeDecoder.Decode(genome);

                string[] filePath = genomeFile.Split('\\');
                string[] fileName = (filePath[filePath.Length - 1]).Split('-');


                String fileNumber = (fileName[1]).Split('.')[0];

                genomeNumber = Convert.ToInt32(fileNumber);


                //FileStream fs = File.Open(@"..\..\..\experiments\genomes\genome-results\genome-"+genomeNumber+"-results.txt", FileMode.CreateNew, FileAccess.Write);
                TextWriter tw = new StreamWriter(@"..\..\..\experiments\genomes\genome-results\genome-" + genomeNumber + "-results.txt");

                // Evaluate
                if (null == phenome)
                {   // Non-viable genome.
                    tw.WriteLine("0.0 0.0");
                }
                else
                {
                    FitnessInfo fitnessInfo = passwordCrackingEvaluator.Evaluate(phenome);
                    double      val         = fitnessInfo._fitness;
                    double      val2        = fitnessInfo._alternativeFitness;
                    tw.WriteLine(fitnessInfo._fitness + " " + fitnessInfo._alternativeFitness);
                }
                tw.Close();
                File.Create(@"..\..\..\experiments\genomes\genome-finished\genome-" + genomeNumber + "-finished.txt");
            }

            // Write results?? -> genome_#_results
            // Write finished flag -> genome_#_finished
        }
예제 #10
0
        /// <summary>
        /// Trains a Markov model on a the training set of passwords, then evolves it against the target password database
        /// specified in the config file. At the end of the evolution, the champion model is evaluated for a larger number
        /// of guesses.
        /// </summary>
        /// <param name="trainingSetFile">The file containing the passwords from which to build the initial Markov model.</param>
        /// <param name="seedFile">The file to which the initial Markov model will be saved.</param>
        /// <param name="configFile">The file containing all the configuration parameters of the evolution.</param>
        /// <param name="resultsFile">The file to which the results will be saved at each generation.</param>
        /// <param name="validateSeed">If true, the seed model will first be validated against a large number of guesses.</param>
        //private static void RunExperiment(string trainingSetFile, string seedFile, string configFile, string resultsFile, bool validateSeed = false)
        private static void RunExperiment(string configFile, bool validateSeed = false)
        {
            Console.WriteLine("Removing previous champions...");
            string[] oldChampionFiles = Directory.GetFiles(@"../../../experiments/champions/", "*.xml");
            foreach (string oldChampion in oldChampionFiles)
            {
                File.Delete(oldChampion);
            }

            Console.Write("Building Markov model...");

            // Load the XML configuration file
            XmlDocument xmlConfig = new XmlDocument();

            xmlConfig.Load(configFile);
            XmlElement xmlConfigElement = xmlConfig.DocumentElement;

            // Set Training File
            string trainingSetFile = XmlUtils.GetValueAsString(xmlConfigElement, "TrainingFile");

            // Create seedFile
            string seedFile = XmlUtils.GetValueAsString(xmlConfigElement, "SeedFile");

            // Create results file.
            string resultsFile = XmlUtils.GetValueAsString(xmlConfigElement, "ResultsFile");

            Console.WriteLine();
            Console.WriteLine("Training File: {0}", trainingSetFile);
            Console.WriteLine("Seed File: {0}", seedFile);
            Console.WriteLine("Results File: {0}", resultsFile);


            // Load the training set passwords from file
            var passwords = PasswordUtil.LoadPasswords(trainingSetFile, 8);

            // Create a Markov model from the passwords. This model will be used
            // as our seed for the evolution.
            int outputs = MarkovFilterCreator.GenerateFirstOrderMarkovFilter(seedFile, passwords);

            // Free up the memory used by the passwords
            passwords = null;

            Console.WriteLine("Done! Outputs: {0}", outputs);

            _experiment             = new PasswordEvolutionExperiment();
            _experiment.OutputCount = outputs;

            // Initialize the experiment with the specifications in the config file.
            _experiment.Initialize("PasswordEvolution", xmlConfig.DocumentElement);

            // Set the passwords to be used by the fitness evaluator.
            // These are the passwords our models will try to guess.
            // PasswordsWithAccounts is the file used for validation. Its account values won't be changed.
            PasswordCrackingEvaluator.Passwords = _experiment.Passwords;

            Console.WriteLine("Loading seed...");

            // Load the seed model that we created at the start of this function
            var seed = _experiment.LoadPopulation(XmlReader.Create(seedFile))[0];

            // Validates the seed model by running it for a large number of guesses
            if (validateSeed)
            {
                Console.WriteLine("Validating seed model...");
                var seedModel = _experiment.CreateGenomeDecoder().Decode(seed);
                ValidateModel(seedModel, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
            }

            // Create evolution algorithm using the seed model to initialize the population
            Console.WriteLine("Creating population...");
            _ea = _experiment.CreateEvolutionAlgorithm(seed);

            // Attach an update event handler. This will be called at the end of every generation
            // to log the progress of the evolution (see function logEvolutionProgress below).
            _ea.UpdateEvent += new EventHandler(logEvolutionProgress);
            //_ea.UpdateScheme = new UpdateScheme(1);//.UpdateMode.

            // Setup results file
            using (TextWriter writer = new StreamWriter(resultsFile))
                writer.WriteLine("Generation,Champion Accounts,Champion Uniques,Average Accounts,Average Uniques,Total Accounts,Total Uniques");
            _generationalResultsFile = resultsFile;

            // Start algorithm (it will run on a background thread).
            Console.WriteLine("Starting evolution. Pop size: {0} Guesses: {1}", _experiment.DefaultPopulationSize, _experiment.GuessesPerIndividual);
            _ea.StartContinue();

            // Wait until the evolution is finished.
            while (_ea.RunState == RunState.Running)
            {
                Thread.Sleep(1000);
            }

            if (VALIDATE_ALL_STAR)
            {
                // Validate the champions of each generation.
                List <MarkovChain> championModels = new List <MarkovChain>();
                string[]           championFiles  = Directory.GetFiles(@"../../../experiments/champions/", "*.xml");
                foreach (string championFile in championFiles)
                {
                    var currentChamp = _experiment.LoadPopulation(XmlReader.Create(championFile))[0];
                    var champModel   = _experiment.CreateGenomeDecoder().Decode(currentChamp);
                    championModels.Add(champModel);
                }
                ValidateForest(championModels, _experiment.Passwords, VALIDATION_GUESSES / championFiles.Length, _experiment.Hashed);

                // Validate a population made up of copies of the final champion.

                /*    List<MarkovChain> championCopyPop = new List<MarkovChain>();
                 *
                 *  Console.WriteLine();
                 *  Console.WriteLine("Validating the final champion population");
                 *  for (int i = 0; i < MAX_GENERATIONS; i++)
                 *  {
                 *      var decoder = _experiment.CreateGenomeDecoder();
                 *      var champ = decoder.Decode(_ea.CurrentChampGenome);
                 *      championCopyPop.Add(champ);
                 *  }
                 *  ValidateAllstarTeam(championCopyPop, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
                 */
            }
            else
            {
                // Validate the resulting model.
                var decoder = _experiment.CreateGenomeDecoder();
                var champ   = decoder.Decode(_ea.CurrentChampGenome);
                ValidateModel(champ, _experiment.Passwords, VALIDATION_GUESSES, _experiment.Hashed);
            }
        }
 /// <summary>
 /// Construct with the provided IGenomeDecoder and IPhenomeEvaluator.
 /// Phenome caching is enabled by default.
 /// The number of parallel threads defaults to Environment.ProcessorCount.
 /// </summary>
 public ParallelNEATGenomeListEvaluator(IGenomeDecoder <NeatGenome, MarkovChain> genomeDecoder,
                                        PasswordCrackingEvaluator passwordCrackingEvaluator, PasswordEvolutionExperiment experiment)
     : this(genomeDecoder, passwordCrackingEvaluator, true)
 {
     this.experiment = experiment;
 }