Example #1
0
 def getPorts(self):
     """Returns ip assigned ports as a list of mongo fetched defects dict
     Returns:
         list of port raw mongo data dictionnaries
     """
     apiclient = APIClient.getInstance()
     return apiclient.find("ports", {"ip": self.ip})
Example #2
0
 def getTools(self):
     """Return port assigned tools as a list of mongo fetched defects dict
     Returns:
         list of tool raw mongo data dictionnaries
     """
     apiclient = APIClient.getInstance()
     return apiclient.find("tools", {"wave": self.wave, "$or": [{"lvl": "network"}, {"lvl": "domain"}], "scope": self.scope})
Example #3
0
 def delete(self):
     """
     Delete the command group represented by this model in database.
     """
     ret = self._id
     apiclient = APIClient.getInstance()
     apiclient.delete("group_commands", ret)
Example #4
0
    def addInDb(self):
        """
        Add this tool in database.

        Returns: a tuple with :
                * bool for success
                * mongo ObjectId : already existing object if duplicate, create object id otherwise 
        """
        base = self.getDbKey()
        apiclient = APIClient.getInstance()
        # Checking unicity
        existing = apiclient.find("tools", base, False)
        if existing is not None:
            return False, existing["_id"]
        # Those are added to base after tool's unicity verification
        base["command_iid"] = self.command_iid
        base["scanner_ip"] = self.scanner_ip
        base["dated"] = self.dated
        base["datef"] = self.datef
        if isinstance(self.status, str):
            self.status = [self.status]
        base["status"] = self.status
        base["tags"] = self.tags
        base["text"] = self.text
        base["resultfile"] = self.resultfile
        base["notes"] = self.notes
        res, iid = apiclient.insert("tools", base)
        self._id = iid
        return True, iid
Example #5
0
 def delete(self):
     """
     Delete the wave represented by this model in database.
     Also delete the tools, intervals, scopes associated with this wave
     """
     apiclient = APIClient.getInstance()
     apiclient.delete("waves", ObjectId(self._id))
Example #6
0
    def _getParentId(self):
        """
        Return the mongo ObjectId _id of the first parent of this object. For a Tool it is either a scope, an ip or a port depending on the tool's level.

        Returns:
            Returns the parent's ObjectId _id". or None if a type error occurs
        """
        apiclient = APIClient.getInstance()
        try:
            if self.lvl == "wave":
                wave = apiclient.find("waves", {"wave": self.wave}, False)
                return wave["_id"]
            elif self.lvl == "network" or self.lvl == "domain":
                return apiclient.find("scopes", {
                    "wave": self.wave,
                    "scope": self.scope
                }, False)["_id"]
            elif self.lvl == "ip":
                return apiclient.find("ips", {"ip": self.ip}, False)["_id"]
            else:
                return apiclient.find("ports", {
                    "ip": self.ip,
                    "port": self.port,
                    "proto": self.proto
                }, False)["_id"]
        except TypeError:
            # None type returned:
            return None
Example #7
0
 def getScopes(self):
     """Return wave assigned scopes as a list of mongo fetched scopes dict
     Returns:
         list of defect raw mongo data dictionnaries
     """
     apiclient = APIClient.getInstance()
     return apiclient.find("scopes", {"wave": self.wave})
Example #8
0
 def getTools(self):
     """Return port assigned tools as a list of mongo fetched defects dict
     Returns:
         list of tool raw mongo data dictionnaries
     """
     apiclient = APIClient.getInstance()
     return apiclient.find("tools", {"lvl": "port", "ip": self.ip, "port": self.port, "proto": self.proto})
Example #9
0
 def getDefects(self):
     """Return port assigned defects as a list of mongo fetched defects dict
     Returns:
         list of defect raw mongo data dictionnaries
     """
     apiclient = APIClient.getInstance()
     return apiclient.find("defects", {"ip": self.ip, "port": self.port, "proto": self.proto})
