Example #1
0
        internal TLSListenerForm( MainForm UseForm )
        {
            InitializeComponent();

            MForm = UseForm;

            DNSBackgroundWorker.WorkerReportsProgress = true;
            DNSBackgroundWorker.WorkerSupportsCancellation = true;

            ClientsLast = 0;
            // It will resize this as it needs more.
            Clients = new TLSClient[8];

            Listener = new TcpListener( IPAddress.Any, 443 );
            Listener.ExclusiveAddressUse = true;

            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            UniqueEntityTag = RightNow.GetIndex(); // Start it with something new.
        }
Example #2
0
        internal string GetRandomDomainName()
        {
            try
            {
            ECTime OldDate = new ECTime();
            OldDate.SetToNow();
            OldDate.AddMinutes( -(60 * 24 * 90)); // Go back 90 days.
            ulong OldDateIndex = OldDate.GetIndex();

            // A limited while( true ) that won't go forever.
            for( int Count = 0; Count < 10000; Count++ )
              {
              int Index = MForm.GetRandomNumber();
              Index = Index % DomainX509RecArrayLast;
              DomainX509Record Rec = DomainX509RecArray[Index];
              if( Rec.GetModifyTimeIndex() > OldDateIndex )
            continue; // Don't get a recently used one.

              // if( anything else )
            // continue;

              // return "127.0.0.1"; // For testing with local loopback.
              // return "promocodeclub.com"; // Good for testing X.509.
              return "secure.ballantinecommunications.net";
              // return "schneier.com"; //  Bruce Schneier, the cryptographer.
              // return "vantiv.com";

              // return Rec.DomainName;
              }

            return ""; // It shouldn't get here.

            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Exception in GetRandomDomainName():" );
              MForm.ShowStatus( Except.Message );
              return "";
              }
        }
Example #3
0
        internal void AddToBadWebPageCount( string Address, string SentText )
        {
            try
            {
            IPStatusRec StatusRec;
            if( IPsDictionary.ContainsKey( Address ))
              StatusRec = IPsDictionary[Address];
            else
              StatusRec = MakeNewStatusRec();

            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            StatusRec.TimeIndex = RightNow.GetIndex();
            StatusRec.BadWebPageCount++;
            StatusRec.SentText = Utility.CleanAsciiString( SentText, 2048 );

            IPsDictionary[Address] = StatusRec;
            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Exception in AddToBadWebPageCountCount():" );
              MForm.ShowStatus( Except.Message );
              }
        }
