public static void Run(string[] hashes, HashingMethod method, string alphabet, int length = 6) { #if LIBNOTIFYNET Notification.Send ("Hashlecter", "Started bruteforce attack.", 5000); #endif // Stopwatch for measuring time var watch = Stopwatch.StartNew (); if (!MainClass.options.silent) { // Update_Screen task var update = Task.Factory.StartNew (() => Update_Screen (watch)); // Update_Stats task var update_avg = Task.Factory.StartNew (Update_Stats); } string output; var alphabet_first = alphabet.First (); var alphabet_last = alphabet.Last (); for (var ihash = 0; ihash < hashes.Length; ihash++) { // Skip comments if (hashes [ihash].StartsWith ("#")) continue; current_hash = hashes [ihash]; // Incremental bruteforce if (MainClass.options.incremental) { // Calculate maximum for (var i = 1; i <= length; i++) bruteforce_max += Math.Pow (i, alphabet.Length); for (var curlen = 1; curlen <= length; ++curlen) { // Initialize buffer var accum = new StringBuilder (new String (alphabet_first, curlen)); while (true) { ++generated; ++avg_tmp; var value = accum.ToString (); current_str = value; var success = method.CheckHash (current_hash, value, out output); if (success) { ++cracked; MainClass.db.Add (MainClass.session, current_hash, value, method); #if LIBNOTIFYNET var _libnotifynet_format = string.Format ("Successfully cracked {0} hash:\n{1}\nValue was: {2}", method.Name, current_hash, output); Notification.Send ("Hashlecter", _libnotifynet_format, 7500, 250, 100); #endif done = true; goto end; } if (value.All (val => val == alphabet_last)) break; // TODO: Parallelize this for (var i = curlen - 1; i >= 0; --i) { if (accum [i] != alphabet_last) { accum [i] = alphabet [alphabet.IndexOf (accum [i]) + 1]; break; } else accum [i] = alphabet_first; } } } } // Fixed-length bruteforce else { // Calculated maximum bruteforce_max = Math.Pow (length, alphabet.Length); // Initialize buffer var accum = new StringBuilder (new String (alphabet_first, length)); while (true) { ++generated; ++avg_tmp; var value = accum.ToString (); current_str = value; var success = method.CheckHash (current_hash, value, out output); if (success) { ++cracked; MainClass.db.Add (MainClass.session, current_hash, value, method); #if LIBNOTIFYNET var _libnotifynet_format = string.Format ("Successfully cracked {0} hash:\n{1}\nValue was: {2}", method.Name, current_hash, output); Notification.Send ("Hashlecter", _libnotifynet_format, 7500, 250, 100); #endif done = true; goto end; } if (value.All (val => val == alphabet_last)) break; // TODO: Parallelize this for (var i = length - 1; i >= 0; --i) { if (accum [i] != alphabet_last) { accum [i] = alphabet [alphabet.IndexOf (accum [i]) + 1]; break; } else accum [i] = alphabet_first; } } } end: {} } watch.Stop (); // Display the correct stats after exiting if (!MainClass.options.silent) { Update_Screen (watch, force: true); } }
public static void Run(string[] hashes, HashingMethod method, string dictionary_path) { #if LIBNOTIFYNET Notification.Send("Hashlecter", "Started dictionary attack.", 5000); #endif // Dictionary buffer string[] dict = new string[BUFFER_SZ]; // Stopwatch for measuring time var watch = Stopwatch.StartNew(); if (!MainClass.options.silent) { // Update_Screen task var update = Task.Factory.StartNew(() => Update_Screen(watch)); // Update_Stats task var update_avg = Task.Factory.StartNew(Update_Stats); } // Open dictionary file for reading using (var fdict = File.OpenRead(dictionary_path)) using (var reader = new StreamReader(fdict)) { // Iterate over all hashes in the array for (var i = 0; i < hashes.Length; i++) { // Skip comments if (hashes[i].StartsWith("#")) { continue; } current_hash = hashes[i]; // Check if there is still something in the dictionary to read while (reader.BaseStream.Position < reader.BaseStream.Length) { // Iterate over all values in [0..BUFFER_SZ] for (var j = 0; j < BUFFER_SZ; j++) { // Add the next line from the dictionary to the buffer dict[j] = reader.ReadLine(); // Increment the loaded variable if the line is valid if (dict[j] != null) { dict[j] = dict[j].Replace("\r", ""); loaded++; } } var breakout = false; // Use parallel processing to iterate over all entries in the dictionary buffer Parallel.ForEach <string> (dict, (dict_entry, loopstate_inner) => { // Get the current hash var hash = hashes[i]; // Create a variable for storing the output (if valid) string output; // Get the current dictionary entry // (for the Update_Screen task) dict_current = dict_entry; // Try to collide the hashes var success = method.CheckHash(hash, dict_entry, out output); // Increment the statistically relevant variables ++processed; ++avg_tmp; // Check if the collision succeeded if (success) { // Increment the amount of successfully collided hashes // (for the Update_Screen task) ++cracked; // Add the collision to the database MainClass.db.Add(MainClass.session, hash, output, method); #if LIBNOTIFYNET var _libnotifynet_format = string.Format("Successfully cracked {0} hash:\n{1}\nValue was: {2}", method.Name, hash, output); Notification.Send("Hashlecter", _libnotifynet_format, 7500, 250, 100); #endif if (!MainClass.options.exp_single_cont) { // Break out of the loop breakout = true; loopstate_inner.Stop(); } } }); if (breakout) { break; } } // Reset the dictionary position to 0 // for processing the next hash reader.BaseStream.Position = 0; // Reset the loaded = 0; } // We're done! // Tell all tasks to stop done = true; watch.Stop(); } // Display the correct stats after exiting if (!MainClass.options.silent) { Update_Screen(watch, force: true); } }
// // This is an experimental method. // Enable using the --exp-lazy-eval switch // public static void RunLazy(string[] hashes, HashingMethod method, string dictionary_path) { // Dictionary buffer IEnumerable <string> dict; // Stopwatch for measuring time var watch = Stopwatch.StartNew(); if (!MainClass.options.silent) { // Update_Screen task var update = Task.Factory.StartNew(() => Update_Screen(watch)); // Update_Stats task var update_avg = Task.Factory.StartNew(Update_Stats); } // Lazy approach var dictionary = File.ReadLines(dictionary_path); var dictionary_pos = 0; var dictionary_count = dictionary.Count(); // Iterate over all hashes in the array for (var i = 0; i < hashes.Length; i++) { // Skip comments if (hashes[i].StartsWith("#")) { continue; } current_hash = hashes[i]; //while (dictionary_pos <= dictionary_count) { while (dictionary_pos < dictionary_count) { dict = dictionary.Skip(dictionary_pos).Take(BUFFER_SZ); dictionary_pos += BUFFER_SZ; loaded = dictionary_pos; var breakout = false; // Use parallel processing to iterate over all entries in the dictionary buffer Parallel.ForEach <string> (dict, (dict_entry, loopstate_inner) => { // Get the current hash var hash = hashes[i]; // Create a variable for storing the output (if valid) string output; // Get the current dictionary entry // (for the Update_Screen task) dict_current = dict_entry; // Try to collide the hashes var success = method.CheckHash(hash, dict_entry, out output); // Increment the statistically relevant variables ++processed; ++avg_tmp; // Check if the collision succeeded if (success) { // Increment the amount of successfully collided hashes // (for the Update_Screen task) ++cracked; // Add the collision to the database MainClass.db.Add(MainClass.session, hash, output, method); // Break out of the loop breakout = true; loopstate_inner.Stop(); } }); if (breakout) { break; } } dictionary_pos = 0; } done = true; watch.Stop(); // Display the correct stats after exiting if (!MainClass.options.silent) { Update_Screen(watch, force: true); } }
public static void Run(string[] hashes, HashingMethod method, string dictionary_path) { #if LIBNOTIFYNET Notification.Send ("Hashlecter", "Started dictionary attack.", 5000); #endif // Dictionary buffer string[] dict = new string[BUFFER_SZ]; // Stopwatch for measuring time var watch = Stopwatch.StartNew (); if (!MainClass.options.silent) { // Update_Screen task var update = Task.Factory.StartNew (() => Update_Screen (watch)); // Update_Stats task var update_avg = Task.Factory.StartNew (Update_Stats); } // Open dictionary file for reading using (var fdict = File.OpenRead (dictionary_path)) using (var reader = new StreamReader (fdict)) { // Iterate over all hashes in the array for (var i = 0; i < hashes.Length; i++) { // Skip comments if (hashes[i].StartsWith ("#")) continue; current_hash = hashes[i]; // Check if there is still something in the dictionary to read while (reader.BaseStream.Position < reader.BaseStream.Length) { // Iterate over all values in [0..BUFFER_SZ] for (var j = 0; j < BUFFER_SZ; j++) { // Add the next line from the dictionary to the buffer dict[j] = reader.ReadLine (); // Increment the loaded variable if the line is valid if (dict[j] != null) { dict[j] = dict[j].Replace ("\r", ""); loaded++; } } var breakout = false; // Use parallel processing to iterate over all entries in the dictionary buffer Parallel.ForEach<string> (dict, (dict_entry, loopstate_inner) => { // Get the current hash var hash = hashes[i]; // Create a variable for storing the output (if valid) string output; // Get the current dictionary entry // (for the Update_Screen task) dict_current = dict_entry; // Try to collide the hashes var success = method.CheckHash (hash, dict_entry, out output); // Increment the statistically relevant variables ++processed; ++avg_tmp; // Check if the collision succeeded if (success) { // Increment the amount of successfully collided hashes // (for the Update_Screen task) ++cracked; // Add the collision to the database MainClass.db.Add (MainClass.session, hash, output, method); #if LIBNOTIFYNET var _libnotifynet_format = string.Format ("Successfully cracked {0} hash:\n{1}\nValue was: {2}", method.Name, hash, output); Notification.Send ("Hashlecter", _libnotifynet_format, 7500, 250, 100); #endif if (!MainClass.options.exp_single_cont) { // Break out of the loop breakout = true; loopstate_inner.Stop (); } } }); if (breakout) break; } // Reset the dictionary position to 0 // for processing the next hash reader.BaseStream.Position = 0; // Reset the loaded = 0; } // We're done! // Tell all tasks to stop done = true; watch.Stop (); } // Display the correct stats after exiting if (!MainClass.options.silent) { Update_Screen (watch, force: true); } }
// // This is an experimental method. // Enable using the --exp-lazy-eval switch // public static void RunLazy(string[] hashes, HashingMethod method, string dictionary_path) { // Dictionary buffer IEnumerable<string> dict; // Stopwatch for measuring time var watch = Stopwatch.StartNew (); if (!MainClass.options.silent) { // Update_Screen task var update = Task.Factory.StartNew (() => Update_Screen (watch)); // Update_Stats task var update_avg = Task.Factory.StartNew (Update_Stats); } // Lazy approach var dictionary = File.ReadLines (dictionary_path); var dictionary_pos = 0; var dictionary_count = dictionary.Count (); // Iterate over all hashes in the array for (var i = 0; i < hashes.Length; i++) { // Skip comments if (hashes[i].StartsWith ("#")) continue; current_hash = hashes[i]; //while (dictionary_pos <= dictionary_count) { while (dictionary_pos < dictionary_count) { dict = dictionary.Skip (dictionary_pos).Take (BUFFER_SZ); dictionary_pos += BUFFER_SZ; loaded = dictionary_pos; var breakout = false; // Use parallel processing to iterate over all entries in the dictionary buffer Parallel.ForEach<string> (dict, (dict_entry, loopstate_inner) => { // Get the current hash var hash = hashes[i]; // Create a variable for storing the output (if valid) string output; // Get the current dictionary entry // (for the Update_Screen task) dict_current = dict_entry; // Try to collide the hashes var success = method.CheckHash (hash, dict_entry, out output); // Increment the statistically relevant variables ++processed; ++avg_tmp; // Check if the collision succeeded if (success) { // Increment the amount of successfully collided hashes // (for the Update_Screen task) ++cracked; // Add the collision to the database MainClass.db.Add (MainClass.session, hash, output, method); // Break out of the loop breakout = true; loopstate_inner.Stop (); } }); if (breakout) break; } dictionary_pos = 0; } done = true; watch.Stop (); // Display the correct stats after exiting if (!MainClass.options.silent) { Update_Screen (watch, force: true); } }
public static void Run(string[] hashes, HashingMethod method, string alphabet, int length = 6) { #if LIBNOTIFYNET Notification.Send("Hashlecter", "Started bruteforce attack.", 5000); #endif // Stopwatch for measuring time var watch = Stopwatch.StartNew(); if (!MainClass.options.silent) { // Update_Screen task var update = Task.Factory.StartNew(() => Update_Screen(watch)); // Update_Stats task var update_avg = Task.Factory.StartNew(Update_Stats); } string output; var alphabet_first = alphabet.First(); var alphabet_last = alphabet.Last(); for (var ihash = 0; ihash < hashes.Length; ihash++) { // Skip comments if (hashes [ihash].StartsWith("#")) { continue; } current_hash = hashes [ihash]; // Incremental bruteforce if (MainClass.options.incremental) { // Calculate maximum for (var i = 1; i <= length; i++) { bruteforce_max += Math.Pow(i, alphabet.Length); } for (var curlen = 1; curlen <= length; ++curlen) { // Initialize buffer var accum = new StringBuilder(new String(alphabet_first, curlen)); while (true) { ++generated; ++avg_tmp; var value = accum.ToString(); current_str = value; var success = method.CheckHash(current_hash, value, out output); if (success) { ++cracked; MainClass.db.Add(MainClass.session, current_hash, value, method); #if LIBNOTIFYNET var _libnotifynet_format = string.Format("Successfully cracked {0} hash:\n{1}\nValue was: {2}", method.Name, current_hash, output); Notification.Send("Hashlecter", _libnotifynet_format, 7500, 250, 100); #endif done = true; goto end; } if (value.All(val => val == alphabet_last)) { break; } // TODO: Parallelize this for (var i = curlen - 1; i >= 0; --i) { if (accum [i] != alphabet_last) { accum [i] = alphabet [alphabet.IndexOf(accum [i]) + 1]; break; } else { accum [i] = alphabet_first; } } } } } // Fixed-length bruteforce else { // Calculated maximum bruteforce_max = Math.Pow(length, alphabet.Length); // Initialize buffer var accum = new StringBuilder(new String(alphabet_first, length)); while (true) { ++generated; ++avg_tmp; var value = accum.ToString(); current_str = value; var success = method.CheckHash(current_hash, value, out output); if (success) { ++cracked; MainClass.db.Add(MainClass.session, current_hash, value, method); #if LIBNOTIFYNET var _libnotifynet_format = string.Format("Successfully cracked {0} hash:\n{1}\nValue was: {2}", method.Name, current_hash, output); Notification.Send("Hashlecter", _libnotifynet_format, 7500, 250, 100); #endif done = true; goto end; } if (value.All(val => val == alphabet_last)) { break; } // TODO: Parallelize this for (var i = length - 1; i >= 0; --i) { if (accum [i] != alphabet_last) { accum [i] = alphabet [alphabet.IndexOf(accum [i]) + 1]; break; } else { accum [i] = alphabet_first; } } } } end : {} } watch.Stop(); // Display the correct stats after exiting if (!MainClass.options.silent) { Update_Screen(watch, force: true); } }