Example #10
0
 def update(self, pipeline_set=None):
     """Update this object in database.
     Args:
         pipeline_set: (Opt.) A dictionnary with custom values. If None (default) use model attributes.
     """
     apiclient = APIClient.getInstance()
     if pipeline_set is None:
         apiclient.update(
             "defects", ObjectId(self._id), {
                 "ip": self.ip,
                 "title": self.title,
                 "port": self.port,
                 "proto": self.proto,
                 "notes": self.notes,
                 "ease": self.ease,
                 "impact": self.impact,
                 "risk": self.risk,
                 "redactor": self.redactor,
                 "type": list(self.mtype),
                 "proofs": self.proofs,
                 "infos": self.infos,
                 "index": int(self.index)
             })
     else:
         apiclient.update("defects", ObjectId(self._id), pipeline_set)
Example #11
0
 def delete(self):
     """
     Delete the defect represented by this model in database.
     """
     ret = self._id
     apiclient = APIClient.getInstance()
     apiclient.delete("defects", ret)
Example #12
0
    def _getParentId(self):
        """
        Return the mongo ObjectId _id of the first parent of this object.

        Returns:
            Returns the parent's ObjectId _id".
        """
        if self.parent is not None:
            return self.parent
        try:
            if IPAddress(self.ip).is_private():
                return None
        except AddrFormatError:
            return None
        except ValueError:
            return None
        ip_real = performLookUp(self.ip)
        if ip_real is not None:
            apiclient = APIClient.getInstance()
            ip_in_db = apiclient.find("ips", {"ip": ip_real}, False)
            if ip_in_db is None:
                return None
            self.parent = ip_in_db["_id"]
            self.update({"parent": self.parent})
            return ip_in_db["_id"]
        return None
Example #13
0
 def setStatus(self, status):
     """Set this tool status with given list of status
     Args:
         list of string with status inside (accepted values are OOS, OOT, running, done)
     """
     self.status = status
     apiclient = APIClient.getInstance()
     apiclient.setToolStatus(self, self.status)
Example #14
0
 def removeProof(self, ind):
     """Removes the proof file at given proof index
     """
     apiclient = APIClient.getInstance()
     filename = self.proofs[ind]
     ret = apiclient.rmProof(self._id, filename)
     del self.proofs[ind]
     return ret
Example #15
0
    def _getParentId(self):
        """
        Return the mongo ObjectId _id of the first parent of this object. For an interval it is the wave.

        Returns:
            Returns the parent wave's ObjectId _id".
        """
        apiclient = APIClient.getInstance()
        return apiclient.find("waves", {"wave": self.wave}, False)["_id"]
Example #16
0
 def setTags(self, tags):
     """Change all tags for the given new ones  and update database
     Args:
         tags: a list of tag string
     """
     self.tags = tags
     apiclient = APIClient.getInstance()
     apiclient.update(self.__class__.coll_name, ObjectId(self._id),
                      {"tags": tags})
Example #17
0
 def delete(self):
     """
     Delete the Scope represented by this model in database.
     Also delete the tools associated with this scope
     Also remove this scope from ips in_scopes attributes
     """
     # deleting tool with scope lvl
     apiclient = APIClient.getInstance()
     apiclient.delete("scopes", ObjectId(self._id))
Example #18
0
 def delete(self):
     """
     Deletes the Port represented by this model in database.
     Also deletes the tools associated with this port
     Also deletes the defects associated with this port
     """
     apiclient = APIClient.getInstance()
     
     apiclient.delete("ports", ObjectId(self._id))
Example #19
0
    def addCustomTool(self, command_name):
        """
        Add the appropriate tools (level check and wave's commands check) for this port.

        Args:
            command_name: The command that we want to create all the tools for.
        """
        apiclient = APIClient.getInstance()
        return apiclient.addCustomTool(self._id, command_name)
Example #20
0
    def _getParentId(self):
        """
        Return the mongo ObjectId _id of the first parent of this object. For a port it is the ip.

        Returns:
            Returns the parent ip's ObjectId _id".
        """
        apiclient = APIClient.getInstance()
        return apiclient.find("ips", {"ip": self.ip}, False)["_id"]
