コード例 #1
0
ファイル: views.py プロジェクト: djbios/WebHashcat
def api_node_status(request):
    if request.method == "POST":
        params = request.POST
    else:
        params = request.GET

    result = {
        "draw": params["draw"],
    }

    node_object_list = Node.objects.all()

    data = []
    for node in node_object_list:
        try:
            hashcat_api = HashcatAPI(node.hostname, node.port, node.username,
                                     node.password)
            node_data = hashcat_api.get_hashcat_info()

            status = "Stopped"
            for session in node_data["sessions"]:
                if session["status"] == "Running":
                    status = "Running"
                    break

            data.append([
                node.name,
                node_data["version"],
                status,
            ])
        except ConnectionRefusedError:
            data.append([
                node.name,
                "",
                "Error",
            ])
        except requests.exceptions.ConnectionError:
            data.append([
                node.name,
                "",
                "Error",
            ])

    result["data"] = data

    for query in connection.queries[-1:]:
        print(query["sql"])
        print(query["time"])

    return HttpResponse(json.dumps(result), content_type="application/json")
コード例 #2
0
ファイル: views.py プロジェクト: opt9/WebHashcat
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('Hashcat/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

    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 = node_data["rules"]
    rule_list.sort()
    mask_list = node_data["masks"]
    mask_list.sort()
    wordlist_list = node_data["wordlists"]
    wordlist_list.sort()
    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('Hashcat/node.html')
    return HttpResponse(template.render(context, request))
コード例 #3
0
ファイル: views.py プロジェクト: opt9/WebHashcat
def index(request, error_msg=''):

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

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

    node_object_list = Node.objects.all()

    session_list = []
    rule_list = []
    mask_list = []
    hash_type_list = {}
    node_list = []
    wordlist_list = []

    connection_error_nodes = []

    for node in node_object_list:
        try:
            hashcat_api = HashcatAPI(node.hostname, node.port, node.username,
                                     node.password)
            node_data = hashcat_api.get_hashcat_info()

            node_list.append(node.name)

            for session in node_data["sessions"]:
                session_list.append({
                    "name": session["name"],
                    "node": node.name,
                    "crack_type": session["crack_type"],
                    "status": session["status"],
                    "cracked": int(session["cracked"]),
                    "progress": session["progress"],
                })

            rule_list += node_data["rules"]
            mask_list += node_data["masks"]
            wordlist_list += node_data["wordlists"]

            for hash_type in node_data["hash_types"]:
                hash_type_list[hash_type["id"]] = hash_type
        except ConnectionRefusedError:
            connection_error_nodes.append(node.name)

    rule_list = list(set(rule_list))
    rule_list.sort()
    mask_list = list(set(mask_list))
    mask_list.sort()
    wordlist_list = list(set(wordlist_list))
    wordlist_list.sort()
    hash_type_list = sorted(list(hash_type_list.values()),
                            key=itemgetter('name'))

    context["node_list"] = node_list
    context["session_list"] = session_list
    context["rule_list"] = rule_list
    context["mask_list"] = mask_list
    context["wordlist_list"] = wordlist_list
    context["hash_type_list"] = hash_type_list

    if len(connection_error_nodes) != 0:
        context[
            "error_message"] = "Connection error with the following nodes : %s" % ", ".join(
                connection_error_nodes)

    template = loader.get_template('Hashcat/index.html')
    return HttpResponse(template.render(context, request))
コード例 #4
0
ファイル: views.py プロジェクト: djbios/WebHashcat
def api_hashfiles(request):
    if request.method == "POST":
        params = request.POST
    else:
        params = request.GET

    result = {
        "draw": params["draw"],
    }

    session_status = {}

    node_object_list = Node.objects.all()
    for node in node_object_list:
        try:
            hashcat_api = HashcatAPI(node.hostname, node.port, node.username,
                                     node.password)
            hashcat_info = hashcat_api.get_hashcat_info()
            for session in hashcat_info["sessions"]:
                session_status[session["name"]] = session["status"]
        except ConnectionRefusedError:
            pass
        except requests.exceptions.ConnectTimeout:
            pass

    sort_index = [
        "name", "name", "hash_type", "line_count", "cracked_count", "name",
        "name", "name"
    ][int(params["order[0][column]"])]
    sort_index = "-" + sort_index if params[
        "order[0][dir]"] == "desc" else sort_index
    hashfile_list = Hashfile.objects.filter(
        name__contains=params["search[value]"]).order_by(
            sort_index)[int(params["start"]):int(params["start"]) +
                        int(params["length"])]

    data = []
    for hashfile in hashfile_list:
        buttons = "<a href='%s'><button title='Export cracked results' class='btn btn-info btn-xs' ><span class='glyphicon glyphicon-download-alt'></span></button></a>" % reverse(
            'Hashcat:export_cracked', args=(hashfile.id, ))
        buttons += "<button title='Create new cracking session' style='margin-left: 5px' class='btn btn-primary btn-xs' data-toggle='modal' data-target='#action_new' data-hashfile='%s' data-hashfile_id=%d ><span class='glyphicon glyphicon-plus'></span></button>" % (
            hashfile.name, hashfile.id)
        buttons += "<button title='Remove hashfile' style='margin-left: 5px' type='button' class='btn btn-danger btn-xs' onClick='hashfile_action(%d, \"%s\")'><span class='glyphicon glyphicon-remove'></span></button>" % (
            hashfile.id, "remove")

        buttons = "<div style='float: right'>%s</div>" % buttons

        running_session_count = 0
        total_session_count = Session.objects.filter(
            hashfile_id=hashfile.id).count()
        for session in Session.objects.filter(hashfile_id=hashfile.id):
            try:
                if session_status[session.name] == "Running":
                    running_session_count += 1
            except KeyError:
                pass

        data.append({
            "DT_RowId":
            "row_%d" % hashfile.id,
            "name":
            "<a href='%s'>%s<a/>" %
            (reverse('Hashcat:hashfile', args=(hashfile.id, )), hashfile.name),
            "type":
            "Plaintext" if hashfile.hash_type == -1 else
            Hashcat.get_hash_types()[hashfile.hash_type]["name"],
            "line_count":
            humanize.intcomma(hashfile.line_count),
            "cracked":
            "%s (%.2f%%)" %
            (humanize.intcomma(hashfile.cracked_count),
             hashfile.cracked_count / hashfile.line_count * 100)
            if hashfile.line_count > 0 else "0",
            "username_included":
            "yes" if hashfile.username_included else "no",
            "sessions_count":
            "%d / %d" % (running_session_count, total_session_count),
            "buttons":
            buttons,
        })

    result["data"] = data
    result["recordsTotal"] = Hashfile.objects.all().count()
    result["recordsFiltered"] = Hashfile.objects.filter(
        name__contains=params["search[value]"]).count()

    for query in connection.queries[-4:]:
        print(query["sql"])
        print(query["time"])

    return HttpResponse(json.dumps(result), content_type="application/json")
コード例 #5
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))