コード例 #1
0
 def spawn(self,
           cmd,
           stdin_content="",
           stdin=False,
           shell=False,
           timeout=2):
     """
     Spawn a new process using subprocess
     """
     try:
         if type(cmd) != list:
             raise PJFInvalidType(type(cmd), list)
         if type(stdin_content) != str:
             raise PJFInvalidType(type(stdin_content), str)
         if type(stdin) != bool:
             raise PJFInvalidType(type(stdin), bool)
         self._in = stdin_content
         try:
             self.process = subprocess.Popen(cmd,
                                             stdout=PIPE,
                                             stderr=PIPE,
                                             stdin=PIPE,
                                             shell=shell)
             self.finish_read(timeout, stdin_content, stdin)
             if self.process.poll() is not None:
                 self.close()
         except KeyboardInterrupt:
             return
     except OSError:
         raise PJFProcessExecutionError("Binary <%s> does not exist" %
                                        cmd[0])
     except Exception as e:
         raise PJFBaseException(e.message)
コード例 #2
0
 def __init__(self, arguments):
     """
     Init the command line
     """
     super(PJFConfiguration, self).__init__(**arguments.__dict__)
     if self.json:
         if type(self.json) != dict:
             if type(self.json) != list:
                 raise PJFInvalidType(self.json, dict)
     if self.level:
         if type(self.level) != int:
             raise PJFInvalidType(self.level, int)
     if self.techniques:
         if type(self.techniques) != str:
             raise PJFInvalidType(self.techniques, str)
     if self.command:
         if type(self.command) != list:
             raise PJFInvalidType(self.command, list)
     if self.parameters:
         if type(self.parameters) != str:
             raise PJFInvalidType(self.parameters, str)
     if not self.nologo:
         sys.stderr.write("{0}\n".format(PYJFUZZ_LOGO))
     if self.recheck_ports:
         with open(CONF_PATH, "rb") as config:
             setattr(self, "ports", self.check_ports(json.loads(config.read())))
             config.close()
     if self.parameters:
         self.parameters = str(self.parameters).split(",")
     if self.techniques:
         techniques = {
             "C": [10, 5],
             "H": [9],
             "P": [6, 2, 8],
             "T": [11, 12],
             "R": [13],
             "S": [3, 1],
             "X": [0, 4, 7]
         }
         temp = []
         for technique in self.techniques:
             if technique in techniques:
                 temp += techniques[str(technique)]
         self.techniques = temp
     else:
         self.techniques = range(0, 14)
     if not self.utf8:
         self.utf8 = False
     if not self.command:
         self.command = ["echo"]
         self.stdin = True
     else:
         if "@@" in self.command:
             self.stdin = False
         else:
             self.stdin = True
     if not self.parameters:
         self.parameters = []
コード例 #3
0
    def __init__(self, configuration):
        """
        Class that represent a JSON object
        """
        self.logger = self.init_logger()
        if [
                "json", "json_file", "strong_fuzz", "parameters",
                "exclude_parameters", "url_encode", "indent", "utf8"
        ] not in configuration:
            raise PJFMissingArgument(
                "Some arguments are missing from PJFFactory object")

        self.config = configuration
        self.mutator = PJFMutation(self.config)
        other = self.config.json
        if not self.config.strong_fuzz:
            if type(other) == dict:
                self.json = other
            elif type(other) == list:
                self.json = {"array": other}
            else:
                raise PJFInvalidType(other, dict)
        else:
            if self.config.json_file:
                self.json = other
            else:
                self.json = json.dumps(other)
        self.logger.debug("[{0}] - PJFFactory successfully initialized".format(
            time.strftime("%H:%M:%S")))
コード例 #4
0
 def __contains__(self, items):
     if type(items) != list:
         raise PJFInvalidType(type(items), list)
     for element in items:
         try:
             getattr(self, element)
         except AttributeError:
             return False
     return True
コード例 #5
0
 def __sub__(self, other):
     """
     Removes keys from self dictionary based on provided list
     """
     if type(other) == list:
         for element in other:
             if element in self.json:
                 del self.json[element]
         return self
     else:
         raise PJFInvalidType(other, list)
コード例 #6
0
 def __init__(self, other):
     """
     Class that represent a JSON object
     """
     if type(other) == dict:
         for k in other:
             if type(other[k]) == dict:
                 other[k] = JsonFactory(other[k])
         self.__dict__ = other
     else:
         raise PJFInvalidType(other, dict)
コード例 #7
0
 def __contains__(self, items):
     """
     Check if JSON object contains a key
     """
     if type(items) != list:
         raise PJFInvalidType(items, list)
     ret = 0
     for item in items:
         for key in self.__dict__:
             if isinstance(self.__dict__[key], JsonFactory):
                 ret += item in self.__dict__[key]
             elif item == key:
                 ret += 1
     return len(items) == ret
コード例 #8
0
 def __contains__(self, items):
     """
     Check if JSON object contains a key
     """
     try:
         if type(items) != list:
             raise PJFInvalidType(items, list)
         ret = 0
         for item in items:
             for key in self.json:
                 if isinstance(self.json[key], PJFFactory):
                     ret += item in self.json[key]
                 elif item == key:
                     ret += 1
         return len(items) == ret
     except Exception as e:
         raise PJFBaseException(e.message)