Example #1
0
def global_state():
    """
        Return an overview of the ongoing cracks
    """
    running_crack_list = running_crack_nb()
    # Retrieve the GPU memory used for each crack (search by output file name)
    total_memory_used, total_memory_free, total_memory, memory_per_crack = \
        get_memory_info([_[4] for _ in running_crack_list])

    running_crack_list_and_memory = []
    for crack in running_crack_list:
        try:
            running_crack_list_and_memory.append(crack + [memory_per_crack[crack[4]]])
        except KeyError:
            running_crack_list_and_memory.append(crack + [0])

    return render_template(
        'crack_nb.html',
        title=u'Global status',
        MAX_CRACKSESSIONS=conf.MAX_CRACKSESSIONS,
        total_memory_used = total_memory_used,
        total_memory_free = total_memory_free,
        total_memory = total_memory,
        running_crack_list=running_crack_list_and_memory,
        crack_count=len(running_crack_list)
    )
Example #2
0
def new_hashes_form():
    """
        Form to add new hashes
    """
    running_crack_list = running_crack_nb()
    if len(running_crack_list) > conf.MAX_CRACKSESSIONS:
        return render_template('crack_nb.html',
                               title=u'Failed launch',
                               MAX_CRACKSESSIONS=conf.MAX_CRACKSESSIONS,
                               liste_en_cours=running_crack_list,
                               crack_count=len(running_crack_list))

    else:
        return render_template('add.html',
                               title=u'Add new crack',
                               HASHS_LIST=hashcatconf.HASHS_LIST,
                               wordlist_dictionary=conf.wordlist_dictionary,
                               separator=conf.separator,
                               max_size=app.config['MAX_CONTENT_LENGTH'],
                               CRACK_DURATIONS=conf.CRACK_DURATIONS)
Example #3
0
def new_hashes_start():
    """
        Effective launch of a crack
    """
    # Retrieve information from previous page form
    hashes = request.form['hashes']
    hashes_count = len(hashes.splitlines())
    hashtype_selected = int(request.form['hashtype'])

    # By default, no options selected
    optionList = []
    wordlistList = []
    wordlistRulesList = []
    selectedMask = ''
    selectedKeywords = ''

    # Information from the previous page form
    usernames = parameters_getter('Withusernames', [])

    selectedKeywords = request.form['ChosenKeyword']
    parameters_getter('Keywords', optionList)
    if parameters_getter('Wordlist', optionList):
        for dictionary in conf.wordlist_dictionary:
            parameters_getter(slugify(dictionary), wordlistList)

    if parameters_getter('WordlistVariations', optionList):
        for dictionary in conf.wordlist_dictionary:
            parameters_getter(
                slugify(dictionary), wordlistRulesList, beginsWith="rule")

    selectedMask = request.form['ChosenMask']
    parameters_getter('Mask', optionList)

    parameters_getter('Bruteforce', optionList)

    crackDuration = int(request.form.get('ChosenDuration', ''))
    if crackDuration not in conf.CRACK_DURATIONS:
        crackDuration = conf.CRACK_DURATIONS[0]

    # Determination of current crack output file
    output_file_name_prefix = strftime("%y-%m-%d_%H-%M")
    output_file_name_suffix = ''.join(random.SystemRandom().choice(
        string.ascii_uppercase + string.digits) for _ in range(6))
    output_file_name = output_file_name_prefix + output_file_name_suffix

    # Crack option
    crackOption = []
    rules_list = conf.rule_name_list

    #pwdump format needs specific option (cf tasks.py to understand pwdump crack algorithm)
    if hashtype_selected == 999999:
        pwdump_bruteforce_lm_dict = OrderedDict([])
        pwdump_bruteforce_lm_dict['BruteForce_lm'] = []
        crackOption.append(['BruteForce_lm', pwdump_bruteforce_lm_dict])

        pwdump_wordlist_dict = OrderedDict([])
        pwdump_wordlist_dict['Dict'] = []
        crackOption.append(['Dict', pwdump_wordlist_dict])

    for option in optionList :

        if option == 'Keywords':
            keywords_list = []
            keywords_dict = OrderedDict([])
            keywords_dict[option] = []
            for rule in rules_list:
                keywords_dict[rule] = []
            keywords_list = [option, keywords_dict]
            crackOption.append(keywords_list)

        elif option == 'Wordlist':
            wordlist_list = []
            wordlist_dict = OrderedDict([])
            for wordlist in wordlistList:
                wordlist_dict[wordlist] = []
            wordlist_list = [option, wordlist_dict]
            crackOption.append(wordlist_list)

        elif option == 'WordlistVariations':
            variation_list = []
            variation_dict = OrderedDict([])
            for wordlist in wordlistRulesList:
                rule_dict = OrderedDict([])
                for rule in rules_list:
                    rule_dict[rule] = []
                variation_dict[wordlist] = rule_dict
            variation_list = [option, variation_dict]
            crackOption.append(variation_list)

        else:
            option_dict = OrderedDict([])
            option_dict[option] = []
            crackOption.append([option, option_dict])

    option = json.dumps(crackOption)

    running_crack_list = running_crack_nb()
    if len(running_crack_nb()) > conf.MAX_CRACKSESSIONS:
        return render_template('crack_nb.html', title=u'Launching error', MAX_CRACKSESSIONS=conf.MAX_CRACKSESSIONS,
                               liste_en_cours=running_crack_list, crack_count=len(running_crack_list))
    else:
        # Asynchronous launching:
        # synchronous process is hashcatCrack(a,b,c,d) and
        # asynchronous process is hashcatCrack.delay(a,b,c,d)
        crack_task = hashcatCrack.delay(hashtype_selected, hashes, optionList, wordlistList, wordlistRulesList,
                                        output_file_name, selectedMask, selectedKeywords, usernames_with_hash=usernames)

        # Save crack information in the database
        g.db.execute('insert into cracks (crack_id, user_id, output_file, start_date, hashes_number, hash_type, crack_duration, email_end_job_sent) values (?,(select id from users where name=?),?,?,?,?,?,?)',
                     (crack_task.id,
                      request.authorization.username.lower(),
                      output_file_name,
                      strftime("%Y-%m-%dT%H:%M:%S"),
                      hashes_count,
                      hashtype_selected,
                      crackDuration,
                      0))
        g.db.commit()

        # Save crack options in the database
        g.db.execute('insert into cracksOption (crack_id, user_id, options) values (?,(select id from users where name=?),?)',
                     (crack_task.id,
                      request.authorization.username.lower(),
                      option))
        g.db.commit()

        return render_template('launching.html', title=u'Crack launching', _id=crack_task)
