def process_package_7(package):
    package['attack_settings']['attack_submode'] = 0
    if package['attack_settings']['rule_left'] and package['attack_settings'][
            'rule_right']:
        package['attack_settings']['attack_submode'] = 3
    elif package['attack_settings']['rule_left']:
        package['attack_settings']['attack_submode'] = 1
    elif package['attack_settings']['rule_right']:
        package['attack_settings']['attack_submode'] = 2

    check_mask_syntax(package['attack_settings']['mask'])
    leftDict = make_dict_from_mask(package['attack_settings']['mask'])
    package['attack_settings']['left_dictionaries'] = [leftDict]

    dictsLeftKeyspace = leftDict.keyspace
    dictsRightKeyspace = 0
    for dictObj in package['attack_settings']['right_dictionaries']:
        dict = FcDictionary.query.filter(
            FcDictionary.id == dictObj['id']).first()
        if not dict:
            abort(500, 'Wrong dictionary selected.')

        if not os.path.exists(os.path.join(DICTIONARY_DIR, dict.path)):
            abort(500, 'Dictionary does not exist.')

        dictsRightKeyspace += dict.keyspace

    keyspace = dictsLeftKeyspace * dictsRightKeyspace

    package['attack_name'] = 'hybrid (Mask + Wordlist)'
    package['hc_keyspace'] = dictsLeftKeyspace
    package['keyspace'] = keyspace
    return package
Exemple #2
0
    def post(self):
        """
        Nahrava mask subor na server
        """
        # check if the post request has the file part
        if 'file' not in request.files:
            abort(500, 'No file part')
            return redirect(request.url)
        file = request.files['file']
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            abort(500, 'No selected file')

        content = file.read().splitlines()
        for line in content:
            check_mask_syntax(line.decode("utf-8"))

        uploadedFile = fileUpload(
            file,
            MASKS_DIR,
            ALLOWED_EXTENSIONS,
            "".join(x.decode("utf-8") + "\n" for x in content),
            suffix='.hcmask',
            withTimestamp=True)
        if uploadedFile:
            maskSet = FcMasksSet(name=uploadedFile['filename'],
                                 path=uploadedFile['path'])
            try:
                db.session.add(maskSet)
                db.session.commit()
            except exc.IntegrityError as e:
                db.session().rollback()
                abort(
                    500, 'Masks set with name ' + uploadedFile['filename'] +
                    ' already exists.')
            return {
                'message':
                'File ' + uploadedFile['filename'] + ' successfuly uploaded.',
                'status': True
            }
        else:
            abort(500, 'Wrong file format')
Exemple #3
0
    def post(self, id):
        """
        Nahradí mask set novým stringom
        """

        args = updateMask_parser.parse_args(request)
        newData = args.get('newMaskSet', None)

        for line in newData.splitlines():
            check_mask_syntax(line)

        maskSet = FcMasksSet.query.filter(FcMasksSet.id == id).first()
        file = open(os.path.join(MASKS_DIR, maskSet.path), 'r+')

        file.seek(0)
        file.write(newData)
        file.truncate()
        file.close()

        return {
            'message': 'File ' + maskSet.name + ' successfuly changed.',
            'status': True
        }
Exemple #4
0
def process_job_6(job, actually7=False):
    job['attack_settings']['attack_submode'] = 0
    if job['attack_settings']['rule_left']:
        job['attack_settings']['attack_submode'] = 1
    elif job['attack_settings']['rule_right']:
        job['attack_settings']['attack_submode'] = 2

    mask = job['attack_settings']['mask']

    check_mask_syntax(mask)
    maskKeyspace = compute_keyspace_from_mask(mask)

    job['mask_data'] = {
        'mask': mask,
        'keyspace': maskKeyspace,
        'hc_keyspace': maskKeyspace
    }

    dictsKeyspace = 0
    for dictObj in job['attack_settings'][
            'left_dictionaries' if not actually7 else 'right_dictionaries']:
        dict = FcDictionary.query.filter(
            FcDictionary.id == dictObj['id']).first()
        if not dict:
            abort(500, 'Wrong dictionary selected.')

        if not os.path.exists(os.path.join(DICTIONARY_DIR, dict.path)):
            abort(500, 'Dictionary does not exist.')

        dictsKeyspace += dict.keyspace

    keyspace = dictsKeyspace * maskKeyspace

    job['attack_name'] = 'hybrid (Wordlist + Mask)' if not actually7 else 'hybrid (Mask + Wordlist)'
    job['hc_keyspace'] = dictsKeyspace if not actually7 else maskKeyspace
    job['keyspace'] = keyspace
    return job
