http访问拦截器,过滤xxs构建的请求
public class HttpAccessInterceptModule : IHttpModule
{
private static List<string> _RegexWords;
static HttpAccessInterceptModule()
{
_RegexWords = new List<string>()
{
@"<[^>]+>'",
@"</[^>]+>'",
@"<[^>]+?style=[\w]+?:expression\(|\b(alert|confirm|prompt|window|location|eval|console|debugger|Function|var|let)\b|^\+/v(8|9)|<[^>]*?=[^>]*?&#[^>]*?>|\b(and|or)\b.{1,6}?(=|>|<|\bin\b|\blike\b)|/\*.+?\*/|<\s*script\b|\bEXEC\b|UNION.+?SELECT|UPDATE.+?SET|INSERT\s+INTO.+?VALUES|(SELECT|DELETE).+?FROM|(CREATE|ALTER|DROP|TRUNCATE)\s+(TABLE|DATABASE)"
};
}
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.PreSendRequestHeaders += OnPreSendRequestHeaders;
context.BeginRequest += Context_BeginRequest;
}
private void OnPreSendRequestHeaders(object sender, EventArgs e)
{
try
{
if (sender is HttpApplication app)
{
app.Response.Headers.Set("Server", "WebServer");
app.Response.Headers.Remove("X-AspNet-Version");
app.Response.Headers.Remove("X-AspNetMvc-Version");
app.Response.Headers.Remove("X-Powered-By");
}
}
catch (Exception ex)
{
Log.Error(this, ex);
}
}
private void Context_BeginRequest(object sender, EventArgs e)
{
if (sender is HttpApplication app)
{
try
{