private void _QueuePoolHelper_SendMessage(object sender, QueuePoolEventArgs <OperationLogInfo> e)
        {
            OperationLogInfo message = e.Message;

            try
            {
                LogSection logSection = LogSectionHelper.GetLogSection();
                if (!string.IsNullOrWhiteSpace(logSection.Application))
                {
                    LogRule           rule             = new LogRule();
                    loger_application cacheApplication = rule.GetCacheApplication(logSection.Application);
                    if (cacheApplication != null)
                    {
                        loger_operationloging _operationloging = new loger_operationloging {
                            ApplicationID   = cacheApplication.ApplicationID,
                            ApplicationName = cacheApplication.ApplicationName,
                            Account         = message.UserAccount,
                            TableName       = message.TableName,
                            OperationTypeID = (int)message.OperationType,
                            SqlQuery        = message.SqlQuery,
                            CreateDate      = message.CreateDate,
                            IDPath          = cacheApplication.IDPath,
                            ModuleTypeCode  = message.LogModuleTypeCode,
                            ApplicationHost = LogSectionHelper.Host,
                            UserHostAddress = message.UserHostAddress,
                            UrlReferrer     = message.UrlReferrer,
                            RawUrl          = message.RawUrl
                        };
                        rule.CurrentEntities.AddTologer_operationloging(_operationloging);
                        rule.SaveChanges();
                    }
                }
            }
            catch (Exception exception)
            {
                try
                {
                    LogHelper <LogModuleType> .Write(LogModuleType.LogManager, "记录操作日志出现异常", exception, "");
                }
                catch (Exception exception2)
                {
                    EventLogWriter.WriterLog(exception2);
                }
            }
        }
Exemple #2
0
 public static void ProcessNoUserAgentBeginRequest()
 {
     try
     {
         if (((SysVariable.CurrentContext != null) && (SysVariable.CurrentContext.Request != null)) && (SysVariable.CurrentContext.Request.UserAgent == null))
         {
             HttpResponse response   = SysVariable.CurrentContext.Response;
             LogSection   logSection = LogSectionHelper.GetLogSection();
             response.ContentType = "text/plain";
             response.Write(logSection.Error.ErrorHint);
             HttpContext.Current.ApplicationInstance.CompleteRequest();
             Write("Application", LogCategory.AttackInfo, "NoUserAgentBeginRequest抓取处理", "NoUserAgentBeginRequest抓取处理", "");
         }
     }
     catch (Exception exception)
     {
         Write("Application", "Application_Error", exception, "");
     }
 }
Exemple #3
0
 public static bool ProcessAttackBeginRequest(params string[] excludeUrlPattern)
 {
     try
     {
         if ((SysVariable.CurrentContext != null) && (SysVariable.CurrentContext.Request != null))
         {
             HttpResponse response;
             LogSection   logSection;
             if (SysVariable.CurrentContext.Request.Url.AbsolutePath.Contains(":"))
             {
                 response             = SysVariable.CurrentContext.Response;
                 response.ContentType = "text/html";
                 response.StatusCode  = 0x194;
                 logSection           = LogSectionHelper.GetLogSection();
                 if (logSection.Error.ErrorIsRedirect && logSection.Error.ErrorNoFoundUrl.IsNoNullOrWhiteSpace())
                 {
                     response.WriteFile(logSection.Error.ErrorNoFoundUrl);
                 }
                 else
                 {
                     response.Write("对不起找不到此页面");
                 }
                 Write("Application", LogCategory.AttackInfo, "路经包含英文:地址不正确", SysVariable.CurrentContext.Request.Url.AbsolutePath, "");
                 HttpContext.Current.ApplicationInstance.CompleteRequest();
                 return(true);
             }
             string input = SysVariable.CurrentContext.Request.Url.PathAndQuery.DecodeUrl();
             bool   flag  = false;
             if ((excludeUrlPattern != null) && (excludeUrlPattern.Length > 0))
             {
                 foreach (string str2 in excludeUrlPattern)
                 {
                     if (input.IsMatch(str2, RegexOptions.IgnoreCase))
                     {
                         flag = true;
                         break;
                     }
                 }
             }
             if (!flag && input.IsMatch(@"exec |<script|script:|alert\(|execute |insert |select |delete |union |update |alter |create |drop |chr |char |limit |asc |mid |'%|%'|substring |truncate |declare |xp_cmdshell |xp_ |sp_ |restore |backup |net +user |net +localgroup +administrators| exec| execute| insert| select| delete| union| update| alter| create| drop|chr\(|char\(| asc| mid| substring| truncate| declare| xp_cmdshell| xp_| sp_| restore| backup| net +user| net +localgroup +administrators", RegexOptions.IgnoreCase))
             {
                 response             = SysVariable.CurrentContext.Response;
                 response.ContentType = "text/html";
                 response.StatusCode  = 0x194;
                 logSection           = LogSectionHelper.GetLogSection();
                 if (logSection.Error.ErrorIsRedirect && logSection.Error.ErrorNoFoundUrl.IsNoNullOrWhiteSpace())
                 {
                     response.WriteFile(logSection.Error.ErrorNoFoundUrl);
                 }
                 else
                 {
                     response.Write("对不起找不到此页面");
                 }
                 Write("Application", LogCategory.AttackInfo, "AttackBeginRequest攻击处理", input, "");
                 HttpContext.Current.ApplicationInstance.CompleteRequest();
                 return(true);
             }
         }
     }
     catch (Exception exception)
     {
         Write("Application", "处理AttackBeginRequest异常", exception, "");
     }
     return(false);
 }