Example #4
0
        internal void CloseTimedOut()
        {
            ECTime OldTime = new ECTime();
            OldTime.SetToNow();
            ////////////////////////
            OldTime.AddSeconds( -4 );

            ECTime OldWebTime = new ECTime();
            OldWebTime.SetToNow();
            // Browsers that are cooperative don't open too many connections at once.
            // Denial of service people will.
            // This delay makes browsers that are cooperative hold off on sending more
            // requests until they've closed some sockets.
            // Apparently this is the operating system that is being cooperative.
            // And if this server is too busy it's not going to be calling this
            // function to close it until it can get around to it.
            // So cooperative web clients will wait.
            OldWebTime.AddSeconds( -0.1 );
            // OldWebTime.AddSeconds( 10 ); // If I put it 10 seconds in the _future_ it works.
            // OldWebTime.AddSeconds( -10 );
            // The socket is setting LastTransactTime when AsyncResult.IsCompleted.
            // So it's setting it when the socket thinks it's done sending it.
            ulong OldIndex = OldTime.GetIndex();
            ulong OldWebIndex = OldWebTime.GetIndex();
            for( int Count = 0; Count < ClientsLast; Count++ )
              {
              if( Clients[Count] == null ) // This should never happen but...
            continue;

              if( Clients[Count].IsShutDown())
            continue;

              /*
              // Close a web request only after it has started processing the request.
              if( Clients[Count].GetProcessingStarted())
            {
            if( Clients[Count].GetIsAWebRequest())
              {
              if( Clients[Count].GetLastTransactTimeIndex() < OldWebIndex )
            {
            if( Clients[Count].IsProcessingInBackground())
              {
              // ShowStatus( " " );
              // ShowStatus( "Web request is still sending." );
              // MForm.ServerLog.AddToLog( "Web Still Sending", "Nada", Clients[Count].GetRemoteAddress() );
              }

            Clients[Count].FreeEverything();
            }
              }
            }
            */

              // If it's more recent than the old index then it's OK.
              if( Clients[Count].GetLastTransactTimeIndex() > OldIndex )
            continue;

              /*
              // If this message has not already been processed.
              if( !Clients[Count].GetProcessingStarted())
            {
            string InputS = Utility.GetCleanUnicodeString( Clients[Count].GetAllInputS(), 2000 );
            InputS = InputS.Trim();
            if( InputS.Length > 0 )
              {
              // ShowStatus( "Timed out with: " + InputS );
              }

            MForm.NetStats.AddToTimedOutCount( Clients[Count].GetRemoteAddress(), InputS );
            }
            */

              if( Clients[Count].IsProcessingInBackground())
            {
            ShowStatus( " " );
            ShowStatus( "**************************************" );
            ShowStatus( "Still sending after time out period." );
            ShowStatus( "**************************************" );
            ShowStatus( " " );
            }

              // They normally time out.
              ShowStatus( "Closing timed out: " + Clients[Count].GetRemoteAddress());
              Clients[Count].FreeEverything();
              }
        }
