Esempio n. 1
0
        private void PrintNetShares()
        {
            try
            {
                Beaprint.MainPrint("Network Shares");
                Dictionary <string, string> colorsN = new Dictionary <string, string>()
                {
                    { commonShares, Beaprint.ansi_color_good },
                    { "Permissions.*", Beaprint.ansi_color_bad }
                };

                List <Dictionary <string, string> > shares = NetworkInfoHelper.GetNetworkShares("127.0.0.1");

                foreach (Dictionary <string, string> share in shares)
                {
                    string line = string.Format("    {0} (" + Beaprint.ansi_color_gray + "Path: {1}" + Beaprint.NOCOLOR + ")", share["Name"], share["Path"]);
                    if (share["Permissions"].Length > 0)
                    {
                        line += " -- Permissions: " + share["Permissions"];
                    }
                    Beaprint.AnsiPrint(line, colorsN);
                }
            }
            catch (Exception ex)
            {
                Beaprint.PrintException(ex.Message);
            }
        }
Esempio n. 2
0
        private void PrintNetworkIfaces()
        {
            try
            {
                Beaprint.MainPrint("Network Ifaces and known hosts");
                Beaprint.LinkPrint("", "The masks are only for the IPv4 addresses");
                foreach (Dictionary <string, string> card in NetworkInfoHelper.GetNetCardInfo())
                {
                    string formString = "    {0}[{1}]: {2} / {3}";
                    if (card["Gateways"].Length > 1)
                    {
                        formString += "\n        " + Beaprint.ansi_color_gray + "Gateways: " + Beaprint.NOCOLOR + "{4}";
                    }
                    if (card["DNSs"].Length > 1)
                    {
                        formString += "\n        " + Beaprint.ansi_color_gray + "DNSs: " + Beaprint.NOCOLOR + "{5}";
                    }
                    if (card["arp"].Length > 1)
                    {
                        formString += "\n        " + Beaprint.ansi_color_gray + "Known hosts:" + Beaprint.NOCOLOR + "\n{6}";
                    }

                    Console.WriteLine(string.Format(formString, card["Name"], card["PysicalAddr"], card["IPs"], card["Netmasks"].Replace(", 0.0.0.0", ""), card["Gateways"], card["DNSs"], card["arp"]));
                }
            }
            catch (Exception ex)
            {
                Beaprint.PrintException(ex.Message);
            }
        }
Esempio n. 3
0
        private void PrintListeningPortsUdpIPv6(Dictionary <int, Process> processesByPid)
        {
            try
            {
                Beaprint.ColorPrint("  Enumerating IPv6 connections\n", Beaprint.LBLUE);

                string formatString = @"{0,-12} {1,-43} {2,-13} {3,-30} {4,-17} {5}";

                Beaprint.NoColorPrint(
                    string.Format($"{formatString}\n", "  Protocol", "Local Address", "Local Port", "Remote Address:Remote Port", "Process ID", "Process Name"));

                foreach (var udpConnectionInfo in NetworkInfoHelper.GetUdpConnections(IPVersion.IPv6, processesByPid))
                {
                    Beaprint.AnsiPrint(
                        string.Format(formatString,
                                      "  UDP",
                                      $"[{udpConnectionInfo.LocalAddress}]",
                                      udpConnectionInfo.LocalPort,
                                      "*:*",    // UDP does not have remote address/port
                                      udpConnectionInfo.ProcessId,
                                      udpConnectionInfo.ProcessName
                                      ),
                        colorsN);
                }
            }
            catch (Exception ex)
            {
                Beaprint.PrintException(ex.Message);
            }
        }
Esempio n. 4
0
        private void PrintListeningPortsTcpIPv6(Dictionary <int, Process> processesByPid)
        {
            try
            {
                Beaprint.ColorPrint("  Enumerating IPv6 connections\n", Beaprint.LBLUE);

                string formatString = @"{0,-12} {1,-43} {2,-13} {3,-43} {4,-15} {5,-17} {6,-15} {7}";

                Beaprint.NoColorPrint(
                    string.Format($"{formatString}\n", "  Protocol", "Local Address", "Local Port", "Remote Address", "Remote Port", "State", "Process ID", "Process Name"));

                foreach (var tcpConnectionInfo in NetworkInfoHelper.GetTcpConnections(IPVersion.IPv6, processesByPid))
                {
                    Beaprint.AnsiPrint(
                        string.Format(formatString,
                                      "  TCP",
                                      $"[{tcpConnectionInfo.LocalAddress}]",
                                      tcpConnectionInfo.LocalPort,
                                      $"[{tcpConnectionInfo.RemoteAddress}]",
                                      tcpConnectionInfo.RemotePort,
                                      tcpConnectionInfo.State.GetDescription(),
                                      tcpConnectionInfo.ProcessId,
                                      tcpConnectionInfo.ProcessName
                                      ),
                        colorsN);
                }
            }
            catch (Exception ex)
            {
                Beaprint.PrintException(ex.Message);
            }
        }
