Ejemplo n.º 1
0
 def generate(self, cli_object):
     if cli_object.salt is not False:
         if cli_object.rounds is not False:
             try:
                 generatedhash = sha512_crypt.encrypt(cli_object.plaintext, rounds=int(cli_object.rounds), salt=cli_object.salt)
                 return generatedhash
             except ValueError:
                 print helpers.color("sha512_crypt and sha512_crypt require at least 1000 rounds.", warning=True)
                 print helpers.color("[*] Running with default of 60000 rounds.", warning=True)
                 generatedhash = sha512_crypt.encrypt(cli_object.plaintext, salt=cli_object.salt)
                 return generatedhash
         else:
             generatedhash = sha512_crypt.encrypt(cli_object.plaintext, salt=cli_object.salt)
             return generatedhash
     else:
         if cli_object.rounds is not False:
             try:
                 generatedhash = sha512_crypt.encrypt(cli_object.plaintext, rounds=int(cli_object.rounds))
                 return generatedhash
             except ValueError:
                 print helpers.color("[*] Warning: sha512_crypt and sha512_crypt require at least 1000 rounds.", warning=True)
                 print helpers.color("[*] Running with default of 60000 rounds.", warning=True)
                 generatedhash = sha512_crypt.encrypt(cli_object.plaintext)
                 return generatedhash
         else:
             generatedhash = sha512_crypt.encrypt(cli_object.plaintext)
             return generatedhash
     return
Ejemplo n.º 2
0
 def generate(self, cli_object):
     if cli_object.salt is not False:
         if cli_object.rounds is not False:
             try:
                 generatedhash = getattr(hashes, "bcrypt").encrypt(cli_object.plaintext, rounds=cli_object.rounds, salt=cli_object.salt)
             except ValueError:
                 print helpers.color("Error: BCrypt requres a salt of 22 alphanumeric characters", warning=True)
                 sys.exit()
             return generatedhash
         else:
             try:
                 generatedhash = getattr(hashes, "bcrypt").encrypt(cli_object.plaintext, salt=cli_object.salt)
             except ValueError:
                 print helpers.color("Error: BCrypt requres a salt of 22 alphanumeric characters", warning=True)
                 sys.exit()
             return generatedhash
     else:
         if cli_object.rounds is not False:
             try:
                 generatedhash = getattr(hashes, "bcrypt").encrypt(cli_object.plaintext, rounds=cli_object.rounds)
             except ValueError:
                 print helpers.color("[*] Warning: BCrypt requires > 4 rounds! Running with 12 (default) rounds now.", warning=True)
                 generatedhash = getattr(hashes, "bcrypt").encrypt(cli_object.plaintext)
             return generatedhash
         else:
             generatedhash = getattr(hashes, "bcrypt").encrypt(cli_object.plaintext)
         return generatedhash
Ejemplo n.º 3
0
 def generate(self, cli_object):
     if cli_object.salt is not False:
         if cli_object.rounds is not False:
             try:
                 generatedhash = sha512_crypt.encrypt(
                     cli_object.plaintext,
                     rounds=int(cli_object.rounds),
                     salt=cli_object.salt)
                 return generatedhash
             except ValueError:
                 print helpers.color(
                     "sha512_crypt and sha512_crypt require at least 1000 rounds.",
                     warning=True)
                 print helpers.color(
                     "[*] Running with default of 60000 rounds.",
                     warning=True)
                 generatedhash = sha512_crypt.encrypt(cli_object.plaintext,
                                                      salt=cli_object.salt)
                 return generatedhash
         else:
             generatedhash = sha512_crypt.encrypt(cli_object.plaintext,
                                                  salt=cli_object.salt)
             return generatedhash
     else:
         if cli_object.rounds is not False:
             try:
                 generatedhash = sha512_crypt.encrypt(
                     cli_object.plaintext, rounds=int(cli_object.rounds))
                 return generatedhash
             except ValueError:
                 print helpers.color(
                     "[*] Warning: sha512_crypt and sha512_crypt require at least 1000 rounds.",
                     warning=True)
                 print helpers.color(
                     "[*] Running with default of 60000 rounds.",
                     warning=True)
                 generatedhash = sha512_crypt.encrypt(cli_object.plaintext)
                 return generatedhash
         else:
             generatedhash = sha512_crypt.encrypt(cli_object.plaintext)
             return generatedhash
     return