Example #4
0
def new_hashes_validation():
    """
        Cracking options validation
    """
    # Was a file uploaded ?
    file_content = ""
    if 'file' in request.files:
        file = request.files['file']
        # Check that the file is correct
        if file.filename != '':
            filename, file_extension = os.path.splitext(file.filename)
            if file_extension == ".txt":
                file_content = file.read()
            else:
                # Invalid file name
                return render_template(
                    'add.html',
                    title=u'Add new crack',
                    error=u'Invalid file name',
                    HASHS_LIST=hashcatconf.HASHS_LIST,
                    wordlist_dictionary=conf.wordlist_dictionary,
                    separator=conf.separator,
                    max_size=app.config['MAX_CONTENT_LENGTH'],
                    CRACK_DURATIONS=conf.CRACK_DURATIONS)

    # Retrieve information from previous page form
    if file_content != "":
        hashes = file_content
    else:
        hashes = request.form['hashes']
    hashtype_selected = int(request.form['hashtype'])

    # By default, no options selected
    optionList = []
    wordlistList = []
    wordlistRulesList = []
    selectedMask = ""
    selectedKeywords = ""
    crackDuration = conf.CRACK_DURATIONS[0]

    # Information from previous page form
    usernames = parameters_getter('Withusernames', [])
    selectedMask = request.form['ChosenMask']
    selectedKeywords = request.form['ChosenKeyword']

    #Check the mask form:
    if not checking_mask_form(selectedMask):
        return render_template(
            'add.html',
            title=u'Add new crack',
            error=u'Wrong Mask form',
            HASHS_LIST=hashcatconf.HASHS_LIST,
            wordlist_dictionary=conf.wordlist_dictionary,
            separator=conf.separator,
            max_size=app.config['MAX_CONTENT_LENGTH'],
            CRACK_DURATIONS=conf.CRACK_DURATIONS)

    parameters_getter('Keywords', optionList)

    if parameters_getter('Wordlist', optionList):
        for dictionary in conf.wordlist_dictionary:
            parameters_getter(slugify(dictionary), wordlistList)

    if parameters_getter('WordlistVariations', optionList):
        for dictionary in conf.wordlist_dictionary:
            parameters_getter("rule" + slugify(dictionary), wordlistRulesList)

    parameters_getter('Mask', optionList)
    parameters_getter('Bruteforce', optionList)

    #Check that optionList is not empty
    if not checking_crackMode(optionList):
        return render_template(
            'add.html',
            title=u'Add new crack',
            error=u'No attack mode selected',
            HASHS_LIST=hashcatconf.HASHS_LIST,
            wordlist_dictionary=conf.wordlist_dictionary,
            separator=conf.separator,
            max_size=app.config['MAX_CONTENT_LENGTH'],
            CRACK_DURATIONS=conf.CRACK_DURATIONS)

    crackDuration = int(request.form.get('ChosenDuration', ''))
    if crackDuration not in conf.CRACK_DURATIONS:
        crackDuration = conf.CRACK_DURATIONS[0]

    # Retrieve the number of ongoing crack
    running_crack_list = running_crack_nb()

    # If too many cracks are currently launched:
    if len(running_crack_list) > conf.MAX_CRACKSESSIONS:
        # Redirect the user to an error page
        return render_template('crack_nb.html', title=u'Launch error', MAX_CRACKSESSIONS=conf.MAX_CRACKSESSIONS,
                               liste_en_cours=running_crack_list, crack_count=len(running_crack_list))

    # Otherwise, return validation page
    else:
        return render_template(
            'validation.html',
            title=u'Crack form validation',
            usernames_with_hash=usernames,
            crack_duration=crackDuration,
            hashes=hashes,
            HASHS_LIST=hashcatconf.HASHS_LIST,
            hashtype_selected=hashtype_selected,
            crackOptions=optionList,
            wordlistRulesList=wordlistRulesList,
            wordlistList=wordlistList,
            listOfAllWordlists=sorted(conf.wordlist_dictionary),
            mask=selectedMask,
            keywords=selectedKeywords,
            separator=conf.separator
        )