Example #21
0
 def uploadProof(self, proof_local_path):
     """Upload the given proof file to the server
     Args:
         proof_local_path: a path to a local proof file
     Returns:
         the basename of the file 
     """
     apiclient = APIClient.getInstance()
     apiclient.putProof(self._id, proof_local_path)
     return os.path.basename(proof_local_path)
Example #22
0
 def update(self, pipeline_set=None):
     """Update this object in database.
     Args:
         pipeline_set: (Opt.) A dictionnary with custom values. If None (default) use model attributes.
     """
     apiclient = APIClient.getInstance()
     if pipeline_set is None:
         apiclient.update("scopes", ObjectId(self._id), {"notes": self.notes, "tags": self.tags})
     else:
         apiclient.update("scopes", ObjectId(self._id), pipeline_set)
Example #23
0
 def update(self, pipeline_set=None):
     """Update this object in database.
     Args:
         pipeline_set: (Opt.) A dictionnary with custom values. If None (default) use model attributes.
     """
     apiclient = APIClient.getInstance()
     # Update variable instance. (this avoid to refetch the whole command in database)
     if pipeline_set is None:
         apiclient.update("ports", ObjectId(self._id), {"service": self.service, "product":self.product, "notes": self.notes, "tags": self.tags, "infos": self.infos})
     else:
         apiclient.update("ports", ObjectId(self._id),  pipeline_set)
Example #24
0
 def listWaves(cls):
     """Return all waves names as a list 
     Returns:
         list of all wave names
     """
     ret = []
     apiclient = APIClient.getInstance()
     waves = apiclient.find("waves", {})
     for wave in waves:
         ret.append(wave["wave"])
     return ret
Example #25
0
 def update(self, pipeline_set=None):
     """Update this object in database.
     Args:
         pipeline_set: (Opt.) A dictionnary with custom values. If None (default) use model attributes.
     """
     apiclient = APIClient.getInstance()
     if pipeline_set is None:
         apiclient.update("waves", ObjectId(self._id),
                          {"wave_commands": list(self.wave_commands)})
     else:
         apiclient.update("waves", ObjectId(self._id), pipeline_set)
Example #26
0
    def getCommand(self):
        """
        Get the tool associated command.

        Return:
            Returns the Mongo dict command fetched instance associated with this tool's name.
        """
        apiclient = APIClient.getInstance()
        commandTemplate = apiclient.findInDb(
            apiclient.getCurrentPentest(), "commands",
            {"_id": ObjectId(self.command_iid)}, False)
        return commandTemplate
Example #27
0
 def delTag(self, tagToDelete):
     """Delete the given tag in this object.
     Args:
         tagToDelete: a tag as a string to be deleted from this model tags
     """
     tags = self.getTags()
     apiclient = APIClient.getInstance()
     if tagToDelete in tags:
         del tags[tags.index(tagToDelete)]
         notify = tagToDelete != "hidden"
         apiclient.update(self.__class__.coll_name, ObjectId(self._id),
                          {"tags": tags}, False, notify)
Example #28
0
    def addInDb(self):
        """
        Add this interval in database.

        Returns: a tuple with :
                * bool for success
                * mongo ObjectId : already existing object if duplicate, create object id otherwise 
        """
        base = {"wave": self.wave, "dated": self.dated, "datef": self.datef}
        apiclient = APIClient.getInstance()
        res, iid = apiclient.insert("intervals", base)
        self._id = iid
        return True, iid
Example #29
0
 def fetchObject(cls, pipeline):
     """Fetch one command from database and return the CommandGroup object 
     Args:
         pipeline: a Mongo search pipeline (dict)
     Returns:
         Returns a CommandGroup or None if nothing matches the pipeline.
     """
     apiclient = APIClient.getInstance()
     d = apiclient.findInDb("pollenisator", "group_commands", pipeline,
                            False)
     if d is None:
         return None
     return CommandGroup(d)
Example #30
0
    def getList(cls):
        """
        Get all group of command's name registered on database

        Returns:
            Returns the list of command groups name found inside the database. List may be empty.
        """
        apiclient = APIClient.getInstance()
        gcommands = apiclient.findInDb("pollenisator", "group_commands")
        ret = []
        for gcommand in gcommands:
            ret.append(gcommand["name"])
        return ret