コード例 #1
0
        public static void ScanResource(object line)
        {
            var request = ConfigureRequest(_baseUrl.TrimEnd(), ( string )line);
            var details = new ScanDetails
            {
                Url = request.RequestUri
            };

            try
            {
                using (var response = ( HttpWebResponse )request.GetResponse())
                {
                    WriteResponseInfo(response, details);
                }
            }
            catch (WebException ex)
            {
                WriteResponseInfo(( HttpWebResponse )ex.Response, details);
            }
            catch (ThreadInterruptedException)
            {
                /* Clean up. */
                ScanDetails = null;
            }
        }
コード例 #2
0
        private static void SearchErrorContent(ScanDetails details)
        {
            if (!String.IsNullOrEmpty(_errorPageTitle) || !String.IsNullOrEmpty(_errorPageBodyText))
            {
                var doc = new HtmlDocument();
                doc.LoadHtml(details.PageTitle);

                var title = doc.DocumentNode.SelectNodes("//title");
                var body  = doc.DocumentNode.SelectNodes("//body");

                if (title != null)
                {
                    foreach (var item in title)
                    {
                        details.ErrorPageTitle = item.InnerText.Contains(_errorPageTitle) ? "exists!" : "not found";
                        break;
                    }
                }

                if (body != null)
                {
                    foreach (var item in body)
                    {
                        details.ErrorPageTitle = item.InnerText.Contains(_errorPageBodyText) ? "exists!" : "not found";
                        break;
                    }
                }
            }
        }
コード例 #3
0
        private static void WriteResponseInfo(HttpWebResponse response, ScanDetails details)
        {
            if (response != null)
            {
                try
                {
                    if (ScannerSetting.GetStatusCodesList(_scannerSetting.ResponseTypes).Contains(
                            Convert.ToString(response.StatusCode)))
                    {
                        details.Response = String.Format("{0}{1}{2}", Convert.ToString(( int )response.StatusCode), ' ', response.StatusDescription);
                        details.Size     = response.ContentLength == -1 ? 0 : response.ContentLength;

                        using (var stream = response.GetResponseStream())
                        {
                            if (stream != null)
                            {
                                using (var reader = new StreamReader(stream, Encoding.Default))
                                {
                                    if (!response.ContentType.Equals("application/octet_stream"))
                                    {
                                        details.PageTitle = reader.ReadToEnd();
                                        details.PageBody  = details.PageTitle;
                                    }
                                }
                            }
                        }
                        //Critical section
                        //_mutex.WaitOne();
                        if (response.ContentType.Contains("text/html"))
                        {
                            SearchErrorContent(details);
                            details.PageTitle = SearchSpecificContent(details.PageTitle);
                        }
                        else
                        {
                            details.PageTitle = String.Empty;
                        }

                        if (!String.IsNullOrEmpty(details.PageBody))
                        {
                            details.PageBody = details.PageBody.Substring(0, 150);
                        }

                        if (ScanDetails != null)
                        {
                            ScanDetails.Add(details);
                        }
                        //_mutex.ReleaseMutex();
                    }
                }
                catch (ArgumentException)
                {
                }
            }
        }
コード例 #4
0
		private static void WriteResponseInfo( HttpWebResponse response, ScanDetails details )
		{
			if( response != null )
			{
				try
				{
					if( ScannerSetting.GetStatusCodesList( _scannerSetting.ResponseTypes ).Contains(
						Convert.ToString( response.StatusCode ) ) )
					{
						details.Response = String.Format( "{0}{1}{2}", Convert.ToString( ( int )response.StatusCode ), ' ', response.StatusDescription );
						details.Size = response.ContentLength == -1 ? 0 : response.ContentLength;

						using( var stream = response.GetResponseStream() )
						{
							if( stream != null )
							{
								using( var reader = new StreamReader( stream, Encoding.Default ) )
								{
									if( !response.ContentType.Equals( "application/octet_stream" ) )
									{
										details.PageTitle = reader.ReadToEnd();
										details.PageBody = details.PageTitle;
									}
								}
							}
						}
						//Critical section
						//_mutex.WaitOne();
						if( response.ContentType.Contains( "text/html" ) )
						{
							SearchErrorContent( details );
							details.PageTitle = SearchSpecificContent( details.PageTitle );
						}
						else
						{
							details.PageTitle = String.Empty;
						}

						if( !String.IsNullOrEmpty( details.PageBody ) )
						{
							details.PageBody = details.PageBody.Substring( 0, 150 );
						}

						if (ScanDetails != null)
							ScanDetails.Add( details );
						//_mutex.ReleaseMutex();
					}
				}
				catch( ArgumentException )
				{
				}
			}
		}
コード例 #5
0
		public static void ScanResource( object line )
		{
			var request = ConfigureRequest( _baseUrl.TrimEnd(), ( string )line );
			var details = new ScanDetails
				{
					Url = request.RequestUri
				};

			try
			{
				using( var response = ( HttpWebResponse )request.GetResponse() )
				{
					WriteResponseInfo( response, details );
				}
			}
			catch( WebException ex )
			{
				WriteResponseInfo( ( HttpWebResponse )ex.Response, details );
			}
			catch( ThreadInterruptedException )
			{
				/* Clean up. */
				ScanDetails = null;
			}
		}
コード例 #6
0
		private static void SearchErrorContent( ScanDetails details )
		{
			if( !String.IsNullOrEmpty( _errorPageTitle ) || !String.IsNullOrEmpty( _errorPageBodyText ) )
			{
				var doc = new HtmlDocument();
				doc.LoadHtml( details.PageTitle );

				var title = doc.DocumentNode.SelectNodes( "//title" );
				var body = doc.DocumentNode.SelectNodes( "//body" );

				if( title != null )
				{
					foreach( var item in title )
					{
						details.ErrorPageTitle = item.InnerText.Contains( _errorPageTitle ) ? "exists!" : "not found";
						break;
					}
				}

				if( body != null )
				{
					foreach( var item in body )
					{
						details.ErrorPageTitle = item.InnerText.Contains( _errorPageBodyText ) ? "exists!" : "not found";
						break;
					}
				}
			}
		}