Exemplo n.º 1
0
 def cache_handler(self):
     """根据模块监听配置生成虚拟监听"""
     if self.param(CACHE_HANDLER_OPTION.get("name")):
         handler_config = self.param(HANDLER_OPTION.get('name'))
         if handler_config is None:
             return False
         handler_config[
             "HandlerName"] = f"用于: {self.NAME} IP: {self.host_ipaddress}"
         Handler.create_virtual_handler(handler_config)
         self.log_good("监听配置已缓存")
         return True
     else:
         return False
Exemplo n.º 2
0
 def destroy(self, request, pk=None, **kwargs):
     try:
         jobid = int(request.query_params.get('jobid', None))
         context = Handler.destroy(jobid)
     except Exception as E:
         logger.error(E)
         context = data_return(500, CODE_MSG.get(500), {})
     return Response(context)
Exemplo n.º 3
0
 def list():
     from Msgrpc.Handle.handler import Handler
     data = Xcache.list_lazyloader()
     handlers = Handler.list_handler_config()
     context = data_return(200, CODE_MSG.get(200), {
         "lazyloaders": data,
         "handlers": handlers
     })
     return context
Exemplo n.º 4
0
 def create(self, request, **kwargs):
     try:
         opts = request.data.get('opts', None)
         if isinstance(opts, str):
             opts = json.loads(opts)
         context = Handler.create(opts)
     except Exception as E:
         logger.error(E)
         context = data_return(500, CODE_MSG.get(500), {})
     return Response(context)
Exemplo n.º 5
0
    def list_transport(sessionid):
        tmp_enum_list = Handler.list_handler_config()
        result_list = RpcClient.call(Method.SessionMeterpreterTransportList,
                                     [sessionid])
        if result_list is None:
            transports = []
            return {
                'session_exp': 0,
                'transports': transports,
                "handlers": tmp_enum_list
            }
        else:
            result_list["handlers"] = tmp_enum_list
            transports = result_list.get("transports")
            current_transport_url = None
            if len(transports) > 0:
                transports[0]["active"] = True
                current_transport_url = transports[0].get("url")

            i = 0
            for transport in transports:
                transport["tid"] = i
                i += 1
                if transport.get("url") == current_transport_url:
                    transport["active"] = True

                if transport.get("cert_hash") is not None:
                    cert_hash = transport.get("cert_hash")
                    transport["cert_hash"] = base64.b64encode(
                        cert_hash.encode("utf-8"))

            def get_url(data):
                return data.get("url")

            transports.sort(key=get_url)
            return result_list
Exemplo n.º 6
0
 def list(self, request, **kwargs):
     data = Handler.list()
     return Response(data)
Exemplo n.º 7
0
    def _deal_dynamic_option(one_module_config=None):
        """处理handler及凭证等动态变化参数,返回处理后参数列表"""
        options = one_module_config.get('OPTIONS')
        for option in options:
            # handler处理
            if option.get('name') == HANDLER_OPTION.get("name"):
                option['enum_list'] = Handler.list_handler_config()
                if len(option['enum_list']) == 1:  # 只有一个监听
                    option['default'] = option['enum_list'][0].get("value")

            # 凭证处理
            elif option.get('name') == CREDENTIAL_OPTION.get("name"):
                credentials = Credential.list_credential()
                tmp_enum_list = []
                try:
                    if option.get('extra_data') is None or option.get(
                            'extra_data').get('password_type') is None:
                        pass
                    else:
                        type_list = option.get('extra_data').get(
                            'password_type')
                        for credential in credentials:
                            if credential.get('password_type') in type_list:
                                name = "用户名:{} | 密码:{} | 标签:{} | 主机:{}".format(
                                    credential.get('username'),
                                    credential.get('password'),
                                    credential.get('tag'),
                                    credential.get('host_ipaddress'))
                                import json
                                value = json.dumps(credential)
                                tmp_enum_list.append({
                                    'name': name,
                                    'value': value
                                })
                    option['enum_list'] = tmp_enum_list
                except Exception as E:
                    logger.warning(E)
            # 文件处理
            elif option.get('name') == FILE_OPTION.get("name"):
                if option.get('extra_data') is None or option.get(
                        'extra_data').get('file_extension') is None:
                    file_extension_list = None
                else:
                    file_extension_list = option.get('extra_data').get(
                        'file_extension')

                files = FileMsf.list_msf_files()
                tmp_enum_list = []
                for file in files:
                    import json
                    # {
                    #     "filename": "test",
                    #     "filesize": 0,
                    #     "mtime": 1552273961
                    # },
                    name = file.get("name")
                    size = FileSession.get_size_in_nice_string(
                        file.get('size'))
                    mtime = file.get("mtime")
                    style_time = time.strftime("%Y-%m-%d %H:%M:%S",
                                               time.localtime(mtime))
                    show = False  # 是否满足文件后缀要求
                    if isinstance(file_extension_list, list):
                        for ext in file_extension_list:
                            if name.lower().endswith(ext.lower()):
                                show = True
                    else:
                        show = True
                    if show:
                        name = "文件: {}   大小: {}   修改时间: {}".format(
                            name, size, style_time)
                        value = json.dumps(file)
                        tmp_enum_list.append({'name': name, 'value': value})
                option['enum_list'] = tmp_enum_list
        return one_module_config