Exemplo n.º 1
0
    def __init__(self, check_rc_file=True):
        OverrideCmd.__init__(self)
        self.__hidden_commands__.append('cd')
        self.__hidden_commands__.append('exploit')
        self.logger = logging.getLogger(self.__package__ + '.interpreter')
        self.frmwk = Framework()
        self.print_error = self.frmwk.print_error
        self.print_good = self.frmwk.print_good
        self.print_line = self.frmwk.print_line
        self.print_status = self.frmwk.print_status

        if check_rc_file:
            if check_rc_file == True:
                check_rc_file = self.frmwk.directories.user_data + 'console.rc'
                if os.path.isfile(check_rc_file) and os.access(
                        check_rc_file, os.R_OK):
                    self.print_status('Running commands from resource file: ' +
                                      check_rc_file)
                    self.run_rc_file(check_rc_file)
            elif isinstance(check_rc_file, str):
                if os.path.isfile(check_rc_file) and os.access(
                        check_rc_file, os.R_OK):
                    self.print_status('Running commands from resource file: ' +
                                      check_rc_file)
                    self.run_rc_file(check_rc_file)
                else:
                    self.logger.error('could not access resource file: ' +
                                      check_rc_file)
                    self.print_error('Could not access resource file: ' +
                                     check_rc_file)
Exemplo n.º 2
0
    def __init__(self,
                 check_rc_file=True,
                 stdin=None,
                 stdout=None,
                 log_handler=None):
        OverrideCmd.__init__(self, stdin=stdin, stdout=stdout)
        if stdin != None:
            self.use_rawinput = False
            # No 'use_rawinput' will cause problems with the ipy command so disable it for now
            self.__disabled_commands__.append('ipy')

        if not its.on_linux:
            self.__hidden_commands__.append('prep_driver')
        self.__hidden_commands__.append('cd')
        self.__hidden_commands__.append('exploit')
        self.log_handler = log_handler
        if self.log_handler == None:
            self.__disabled_commands__.append('logging')
        self.logger = logging.getLogger(self.__package__ + '.interpreter')
        self.frmwk = Framework(stdout=stdout)
        self.print_error = self.frmwk.print_error
        self.print_good = self.frmwk.print_good
        self.print_line = self.frmwk.print_line
        self.print_status = self.frmwk.print_status

        if check_rc_file:
            if check_rc_file == True:
                check_rc_file = self.frmwk.directories.user_data + 'console.rc'
                if os.path.isfile(check_rc_file) and os.access(
                        check_rc_file, os.R_OK):
                    self.print_status('Running commands from resource file: ' +
                                      check_rc_file)
                    self.run_rc_file(check_rc_file)
            elif isinstance(check_rc_file, str):
                if os.path.isfile(check_rc_file) and os.access(
                        check_rc_file, os.R_OK):
                    self.print_status('Running commands from resource file: ' +
                                      check_rc_file)
                    self.run_rc_file(check_rc_file)
                else:
                    self.logger.error('could not access resource file: ' +
                                      check_rc_file)
                    self.print_error('Could not access resource file: ' +
                                     check_rc_file)
        try:
            import readline
            readline.read_history_file(self.frmwk.directories.user_data +
                                       'history.txt')
            readline.set_completer_delims(
                readline.get_completer_delims().replace('/', ''))
        except (ImportError, IOError):
            pass