Exemple #5
0
def process_job_3(job, hashcatKeyspace=True):
    if not job['attack_settings'].get('attack_submode'):
        job['attack_settings']['attack_submode'] = 0
    # check masks syntax
    for mask in job['attack_settings']['masks']:
        check_mask_syntax(mask)

    # charsets
    hashcatArgs = ''
    charsetsSize = {}
    if job['attack_settings'].get('charset'):
        if len(job['attack_settings']['charset']) > 4:
            abort(500, 'Maximum of charsets files is 4.')
        for i, charset in enumerate(job['attack_settings']['charset'], 1):
            charsetPath = os.path.join(CHARSET_DIR, charset['name'] + '.hcchr')
            charsetsSize = dict()
            with open(charsetPath, 'rb') as f:
                content = f.read()
                charsetsSize[i] = len(content)

            hashcatArgs += ' -' + str(i) + ' ' + charsetPath
            hexCharset = content.hex()
            job['charset' + str(i)] = hexCharset

    # compute keyspace
    if job['attack_settings'].get('markov_treshold') and job[
            'attack_settings']['markov_treshold'] > 1:
        markovTresh = job['attack_settings']['markov_treshold']
        job['markov_threshold'] = job['attack_settings']['markov_treshold']

        job['mask_table'] = []
        job['keyspace'] = 0
        job['hc_keyspace'] = 0
        for (i, mask) in enumerate(job['attack_settings']['masks']):
            keyspace_for_mask = compute_keyspace_from_mask(
                mask, charsetsSize, markovTresh)
            hc_keyspace_for_mask = 0
            if hashcatKeyspace:

                tmp = HASHCAT_PATH + ' -m ' + job['hash_settings'][
                    'hash_type'] + ' -a 3 ' + mask + ' --markov-threshold ' + str(
                        job['attack_settings']['markov_treshold'])
                hc_keyspace_for_mask = shellExec(
                    HASHCAT_PATH + ' -m ' + job['hash_settings']['hash_type'] +
                    ' --keyspace -a 3 ' + mask + ' --markov-threshold ' +
                    str(job['attack_settings']['markov_treshold']),
                    cwd=HASHCAT_DIR,
                    abortOnError=True)
                if hc_keyspace_for_mask == '':
                    abort(500,
                          'Server can not compute keyspace for mask ' + mask)
                try:
                    job['hc_keyspace'] += int(hc_keyspace_for_mask)
                except ValueError:
                    abort(500, 'Hashcat says: "' + hc_keyspace_for_mask + '".')

            job['keyspace'] += keyspace_for_mask
            job['mask_table'].append({
                'mask': mask,
                'keyspace': keyspace_for_mask,
                'hc_keyspace': hc_keyspace_for_mask
            })

    else:
        job['mask_table'] = []
        job['keyspace'] = 0
        job['hc_keyspace'] = 0
        for (i, mask) in enumerate(job['attack_settings']['masks']):
            keyspace_for_mask = compute_keyspace_from_mask(mask, charsetsSize)
            hc_keyspace_for_mask = 0
            if hashcatKeyspace:
                hc_keyspace_for_mask = shellExec(
                    HASHCAT_PATH + ' -m ' + job['hash_settings']['hash_type'] +
                    ' --keyspace -a 3 ' + mask + ' ' + hashcatArgs,
                    cwd=HASHCAT_DIR,
                    abortOnError=True)
                if hc_keyspace_for_mask == '':
                    abort(500,
                          'Server can not compute keyspace for mask ' + mask)
                try:
                    job['hc_keyspace'] += int(hc_keyspace_for_mask)
                except ValueError:
                    abort(500, 'Hashcat says: "' + hc_keyspace_for_mask + '".')

            job['keyspace'] += keyspace_for_mask
            job['mask_table'].append({
                'mask': mask,
                'keyspace': keyspace_for_mask,
                'hc_keyspace': hc_keyspace_for_mask
            })

    if job['attack_settings'].get('markov'):
        markov = FcHcstat.query.filter(
            FcHcstat.id == job['attack_settings']['markov']['id']).first()
        if not markov:
            abort(500, 'Wrong markov file selected.')
        if not os.path.exists(os.path.join(HCSTATS_DIR, markov.path)):
            abort(500, 'Markov file does not exist.')
        job['markov_hcstat'] = markov.name

    job['attack_name'] = 'mask'

    return job
