Exemple #1
0
        public void UpdateListenerConfig(string listenername, ListenerConfig listenerconfig)
        {
            try
            {
                listeners.Remove(listenerconfig.GetName());
                Listener res = dbcontext.Listeners.FirstOrDefault <Listener>(s => s.name == listenerconfig.GetName());
                res.name    = listenerconfig.GetName();
                res.lhost   = listenerconfig.GetHost();
                res.lport   = listenerconfig.GetPort();
                res.profile = listenerconfig.GetProfileid();
                if (listenerconfig.GetSsl())
                {
                    res.ListenerType = ListenerType.Https;
                }
                else
                {
                    res.ListenerType = ListenerType.Http;
                }

                dbcontext.Listeners.Update(res);
                dbcontext.SaveChanges();
            }
            catch (Exception)
            {
                Console.WriteLine("[x] Error removing listener");
            }
        }
Exemple #2
0
        public void RegisterListenerConfig(string listenername, ListenerConfig listenerconfig)
        {
            try
            {
                if (!listeners.ContainsKey(listenername))
                {
                    listeners.Add(listenername, listenerconfig);
                    Listener listener = dbcontext.Listeners.FirstOrDefault <Listener>(s => s.name == listenername);
                    if (listener == null)
                    {
                        listener = new Listener
                        {
                            name    = listenerconfig.GetName(),
                            lhost   = listenerconfig.GetHost(),
                            lport   = listenerconfig.GetPort(),
                            profile = listenerconfig.GetProfileid(),
                        };

                        if (listenerconfig.GetSsl())
                        {
                            listener.ListenerType = ListenerType.Https;
                        }
                        else
                        {
                            listener.ListenerType = ListenerType.Http;
                        }
                        dbcontext.Listeners.Add(listener);
                        dbcontext.SaveChanges();
                    }
                }
                else
                {
                    Console.WriteLine("[x] Listener already exist");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("[x] Error adding listener {0}", e.Message);
            }
        }
Exemple #3
0
        public void Execute()
        {
            //Check ssl setup
            X509Certificate2 x509cert = null;

            if ((!File.Exists(pfx) || !File.Exists(cert)) && ssl)
            {
                Console.WriteLine("Building cert...");
                if (!Directory.Exists("certs"))
                {
                    Directory.CreateDirectory("certs");
                }

                BuildSelfSignedServerCertificate("RedPeanut", Lconfig.GetHost(), pfx, cert);
            }
            try
            {
                CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

                if (ssl)
                {
                    x509cert = new X509Certificate2(pfx);

                    CreateWebHostBuilder(new string[] { })
                    .UseKestrel(options =>
                    {
                        options.Listen(new IPEndPoint(IPAddress.Parse(Lconfig.GetHost()), Lconfig.GetPort()), listenOptions =>
                        {
                            listenOptions.UseHttps(httpsOptions =>
                            {
                                httpsOptions.ServerCertificate     = x509cert;
                                httpsOptions.ClientCertificateMode = ClientCertificateMode.AllowCertificate;
                                httpsOptions.SslProtocols          = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12;
                                Console.WriteLine("\n[*] Using cert with hash: {0}", httpsOptions.ServerCertificate.GetCertHashString());
                            });
                        });

                        options.AddServerHeader = false;
                    })
                    .UseContentRoot(Path.Combine(Directory.GetCurrentDirectory(), WORKSPACE_FOLDER, PAYLOADS_FOLDER))
                    .ConfigureLogging((hostingContext, logging) =>
                    {
                        logging.ClearProviders();
                        logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                        logging.AddConsole();
                        logging.AddDebug();
                        logging.AddFilter("System", LogLevel.Error)
                        .AddFilter("Microsoft", LogLevel.Error);
                    })
                    .UseUrls("https://" + Lconfig.GetHost() + ":" + Lconfig.GetPort())
                    .UseSetting("FrameworkHost", Lconfig.GetHost())
                    .UseSetting("FrameworkPort", Lconfig.GetPort().ToString())
                    .UseSetting("FrameworkSSL", ssl.ToString())
                    .UseSetting("FrameworkProfileid", Lconfig.GetProfileid().ToString())
                    .Build()
                    .RunAsync(cancellationTokenSource.Token);
                }
                else
                {
                    CreateWebHostBuilder(new string[] { })
                    .UseKestrel(options =>
                    {
                        options.Listen(new IPEndPoint(IPAddress.Parse(Lconfig.GetHost()), Lconfig.GetPort()));
                        options.AddServerHeader = false;
                    })
                    .UseContentRoot(Path.Combine(Directory.GetCurrentDirectory(), WORKSPACE_FOLDER, PAYLOADS_FOLDER))
                    .ConfigureLogging((hostingContext, logging) =>
                    {
                        logging.ClearProviders();
                        logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                        logging.AddConsole();
                        logging.AddDebug();
                        logging.AddFilter("System", LogLevel.Error)
                        .AddFilter("Microsoft", LogLevel.Error);
                    })
                    .UseUrls("http://" + Lconfig.GetHost() + ":" + Lconfig.GetPort())
                    .UseSetting("FrameworkHost", Lconfig.GetHost())
                    .UseSetting("FrameworkPort", Lconfig.GetPort().ToString())
                    .UseSetting("FrameworkSSL", ssl.ToString())
                    .UseSetting("FrameworkProfileid", Lconfig.GetProfileid().ToString())
                    .Build()
                    .RunAsync(cancellationTokenSource.Token);
                }
                Lconfig.CancellationTokenSource = cancellationTokenSource;
            }
            catch (CryptographicException)
            {
                Console.Error.WriteLine("Error importing certificate.");
            }
        }
Exemple #4
0
        public void ListListeners()
        {
            if (GetListenersConfig() != null)
            {
                Console.WriteLine("[*]  {0}", new string('-', 66));
                Console.WriteLine("[*] | {0,-20} | {1,-15} | {2,-5} | {3,-7} | {4,-5} |", "Name", "IP", "Port", "Profile", "SSL");
                Console.WriteLine("[*]  {0}", new string('-', 66));

                foreach (KeyValuePair <string, ListenerConfig> item in GetListenersConfig())
                {
                    try
                    {
                        ListenerConfig listenerConfig = item.Value;
                        Console.WriteLine("[*] | {0,-20} | {1,-15} | {2,-5} | {3,-7} | {4,-5} |", listenerConfig.GetName(), listenerConfig.GetHost(), listenerConfig.GetPort(), listenerConfig.GetProfileid(), listenerConfig.GetSsl());
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("[x] Listener need to be removed {0}", e.Message);
                    }
                }
                Console.WriteLine("[*]  {0}", new string('-', 66));
            }
        }
Exemple #5
0
 public void ListListeners()
 {
     if (GetListenersConfig() != null)
     {
         foreach (KeyValuePair <string, ListenerConfig> item in GetListenersConfig())
         {
             try
             {
                 ListenerConfig listenerConfig = item.Value;
                 Console.WriteLine("[*] {0} | Host: {1} | port: {2} | profile: {3}", listenerConfig.GetName(), listenerConfig.GetHost(), listenerConfig.GetPort(), listenerConfig.GetProfileid());
             }
             catch (Exception e)
             {
                 Console.WriteLine("[x] Listener need to be removed {0}", e.Message);
             }
         }
     }
 }