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);
            }
        }
Beispiel #2
0
        public async Task <IActionResult> EditBridge(BridgeProfile profile)
        {
            try
            {
                await _context.EditBridgeProfile(profile, await _userManager.GetUserAsync(HttpContext.User));

                return(RedirectToAction("Index", "Listener"));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                return(RedirectToAction("Index", "Listener"));
            }
        }
        // GET: /listener/createbridge
        public async Task <IActionResult> CreateBridge()
        {
            try
            {
                ListenerType  bridgeType = (await _context.GetListenerTypes()).FirstOrDefault(LT => LT.Name == "Bridge");
                BridgeProfile profile    = (await _context.GetBridgeProfiles()).FirstOrDefault();
                ViewBag.Profiles = await _context.GetBridgeProfiles();

                ViewBag.ListenerType = bridgeType;
                return(View(new BridgeListener
                {
                    ListenerTypeId = bridgeType.Id,
                    ProfileId = profile.Id,
                    Profile = profile
                }));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                return(RedirectToAction(nameof(Index)));
            }
        }
        public async Task <IActionResult> CreateBridge(BridgeListener listener)
        {
            try
            {
                listener = await _context.CreateBridgeListener(_userManager, _configuration, listener, _ListenerCancellationTokens, _eventhub);

                return(RedirectToAction(nameof(Index)));
            }
            catch (Exception e) when(e is ControllerNotFoundException || e is ControllerBadRequestException || e is ControllerUnauthorizedException)
            {
                ModelState.AddModelError(string.Empty, e.Message);
                ViewBag.Profiles     = (await _context.GetBridgeProfiles()).FirstOrDefault().Id;
                ViewBag.ListenerType = (await _context.GetListenerTypes()).FirstOrDefault(LT => LT.Name == "Bridge");
                BridgeProfile profile = (await _context.GetBridgeProfiles()).FirstOrDefault();

                return(View(new BridgeListener
                {
                    ListenerTypeId = ViewBag.ListenerType.Id,
                    ProfileId = profile.Id,
                    Profile = profile
                }));
            }
        }
Beispiel #5
0
 public Task <BridgeProfile> CreateBridgeProfile(BridgeProfile profile, CovenantUser currentUser)
 {
     return(_connection.InvokeAsync <BridgeProfile>("CreateBridgeProfile", profile, currentUser));
 }