def _execute(self, argv, context): cmd = argv[0] + ' ' + self._kwargs.get('output_opts', self.DEFAULT_OUTPUT_OPTIONS) + " " + ' '.join(argv[1:]) self.logger.debug('CMD = ' + cmd) p = subprocess.Popen(miscellaneous.shell_split(cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.wait() return p.returncode
def _execute(self, argv, context): cmd = argv[0] + " " + self._kwargs.get("output_opts", self.DEFAULT_OUTPUT_OPTIONS) + " " + " ".join(argv[1:]) self.logger.debug("CMD = " + cmd) p = subprocess.Popen( miscellaneous.shell_split(cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) p.wait() return p.returncode
def _execute(self, argv, context): cmd = argv[0] + ' ' + self._kwargs.get('output_opts', self.DEFAULT_OUTPUT_OPTIONS) + " " + ' '.join(argv[1:]) self.logger.debug('CMD = ' + cmd) p = subprocess.Popen(miscellaneous.shell_split(cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) p_stdout = p.communicate(input=self._kwargs.get('stdin', self.DEFAULT_STDIN_BUFFER))[0] self.logger.debug('DATA (%d bytes) = %s' % (len(p_stdout), p_stdout)) return p_stdout
def _execute(self, argv, context): cmd = argv[0] + " " + self._kwargs.get("output_opts", self.DEFAULT_OUTPUT_OPTIONS) + " " + " ".join(argv[1:]) self.logger.debug("CMD = " + cmd) p = subprocess.Popen( miscellaneous.shell_split(cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) p_stdout = p.communicate(input=self._kwargs.get("stdin", self.DEFAULT_STDIN_BUFFER))[0] self.logger.debug("DATA (%d bytes) = %s" % (len(p_stdout), p_stdout)) return p_stdout
def _execute(self, argv, context): tmpfile = tempfile.NamedTemporaryFile(delete=False) fname = tmpfile.name data = "" try: cmd = ( argv[0] + " " + self._kwargs.get("output_opts", self.DEFAULT_OUTPUT_OPTIONS) + " " + tmpfile.name + " " + " ".join(argv[1:]) ) self.logger.debug("CMD = " + cmd) p = subprocess.Popen( miscellaneous.shell_split(cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) (stdout_output, stderr_output) = p.communicate(input=self._kwargs.get("stdin", self.DEFAULT_STDIN_BUFFER)) self.logger.debug(stdout_output) tmpfile.flush() os.fsync(tmpfile.fileno()) tmpfile.close() tmpfile = open(fname, "r") data = tmpfile.read() self.logger.debug("DATA (%d bytes) = %s" % (len(data), data)) except Exception: os.remove(fname) return data
def _execute(self, argv, context): tmpfile = tempfile.NamedTemporaryFile(delete=False) fname = tmpfile.name data = "" try: cmd = argv[0] + ' ' + self._kwargs.get('output_opts', self.DEFAULT_OUTPUT_OPTIONS) + " " + tmpfile.name + " " + ' '.join(argv[1:]) self.logger.debug('CMD = ' + cmd) p = subprocess.Popen(miscellaneous.shell_split(cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout_output, stderr_output) = p.communicate(input=self._kwargs.get('stdin', self.DEFAULT_STDIN_BUFFER)) self.logger.debug(stdout_output) tmpfile.flush() os.fsync(tmpfile.fileno()) tmpfile.close() tmpfile = open(fname, 'r') data = tmpfile.read() self.logger.debug('DATA (%d bytes) = %s' % (len(data), data)) except Exception: os.remove(fname) return data
def __call__(self, arg): context = arg if not eval(self._kwargs.get("filter", self.DEFAULT_FILTER), {"context": context}): self.logger.debug("Filter %s is False" % self._kwargs.get("filter", self.DEFAULT_FILTER)) raise exceptions.HackershError(context, "%s: not enough data to start" % self.__class__.__name__.lower()) self.logger.debug("Filter %s is True" % self._kwargs.get("filter", self.DEFAULT_FILTER)) component_args_as_str = eval(self._kwargs.get("query", self.DEFAULT_QUERY), {"context": context}) self.logger.debug("Query = %s" % component_args_as_str) argv = [] try: argv = miscellaneous.shell_split(self._args[0] + " " + component_args_as_str) except IndexError: try: argv = miscellaneous.shell_split(component_args_as_str) except Exception: # "AS IT IS" argv = [component_args_as_str] self.logger.debug("Running with argv = %s and context = %s" % (argv, repr(context))) context = self.run(argv, context) if context: if isinstance(context, list): for _context in context: # Update STACK _context.update({"STACK": _context.get("STACK", []) + [self.__class__.__name__]}) else: # Don't iterate Generator, wrap it with another Generator if isinstance(context, types.GeneratorType): # TODO: Add support for Generaor pass else: context.update({"STACK": context.get("STACK", []) + [self.__class__.__name__]}) return context
def __call__(self, arg): context = arg if not eval(self._kwargs.get('filter', self.DEFAULT_FILTER), {'context': context}): self.logger.debug("Filter %s is False" % self._kwargs.get('filter', self.DEFAULT_FILTER)) raise exceptions.HackershError(context, "%s: not enough data to start" % self.__class__.__name__.lower()) self.logger.debug("Filter %s is True" % self._kwargs.get('filter', self.DEFAULT_FILTER)) component_args_as_str = eval(self._kwargs.get('query', self.DEFAULT_QUERY), {'context': context}) self.logger.debug("Query = %s" % component_args_as_str) argv = [] try: argv = miscellaneous.shell_split(self._args[0] + ' ' + component_args_as_str) except IndexError: try: argv = miscellaneous.shell_split(component_args_as_str) except Exception: # "AS IT IS" argv = [component_args_as_str] self.logger.debug('Running with argv = %s and context = %s' % (argv, repr(context))) context = self.run(argv, context) if context: if isinstance(context, list): for _context in context: # Update STACK _context.update({'STACK': _context.get('STACK', []) + [self.__class__.__name__]}) else: # Don't iterate Generator, wrap it with another Generator if isinstance(context, types.GeneratorType): # TODO: Add support for Generaor pass else: context.update({'STACK': context.get('STACK', []) + [self.__class__.__name__]}) return context