public async static Task InitializeListeners(ICovenantService service, CovenantContext context, ConcurrentDictionary <int, CancellationTokenSource> ListenerCancellationTokens) { if (!context.ListenerTypes.Any()) { await service.CreateEntities <ListenerType>( new ListenerType { Name = "HTTP", Description = "Listens on HTTP protocol." }, new ListenerType { Name = "Bridge", Description = "Creates a C2 Bridge for custom listeners." } ); } if (!context.Profiles.Any()) { string[] files = Directory.GetFiles(Common.CovenantProfileDirectory, "*.yaml", SearchOption.AllDirectories); HttpProfile[] httpProfiles = files.Where(F => F.Contains("HTTP", StringComparison.CurrentCultureIgnoreCase)) .Select(F => HttpProfile.Create(F)) .ToArray(); BridgeProfile[] bridgeProfiles = files.Where(F => F.Contains("Bridge", StringComparison.CurrentCultureIgnoreCase)) .Select(F => BridgeProfile.Create(F)) .ToArray(); await service.CreateProfiles(httpProfiles); await service.CreateProfiles(bridgeProfiles); } var listeners = (await service.GetListeners()).Where(L => L.Status == ListenerStatus.Active); foreach (Listener l in listeners) { l.Profile = await service.GetProfile(l.ProfileId); await service.StartListener(l.Id); } }