Ejemplo n.º 1
0
        public bool SmartDataSentCallbackForDirectConnections(byte[] binary, bool isSocks)
        {
            SmartPear smart = this.Controller.SmartPear;

            if (this.IsSmartForwarderEnable && smart.ForwarderHttpsEnable && (!isSocks || smart.ForwarderSocksEnable))
            {
                byte[] smartRequestBuffer = this.SmartRequestBuffer;
                Array.Resize(ref smartRequestBuffer, smartRequestBuffer.Length + binary.Length);
                Array.Copy(binary, 0, smartRequestBuffer, smartRequestBuffer.Length - binary.Length, binary.Length);
                this.SmartRequestBuffer = smartRequestBuffer;
            }
            else if (this.SmartResponseBuffer.Length > 0)
            {
                this.SmartFlushTheForwarder(smart.ForwarderHttpsEnable && (!isSocks || smart.ForwarderSocksEnable));
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool SmartStatusCallbackForHttpConnections(ServerType currentActiveServer, bool success)
        {
            if (this.IsSmartForwarderEnable)
            {
                SmartPear smart = this.Controller.SmartPear;
                if (!success)
                {
                    if (smart.ForwarderHttpEnable && smart.DetectorTimeoutEnable)
                    {
                        this.IsSmartForwarderEnable = false;
                        Http.DirectHandle(
                            this,
                            currentActiveServer.GetRequestedAddress(),
                            currentActiveServer.GetRequestedPort(),
                            this.SmartRequestBuffer);
                        return(false);
                    }
                }
                else
                {
                    if (smart.ForwarderHttpEnable && smart.DetectorDnsPoisoningEnable &&
                        currentActiveServer.UnderlyingSocket != null)
                    {
                        if (currentActiveServer.UnderlyingSocket.RemoteEndPoint != null &&
                            smart.DetectorDnsPoisoningRegEx.IsMatch(
                                ((IPEndPoint)currentActiveServer.UnderlyingSocket.RemoteEndPoint).Address.ToString()))
                        {
                            this.IsSmartForwarderEnable = false;
                            Http.DirectHandle(
                                this,
                                currentActiveServer.GetRequestedAddress(),
                                currentActiveServer.GetRequestedPort(),
                                this.SmartRequestBuffer);
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 3
0
        public bool SmartDataSentCallbackForHttpConnections(byte[] binary)
        {
            SmartPear smart = this.Controller.SmartPear;

            if (smart.ForwarderHttpEnable && (smart.DetectorHttpCheckEnable || smart.DetectorDnsPoisoningEnable))
            {
                // If we have Forwarder Enabled
                if (this.IsSmartForwarderEnable)
                {
                    // If Client using NoServer
                    byte[] smartRequestBuffer = this.SmartRequestBuffer;
                    Array.Resize(ref smartRequestBuffer, smartRequestBuffer.Length + binary.Length);
                    Array.Copy(binary, 0, smartRequestBuffer, smartRequestBuffer.Length - binary.Length, binary.Length);
                    this.SmartRequestBuffer = smartRequestBuffer;
                }
                else if (this.SmartResponseBuffer.Length > 0)
                {
                    // If client use Proxy and there is a response already.
                    this.SmartFlushTheForwarder(smart.ForwarderHttpEnable);
                }
            }

            return(true);
        }
Ejemplo n.º 4
0
        public bool SmartDataReceivedCallbackForHttpConnections(ref byte[] binary, ServerType currentActiveServer)
        {
            SmartPear smart = this.Controller.SmartPear;

            if (smart.ForwarderHttpEnable)
            {
                // If we have Forwarder Enabled
                bool blocked = false;
                if (smart.DetectorStatusHttp && this.SmartResponseBuffer.Length < smart.DetectorHttpMaxBuffering)
                {
                    // If detector is enable and response is less than buffer size
                    byte[] smartResponseBuffer = this.SmartResponseBuffer;
                    Array.Resize(ref smartResponseBuffer, smartResponseBuffer.Length + binary.Length);
                    Array.Copy(
                        binary,
                        0,
                        smartResponseBuffer,
                        smartResponseBuffer.Length - binary.Length,
                        binary.Length);
                    Array.Resize(ref binary, 0);
                    // If Response is blocked
                    blocked = smart.DetectorHttpRegEx.IsMatch(Encoding.ASCII.GetString(smartResponseBuffer));
                    if (blocked && this.IsSmartForwarderEnable && currentActiveServer is NoServer)
                    {
                        blocked = false;
                        this.IsSmartForwarderEnable = false;
                    }
                    this.SmartResponseBuffer = smartResponseBuffer;
                }
                if (blocked)
                {
                    currentActiveServer.ReceiveDataDelegate = null;
                    if (this.IsSmartForwarderEnable)
                    {
                        // If client use NoServer
                        byte[] localReqBackup = new byte[this.SmartRequestBuffer.Length];
                        Array.Copy(this.SmartRequestBuffer, localReqBackup, localReqBackup.Length);
                        this.SmartCleanTheForwarder();
                        this.IsSmartForwarderEnable = false;
                        Http.DirectHandle(
                            this,
                            currentActiveServer.GetRequestedAddress(),
                            currentActiveServer.GetRequestedPort(),
                            localReqBackup);
                        return(false);
                    }
                }
                if (!blocked)
                {
                    // Response is OK
                    if (!this.IsSmartForwarderEnable &&
                        (smart.DetectorStatusHttp || smart.DetectorStatusDnsPoisoning || smart.DetectorStatusTimeout))
                    {
                        // If client use Proxy and one of possible detectors is enable
                        Uri url;
                        if (this.RequestAddress != string.Empty &&
                            Uri.TryCreate(this.RequestAddress, UriKind.Absolute, out url))
                        {
                            smart.AddRuleToHttpForwarder(
                                string.Format("*{0}*", url.Host.ToLower().TrimEnd(new[] { '/', '\\' })));
                        }

                        currentActiveServer.ReceiveDataDelegate = null;
                    }
                }

                if (this.SmartResponseBuffer.Length > 0 &&
                    (!this.IsSmartForwarderEnable ||
                     this.SmartResponseBuffer.Length >= smart.DetectorHttpMaxBuffering))
                {
                    // If we have any thing in Response and (Client use Proxy or NoServer but Response buffer is bigger than buffer)
                    this.SmartFlushTheForwarder(smart.ForwarderHttpEnable);
                    currentActiveServer.ReceiveDataDelegate = null;
                }
            }

            return(true);
        }