标签归档:asp网站空间

asp网站空间如何过滤xss攻击_读书小站

本文收集自网络,侵删!

asp网站空间过滤xss攻击的方法:1、在WEB.config增加HttpModules节点;2、编写一个过滤器,过滤危险关键词,并增加安全的header。

具体内容如下:

1、在web.config增加httpModules节点

<httpModules>

<add name="HttpAccessInterceptModule" type="Org.Core.Commons.HttpAccessInterceptModule, Org.Core.Commons"/>

</httpModules>

2、再编写一个过滤器

using System;

using System.Collections.Generic;

using System.Configuration;

using System.Linq;

using System.Text.RegularExpressions;

using System.Web;namespace Org.Core.Commons

{

/// <summary>

/// http访问拦截器模块

/// 1.过滤危险关键词

/// 2.增加安全Header

/// </summary>

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|new|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)"

};

string[] keyWords = { };

//{"'", "alert", "script","case","catch","const","continue","debugge","delete","export*","final","finally","for","function","Goto","if","implements","import*","return","switch","synchronized","throw","throws","transient","try","break"}

//new string[] { "select", "insert", "update", "delete", "drop", "truncate" };_RegexWords.AddRange(keyWords.Select(o => @"(^|(\W+))" + o + @"((\W+)|$)"));

}public void Dispose()

{

}public void Init(HttpApplication context)

{

context.BeginRequest += new EventHandler(Context_BeginRequest);

context.EndRequest += new EventHandler(Context_EndRequest);

}private void Context_BeginRequest(object sender, EventArgs e)

{

HttpApplication app = (HttpApplication) sender;

try

{

if (IgnoreRequest(app.Request.CurrentExecutionFilePath))

return;RequestFiller(app.Request);

AddHeader(app.Response);

}

catch (Exception ex)

{

if (!(ex is PSBaseException))

PSLog4net.Error(this, ex);

app.Response.Write(ex.Message);

app.Response.Flush();

app.Response.End();

}

}private void Context_EndRequest(object sender, EventArgs e)

{

HttpApplication app = (HttpApplication) sender;SetContentType(app);

}private void RequestFiller(HttpRequest request)

{

string error = "";if (request.Path.IndexOf("/log/", StrinGComparison.CurrentCultureIgnoreCase) >= 0)

error = "不允许访问/log/目录";

if (string.IsNullOrEmpty(error) &&

request.Path.IndexOf("/bak/", StringComparison.CurrentCultureIgnoreCase) >= 0)

error = "不允许访问/bak/目录";

if (string.IsNullOrEmpty(error))

{

foreach (string key in request.Params.AllKeys)

{

if (key == "aspxerrorpath")

continue;

string value = request.Params[key];

if (!string.IsNullOrEmpty(value) && (value.Contains("Jquery.alert") || value.Contains("image")))

continue;

if (!string.IsNullOrEmpty(key))

{

//if (Regex.IsMatch(key, @"\W+"))

//{

// error = string.FORMat("存在访问风险,参数[{0}={1}]无法通过“{2}”校验.", key, value, @"\W+");

// break;

//}

foreach (string regex in _RegexWords)

{

if (Regex.IsMatch(key, regex, RegexOptions.IgnoreCase))

{

error = $"存在访问风险,参数[{key}={value}]无法通过“{regex}”校验.";

break;

}

}

}if (!string.IsNullOrEmpty(error))

break;

if (!string.IsNullOrEmpty(value))

{

foreach (string regex in _RegexWords)

{

if (Regex.IsMatch(value, regex, RegexOptions.IgnoreCase))

{

error = $"存在访问风险,参数[{key}={value}]无法通过“{regex}”校验.";

break;

}

}

}if (!string.IsNullOrEmpty(error))

break;

}

}if (!string.IsNullOrEmpty(error))

{

Log4net.Error(this, error);

throw new PSBaseException("存在访问风险,请求无法通过系统校验规则.");

}

}private void AddHeader(HttpResponse response)

{}private void SetContentType(HttpApplication app)

{

if (app.Request.Url.AbsolutePath.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase))

app.Response.ContentType = "image/png";

if (string.IsNullOrEmpty(app.Response.ContentType))

app.Response.ContentType = "text/plain; charset=utf-8";

}private bool IgnoreRequest(string requestPath)

{

if (requestPath.EndsWith(".assx", StringComparison.CurrentCultureIgnoreCase) ||

requestPath.EndsWith(".sjs", StringComparison.CurrentCultureIgnoreCase) ||

requestPath.EndsWith(".asmx", StringComparison.CurrentCultureIgnoreCase))

return true;

else

return false;

}

}

}

asp网站空间有哪些特性_读书小站

本文收集自网络,侵删!

asp网站空间的特性有:1、能打破网页的静态功能,实现动态WEB技术;2、asp文件易于测试和修改;3、能执行多个任务,如EMaiL、对数据库的访问和对文件系统的访问;4、能防止ASP程序代码被盗;5、浏览器能浏览ASP生成的网页。

具体内容如下:

1、使用asp可以打破网页的静态功能,便于动态Web技术的实现。

2、asp文件是一个由html代码组成的文件,易于测试和修改。

3、ASP可以使用服务器组件执行多个任务,例如EMAIL、对数据库的访问和对文件系统的访问。

4、由于服务器以HTML格式将ASP程序执行结果发送回客户端浏览器,用户将看不到ASP编写的原始程序代码,从而防止ASP程序代码被盗。

5、服务器上的ASP解释器在服务器端编写ASP程序,并以HTML格式将结果发送给客户端浏览器。因此,各种浏览器通常都可以浏览ASP生成的网页。

怎么使用asp网站空间_读书小站

本文收集自网络,侵删!

使用 ASP 网站空间需要以下步骤:

1、获取 ASP 网站空间

选择合适的 ASP 网站空间服务商,注册账号并购买 ASP 网站空间。

2、配置 ASP 网站空间

登录 ASP 网站空间服务商提供的管理面板,进行空间的配置,包括 FTP 账号设置、数据库设置、域名绑定等。

3、开发 ASP 网站

使用 ASP 技术开发网站,包括 ASP 程序、ASP 页面、ASP 控件等。

4、上传网站文件

使用 FTP 工具将开发好的 ASP 网站文件上传到 ASP 网站空间中。

5、测试网站

通过访问 ASP 网站的 URL 地址,测试网站是否能够正常访问和运行。

需要注意的是,ASP 网站空间需要运行在 windows 操作系统上,因此需要选择支持 Windows 操作系统的 ASP 网站空间服务商。如果您不熟悉 ASP 技术,可以选择一些提供 ASP 网站模板或者 ASP 网站建设工具的服务提供商,以便更快速地完成 ASP 网站的开发和部署。