Esempio n. 5
0
        private IAsyncSession <DuplexMessage> GetRegisteredAndAuthedSession(ServerBootstrap bootstrap, bool clearSessionCache = false)
        {
            using (var scope = ObjectHost.Host.BeginLifetimeScope())
            {
                var factory = scope.Resolve <IAsyncSessionFactory <DuplexMessage> >();
                var session = factory.OpenSession(string.Format("{0};{1};",
                                                                bootstrap.EndPoint.ToString(), "keepalive=false"));
                var command = session.CreateCommand(CommandCode.Register);
                command.SecurityEnabled = true;
                command.Parameter       = new RegisterInfo {
                    ClientMacAddr = NetworkInfoHelper.GetMacAddr(), ClientPubKey = new TestRsaKeyProvider().GetPublicKey(null)
                };
                var result = command.Run(5000);
                command           = session.CreateCommand(CommandCode.Authentication);
                command.Parameter = new AuthInfo
                {
                    Identifier = scope.Resolve <IIdentifierProvider>().GetIdentifier(),
                    Mac        = NetworkInfoHelper.GetMacAddr()
                };
                command.SecurityEnabled = true;
                result = command.Run(5000);

                if (clearSessionCache)
                {
                    var map = (factory as AsyncSessionFactoryImpl).AsTransparentObject().sessionMap as ConcurrentDictionary <string, IAsyncSession <DuplexMessage> >;
                    map.Clear();
                }

                return(session);
            }
        }
Esempio n. 6
0
        public void RegisterAndAuthTest()
        {
            var bootstrap = new ServerBootstrap(EndPointDispatcher.GetRandomPort());

            bootstrap.AddFilterTypes(typeof(AuthenticationValidationFilter));
            bootstrap.StartUp(null,
                              new CommandServerModule(),
                              new RepositoryModule(),
                              new ClientModule(),
                              new TestModule());

            //dont register client module for they are in the same context.
            //new ClientInitializer().Init(new TestModule());
            using (var scope = ObjectHost.Host.BeginLifetimeScope())
            {
                var factory = scope.Resolve <IAsyncSessionFactory <DuplexMessage> >();
                var session = factory.OpenSession(string.Format("{0};{1};",
                                                                bootstrap.EndPoint.ToString(), "keepalive=false"));
                var command = session.CreateCommand(CommandCode.Register);
                command.SecurityEnabled = true;
                command.Parameter       = new RegisterInfo {
                    ClientMacAddr = NetworkInfoHelper.GetMacAddr(), ClientPubKey = new TestRsaKeyProvider().GetPublicKey(null)
                };
                var result = command.Run(5000);
                Assert.AreEqual(ErrorCode.NoError, result.Header.ErrorCode);
                Assert.AreEqual(command.ID, result.Header.MessageID);
                Assert.AreEqual(MessageType.Callback, result.Header.MessageType);

                command           = session.CreateCommand(CommandCode.Authentication);
                command.Parameter = new AuthInfo
                {
                    Identifier = scope.Resolve <IIdentifierProvider>().GetIdentifier(),
                    Mac        = NetworkInfoHelper.GetMacAddr()
                };
                command.SecurityEnabled = true;
                result = command.Run(5000);
                Assert.AreEqual(ErrorCode.NoError, result.Header.ErrorCode);
                Assert.AreEqual(command.ID, result.Header.MessageID);
                Assert.AreEqual(MessageType.Callback, result.Header.MessageType);

                command = session.CreateCommand(CommandCode.Test);
                result  = command.Run(5000);
                Assert.AreEqual(CommandCode.Test, result.Header.CommandCode);
                Assert.AreEqual(ErrorCode.BadRequest, result.Header.ErrorCode); // test command not registered, it's ture that it returns bad request
            }
        }
Esempio n. 7
0
 private void PrintDNSCache()
 {
     try
     {
         Beaprint.MainPrint("DNS cached --limit 70--");
         Beaprint.GrayPrint(string.Format("    {0,-38}{1,-38}{2}", "Entry", "Name", "Data"));
         List <Dictionary <string, string> > DNScache = NetworkInfoHelper.GetDNSCache();
         foreach (Dictionary <string, string> entry in DNScache.GetRange(0,
                                                                         DNScache.Count <= 70 ? DNScache.Count : 70))
         {
             Console.WriteLine($"    {entry["Entry"],-38}{entry["Name"],-38}{entry["Data"]}");
         }
     }
     catch (Exception ex)
     {
         Beaprint.PrintException(ex.Message);
     }
 }