Exemplo n.º 1
0
 public static SQLite CreateSQLite(string path)
 {
     var db = new SQLite ();
     db.Connect (path);
     db.Prepare ();
     return db;
 }
Exemplo n.º 2
0
		/// <summary>
		/// The entry point of the program, where the program control starts and ends.
		/// </summary>
		/// <param name="args">The command-line arguments.</param>
		public static void Main (string[] args) {

			foreach (var x in args) {
				Console.WriteLine (x);
			}
			
			// Create a hashset for storing the hashing methods
			methods = new HashSet<HashingMethod> {
				
				#if MD5
				HashingMethod.New<hMD5> (),
				HashingMethod.New<hMD5_Double> (),
				HashingMethod.New<hMD5_Salted> (),
				HashingMethod.New<hMD5_Salted2> (),
				HashingMethod.New<hMD5_MyBB> (),
				#endif

				#if SHA1
				HashingMethod.New<hSHA1> (),
				HashingMethod.New<hSHA1_Double> (),
				#endif

				#if SHA256
				HashingMethod.New<hSHA256> (),
				HashingMethod.New<hSHA256_Double> (),
				#endif

				#if SHA384
				HashingMethod.New<hSHA384> (),
				#endif

				#if SHA512
				HashingMethod.New<hSHA512> (),
				#endif

				#if RIPEMD160
				HashingMethod.New<hRIPEMD160> (),
				#endif

				#if WHIRLPOOL
				HashingMethod.New<hWhirlpool> (),
				#endif

				#if JHASH
				HashingMethod.New<hJHash> (),
				#endif
			};

			// Parse command-line arguments using libArgument
			options = ArgumentParser.Parse<Options> (args);

			// Use wizard if lecter was started directly
			options.wizard |= args.Length == 0;

			// Get or create a session identifier
			session = string.IsNullOrEmpty (options.session) ? GenerateSession () : options.session;

			// Connect to the SQLite database
			db = Database.Factory.CreateSQLite (SQLITE_DB);

			// Return if the user just wanted to make
			// sure that the db got created
			if (options.create_db) {
				Environment.Exit (0);
			}

			// Display help
			else if (options.help) {
				PreHelp ();
				ArgumentParser.Help ();
				Help ();
				Environment.Exit (0);
			}

			// Show all the cracked hashes
			else if (options.show) {
				db.Show (string.IsNullOrEmpty (options.session) ? string.Empty : session);
				Environment.Exit (0);
			}

			// Call the magician
			else if (options.wizard) {
				Wizard ();
			}

			// Null-check the method
			if (string.IsNullOrEmpty (options.method))

				// Fall back to MD5
				options.method = "md5";

			// Get the method used for cracking the hashes
			var method = methods.FirstOrDefault (m => m.Name == options.method.ToLowerInvariant ());

			// Check if the cracking method is valid
			if (method == null || method == default(HashingMethod)) {

				Console.Error.WriteLine ("Please specify a valid hashing method.");
				Console.Error.WriteLine ("Run lecter --help to get a list of valid hashing methods.");
				Environment.Exit (0);
			}

			// Check if we need to generate a hash
			if (options.gen) {

				// Read input string from -i/--input argument
				if (!string.IsNullOrEmpty (options.input_file))
					Console.WriteLine (method.Hash (options.input_file));
				
				// Hash an empty string if no string is given
				else
					Console.WriteLine (method.Hash (string.Empty));

				// Exit
				Environment.Exit (0);
			}

			string[] input_hashes = null;

			// Grab input from stdin
			if (options.input_stdin)
				input_hashes = FromStdin ();
			
			// Grab input from file
			else if (!string.IsNullOrEmpty (options.input_file))
				input_hashes = FromFile (options.input_file);

			// Perform dictionary attack
			if (!string.IsNullOrEmpty (options.input_dict)) {

				// Null-check the input file
				if (input_hashes == null) {
					Console.Error.WriteLine ("No input was specified.");
					Environment.Exit (0);
				}

				// Experimental lazy evaluation
				if (options.exp_lazy_eval)
					DictionaryAttack.RunLazy (input_hashes, method, options.input_dict);

				// Stable evaluation
				else
					DictionaryAttack.Run (input_hashes, method, options.input_dict);
			}

			// Perform bruteforce attack
			else {
				// Null-check the input file
				if (input_hashes == null) {
					Console.Error.WriteLine ("No input was specified.");
					Environment.Exit (0);
				}

				string default_alphabet =
					BruteforceAttack.NUMERIC +
					BruteforceAttack.LOWER_ALPHANUMERIC;

				if (options.len == 0)
					options.len = 6;

				if (!string.IsNullOrEmpty (options.alphabet)) {

					// Build alphabet
					var alphabet = options.alphabet
						.Replace ("$$", "\0")
						.Replace ("$n", BruteforceAttack.NUMERIC)
						.Replace ("$l", BruteforceAttack.LOWER_ALPHANUMERIC)
						.Replace ("$u", BruteforceAttack.UPPER_ALPHANUMERIC)
						.Replace ("$s+", BruteforceAttack.SPECIAL_ADVANCED)
						.Replace ("$s",	BruteforceAttack.SPECIAL_BASIC)
						.Replace ("\0", "$")
						.ToList ();
					options.alphabet = new string (alphabet.ToArray ());
				} else
					options.alphabet = default_alphabet;

				BruteforceAttack.Run (input_hashes, method, options.alphabet, options.len);
			}

			if (!options.silent) {
				db.Show (session);

				if (options.wizard)
					Console.Read ();
			}

			#if LIBNOTIFYNET
			Task.Factory.StartNew (() => {
				NotificationManager.Instance.ShutdownWait ();
			}).Wait (7500);
			#endif
		}