コード例 #1
0
ファイル: views.py プロジェクト: cybergh00st/WebHashcat
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)

            hashes = request.POST["hashes"]
            f = open(hashfile_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

            hashfile = Hashfile(
                name=request.POST['name'],
                hashfile=hashfile_name,
                hash_type=hash_type,
                line_count=0,
                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, but it is processed in a background task
            import_hashfile_task.delay(hashfile.id)

            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))
コード例 #2
0
ファイル: views.py プロジェクト: cybergh00st/WebHashcat
def files(request):
    context = {}
    context["Section"] = "Files"

    if request.method == 'POST':
        if request.POST["action"] == "remove":
            if request.POST["filetype"] == "rule":
                Hashcat.remove_rule(request.POST["filename"])
            elif request.POST["filetype"] == "mask":
                Hashcat.remove_mask(request.POST["filename"])
            elif request.POST["filetype"] == "wordlist":
                Hashcat.remove_wordlist(request.POST["filename"])

    context["rule_list"] = Hashcat.get_rules()
    context["mask_list"] = Hashcat.get_masks()
    context["wordlist_list"] = Hashcat.get_wordlists()

    template = loader.get_template('Hashcat/files.html')
    return HttpResponse(template.render(context, request))
コード例 #3
0
ファイル: views.py プロジェクト: jackrichardzon/WebHashcat
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))
コード例 #4
0
def node(request, node_name, error_msg=""):

    context = {}
    context["Section"] = "Nodes"

    if len(error_msg) != 0:
        context["error_message"] = error_msg

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

    node_item = get_object_or_404(Node, name=node_name)

    context["node_name"] = node_item.name
    context["hostname"] = node_item.hostname
    context["port"] = node_item.port

    if request.method == 'POST':
        if request.POST["action"] == "synchronize":

            hashcat_api = HashcatAPI(node_item.hostname, node_item.port,
                                     node_item.username, node_item.password)
            node_data = hashcat_api.get_hashcat_info()

            rule_list = Hashcat.get_rules()
            mask_list = Hashcat.get_masks()
            wordlist_list = Hashcat.get_wordlists()

            for rule in rule_list:
                if not rule["name"] in node_data["rules"]:
                    hashcat_api.upload_rule(rule["name"],
                                            open(rule["path"], 'rb').read())
                elif node_data["rules"][rule["name"]]["md5"] != rule["md5"]:
                    hashcat_api.upload_rule(rule["name"],
                                            open(rule["path"], 'rb').read())

            for mask in mask_list:
                if not mask["name"] in node_data["masks"]:
                    hashcat_api.upload_mask(mask["name"],
                                            open(mask["path"], 'rb').read())
                elif node_data["masks"][mask["name"]]["md5"] != mask["md5"]:
                    hashcat_api.upload_mask(mask["name"],
                                            open(mask["path"], 'rb').read())

            for wordlist in wordlist_list:
                if not wordlist["name"] in node_data["wordlists"]:
                    hashcat_api.upload_wordlist(
                        wordlist["name"],
                        open(wordlist["path"], 'rb').read())
                elif node_data["wordlists"][
                        wordlist["name"]]["md5"] != wordlist["md5"]:
                    hashcat_api.upload_wordlist(
                        wordlist["name"],
                        open(wordlist["path"], 'rb').read())

    hashcat_api = HashcatAPI(node_item.hostname, node_item.port,
                             node_item.username, node_item.password)
    node_data = hashcat_api.get_hashcat_info()

    if node_data["response"] == "error":
        return node(request, node_name, error_msg=node_data["message"])

    rule_list = Hashcat.get_rules()
    mask_list = Hashcat.get_masks()
    wordlist_list = Hashcat.get_wordlists()

    for rule in rule_list:
        if not rule["name"] in node_data["rules"]:
            rule["synchro"] = False
        elif node_data["rules"][rule["name"]]["md5"] != rule["md5"]:
            rule["synchro"] = False
        else:
            rule["synchro"] = True

    for mask in mask_list:
        if not mask["name"] in node_data["masks"]:
            mask["synchro"] = False
        elif node_data["masks"][mask["name"]]["md5"] != mask["md5"]:
            mask["synchro"] = False
        else:
            mask["synchro"] = True

    for wordlist in wordlist_list:
        if not wordlist["name"] in node_data["wordlists"]:
            wordlist["synchro"] = False
        elif node_data["wordlists"][
                wordlist["name"]]["md5"] != wordlist["md5"]:
            wordlist["synchro"] = False
        else:
            wordlist["synchro"] = True

    hash_type_list = sorted(node_data["hash_types"], key=itemgetter('id'))

    context["version"] = node_data["version"]
    context["rule_list"] = rule_list
    context["mask_list"] = mask_list
    context["wordlist_list"] = wordlist_list
    context["hash_type_list"] = hash_type_list

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