def remove_hashfile(self, hashfile): # Check if there is a running session 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) hashcat_api.action(session.name, "remove") except Exception as e: traceback.print_exc() hashfile_path = os.path.join(os.path.dirname(__file__), "..", "Files", "Hashfiles", hashfile.hashfile) # remove from disk try: os.remove(hashfile_path) except Exception as e: pass del_hashfile_locks(hashfile) start = time.perf_counter() # deletion is faster using raw SQL queries cursor = connection.cursor() cursor.execute("DELETE FROM Hashcat_session WHERE hashfile_id = %s", [hashfile.id]) cursor.execute("DELETE FROM Hashcat_hash WHERE hashfile_id = %s", [hashfile.id]) cursor.close() hashfile.delete() end = time.perf_counter() print(">>> Hashfile %s deleted from database in %fs" % (hashfile.name, end-start))
def api_hashfile_action(request): if request.method == "POST": params = request.POST else: params = request.GET hashfile = get_object_or_404(Hashfile, id=params["hashfile_id"]) print("Hashfile %s action %s" % (hashfile.name, params["action"])) if params["action"] == "remove": # Check if there is a running session 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) hashcat_api.action(session.name, "remove") except Exception as e: traceback.print_exc() hashfile_path = os.path.join(os.path.dirname(__file__), "..", "Files", "Hashfiles", hashfile.hashfile) crackedfile_path = os.path.join(os.path.dirname(__file__), "..", "Files", "Crackedfiles", hashfile.crackedfile) # remove from disk try: os.remove(hashfile_path) except Exception as e: messages.error( request, "Error when deleting %s: %s" % (hashfile_path, str(e))) try: os.remove(crackedfile_path) except Exception as e: messages.error( request, "Error when deleting %s: %s" % (crackedfile_path, str(e))) del_hashfile_locks(hashfile) hashfile.delete() return HttpResponse(json.dumps({"result": "success"}), content_type="application/json")
def action(request, node_name, session_name, action): node = get_object_or_404(Node, name=node_name) hashcat_api = HashcatAPI(node.hostname, node.port, node.username, node.password) res = hashcat_api.action(session_name, action) if res["response"] == "error": return index(request, error_msg=res["message"]) return redirect('index')
def api_session_action(request): if request.method == "POST": params = request.POST else: params = request.GET session = get_object_or_404(Session, name=params["session_name"]) node = session.node hashcat_api = HashcatAPI(node.hostname, node.port, node.username, node.password) res = hashcat_api.action(session.name, params["action"]) if params["action"] == "remove": session.delete() return HttpResponse(json.dumps(res), content_type="application/json")