public void Process()
        {
            var localEndPoint  = (IPEndPoint)client.LocalEndPoint;
            var remoteEndPoint = (IPEndPoint)client.RemoteEndPoint;
            var connection     = connectionTracker[new Connection(ProtocolType.Tcp, localEndPoint, remoteEndPoint)].Mirror;

            if (connection != null)
            {
                var initialEndPoint   = connection.Source;
                var requestedEndPoint = connection.Destination;
                var tcpConnection     = connectionTracker.GetTCPConnection(initialEndPoint, requestedEndPoint);

                var logMessage = string.Format("{0}[{1}] {2} {{0}} connection to {3}",
                                               tcpConnection != null ? tcpConnection.ProcessName : "unknown",
                                               tcpConnection != null ? tcpConnection.PID : 0,
                                               initialEndPoint, requestedEndPoint);
                try
                {
                    var proxy = new ProxySocket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    configureProxySocket(proxy, requestedEndPoint);

                    debug.Log(1, logMessage + " via {1}", "requested", proxy.ProxyEndPoint);

                    proxy.Connect(requestedEndPoint);

                    SocketPump.Pump(client, proxy);

                    proxy.Close();
                    debug.Log(1, logMessage, "closing");
                }
                catch (Exception ex)
                {
                    debug.Log(1, logMessage + ": {1}", "failed", ex.Message);
                }

                connectionTracker.QueueForCleanUp(connection);
            }
            else
            {
                var tcpConnection = connectionTracker.GetTCPConnection(remoteEndPoint, localEndPoint);
                debug.Log(1, "{0}[{1}] {2} has no mapping",
                          tcpConnection != null ? tcpConnection.ProcessName : "unknown",
                          tcpConnection != null ? tcpConnection.PID : 0,
                          remoteEndPoint);
                client.Send(Encoding.ASCII.GetBytes("No mapping\r\n"));
            }

            client.Close();
        }
Exemple #2
0
        public void Start()
        {
            connectionTracker = (ConnectionTracker)services["connectionTracker"];

            Port = ((IPEndPoint)transparentSocksServer.Client.LocalEndPoint).Port;
            debug.Log(0, "TransparentUdpPort = " + Port);
            connection = new TransparentUdpConnection(transparentSocksServer, debug, connectionTracker, ConfigureSocksProxy);
            connection.Process();
        }
Exemple #3
0
        public void Start()
        {
            connectionTracker = (ConnectionTracker)services["connectionTracker"];
            natter            = (Natter)services["natter"];

            logServer.Start();
            debug.Log(0, "LogPort = " + ((IPEndPoint)logServer.LocalEndpoint).Port);
            logServer.BeginAcceptTcpClient(NewLogConnection, null);
        }
Exemple #4
0
        public void Start()
        {
            connectionTracker = (ConnectionTracker)services["connectionTracker"];

            transparentSocksServer.Start();
            Port = ((IPEndPoint)transparentSocksServer.LocalEndpoint).Port;
            debug.Log(0, "TransparentSocksPort = " + Port);
            transparentSocksServer.BeginAcceptSocket(NewTransparentSocksConnection, null);
        }
Exemple #5
0
        public void Process()
        {
            connected = true;
            var writer = new StreamWriter(stream);

            stream.BeginRead(buffer, 0, 0x1000, ReadComplete, null);

            var localEndPoint  = (IPEndPoint)client.Client.LocalEndPoint;
            var remoteEndPoint = (IPEndPoint)client.Client.RemoteEndPoint;

            var tcpConnection = connectionTracker.GetTCPConnection(remoteEndPoint, localEndPoint);

            var logMessage = string.Format("{0}[{1}] {2} {{0}} log",
                                           tcpConnection != null ? tcpConnection.ProcessName : "unknown",
                                           tcpConnection != null ? tcpConnection.PID : 0,
                                           client.Client.RemoteEndPoint);

            debug.Log(1, logMessage, "connected to");
            debug.Log(2, natter.GetStatus());

            try
            {
                writer.Write(debug.Status);
                writer.Flush();
                while (connected && client.Connected)
                {
                    string line;
                    if (!debug.Queue.TryDequeue(1000, out line))
                    {
                        continue;
                    }
                    writer.WriteLine(line);
                    writer.Flush();
                }
            }
            catch (SystemException)
            {
            }

            writer.Close();

            debug.Log(1, logMessage, "disconnected from");
        }
Exemple #6
0
        public void Start()
        {
            connectionTracker = (ConnectionTracker)services["connectionTracker"];

            transparentSocksServer.Start();
            Port    = ((IPEndPoint)transparentSocksServer.LocalEndpoint).Port;
            Address = IPAddress.Parse(Settings.Default.IPAddress);

            debug.Log(0, $"TransparentSocks = {Address}:{Port}");
            transparentSocksServer.BeginAcceptSocket(NewTransparentSocksConnection, null);
        }
        public void Process()
        {
            running = true;
            server.BeginReceive(ReceiveCallback, null);

            SynchronizationContext.Current.Post(o =>
            {
                do
                {
                    proxies.Where(pair => pair.Value.Expired.TotalSeconds >= Settings.Default.UDPTimeoutSeconds).ToList().ForEach(pair =>
                    {
                        debug.Log(1, $"UDP disconnected: {pair.Key}");
                        if (proxies.TryRemove(pair.Key, out CountedProxySocket proxy))
                        {
                            proxy.Proxy.Close();
                        }
                    });
                    Thread.Sleep(3000);
                }while (running);
            }, null);
        }
Exemple #8
0
 public void mappingCleanupTimer_Elapsed(object sender, ElapsedEventArgs e)
 {
     lock (mappingCleanUp)
         while (mappingCleanUp.Count > 0 && mappingCleanUp.Peek().Key < DateTime.Now)
         {
             var connection = mappingCleanUp.Dequeue().Value;
             if (!mappings.ContainsKey(connection))
             {
                 continue;
             }
             var expect = mappings[connection];
             debug.Log(3, "src={0} dst={1} [CLN] src={2} dst={3}", connection.Source, connection.Destination, expect.Source, expect.Destination);
             mappings.Remove(expect.Mirror);
             mappings.Remove(connection);
         }
 }