bin/attacks/bruteforce/bf_attack.py
def bruteforce_main(verf_hash, algorithm=None, wordlist=None, salt=None, placement=None, all_algs=False, posx="",
                    use_hex=False, verbose=False, batch=False, rounds=10):
    """
      Main function to be used for bruteforcing a hash
    """
    wordlist_created = False
    if wordlist is None:
        create_dir("bf-dicts", verbose=verbose)
        for item in os.listdir(os.getcwd() + "/bf-dicts"):
            if WORDLIST_RE.match(item):
                wordlist_created = True
                wordlist = "{}/bf-dicts/{}".format(os.getcwd(), item)
        if not wordlist_created:
            LOGGER.info("Creating wordlist..")
            create_wordlist(verbose=verbose)
    else:
        LOGGER.info("Reading from, {}..".format(wordlist))

    if algorithm is None:
        hash_type = verify_hash_type(verf_hash, least_likely=all_algs)
        LOGGER.info("Found {} possible hash type(s) to run against: {} ".format(len(hash_type) - 1 if hash_type[1] is None
                                                                                else len(hash_type),
                                                                                hash_type[0] if hash_type[1] is None else
                                                                                hash_type))
        for alg in hash_type:
            if alg is None:
                err_msg = (
                    "Ran out of algorithms to try. There are no more "
                    "algorithms currently available that match this hashes "
                    "length, and complexity.")
                LOGGER.fatal(err_msg.format(DAGON_ISSUE_LINK))
                break
            else:
                if ":::" in verf_hash:
                    LOGGER.debug("It appears that you are trying to crack an '{}' hash, "
                                 "these hashes have a certain sequence to them that looks "
                                 "like this 'USERNAME:SID:LM_HASH:NTLM_HASH:::'. What you're "
                                 "wanting is the NTLM part, of the hash, fix your hash and try "
                                 "again..".format(alg.upper()))
                    shutdown(1)
                LOGGER.info("Starting bruteforce with {}..".format(alg.upper()))
                bruteforcing = hash_words(verf_hash, wordlist, alg, salt=salt, placement=placement, posx=posx,
                                          use_hex=use_hex, verbose=verbose, rounds=rounds)
                if bruteforcing is None:
                    LOGGER.warning("Unable to find a match for '{}', using {}..".format(verf_hash, alg.upper()))
                else:
                    match_found(bruteforcing)
                    break
    else:
        LOGGER.info("Using algorithm, {}..".format(algorithm.upper()))
        results = hash_words(verf_hash, wordlist, algorithm, salt=salt, placement=placement, posx=posx, verbose=verbose)
        if results is None:
            LOGGER.warning("Unable to find a match using {}..".format(algorithm.upper()))
            if not batch:
                verify = prompt("Would you like to attempt to verify the hash type automatically and crack it", "y/N")
            else:
                verify = "n"
            if verify.startswith(("y", "Y")):
                bruteforce_main(verf_hash, wordlist=wordlist, salt=salt, placement=placement, posx=posx, use_hex=use_hex,
                                verbose=verbose)
            else:
                LOGGER.warning("Unable to produce a result for given hash '{}' using {}..".format(
                    verf_hash, algorithm.upper()))
        else:
            match_found(results)

      Main function to be used for bruteforcing a hash
    
Main function to be used for bruteforcing a hash
Main function to be used for bruteforcing a hash
def bruteforce_main(verf_hash, algorithm=None, wordlist=None, salt=None, placement=None, all_algs=False, posx="",
                    use_hex=False, verbose=False, batch=False, rounds=10):
    wordlist_created = False
    if wordlist is None:
        create_dir("bf-dicts", verbose=verbose)
        for item in os.listdir(os.getcwd() + "/bf-dicts"):
            if WORDLIST_RE.match(item):
                wordlist_created = True
                wordlist = "{}/bf-dicts/{}".format(os.getcwd(), item)
        if not wordlist_created:
            LOGGER.info("Creating wordlist..")
            create_wordlist(verbose=verbose)
    else:
        LOGGER.info("Reading from, {}..".format(wordlist))
    if algorithm is None:
        hash_type = verify_hash_type(verf_hash, least_likely=all_algs)
        LOGGER.info("Found {} possible hash type(s) to run against: {} ".format(len(hash_type) - 1 if hash_type[1] is None
                                                                                else len(hash_type),
                                                                                hash_type[0] if hash_type[1] is None else
                                                                                hash_type))
        for alg in hash_type:
            if alg is None:
                err_msg = (
                    "Ran out of algorithms to try. There are no more "
                    "algorithms currently available that match this hashes "
                    "length, and complexity.")
                LOGGER.fatal(err_msg.format(DAGON_ISSUE_LINK))
                break
            else:
                if ":::" in verf_hash:
                    LOGGER.debug("It appears that you are trying to crack an '{}' hash, "
                                 "these hashes have a certain sequence to them that looks "
                                 "like this 'USERNAME:SID:LM_HASH:NTLM_HASH:::'. What you're "
                                 "wanting is the NTLM part, of the hash, fix your hash and try "
                                 "again..".format(alg.upper()))
                    shutdown(1)
                LOGGER.info("Starting bruteforce with {}..".format(alg.upper()))
                bruteforcing = hash_words(verf_hash, wordlist, alg, salt=salt, placement=placement, posx=posx,
                                          use_hex=use_hex, verbose=verbose, rounds=rounds)
                if bruteforcing is None:
                    LOGGER.warning("Unable to find a match for '{}', using {}..".format(verf_hash, alg.upper()))
                else:
                    match_found(bruteforcing)
                    break
    else:
        LOGGER.info("Using algorithm, {}..".format(algorithm.upper()))
        results = hash_words(verf_hash, wordlist, algorithm, salt=salt, placement=placement, posx=posx, verbose=verbose)
        if results is None:
            LOGGER.warning("Unable to find a match using {}..".format(algorithm.upper()))
            if not batch:
                verify = prompt("Would you like to attempt to verify the hash type automatically and crack it", "y/N")
            else:
                verify = "n"
            if verify.startswith(("y", "Y")):
                bruteforce_main(verf_hash, wordlist=wordlist, salt=salt, placement=placement, posx=posx, use_hex=use_hex,
                                verbose=verbose)
            else:
                LOGGER.warning("Unable to produce a result for given hash '{}' using {}..".format(
                    verf_hash, algorithm.upper()))
        else:
            match_found(results)