Exemple #4
0
        public static void DisposeException(Exception objException, Func <Exception, bool> Disposeing = null)
        {
            Exception innerException = objException;

            while (innerException.InnerException != null)
            {
                innerException = innerException.InnerException;
            }
            Type type = innerException.GetType();

            if ((Disposeing == null) || !Disposeing(objException))
            {
                HttpResponse response   = SysVariable.CurrentContext.Response;
                LogSection   logSection = LogSectionHelper.GetLogSection();
                if (type == typeof(ThreadAbortException))
                {
                    SysVariable.CurrentContext.Server.ClearError();
                }
                else if (innerException is Http404Exception)
                {
                    Http404Exception exception2 = (Http404Exception)innerException;
                    response.ContentType = "text/html";
                    response.StatusCode  = 0x194;
                    if (logSection.Error.ErrorIsRedirect && logSection.Error.ErrorNoFoundUrl.IsNoNullOrWhiteSpace())
                    {
                        response.WriteFile(logSection.Error.ErrorNoFoundUrl);
                    }
                    else
                    {
                        response.Write(exception2.Message);
                    }
                    SysVariable.CurrentContext.Server.ClearError();
                }
                else if ((innerException is HttpException) && (((HttpException)innerException).GetHttpCode() == 0x194))
                {
                    HttpException exception3 = (HttpException)innerException;
                    response.StatusCode  = 0x194;
                    response.ContentType = "text/html";
                    if (logSection.Error.ErrorIsRedirect && logSection.Error.ErrorNoFoundUrl.IsNoNullOrWhiteSpace())
                    {
                        response.WriteFile(logSection.Error.ErrorNoFoundUrl);
                    }
                    else
                    {
                        response.Write(exception3.Message);
                    }
                    SysVariable.CurrentContext.Server.ClearError();
                }
                else if ((innerException is HttpException) && (((HttpException)innerException).GetHttpCode() == 400))
                {
                    if (logSection.Error.ErrorIsRedirect && LogSectionHelper.GetLogSection().Error.ErrorUrl.IsNoNullOrWhiteSpace())
                    {
                        response.StatusCode = 0x12e;
                        response.AddHeader("Location", LogSectionHelper.GetLogSection().Error.ErrorUrl);
                    }
                    else
                    {
                        response.StatusCode = 500;
                        response.Write(logSection.Error.ErrorHint);
                    }
                    SysVariable.CurrentContext.Server.ClearError();
                }
                else if (innerException is Http301Exception)
                {
                    Http301Exception exception4 = innerException as Http301Exception;
                    response.StatusCode = 0x12d;
                    response.Status     = "301 Moved Permanently";
                    response.AddHeader("Location", exception4.RedirectUrl);
                    SysVariable.CurrentContext.Server.ClearError();
                }
                else if (innerException is Http302Exception)
                {
                    Http302Exception exception5 = innerException as Http302Exception;
                    response.StatusCode = 0x12e;
                    response.AddHeader("Location", exception5.RedirectUrl);
                    SysVariable.CurrentContext.Server.ClearError();
                }
                else if (innerException is Http500Exception)
                {
                    Http500Exception exception6 = innerException as Http500Exception;
                    response.ContentType = "text/html";
                    if (logSection.Error.ErrorIsRedirect && LogSectionHelper.GetLogSection().Error.ErrorUrl.IsNoNullOrWhiteSpace())
                    {
                        response.StatusCode = 0x12e;
                        response.AddHeader("Location", LogSectionHelper.GetLogSection().Error.ErrorUrl);
                    }
                    else
                    {
                        response.StatusCode = 500;
                        response.Write(logSection.Error.ErrorHint);
                    }
                    SysVariable.CurrentContext.Server.ClearError();
                }
                else if (innerException is HttpRequestValidationException)
                {
                    response.ContentType = "text/html";
                    Write("Application", LogCategory.AttackInfo, "Application_Error", objException, "");
                    if (logSection.Error.ErrorIsRedirect && LogSectionHelper.GetLogSection().Error.ErrorUrl.IsNoNullOrWhiteSpace())
                    {
                        response.StatusCode = 0x12e;
                        response.AddHeader("Location", LogSectionHelper.GetLogSection().Error.ErrorUrl);
                    }
                    else
                    {
                        response.StatusCode = 500;
                        response.Write(logSection.Error.ErrorHint);
                    }
                    SysVariable.CurrentContext.Server.ClearError();
                }
                else if (logSection.IsDispose)
                {
                    Write("Application", "Application_Error", objException, "");
                    if (logSection.Error.ErrorIsRedirect && LogSectionHelper.GetLogSection().Error.ErrorUrl.IsNoNullOrWhiteSpace())
                    {
                        response.StatusCode = 0x12e;
                        response.AddHeader("Location", LogSectionHelper.GetLogSection().Error.ErrorUrl);
                    }
                    else
                    {
                        response.StatusCode = 500;
                        response.Write(logSection.Error.ErrorHint);
                    }
                    SysVariable.CurrentContext.Server.ClearError();
                }
            }
        }
 private void _QueuePoolHelper_SendMessage(object sender, QueuePoolEventArgs <LogInfo> e)
 {
     try
     {
         Func <loger_category, bool> predicate = null;
         LogInfo    objLogInfo = e.Message;
         LogSection logSection = LogSectionHelper.GetLogSection();
         if (!string.IsNullOrWhiteSpace(logSection.Application))
         {
             loger_application cacheApplication;
             LogMessage        objLogMessage = new LogMessage {
                 ApplicationCode   = logSection.Application,
                 LogCategory       = objLogInfo.LogCategory,
                 LogModuleTypeList = objLogInfo.LogModuleTypeList,
                 Title             = objLogInfo.Title,
                 UserAccount       = objLogInfo.UserAccount,
                 UserHostAddress   = objLogInfo.UserHostAddress,
                 RawUrl            = objLogInfo.RawUrl,
                 UrlReferrer       = objLogInfo.UrlReferrer,
                 CreateDate        = objLogInfo.CreateDate,
                 MessageID         = objLogInfo.MessageID,
                 LogWriteMap       = logSection.LogWriteMap,
                 Message           = objLogInfo.Message.ToString(),
                 ResultMessage     = objLogInfo.ResultMessage.ToString(),
                 UserAgent         = objLogInfo.UserAgent,
                 HeadersData       = objLogInfo.HeadersData,
                 RequestData       = objLogInfo.RequestData
             };
             LogCategoryElement element = logSection.Categorys[objLogInfo.LogCategory];
             if (element != null)
             {
                 if (element.IsRecordDB)
                 {
                     LogRule rule = new LogRule();
                     cacheApplication = rule.GetCacheApplication(logSection.Application);
                     if (cacheApplication != null)
                     {
                         objLogMessage.ApplicationID   = cacheApplication.ApplicationID;
                         objLogMessage.ApplicationName = cacheApplication.ApplicationName;
                         objLogMessage.IDPath          = cacheApplication.IDPath;
                         this.WriteLog(objLogMessage, LogWriterType.DataLogWriter);
                     }
                 }
                 if (element.IsRecordEvent)
                 {
                     this.WriteLog(objLogMessage, LogWriterType.EventLogWriter);
                 }
                 if (objLogMessage.LogWriteMap.IsNoNull())
                 {
                     if (element.IsRecordText)
                     {
                         this.WriteLog(objLogMessage, LogWriterType.TextLogWriter);
                     }
                     if (element.IsRecordXml)
                     {
                         this.WriteLog(objLogMessage, LogWriterType.XmlLogWriter);
                     }
                 }
             }
             else
             {
                 cacheApplication = new LogRule().GetCacheApplication(logSection.Application);
                 if (cacheApplication != null)
                 {
                     objLogMessage.ApplicationID   = cacheApplication.ApplicationID;
                     objLogMessage.ApplicationName = cacheApplication.ApplicationName;
                     objLogMessage.IDPath          = cacheApplication.IDPath;
                     if (predicate == null)
                     {
                         predicate = s => s.CategoryTypeCode == objLogInfo.LogCategory;
                     }
                     loger_category _category = cacheApplication.loger_category.FirstOrDefault <loger_category>(predicate);
                     if (_category != null)
                     {
                         foreach (int num in _category.LogWriteType.ConvertListInt())
                         {
                             LogWriterType objLogWriterType = (LogWriterType)num;
                             if ((objLogWriterType == LogWriterType.DataLogWriter) || (objLogWriterType == LogWriterType.EventLogWriter))
                             {
                                 this.WriteLog(objLogMessage, objLogWriterType);
                             }
                             else if (objLogMessage.LogWriteMap.IsNoNull())
                             {
                                 this.WriteLog(objLogMessage, objLogWriterType);
                             }
                         }
                     }
                 }
             }
         }
     }
     catch (Exception exception)
     {
         EventLogWriter.WriterLog(exception);
     }
 }