Example #5
0
        private void ProcessWebRequests()
        {
            if( MForm.GetIsClosing())
              return;

            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            for( int Count = 0; Count < ClientsLast; Count++ )
              {
              if( Clients[Count] == null ) // This should never happen but...
            continue;

              // If this is something that has already been processed.
              if( Clients[Count].GetProcessingStarted())
            continue;

              // IsShutDown is a little slower than the above checks.
              if( Clients[Count].IsShutDown())
            continue;

              if( !Clients[Count].IsBrowserRequest())
            continue;

              if( !Clients[Count].IsBrowserRequestReady())
            continue;

              // ShowStatus( "Got a browser request 2." );

              Clients[Count].SetProcessingStarted( true );

              string InputS = Utility.GetCleanUnicodeString( Clients[Count].GetAllInputS(), 2000 );

              // This FileName is already cleaned ASCII.
              string FileName = Clients[Count].GetHTTPFileRequested();
              string OriginalFileName = FileName;

              FileName = FileName.ToLower();
              FileName = FileName.Replace( "/", "" );
              // ShowStatus( "FileName is: " + FileName );

              if( FileName.StartsWith( "bad http:" ))
            {
            MForm.NetStats.AddToHackerCount( Clients[Count].GetRemoteAddress(), InputS );
            // MForm.ServerLog.AddToLog( "Bad HTTP", InputS, Clients[Count].GetRemoteAddress() );
            Clients[Count].FreeEverything();
            ShowStatus( FileName );
            continue;
            }

              if( FileName.StartsWith( "hacking:" ))
            {
            DailyHackCount++;
            MForm.NetStats.AddToHackerCount( Clients[Count].GetRemoteAddress(), InputS );
            // MForm.ServerLog.AddToLog( "Hacking", InputS, Clients[Count].GetRemoteAddress() );
            Clients[Count].FreeEverything();
            RightNow.SetToNow();
            ShowStatus( RightNow.ToLocalTimeString() + " on " + RightNow.ToLocalDateString() );
            ShowStatus( FileName );
            ShowStatus( " " );
            continue;
            }

              RightNow.SetToNow();
              string Referer = "None";
              string UserAgent = "None";

              if( FileName == "laplata.htm" )
            {
            if( MForm.GetIsClosing())
              return;

            // MForm.NetStats.AddTo...

            byte[] ToSendBuf = MForm.LaPlataData1.GetHTML( "smith" );
            if( ToSendBuf != null )
              Clients[Count].SendGenericWebResponse( ToSendBuf, RightNow.GetIndex(), UniqueEntityTag, "text/html" );

            Referer = Clients[Count].GetReferer();
            UserAgent = Clients[Count].GetUserAgent();
            // MForm.ServerLog.AddToLog() ...
            continue;
            }

              if( !MForm.WebFData.ContainsFile( FileName ))
            {
            Clients[Count].FreeEverything();
             // This is already clean ASCII.
            string LogText = FileName + ": " + InputS;
            // MForm.ServerLog.AddToLog( "No Web File", LogText, Clients[Count].GetRemoteAddress() );
            MForm.NetStats.AddToBadWebPageCount( Clients[Count].GetRemoteAddress(), InputS );
            ShowStatus( " " );
            RightNow.SetToNow();
            ShowStatus( RightNow.ToLocalTimeString() + " on " + RightNow.ToLocalDateString() );
            ShowStatus( "No Web File" );
            ShowStatus( "Original: " + OriginalFileName );
            ShowStatus( "Fixed: " + FileName );
            ShowStatus( "From IP: " + Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".exe" ) || FileName.EndsWith( ".apk" ))
            {
            ShowStatus( " " );
            RightNow.SetToNow();
            ShowStatus( RightNow.ToLocalTimeString() + " on " + RightNow.ToLocalDateString() );
            ShowStatus( "Request for: " + FileName );
            ShowStatus( "From IP: " + Clients[Count].GetRemoteAddress() );
            ShowStatus( " " );
            }

              Referer = Clients[Count].GetReferer();
              UserAgent = Clients[Count].GetUserAgent();
              MForm.NetStats.AddToUserAgentAndReferer( Clients[Count].GetRemoteAddress(), Referer, UserAgent );

              // Increment UniqueEntityTag when it sends something.
              UniqueEntityTag++;
              // FileName is already clean ASCII, it's lower case, and trimmed.

              // This is a reference to the buffer, but the client copies from it.
              byte[] Buffer = MForm.WebFData.GetBuffer( FileName );
              if( Buffer == null )
            {
            ShowStatus( "The buffer was null for a good web request: " + FileName );
            continue;
            }

              if( FileName.EndsWith( ".jpg" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "image/jpeg" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".gif" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "image/gif" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".htm" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "text/html" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".txt" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "text/plain" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName.EndsWith( ".pdf" ))
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "application/pdf" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              if( FileName == "favicon.ico" )
            {
            Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "image/vnd.microsoft.icon" );
            // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
            continue;
            }

              // Default to sending text unless there's some other way to send it.
              Clients[Count].SendGenericWebResponse( Buffer, RightNow.GetIndex(), UniqueEntityTag, "text/plain" );
              // MForm.ServerLog.AddToLog( "Finished Web Request", FileName, Clients[Count].GetRemoteAddress() );
              }
        }
Example #6
0
        internal void AddToConfirmBillingCount( string Address )
        {
            try
            {
            IPStatusRec StatusRec;
            if( IPsDictionary.ContainsKey( Address ))
              StatusRec = IPsDictionary[Address];
            else
              StatusRec = MakeNewStatusRec();

            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            StatusRec.TimeIndex = RightNow.GetIndex();
            StatusRec.ConfirmBillingCount++;
            StatusRec.TotalConfirmBillingCount++;

            IPsDictionary[Address] = StatusRec;
            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Exception in AddToConfirmBillingCount():" );
              MForm.ShowStatus( Except.Message );
              }
        }
