示例#1
0
def api_error_sessions(request):
    if request.method == "POST":
        params = request.POST
    else:
        params = request.GET

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

    data = []
    for session in Session.objects.all():
        node = session.node

        try:
            hashcat_api = HashcatAPI(node.hostname, node.port, node.username,
                                     node.password)
            session_info = hashcat_api.get_session_info(session.name)

            if session_info['response'] != 'error' and not session_info[
                    "status"] in ["Not started", "Running", "Paused", "Done"]:
                if session_info["crack_type"] == "dictionary":
                    rule_mask = session_info["rule"]
                    wordlist = session_info["wordlist"]
                elif session_info["crack_type"] == "mask":
                    rule_mask = session_info["mask"]
                    wordlist = ""

                data.append({
                    "hashfile": session.hashfile.name,
                    "node": node.name,
                    "type": session_info["crack_type"],
                    "rule_mask": rule_mask,
                    "wordlist": wordlist,
                    "status": session_info["status"],
                    "reason": session_info["reason"],
                })
            elif session_info['response'] == 'error':
                data.append({
                    "hashfile": session.hashfile.name,
                    "node": node.name,
                    "type": "",
                    "rule_mask": "",
                    "wordlist": "",
                    "status": "Inexistant session on node",
                    "reason": "",
                })

        except ConnectionRefusedError:
            pass

    result["data"] = data

    return HttpResponse(json.dumps(result), content_type="application/json")
示例#2
0
def api_running_sessions(request):
    if request.method == "POST":
        params = request.POST
    else:
        params = request.GET

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

    data = []
    for session in Session.objects.all():
        node = session.node

        try:
            hashcat_api = HashcatAPI(node.hostname, node.port, node.username,
                                     node.password)
            session_info = hashcat_api.get_session_info(session.name)

            if session_info['response'] != 'error' and session_info[
                    "status"] == "Running":
                if session_info["crack_type"] == "dictionary":
                    rule_mask = session_info["rule"]
                    wordlist = session_info["wordlist"]
                elif session_info["crack_type"] == "mask":
                    rule_mask = session_info["mask"]
                    wordlist = ""

                data.append({
                    "hashfile":
                    session.hashfile.name,
                    "node":
                    node.name,
                    "type":
                    session_info["crack_type"],
                    "rule_mask":
                    rule_mask,
                    "wordlist":
                    wordlist,
                    "remaining":
                    session_info["time_estimated"],
                    "progress":
                    "%s %%" % session_info["progress"],
                    "speed":
                    session_info["speed"].split('@')[0].strip(),
                })
        except ConnectionRefusedError:
            pass

    result["data"] = data

    return HttpResponse(json.dumps(result), content_type="application/json")
示例#3
0
文件: views.py 项目: opt9/WebHashcat
def session(request, node_name, session_name, error_msg=''):
    context = {}
    context["Section"] = "Sessions"

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

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

    node = get_object_or_404(Node, name=node_name)

    hashcat_api = HashcatAPI(node.hostname, node.port, node.username,
                             node.password)
    session_info = hashcat_api.get_session_info(session_name)

    if session_info["response"] == "error":
        return session(request,
                       node_name,
                       session_name,
                       error_msg=session_info["message"])

    context["node"] = node_name
    context["session"] = session_name
    context["crack_type"] = session_info["crack_type"]
    context["status"] = session_info["status"]
    context["time_started"] = session_info["time_started"]
    context["time_estimated"] = session_info["time_estimated"]
    context["speed"] = session_info["speed"]
    context["recovered"] = session_info["recovered"]
    context["progress"] = session_info["progress"]
    context["results"] = session_info["results"]

    # top10 graph
    data = [
        go.Bar(x=[item[1] for item in session_info["top10_passwords"]][::-1],
               y=[item[0] for item in session_info["top10_passwords"]][::-1],
               orientation='h')
    ]
    layout = go.Layout(
        title="Top 10 passwords",
        margin=go.Margin(l=150, r=0, pad=4),
    )
    figure = go.Figure(data=data, layout=layout)
    div = opy.plot(figure, auto_open=False, output_type='div', show_link=False)

    context['top10_graph'] = div

    # password_lengths graph
    data = [
        go.Bar(x=[item[1] for item in session_info["password_lengths"]][::-1],
               y=[item[0] for item in session_info["password_lengths"]][::-1],
               orientation='h')
    ]
    layout = go.Layout(
        title="Password lengths",
        margin=go.Margin(l=150, r=0, pad=4),
    )
    figure = go.Figure(data=data, layout=layout)
    div = opy.plot(figure, auto_open=False, output_type='div', show_link=False)

    context['pass_len_graph'] = div

    # password_charset graph
    data = [
        go.Bar(x=[item[1] for item in session_info["password_charsets"]][::-1],
               y=[item[0] for item in session_info["password_charsets"]][::-1],
               orientation='h')
    ]
    layout = go.Layout(
        title="Password charsets",
        margin=go.Margin(l=150, r=0, pad=4),
    )
    figure = go.Figure(data=data, layout=layout)
    div = opy.plot(figure, auto_open=False, output_type='div', show_link=False)

    context['pass_charset_graph'] = div

    template = loader.get_template('Hashcat/session.html')
    return HttpResponse(template.render(context, request))