def bruteforce_main ( verf_hash , algorithm = None , wordlist = None , salt = None , placement = None , all_algs = False , posx = "" , use_hex = False , verbose = False , batch = False , rounds = 10 ) : wordlist_created = False if wordlist is None : create_dir ( "bf-dicts" , verbose = verbose ) for item in os . listdir ( os . getcwd ( ) + "/bf-dicts" ) : if WORDLIST_RE . match ( item ) : wordlist_created = True wordlist = "{}/bf-dicts/{}" . format ( os . getcwd ( ) , item ) if not wordlist_created : LOGGER . info ( "Creating wordlist.." ) create_wordlist ( verbose = verbose ) else : LOGGER . info ( "Reading from, {}.." . format ( wordlist ) ) if algorithm is None : hash_type = verify_hash_type ( verf_hash , least_likely = all_algs ) LOGGER . info ( "Found {} possible hash type(s) to run against: {} " . format ( len ( hash_type ) - 1 if hash_type [ 1 ] is None else len ( hash_type ) , hash_type [ 0 ] if hash_type [ 1 ] is None else hash_type ) ) for alg in hash_type : if alg is None : err_msg = ( "Ran out of algorithms to try. There are no more " "algorithms currently available that match this hashes " "length, and complexity." ) LOGGER . fatal ( err_msg . format ( DAGON_ISSUE_LINK ) ) break else : if ":::" in verf_hash : LOGGER . debug ( "It appears that you are trying to crack an '{}' hash, " "these hashes have a certain sequence to them that looks " "like this 'USERNAME:SID:LM_HASH:NTLM_HASH:::'. What you're " "wanting is the NTLM part, of the hash, fix your hash and try " "again.." . format ( alg . upper ( ) ) ) shutdown ( 1 ) LOGGER . info ( "Starting bruteforce with {}.." . format ( alg . upper ( ) ) ) bruteforcing = hash_words ( verf_hash , wordlist , alg , salt = salt , placement = placement , posx = posx , use_hex = use_hex , verbose = verbose , rounds = rounds ) if bruteforcing is None : LOGGER . warning ( "Unable to find a match for '{}', using {}.." . format ( verf_hash , alg . upper ( ) ) ) else : match_found ( bruteforcing ) break else : LOGGER . info ( "Using algorithm, {}.." . format ( algorithm . upper ( ) ) ) results = hash_words ( verf_hash , wordlist , algorithm , salt = salt , placement = placement , posx = posx , verbose = verbose ) if results is None : LOGGER . warning ( "Unable to find a match using {}.." . format ( algorithm . upper ( ) ) ) if not batch : verify = prompt ( "Would you like to attempt to verify the hash type automatically and crack it" , "y/N" ) else : verify = "n" if verify . startswith ( ( "y" , "Y" ) ) : bruteforce_main ( verf_hash , wordlist = wordlist , salt = salt , placement = placement , posx = posx , use_hex = use_hex , verbose = verbose ) else : LOGGER . warning ( "Unable to produce a result for given hash '{}' using {}.." . format ( verf_hash , algorithm . upper ( ) ) ) else : match_found ( results )
Main function to be used for bruteforcing a hash
Main function to be used for bruteforcing a hash
"""
      Main function to be used for bruteforcing a hash
    """
verf_hash
algorithm
wordlist
salt
placement
all_algs
posx
use_hex
verbose
batch
rounds