def process_package_3(package, hashcatKeyspace=True):
    if not package['attack_settings'].get('attack_submode'):
        package['attack_settings']['attack_submode'] = 0
    # check masks syntax
    for mask in package['attack_settings']['masks']:
        check_mask_syntax(mask)

    # charsets
    hashcatArgs = ''
    charsetsSize = []
    if package['attack_settings'].get('charset'):
        if len(package['attack_settings']['charset']) > 4:
            abort(500, 'Maximum of charsets files is 4.')
        for i, charset in enumerate(package['attack_settings']['charset'], 1):
            charsetPath = os.path.join(CHARSET_DIR, charset['name'])
            charsetsSize = dict()
            with open(charsetPath, 'rb') as f:
                content = f.read()
                charsetsSize[i] = len(content)

            hashcatArgs += ' -' + str(i) + ' ' + charsetPath
            hexCharset = content.hex()
            package['config'] += '|||charset' + str(i) + '|String|' + lenStr(
                hexCharset) + '|' + hexCharset + '|||\n'
            package['charset' + str(i) + '_id'] = charset['id']

    # compute keyspace
    package['mask_table'] = []
    package['keyspace'] = 0
    package['hc_keyspace'] = 0
    for (i, mask) in enumerate(package['attack_settings']['masks']):
        keyspace_for_mask = compute_keyspace_from_mask(mask, charsetsSize)
        hc_keyspace_for_mask = 0
        if hashcatKeyspace:
            hc_keyspace_for_mask = shellExec(
                HASHCAT_PATH + ' -m ' + package['hash_settings']['hash_type'] +
                ' --keyspace -a 3 ' + mask + ' ' + hashcatArgs,
                cwd=HASHCAT_DIR,
                abortOnError=True)
            if hc_keyspace_for_mask == '':
                abort(500, 'Server can not compute keyspace for mask ' + mask)
            try:
                package['hc_keyspace'] += int(hc_keyspace_for_mask)
            except ValueError:
                abort(500, 'Hashcat says: "' + hc_keyspace_for_mask + '".')

        package['keyspace'] += keyspace_for_mask
        package['mask_table'].append({
            'mask': mask,
            'keyspace': keyspace_for_mask,
            'hc_keyspace': hc_keyspace_for_mask
        })

    if package['attack_settings'].get('markov'):
        markov = FcHcstat.query.filter(
            FcHcstat.id == package['attack_settings']['markov']['id']).first()
        if not markov:
            abort(500, 'Wrong markov file selected.')
        if not os.path.exists(os.path.join(HCSTATS_DIR, markov.path)):
            abort(500, 'Markov file does not exist.')
        package['markov_hcstat'] = markov.name
        package['attack_settings']['attack_submode'] = 1

    markovTreshold = package['attack_settings'][
        'markov_treshold'] if package['attack_settings'].get(
            'markov_treshold'
        ) and package['attack_settings']['markov_treshold'] > 1 else None

    package['attack_name'] = 'mask'
    package['markov_threshold'] = markovTreshold
    return package