Пример #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);
        }
Пример #2
0
 public InternalListener(APIModels.Profile profile, string ListenerGuid, string CovenantToken)
 {
     _ = Configure(profile, ListenerGuid, CovenantToken);
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the HttpListener class.
 /// </summary>
 /// <param name="status">Possible values include: 'Uninitialized',
 /// 'Active', 'Stopped'</param>
 public HttpListener(bool useSSL, string url, string name, string guid, string description, string bindAddress, int bindPort, string connectAddress, int profileId, int listenerTypeId, ListenerStatus status, string sslCertificate = default(string), string sslCertificatePassword = default(string), string sslCertHash = default(string), int?id = default(int?), Profile profile = default(Profile), ListenerType listenerType = default(ListenerType), string covenantToken = default(string), System.DateTime?startTime = default(System.DateTime?))
 {
     UseSSL                 = useSSL;
     SslCertificate         = sslCertificate;
     SslCertificatePassword = sslCertificatePassword;
     SslCertHash            = sslCertHash;
     Url            = url;
     Id             = id;
     Name           = name;
     Guid           = guid;
     Description    = description;
     BindAddress    = bindAddress;
     BindPort       = bindPort;
     ConnectAddress = connectAddress;
     ProfileId      = profileId;
     Profile        = profile;
     ListenerTypeId = listenerTypeId;
     ListenerType   = listenerType;
     Status         = status;
     CovenantToken  = covenantToken;
     StartTime      = startTime;
     CustomInit();
 }