Ejemplo n.º 4
0
 def generate(self, cli_object):
     if cli_object.salt is not False:
         if cli_object.rounds is not False:
             try:
                 generatedhash = getattr(hashes, "bcrypt").encrypt(
                     cli_object.plaintext,
                     rounds=cli_object.rounds,
                     salt=cli_object.salt)
             except ValueError:
                 print helpers.color(
                     "Error: BCrypt requres a salt of 22 alphanumeric characters",
                     warning=True)
                 sys.exit()
             return generatedhash
         else:
             try:
                 generatedhash = getattr(hashes, "bcrypt").encrypt(
                     cli_object.plaintext, salt=cli_object.salt)
             except ValueError:
                 print helpers.color(
                     "Error: BCrypt requres a salt of 22 alphanumeric characters",
                     warning=True)
                 sys.exit()
             return generatedhash
     else:
         if cli_object.rounds is not False:
             try:
                 generatedhash = getattr(hashes, "bcrypt").encrypt(
                     cli_object.plaintext, rounds=cli_object.rounds)
             except ValueError:
                 print helpers.color(
                     "[*] Warning: BCrypt requires > 4 rounds! Running with 12 (default) rounds now.",
                     warning=True)
                 generatedhash = getattr(hashes, "bcrypt").encrypt(
                     cli_object.plaintext)
             return generatedhash
         else:
             generatedhash = getattr(hashes,
                                     "bcrypt").encrypt(cli_object.plaintext)
         return generatedhash
Ejemplo n.º 5
0
    def cliParser(self):
        parser = argparse.ArgumentParser(description="Create or Verify hashes with plaintext strings.")
        parser.add_argument("--list", action="store_true", default=False, help="List all supported hash algorithms")
        parser.add_argument("-G", default=False, help="Generate a hash from the provided string.", action='store_true')
        parser.add_argument("-C", default=False, help="Compare provided plaintext with a hash", action='store_true')
        parser.add_argument("--hash-type", metavar="md5", default=None, help="The hashing algorithm you want to use")
        parser.add_argument("--plaintext", metavar="password", default=None, help="Plaintext string to hash")
        parser.add_argument("--hash", metavar="HASH", default=None, help="Hash used for comparison")
        parser.add_argument("--rounds", metavar="5000", default=False, type=int, help="Number of rounds to hash your plaintext string")
        parser.add_argument("--salt", metavar="SALT", default=False, help="Salt used for hashing")
        parser.add_argument("--username", metavar="USERNAME", default=None, help="Only required for select hash types")
        args = parser.parse_args()
        if not args.G and not args.C and not args.list:
            print helpers.color("\n\n[*] Error: You must provide an action to perform", warning=True)
            print helpers.color("[*] Actions: [G]enerate or [C]ompare hashes.", warning=True)
            print helpers.color("[*] Please provide an action and re-run Hasher.", warning=True)
            sys.exit()

        if args.G and (args.plaintext is None or args.hash_type is None) :
            print helpers.color("\n\n[*] Error: You must provde a plaintext string and hashing algorithm to use!", warning=True)
            print helpers.color("[*] Please re-run and provide a plaintext string and/or hash algorithm.", warning=True)
            sys.exit()

        if args.C and (args.plaintext is None or args.hash_type is None or args.hash is None):
            print helpers.color("\n\n[*] Error: Comparison function requires plaintext string, hash digest, and hash algorithm.", warning=True)
            print helpers.color("[*] Please re-run and provide the required options", warning=True)
            sys.exit()
        return args
Ejemplo n.º 6
0
    def menu_system(self):

        # Parse the command line arguments and load up hashing modules
        cli_args = self.cliParser()
        self.load_hash_operations()

        # If listing payloads, do it and then exit
        if cli_args.list:
            print "Supported Hashing Algorithms: "
            for path, hash_obj in self.hashing_algorithms.iteritems():
                print "[*] " + hash_obj.hash_type
            sys.exit()

        # Generate a hash digest for the provided plaintext string
        # Iterates over all loaded hash_op modules, finds the hash type
        # generates the digest, and returns it
        if cli_args.G:
            if cli_args.hash_type.lower().strip() == "all":
                print "Plaintext string : " + helpers.color(cli_args.plaintext)
            for path, hash_obj in self.hashing_algorithms.iteritems():

                if cli_args.hash_type.lower().strip() == "all":
                    hashed_string = hash_obj.generate(cli_args)
                    print hash_obj.hash_type + " hash : " + helpers.color(hashed_string)

                elif cli_args.hash_type.lower().strip() == hash_obj.hash_type.lower():
                    hashed_string = hash_obj.generate(cli_args)
                    print "Hash Type        : " + helpers.color(cli_args.hash_type)
                    print "Plaintext string : " + helpers.color(cli_args.plaintext)
                    print "Digest Value     : " + helpers.color(hashed_string)

        if cli_args.C:
            found_hash = False
            for path, hash_obj in self.hashing_algorithms.iteritems():
                if cli_args.hash_type.lower().strip() == hash_obj.hash_type.lower():
                    hashed_string = hash_obj.generate(cli_args)
                    found_hash = True
                    if hashed_string == cli_args.hash.lower().strip():
                        print helpers.color("True - The hash " + cli_args.hash + " and plaintext " + cli_args.plaintext + " match!")
                    else:
                        print helpers.color("False - The hash " + cli_args.hash + " and plaintext " + cli_args.plaintext + " do not match!", warning=True)
            if not found_hash:
                print helpers.color("[*] Error: You did not provide a valid hash-type to compare!", warning=True)
                print helpers.color("[*] Error: Please re-run with a valid hash-type.", warning=True)

        return