示例#1
0
 def threadProc():
     log.i("thread %s started!", name)
     try:
         target(*args)
         log.i("thread %s ended!", name)
     except Exception as e:
         log.e("thread %s crash!err=%s", name, e)
示例#2
0
文件: session.py 项目: p1ra/deception
    def process_server_cmd(self,cmd):
        '''
        Process a command sent by the server.
        It does not require checking for permissions.
        '''
        if cmd.name not in self.server_commands:
            return False

        log.i("Command from server: %s" % cmd.name)

        result = getattr(self, cmd.name)(cmd)

        if result == False:
            log.e("Unable to send command response to server: '%s'" % cmd.name)

        return True
示例#3
0
文件: session.py 项目: p1ra/deception
    def process_cmd(self,cmd):
        ''' Execute plugins commands '''
        if cmd.name not in self.cmd_handlers.keys():
            return False

        log.i("Command from user: %s" % cmd.name)

        if not self.check_permission(cmd):
            log.e("User %s does not have enough permission for command %s" % (cmd.user, cmd.name))
            return False

        #Try block to avoid breaking on bugged plugins
        try:
            result = self.cmd_handlers[cmd.name][0](self,cmd)

            if result == False:
                log.e("Unable to send command response to server: '%s'" % cmd.name)
        except:
            log.e("Command '%s' crashed." % cmd.name)
            log.e(traceback.format_exc())

        return True
示例#4
0
文件: session.py 项目: p1ra/deception
    def load_plugin(self, name, sync=False):
        ''' Load plugin on runtime '''
        log.i("Loading plugin: '%s'" % name)

        try:
            module = __import__('plugins.' + name, fromlist=["plugins"])

            if sync: reload(module)

            #Load event hooks
            if hasattr(module, 'ON_CONNECT'):
                for hook in module.ON_CONNECT:
                    self.on_connect_hooks.append(hook)

            if hasattr(module, 'ON_DISCONNECT'):
                for hook in module.ON_DISCONNECT:
                    self.on_disconnect_hooks.append(hook)

            if hasattr(module, 'ON_MSG_RECV'):
                for hook in module.ON_MSG_RECV:
                    self.on_msg_recv_hooks.append(hook)

            if hasattr(module, 'ON_UNKNOWN_CMD'):
                for hook in module.ON_UNKNOWN_CMD:
                    self.on_unknown_cmd_hooks.append(hook)

            if hasattr(module, 'ON_PERMISSION_DENIED'):
                for hook in module.ON_PERMISSION_DENIED:
                    self.on_permission_denied_hooks.append(hook)

            #Load plugin commands
            if hasattr(module, 'COMMAND_HANDLERS'):
                for handler in module.COMMAND_HANDLERS.keys():
                    self.cmd_handlers[handler] = module.COMMAND_HANDLERS[handler]

        except:
            log.e("Unable to load plugin '%s'" % name)
            log.e(traceback.format_exc())
示例#5
0
文件: session.py 项目: p1ra/deception
    def run(self):
        self.load_plugin_list()
        log.i("Plugins Loaded.")

        self.connect()
        log.i("Bot Connected.")

        self.on_connect()
        log.i("Deception locked and loaded!")

        while self.connected:
            msg = self.recv()

            if len(msg) == 0:
                self.connected = False
                continue

            msglist = msg.split('\n')

            for line in msglist:
                if len(line) == 0: continue

                log.d(line)

                cmd = self.parse_cmd(line.strip())
                if cmd == None:
                    self.on_msg_recv(line)
                    continue

                log.d(cmd);

                if self.process_server_cmd(cmd):
                    continue

                if cmd.name not in self.cmd_handlers.keys():
                    log.e("Command '%s' not recognized." % cmd.name)
                    self.on_unknown_cmd(cmd)
                    continue

                if not self.check_permission(cmd):
                    self.on_permission_denied(cmd)

                self.process_cmd(cmd)

        self.on_disconnect()