Ejemplo n.º 1
0
def import_hashfile_task(hashfile_id):

    hashfile = Hashfile.objects.get(id=hashfile_id)

    task = Task(
        time = datetime.datetime.now(),
        message = "Importing hash file %s..." % hashfile.name
    )
    task.save()

    try:

        if hashfile.hash_type != -1: # if != plaintext
            task.message = "Importing hash file %s..." % hashfile.name
            task.save()

            Hashcat.insert_hashes(hashfile)

            task.message = "Comparing hash file %s to potfile..." % hashfile.name
            task.save()

            Hashcat.compare_potfile(hashfile)
        else:
            task.message = "Importing plaintext file %s..." % hashfile.name
            task.save()

            Hashcat.insert_plaintext(hashfile)
    except Exception as e:
        traceback.print_exc()
    finally:
        task.delete()
Ejemplo n.º 2
0
def hashfiles(request):
    context = {}
    context["Section"] = "Hashes"

    if request.method == 'POST':
        if request.POST["action"] == "add":
            hash_type = int(request.POST["hash_type"])

            hashfile_name = ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for _ in range(12)) + ".hashfile"
            hashfile_path = os.path.join(os.path.dirname(__file__), "..",
                                         "Files", "Hashfiles", hashfile_name)

            crackedfile_name = ''.join(
                random.choice(string.ascii_uppercase + string.digits)
                for _ in range(12)) + ".crackedfile"
            crackedfile_path = os.path.join(os.path.dirname(__file__), "..",
                                            "Files", "Crackedfiles",
                                            crackedfile_name)

            hashes = request.POST["hashes"]
            if hash_type != -1:  # if != plaintext
                f = open(hashfile_path, 'w')
            else:
                f = open(crackedfile_path, 'w')
            if len(hashes) == 0 and "hashfile" in request.FILES:
                for chunk in request.FILES['hashfile'].chunks():
                    f.write(chunk.decode('UTF-8', 'backslashreplace'))
            else:
                f.write(hashes.strip())
            f.close()

            username_included = "username_included" in request.POST

            if hash_type != -1:  # if != plaintext
                line_count = sum(
                    1 for _ in open(hashfile_path, errors="backslashreplace"))
            else:
                line_count = sum(
                    1
                    for _ in open(crackedfile_path, errors="backslashreplace"))

            hashfile = Hashfile(
                name=request.POST['name'],
                hashfile=hashfile_name,
                crackedfile=crackedfile_name,
                hash_type=hash_type,
                line_count=line_count,
                cracked_count=0,
                username_included=username_included,
            )
            hashfile.save()
            init_hashfile_locks(hashfile)

            # Update the new file with the potfile, this may take a while
            updated = False
            while not updated:
                try:
                    if hash_type != -1:  # if != plaintext
                        Hashcat.compare_potfile(hashfile)
                    else:
                        Hashcat.insert_plaintext(hashfile)
                    updated = True
                except OperationalError:
                    # db locked, try again !!!
                    pass

            if hash_type != -1:  # if != plaintext
                messages.success(request, "Hashfile successfully added")
            else:
                messages.success(request, "Plaintext file successfully added")

    context["node_list"] = Node.objects.all()
    context["hash_type_list"] = [{
        'id': -1,
        'name': 'Plaintext'
    }] + sorted(list(Hashcat.get_hash_types().values()),
                key=itemgetter('name'))
    context["rule_list"] = [{
        'name': None
    }] + sorted(Hashcat.get_rules(detailed=False), key=itemgetter('name'))
    context["mask_list"] = sorted(Hashcat.get_masks(detailed=False),
                                  key=itemgetter('name'))
    context["wordlist_list"] = sorted(Hashcat.get_wordlists(detailed=False),
                                      key=itemgetter('name'))

    template = loader.get_template('Hashcat/hashes.html')
    return HttpResponse(template.render(context, request))