Example #1
0
        public async Task Configure(APIModels.Profile profile, string ListenerGuid, string CovenantToken)
        {
            _transform = new ProfileTransformAssembly
            {
                ProfileTransformBytes = Compiler.Compile(new Compiler.CompilationRequest
                {
                    Language            = Grunts.ImplantLanguage.CSharp,
                    Source              = profile.MessageTransform,
                    TargetDotNetVersion = Common.DotNetVersion.NetCore21,
                    References          = Common.DefaultReferencesCore21
                })
            };

            X509Certificate2  covenantCert  = new X509Certificate2(Common.CovenantPublicCertFile);
            HttpClientHandler clientHandler = new HttpClientHandler
            {
                ServerCertificateCustomValidationCallback = (sender, cert, chain, errors) =>
                {
                    return(cert.GetCertHashString() == covenantCert.GetCertHashString());
                }
            };

            _client = new CovenantAPI(
                new Uri("https://localhost:7443"),
                new TokenCredentials(CovenantToken),
                clientHandler
                );

            _connection = new HubConnectionBuilder()
                          .WithUrl("https://localhost:7443/gruntHub", options =>
            {
                options.AccessTokenProvider       = () => { return(Task.FromResult(CovenantToken)); };
                options.HttpMessageHandlerFactory = inner =>
                {
                    var HttpClientHandler = (HttpClientHandler)inner;
                    HttpClientHandler.ServerCertificateCustomValidationCallback = clientHandler.ServerCertificateCustomValidationCallback;
                    return(HttpClientHandler);
                };
            })
                          .Build();
            _connection.Closed += async(error) =>
            {
                await Task.Delay(new Random().Next(0, 5) * 1000);

                await _connection.StartAsync();
            };
            _connection.On <string>("NotifyListener", (guid) => { InternalRead(guid).Wait(); });
            try
            {
                await Task.Delay(5000);

                await _connection.StartAsync();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine("InnerListener SignalRConnection Exception: " + e.Message + Environment.NewLine + e.StackTrace);
            }
            await _connection.InvokeAsync("JoinGroup", ListenerGuid);
        }
 public HttpListenerController(HttpListenerContext context, ICovenantAPI api, IHttpContextAccessor httpContextAccessor)
 {
     this._context             = context;
     this.CovenantClient       = api;
     this._httpContextAccessor = httpContextAccessor;
 }
 public HttpListenerController(ICovenantAPI api, Covenant.Models.Listeners.HttpListenerContext context)
 {
     _client  = api;
     _context = context;
 }