示例#4
0
def api_hashfile_sessions(request):
    if request.method == "POST":
        params = request.POST
    else:
        params = request.GET

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

    hashfile_id = int(params["hashfile_id"][4:] if params["hashfile_id"].
                      startswith("row_") else params["hashfile_id"])

    data = []
    for session in Session.objects.filter(hashfile_id=hashfile_id):
        node = session.node

        try:
            hashcat_api = HashcatAPI(node.hostname, node.port, node.username,
                                     node.password)
            session_info = hashcat_api.get_session_info(session.name)
            print(session_info)
            if session_info["response"] != "error":
                if session_info["status"] == "Not started":
                    buttons = "<button title='Start session' type='button' class='btn btn-success btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-play'></span></button>" % (
                        session.name, "start")
                    buttons += "<button title='Remove session' style='margin-left: 5px' type='button' class='btn btn-danger btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-remove'></span></button>" % (
                        session.name, "remove")
                elif session_info["status"] == "Running":
                    buttons = "<button title='Pause session' type='button' class='btn btn-warning btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-pause'></span></button>" % (
                        session.name, "pause")
                    buttons += "<button title='Stop session' style='margin-left: 5px' type='button' class='btn btn-danger btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-stop'></span></button>" % (
                        session.name, "quit")
                elif session_info["status"] == "Paused":
                    buttons = "<button title='Resume session' type='button' class='btn btn-success btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-play'></span></button>" % (
                        session.name, "resume")
                    buttons += "<button title='Stop session' style='margin-left: 5px' type='button' class='btn btn-danger btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-stop'></span></button>" % (
                        session.name, "quit")
                else:
                    buttons = "<button title='Start session' type='button' class='btn btn-success btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-play'></span></button>" % (
                        session.name, "start")
                    buttons += "<button title='Remove session' style='margin-left: 5px' type='button' class='btn btn-danger btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-remove'></span></button>" % (
                        session.name, "remove")

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

                if session_info["crack_type"] == "dictionary":
                    rule_mask = session_info["rule"]
                    wordlist = session_info["wordlist"]
                elif session_info["crack_type"] == "mask":
                    rule_mask = session_info["mask"]
                    wordlist = ""

                status = session_info["status"]
                if status == "Error":
                    status += ' <a href="#" data-toggle="tooltip" data-placement="right" title="%s"><span class="glyphicon glyphicon-info-sign" aria-hidden="true"></span></a>' % session_info[
                        "reason"]

                crack_type = session_info["crack_type"]
                remaining = session_info["time_estimated"]
                progress = "%s %%" % session_info["progress"]
                speed = session_info["speed"]
            else:
                status = "Inexistant"
                crack_type = ""
                rule_mask = ""
                wordlist = ""
                remaining = ""
                progress = ""
                speed = ""
                buttons = "<button title='Remove session' style='margin-left: 5px' type='button' class='btn btn-danger btn-xs' onClick='session_action(\"%s\", \"%s\")'><span class='glyphicon glyphicon-remove'></span></button>" % (
                    session.name, "remove")

            data.append({
                "node": node.name,
                "type": crack_type,
                "rule_mask": rule_mask,
                "wordlist": wordlist,
                "status": status,
                "remaining": remaining,
                "progress": progress,
                "speed": speed,
                "buttons": buttons,
            })
        except ConnectionRefusedError:
            data.append({
                "node": node.name,
                "type": "",
                "rule_mask": "",
                "wordlist": "",
                "status": "",
                "remaining": "",
                "progress": "",
                "speed": "",
                "buttons": "",
            })

    result["data"] = data

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

    return HttpResponse(json.dumps(result), content_type="application/json")