/// <summary> /// Main, entry point /// </summary> /// <param name="args">args[0] == .json config path</param> static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("Usage: BruteGen.exe <config .json path>"); GenConfig defaultConfig = new GenConfig(); JsonSerializerSettings serializeSettings = new JsonSerializerSettings(); serializeSettings.Formatting = Formatting.Indented; string jsonStringOut = JsonConvert.SerializeObject(defaultConfig, serializeSettings); string jsonOutPath = Directory.GetCurrentDirectory() + @"\default-config.json"; jsonOutPath = Regex.Replace(jsonOutPath, @"\\", "/"); File.WriteAllText(jsonOutPath, jsonStringOut); Console.WriteLine($"Writing default config to {jsonOutPath}"); return; } string configPath = GetPath(args[0]); if (configPath == null) { Console.WriteLine("ERROR: Could not find .json file for path " + args[0]); return; } if (!configPath.Contains(".json")) { Console.WriteLine("ERROR: path does not contain '.json' :" + configPath); return; } GenConfig config = LoadConfig(configPath); if (!Directory.Exists(config.output_path)) { Console.WriteLine("ERROR: could not find config.outputPath: " + config.output_path); return; } if (!Directory.Exists(config.words_base_path)) { Console.WriteLine("ERROR: could not find config.words_path: " + config.words_base_path); return; } Directory.SetCurrentDirectory(config.words_base_path); string outputName = Path.GetFileNameWithoutExtension(configPath);//tex filename for resume state and matches file. string resumeStatePath = Path.Combine(config.output_path, $"{outputName}-resume_state.json"); // hash test info var hashInfo = new HashInfo(); if (config.test_hashes_path != null) { Console.WriteLine("Reading input hashes:"); int maxLength; hashInfo.inputHashes = GetStrings(config.test_hashes_path, out maxLength); if (hashInfo.inputHashes == null) { Console.WriteLine("ERROR: no hashes found in " + config.test_hashes_path); return; } if (config.test_hashes_func == null) { Console.WriteLine("ERROR: Could not find test_'hashes_func' in config"); return; } hashInfo.HashFunc = HashFuncs.GetHashFuncByName(config.test_hashes_func); if (hashInfo.HashFunc == null) { Console.WriteLine("ERROR: Could not find hash function " + config.test_hashes_func); return; } if (hashInfo.inputHashes != null) { Console.WriteLine("Will test strings with " + config.test_hashes_func); } }//if test_hashes_path Console.WriteLine("Reading words lists"); int[] maxWordLengths; var allWordsLists = GetWordsLists(config.words_paths, out maxWordLengths); int maxStringLength = maxWordLengths.Sum(); GenerateWordVariations(config, ref allWordsLists); Console.WriteLine("Word counts:"); string listNames = " "; for (int i = 0; i < allWordsLists.Length; i++) { listNames += Path.GetFileName(config.words_paths[i]) + "\t"; } Console.WriteLine(listNames); string wordCounts = " "; for (int i = 0; i < allWordsLists.Length; i++) { wordCounts += allWordsLists[i].Count + "\t"; } Console.WriteLine(wordCounts); Console.WriteLine("Batch size:" + config.batch_size); string stringsOutPath = Path.Combine(config.output_path, outputName + ".txt"); //LEGACY CULL //Stack<RecurseStep> resumeStackState = ReadResumeStackState(resumeStatePath); //GenerateStringsStack(resumeStackState, allWordsLists, hashInfo, config.batch_size, config.test_on_batch, resumeStatePath, stringsOutPath); int[] lockstepIds = new int[allWordsLists.Length]; int[] lockstepHeads = new int[allWordsLists.Length];//tex maximum number of ids is actually wordsLists.Length / 2 + 1 (id 0 for 'not a lockstep list'). if (config.lockstep_same_word_lists) { BuildLockstepInfo(config.words_paths, ref lockstepIds, ref lockstepHeads); }//config.lockstep_same_word_lists GenerateStrings(allWordsLists, lockstepIds, lockstepHeads, hashInfo, maxStringLength, config.batch_size, config.test_on_batch, resumeStatePath, stringsOutPath);//tex the main generate/test loop if (File.Exists(resumeStatePath)) { File.Delete(resumeStatePath); } //SimpleTests(allWordsLists); Console.WriteLine("done"); }//Main
public static byte[] ToHMacSHA1(string s, string key) { return(HashFuncs.ToHMacSHA1(s, key)); }
public static byte[] ToSHA1Bytes(string s) { return(HashFuncs.ToSHA1(Encoding.UTF8.GetBytes(s))); }
public static string ToSHA1(string s) { return(StringFuncs.ToHexString(HashFuncs.ToSHA1(Encoding.UTF8.GetBytes(s)))); }
public static string ToSHA1(FileInfo file) { return(StringFuncs.ToHexString(HashFuncs.ToSHA1(File.ReadAllBytes(file.FullName)))); }
public static string ToMD5(string s) { return(HashFuncs.ToMD5(Encoding.UTF8.GetBytes(s))); }