def initialize(self): self.app_svc = AppService(None) self.data_svc = DataService() self.rest_svc = RestService() self.planning_svc = PlanningService() self.learning_svc = LearningService() self.services = [self.app_svc.get_services()]
async def initialize(): with open(Path(__file__).parents[2] / 'conf' / 'default.yml', 'r') as fle: BaseWorld.apply_config('main', yaml.safe_load(fle)) with open(Path(__file__).parents[2] / 'conf' / 'payloads.yml', 'r') as fle: BaseWorld.apply_config('payloads', yaml.safe_load(fle)) app_svc = AppService(web.Application()) _ = DataService() _ = RestService() _ = PlanningService() _ = LearningService() auth_svc = AuthService() _ = ContactService() _ = FileSvc() services = app_svc.get_services() os.chdir(str(Path(__file__).parents[2])) await app_svc.register_contacts() await app_svc.load_plugins(['sandcat', 'ssl']) _ = await RestApi(services).enable() await auth_svc.apply(app_svc.application, auth_svc.get_config('users')) await auth_svc.set_login_handlers(services) return app_svc.application
async def app_svc(): # async def _init_app_svc(): # return AppService(None) # def _app_svc(event_loop): # return event_loop.run_until_complete(_init_app_svc()) # return _app_svc return AppService(None)
class TestBase(unittest.TestCase): def initialize(self): self.app_svc = AppService(None) self.data_svc = DataService() self.rest_svc = RestService() self.planning_svc = PlanningService() self.services = [self.app_svc.get_services()] @staticmethod def run_async(c): return asyncio.get_event_loop().run_until_complete(c)
async def initialize(): with open(Path(__file__).parents[1] / 'conf' / 'default.yml', 'r') as fle: BaseWorld.apply_config('main', yaml.safe_load(fle)) with open(Path(__file__).parents[1] / 'conf' / 'payloads.yml', 'r') as fle: BaseWorld.apply_config('payloads', yaml.safe_load(fle)) app_svc = AppService(web.Application(client_max_size=5120**2)) _ = DataService() _ = RestService() _ = PlanningService() _ = LearningService() auth_svc = AuthService() _ = FileSvc() _ = EventService() services = app_svc.get_services() os.chdir(str(Path(__file__).parents[1])) _ = await RestApi(services).enable() await app_svc.register_contacts() await auth_svc.apply(app_svc.application, auth_svc.get_config('users')) await auth_svc.set_login_handlers(services) app_svc.register_subapp('/api/v2', make_app(svcs=services)) aiohttp_apispec.setup_aiohttp_apispec(app=app_svc.application, title='CALDERA', version=version.get_version(), swagger_path='/api/docs', url='/api/docs/swagger.json', static_path='/static/swagger') app_svc.application.middlewares.append( apispec_request_validation_middleware) app_svc.application.middlewares.append(validation_middleware) return app_svc
parser = argparse.ArgumentParser('Welcome to the system') parser.add_argument('-E', '--environment', required=False, default='local', help='Select an env. file to use') parser.add_argument('--fresh', action='store_true', required=False, default=False, help='remove object_store on start') args = parser.parse_args() config = args.environment if pathlib.Path( 'conf/%s.yml' % args.environment).exists() else 'default' with open('conf/%s.yml' % config) as c: BaseWorld.apply_config(yaml.load(c, Loader=yaml.FullLoader)) data_svc = DataService() contact_svc = ContactService( BaseWorld.strip_yml('conf/agents.yml')[0]['agent_config']) planning_svc = PlanningService() rest_svc = RestService() auth_svc = AuthService() file_svc = FileSvc( BaseWorld.strip_yml('conf/payloads.yml')[0]['payload_config']) learning_svc = LearningService() app_svc = AppService(application=web.Application()) if args.fresh: asyncio.get_event_loop().run_until_complete(data_svc.destroy()) run_tasks(services=app_svc.get_services())
async def _init_app_svc(): return AppService(None)
'--environment', required=False, default='local', help='Select an env. file to use') args = parser.parse_args() config = args.environment if pathlib.Path( 'conf/%s.yml' % args.environment).exists() else 'default' with open('conf/%s.yml' % config) as c: cfg = yaml.load(c, Loader=yaml.FullLoader) set_logging_state() sys.path.append('') plugin_modules = build_plugins(cfg['plugins']) data_svc = DataService() planning_svc = PlanningService() auth_svc = AuthService(cfg['api_key']) file_svc = FileSvc([p.name.lower() for p in plugin_modules], cfg['exfil_dir']) agent_svc = AgentService() application = AppService(config=cfg, plugins=plugin_modules) logging.debug( 'Agents will be considered untrusted after %s seconds of silence' % cfg['untrusted_timer']) logging.debug('Uploaded files will be put in %s' % cfg['exfil_dir']) logging.debug('Serving at http://%s:%s' % (cfg['host'], cfg['port'])) main(services=data_svc.get_services(), host=cfg['host'], port=cfg['port'], users=cfg['users'])
logging.info('Using main config from %s' % main_config_path) BaseWorld.apply_config('agents', BaseWorld.strip_yml('conf/agents.yml')[0]) BaseWorld.apply_config('payloads', BaseWorld.strip_yml('conf/payloads.yml')[0]) data_svc = DataService() knowledge_svc = KnowledgeService() contact_svc = ContactService() planning_svc = PlanningService(global_variable_owners=[ Executor, Agent, Link, AppConfigGlobalVariableIdentifier ]) rest_svc = RestService() auth_svc = AuthService() file_svc = FileSvc() learning_svc = LearningService() event_svc = EventService() app_svc = AppService(application=web.Application(client_max_size=5120**2)) app_svc.register_subapp('/api/v2', app.api.v2.make_app(app_svc.get_services())) init_swagger_documentation(app_svc.application) if args.fresh: logging.info( "Fresh startup: resetting server data. See %s directory for data backups.", DATA_BACKUP_DIR) asyncio.get_event_loop().run_until_complete(data_svc.destroy()) asyncio.get_event_loop().run_until_complete(knowledge_svc.destroy()) run_tasks(services=app_svc.get_services())
def app_svc(): return AppService(None)
setup_logger(getattr(logging, args.logLevel)) if args.insecure: logging.warning( '--insecure flag set. Caldera will use the default.yml config file.' ) args.environment = 'default' elif args.environment == 'local': ensure_local_config() main_config_path = 'conf/%s.yml' % args.environment BaseWorld.apply_config('main', BaseWorld.strip_yml(main_config_path)[0]) logging.info('Using main config from %s' % main_config_path) BaseWorld.apply_config('agents', BaseWorld.strip_yml('conf/agents.yml')[0]) BaseWorld.apply_config('payloads', BaseWorld.strip_yml('conf/payloads.yml')[0]) data_svc = DataService() contact_svc = ContactService() planning_svc = PlanningService() rest_svc = RestService() auth_svc = AuthService() file_svc = FileSvc() learning_svc = LearningService() event_svc = EventService() app_svc = AppService(application=web.Application(client_max_size=5120**2)) if args.fresh: asyncio.get_event_loop().run_until_complete(data_svc.destroy()) run_tasks(services=app_svc.get_services())
parser.add_argument('--fresh', action='store_true', required=False, default=False, help='remove object_store on start') args = parser.parse_args() config = args.environment if pathlib.Path( 'conf/%s.yml' % args.environment).exists() else 'default' with open('conf/%s.yml' % config) as c: cfg = yaml.load(c, Loader=yaml.FullLoader) setup_logger(cfg) cfg['agent_config'] = BaseWorld.strip_yml( 'conf/agents.yml')[0]['agent_config'] cfg['secrets']['core'] = BaseWorld.strip_yml('conf/secrets.yml') logging.debug('Serving at http://%s:%s' % (cfg['host'], cfg['port'])) data_svc = DataService() contact_svc = ContactService(cfg['agent_config']) planning_svc = PlanningService() rest_svc = RestService() auth_svc = AuthService(cfg['api_key']) file_svc = FileSvc(cfg['exfil_dir'], file_encryption=cfg['file_encryption'], api_key=cfg['api_key'], crypt_salt=cfg['crypt_salt']) app_svc = AppService(application=web.Application(), config=cfg) if args.fresh: asyncio.get_event_loop().run_until_complete(data_svc.destroy()) main(config=cfg, services=app_svc.get_services())
parser.add_argument('--fresh', action='store_true', required=False, default=False, help='remove object_store on start') args = parser.parse_args() config = args.environment if pathlib.Path( 'conf/%s.yml' % args.environment).exists() else 'default' with open('conf/%s.yml' % config) as c: cfg = yaml.load(c, Loader=yaml.FullLoader) setup_logger(cfg) cfg['agent_config'] = BaseWorld.strip_yml( 'conf/agents.yml')[0]['agent_config'] cfg['secrets']['core'] = BaseWorld.strip_yml('conf/secrets.yml') logging.debug('Serving at http://%s:%s' % (cfg['host'], cfg['port'])) data_svc = DataService() contact_svc = ContactService(cfg['agent_config']) planning_svc = PlanningService() rest_svc = RestService() auth_svc = AuthService(cfg['api_key']) file_svc = FileSvc(cfg['exfil_dir'], file_encryption=cfg['file_encryption'], api_key=cfg['api_key'], crypt_salt=cfg['crypt_salt']) app_svc = AppService(application=web.Application(), config=cfg) if args.fresh: asyncio.get_event_loop().run_until_complete(data_svc.destroy()) run_tasks(config=cfg, services=app_svc.get_services())
parser.add_argument('--fresh', action='store_true', required=False, default=False, help='remove object_store on start') args = parser.parse_args() config = args.environment if pathlib.Path( 'conf/%s.yml' % args.environment).exists() else 'default' with open('conf/%s.yml' % config) as c: cfg = yaml.load(c, Loader=yaml.FullLoader) set_logging_state() sys.path.append('') app = web.Application() data_svc = DataService() planning_svc = PlanningService() auth_svc = AuthService(cfg['api_key']) file_svc = FileSvc(cfg['exfil_dir']) app_svc = AppService(application=app, config=cfg) if args.fresh: asyncio.get_event_loop().run_until_complete(data_svc.reset()) logging.debug( 'Agents will be considered untrusted after %s seconds of silence' % cfg['untrusted_timer']) logging.debug('Uploaded files will be put in %s' % cfg['exfil_dir']) logging.debug('Serving at http://%s:%s' % (cfg['host'], cfg['port'])) main(app=app, config=cfg, services=app_svc.get_services())