Example #7
0
        internal void UpdateHostNameCheckTime( string IP )
        {
            try
            {
            IPStatusRec StatusRec;
            if( IPsDictionary.ContainsKey( IP ))
              StatusRec = IPsDictionary[IP];
            else
              StatusRec = MakeNewStatusRec();

            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            StatusRec.TimeIndex = RightNow.GetIndex();
            StatusRec.LastHostNameUpdate = RightNow.GetIndex();
            IPsDictionary[IP] = StatusRec;
            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Exception in NetStatus.UpdateHostNameCheckTime():" );
              MForm.ShowStatus( Except.Message );
              }
        }
Example #8
0
        internal bool ClearMidnightValues()
        {
            try
            {
            // The IP stuff is also kept in the server log.
            ECTime RecTime = new ECTime();
            ECTime OldTime = new ECTime();
            OldTime.SetToNow();
            OldTime.AddMinutes( -(60 * 24 * 30)); // 30 days.
            ulong OldIndex = OldTime.GetIndex();

            SortedDictionary<string, IPStatusRec> TempIPsDictionary = new SortedDictionary<string, IPStatusRec>();

            foreach( KeyValuePair<string, IPStatusRec> Kvp in IPsDictionary )
              {
              RecTime.SetFromIndex( Kvp.Value.TimeIndex );
              if( RecTime.GetIndex() < OldIndex )
            continue;

              // Keep totals on things like bad reg key count.
              IPStatusRec Rec = Kvp.Value;
              Rec.TimedOutCount = 0;
              Rec.GoodWebRequestCount = 0;
              // TotalGoodWebRequestCount
              // BadWebPageCount
              Rec.GetPublicKeyCount = 0;
              // Rec.TotalGetPublicKeyCount
              Rec.ConfirmBillingCount = 0;
              // Rec.TotalConfirmBillingCount

              TempIPsDictionary[Kvp.Key] = Rec;
              }

            IPsDictionary = TempIPsDictionary;
            return true;

            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Exception in ClearMidnightValues():" );
              MForm.ShowStatus( Except.Message );
              return false;
              }
        }
Example #9
0
        internal void AddToUserAgentAndReferer( string Address, string Referer, string UserAgent )
        {
            try
            {
            Referer = Utility.CleanAsciiString( Referer, 1000 );
            UserAgent = Utility.CleanAsciiString( UserAgent, 1000 );

            IPStatusRec StatusRec;
            if( IPsDictionary.ContainsKey( Address ))
              StatusRec = IPsDictionary[Address];
            else
              StatusRec = MakeNewStatusRec();

            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            StatusRec.TimeIndex = RightNow.GetIndex();
            StatusRec.Referer = Utility.CleanAsciiString( Referer, 2048 );
            StatusRec.UserAgent = Utility.CleanAsciiString( UserAgent, 2048 );

            if( RefererDictionary.ContainsKey( Referer ))
              RefererDictionary[Referer] = RefererDictionary[Referer] + 1;
            else
              RefererDictionary[Referer] = 1;

            if( UserAgentDictionary.ContainsKey( UserAgent ))
              UserAgentDictionary[UserAgent] = UserAgentDictionary[UserAgent] + 1;
            else
              UserAgentDictionary[UserAgent] = 1;

            IPsDictionary[Address] = StatusRec;
            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Exception in AddToUserAgentAndReferer():" );
              MForm.ShowStatus( Except.Message );
              }
        }
Example #10
0
        internal void AddToPort80Count( string IP )
        {
            if( IsBadIP( IP ))
              return;

            try
            {
            IPStatusRec StatusRec;
            if( IPsDictionary.ContainsKey( IP ))
              StatusRec = IPsDictionary[IP];
            else
              StatusRec = MakeNewStatusRec();

            ECTime RightNow = new ECTime();
            RightNow.SetToNow();
            StatusRec.TimeIndex = RightNow.GetIndex();
            StatusRec.Port80Count++;

            IPsDictionary[IP] = StatusRec;
            }
            catch( Exception Except )
              {
              MForm.ShowStatus( "Exception in AddToPort80Count():" );
              MForm.ShowStatus( Except.Message );
              }
        }