示例#1
0
        public void HandleConnectionRequest(Connection acceptedConnection)
        {
            Connection remoteSocksServerConnection = null;

            try
            {
                remoteSocksServerConnection = Connection.ConnectOverHttpProxy(_RemoteSocksServerHost, _RemoteSocksServerPort);
            }
            catch
            {
                acceptedConnection.Close();
                return;
            }

            remoteSocksServerConnection.SetObserver(this);

            remoteSocksServerConnection.Send(Socks4Request.Build(Socks4Request.REQUEST_TYPE_CONNECT, _RedirectHost, _RedirectPort, "").ToByteArray());

            _WaitHandle.WaitOne();

            if (_RemoteSocksServerResponse == null || !_RemoteSocksServerResponse.Success)
            {
                SocksCommon.SendSocksError(acceptedConnection);
                return;
            }

            SocksCommon.SendSocksSuccess(acceptedConnection, _RemoteSocksServerResponse.Port, IPAddress.Parse(_RemoteSocksServerResponse.ResolvedIP));

            acceptedConnection.SetObserver(new TransmissionRedirectConnectionObserver(remoteSocksServerConnection, true));
            remoteSocksServerConnection.SetObserver(new TransmissionRedirectConnectionObserver(acceptedConnection, false));
            acceptedConnection.BeginReceiving();
        }
        public override void HandleConnectionRequest(Connection acceptedConnection)
        {
            Socks4Request request = Socks4Request.Build(Socks4Request.REQUEST_TYPE_BIND, _RedirectHost, _RedirectPort, "");

            Connection redirectConnection = null;

            try
            {
                redirectConnection = Connection.Connect(_SocksServerHost, _SocksServerPort);
            }
            catch (Exception exp)
            {
                acceptedConnection.Close();
                return;
            }

            redirectConnection.SetObserver(new PortRedirectOverSocksConnectionObserver(acceptedConnection));
            acceptedConnection.IsBeingTraced = ObservedServer.IsBeingTraced;
            redirectConnection.BeginReceiving();

            redirectConnection.Send(request.ToByteArray());
        }
示例#3
0
        private static void TestRemoteServer(string remoteHost, int remotePort, string remoteSocksHost, int remoteSocksPort, ref int statuscode, ref string statusmessage)
        {
            Connection testConnection;

            try
            {
                testConnection = Connection.Connect(remoteSocksHost, remoteSocksPort);
            }
            catch (Exception exp)
            {
                statuscode    = 505;
                statusmessage = "Could not connect to the Socks Server: " + exp.Message;
                return;
            }

            try
            {
                testConnection.Send(Socks4Request.Build(Socks4Request.REQUEST_TYPE_CONNECT, remoteHost, remotePort, "").ToByteArray());
                testConnection.BeginReceivingSync();

                byte[] socksRawResponse = testConnection.GetNextSyncReceiveBuffer();
                testConnection.Close();

                Socks4Response socksResponse = Socks4Response.Parse(socksRawResponse);

                if (socksResponse == null || !socksResponse.Success)
                {
                    statuscode    = 504;
                    statusmessage = "Socks server reports that it failed to connect to the remote host";
                }
            }
            catch (Exception exp)
            {
                statuscode    = 504;
                statusmessage = "Failed while trying to connect to the remote host through socks: " + exp.Message;
            }
        }