Beispiel #1
0
    def update_potfile(self):

        updated_hashfile_ids = []

        with transaction.atomic():
            try:
                # Lock: prevent the potfile from being modified
                potfile_locks = list(Lock.objects.select_for_update().filter(
                    lock_ressource="potfile"))

                # update the potfile
                for session in Session.objects.all():
                    try:
                        node = session.node

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

                        remaining = True
                        while (remaining):
                            potfile_data = hashcat_api.get_potfile(
                                session.name, session.potfile_line_retrieved)
                            if potfile_data[
                                    "response"] == "ok" and potfile_data[
                                        "line_count"] > 0:
                                f = open(self.get_potfile(),
                                         "a",
                                         encoding='utf-8')
                                f.write(potfile_data["potfile_data"])
                                f.close()

                                session.potfile_line_retrieved += potfile_data[
                                    "line_count"]
                                session.save()

                                remaining = potfile_data["remaining_data"]

                                updated_hashfile_ids.append(
                                    session.hashfile.id)
                            else:
                                remaining = False

                    except ConnectionRefusedError:
                        pass

                del potfile_locks
            except OperationalError as e:
                # potfile is locked, no need to be concerned about it, this function is executed regularly
                print("Error: potfile locked")

        return list(set(updated_hashfile_ids))
Beispiel #2
0
    def update_potfile(self):

        updated_hash_type = []

        with transaction.atomic():
            potfile_locks = list(Lock.objects.select_for_update().filter(lock_ressource="potfile"))

            print("Updating potfile")

            # update the potfile
            for session in Session.objects.all():
                try:
                    node = session.node

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

                    # Lock: prevent the potfile from being modified


                    remaining = True
                    while(remaining):
                        potfile_data = hashcat_api.get_potfile(session.name, session.potfile_line_retrieved)

                        if potfile_data["response"] == "ok" and potfile_data["line_count"] > 0:
                            updated_hash_type.append(session.hashfile.hash_type)

                            f = open(self.get_potfile(), "a", encoding='utf-8')
                            f.write(potfile_data["potfile_data"])
                            f.close()

                            session.potfile_line_retrieved += potfile_data["line_count"]
                            session.save()

                            remaining = potfile_data["remaining_data"]

                            # Probably quicker than a python equivalent code
                            tmp_potfile = "/tmp/webhashcat_potfile"
                            os.system("sort %s | uniq > %s; mv %s %s" % (Hashcat.get_potfile(), tmp_potfile, tmp_potfile, Hashcat.get_potfile()))
                        else:
                            remaining = False

                except ConnectionRefusedError:
                    pass

            print("Done updating potfile")

            del potfile_locks

        return updated_hash_type