コード例 #1
0
        public override void HandleSocksRequest(ISocksClient clientToHandle)
        {
            logger.Trace($"Received new client request from {((IPEndPoint)(clientToHandle.Client.RemoteEndPoint)).Address}");
            var socks4Request = Socks4Request.From(clientToHandle);

            if (socks4Request.Header.RequestType == Socks4RequestType.TcpIpConnection)
            {
                logger.Notice($"Request command is TCP/IP connection to:{socks4Request.IpAddress} on:{socks4Request.Port}");
                var connectionTarget = new IPEndPoint(socks4Request.IpAddress, socks4Request.Port);

                try
                {
                    logger.Notice("Trying to connect");
                    clientToHandle.Connect(connectionTarget);
                }
                catch (SocketException e)
                {
                    logger.Error($"Connection to {socks4Request.IpAddress} on port {socks4Request.Port} thrown an exception:{Environment.NewLine}{e.Message}");
                    CloseConnectionAndSendError(clientToHandle, (uint)SocksCore.Socks4ErrorCodes.Error);
                    return;
                }
            }
            if (socks4Request.Header.RequestType == Socks4RequestType.PortBinding)
            {
                throw new NotImplementedException();
                // TODO: add port binding functionality
            }
            CloseConnectionAndSendError(clientToHandle, (uint)SocksCore.Socks4ErrorCodes.Error);
        }
コード例 #2
0
ファイル: SocksCore.cs プロジェクト: voidsharp/Socks-core
        public void AcceptClientConnection(ISocksClient client /*Socket client*/)
        {
            var socksVersionFromClientRequest = SocksVersion.Unknown;

            socksVersionFromClientRequest = FromRequest(client);



            switch (socksVersionFromClientRequest)
            {
            case SocksVersion.Unknown:
                CloseConnectionAndSendError(client, DefaultSocksError);
                break;

            case SocksVersion.Socks4:
                socks4ClientHandler.HandleSocksRequest(client);
                break;

            case SocksVersion.Socks5:
                socks5ClientHandler.HandleSocksRequest(client);
                break;

            default:
                CloseConnectionAndSendError(client, DefaultSocksError);
                break;
            }
        }
コード例 #3
0
        public virtual void CloseConnectionAndSendError(ISocksClient connectionToClose, uint errorCode)
        {
            var errorArray = BitConverter.GetBytes(errorCode);

            try
            {
                connectionToClose.Send(errorArray);
            }
            finally
            {
                connectionToClose.Close();
            }
        }
コード例 #4
0
 protected virtual void OnNewSocksClientConnected(ISocksClient e)
 {
     NewSocksClientConnected?.Invoke(this, e);
 }
コード例 #5
0
ファイル: SocksCore.cs プロジェクト: voidsharp/Socks-core
 public void CloseConnectionAndSendError(ISocksClient connectionToClose, uint errorCode)
 {
     connectionToClose.Close();
     //            throw new NotImplementedException();
 }
コード例 #6
0
 public abstract void HandleSocksRequest(ISocksClient clientToHandle);