1.防止sql注入

 /// <summary>
/// 分析用户请求是否正常
/// </summary>
/// <param name="Str">传入用户提交数据</param>
/// <returns>返回是否含有SQL注入式攻击代码</returns>
///
private bool ProcessSqlStr(string Str)
{
bool ReturnValue = true;
try
{
if (!string.IsNullOrWhiteSpace(Str))
{
Str = Str.Replace("/*", "");
Str = Str.Replace("*/", "");
Str = Str.ToLower();
string SqlStr = "and |exec |insert |select |delete |update |count | * |chr |mid |master |truncate |char |declare ";
string[] anySqlStr = SqlStr.Split('|');
foreach (string ss in anySqlStr)
{
if (Str.IndexOf(ss) >= )
{
ReturnValue = false;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}

2.防止xss注入

   private bool ProcessXSSStr(string Str)
{
bool ReturnValue = true;
try
{
if (!string.IsNullOrWhiteSpace(Str))
{
Str = Str.Replace("/*", "");
Str = Str.Replace("*/", "");
Str = Str.ToLower();
string[] anyXSSStr = {"javascript", "vbscript", "script","alert(","expression("
,"onabort", "onactivate", "onafterprint", "onafterupdate", "onbeforeactivate", "onbeforecopy", "onbeforecut", "onbeforedeactivate", "onbeforeeditfocus", "onbeforepaste", "onbeforeprint", "onbeforeunload", "onbeforeupdate", "onblur",
"onbounce", "oncellchange", "onchange", "onclick", "oncontextmenu", "oncontrolselect", "oncopy", "oncut", "ondataavailable", "ondatasetchanged", "ondatasetcomplete", "ondblclick", "ondeactivate", "ondrag", "ondragend", "ondragenter",
"ondragleave", "ondragover", "ondragstart", "ondrop", "onerror", "onerrorupdate", "onfilterchange", "onfinish", "onfocus", "onfocusin", "onfocusout", "onhelp", "onkeydown", "onkeypress", "onkeyup", "onlayoutcomplete", "onload",
"onlosecapture", "onmousedown", "onmouseenter", "onmouseleave", "onmousemove", "onmouseout", "onmouseover", "onmouseup", "onmousewheel", "onmove", "onmoveend", "onmovestart", "onpaste", "onpropertychange", "onreadystatechange",
"onreset", "onresize", "onresizeend", "onresizestart", "onrowenter", "onrowexit", "onrowsdelete", "onrowsinserted", "onscroll", "onselect", "onselectionchange", "onselectstart", "onstart", "onstop", "onsubmit", "onunload"};
foreach (string ss in anyXSSStr)
{
if (Str.IndexOf(ss) >= )
{
ReturnValue = false;
}
}
}
}
catch
{
ReturnValue = false;
}
return ReturnValue;
}

3.对http请求进行拦截处理,上下文根据程序进行修改

 public System.Web.Mvc.ActionResult Execute(Page_Context pageViewContext, PagePositionContext positionContext)
{
if (pageViewContext.ControllerContext.HttpContext.Request.Form != null)
{
for (int i = ; i < pageViewContext.ControllerContext.HttpContext.Request.Form.Keys.Count; i++)
{
string getkeys = pageViewContext.ControllerContext.HttpContext.Request.Form.Keys[i];
string str = pageViewContext.ControllerContext.HttpContext.Request.Form[getkeys];
if (!ProcessSqlStr(str))
{
pageViewContext.ControllerContext.HttpContext.Response.Redirect("~/safe_error");
pageViewContext.ControllerContext.HttpContext.Response.End();
}
}
} if (pageViewContext.ControllerContext.HttpContext.Request.QueryString != null)
{
string url = pageViewContext.ControllerContext.HttpContext.Request.Url.AbsoluteUri; if (!ProcessXSSStr(url))
{
pageViewContext.ControllerContext.HttpContext.Response.Redirect("~/safe_error");
pageViewContext.ControllerContext.HttpContext.Response.End();
} for (int i = ; i < pageViewContext.ControllerContext.HttpContext.Request.QueryString.Count; i++)
{
string getkeys = pageViewContext.ControllerContext.HttpContext.Request.QueryString.Keys[i]; string str = pageViewContext.ControllerContext.HttpContext.Request.Form[getkeys]; if (!ProcessXSSStr(getkeys))
{
pageViewContext.ControllerContext.HttpContext.Response.Redirect("~/safe_error");
pageViewContext.ControllerContext.HttpContext.Response.End();
} if (!ProcessSqlStr(str))
{
pageViewContext.ControllerContext.HttpContext.Response.Redirect("~/safe_error");
pageViewContext.ControllerContext.HttpContext.Response.End();
} }
}
return null;
}

其他方法:

antixss:      http://www.cnblogs.com/coderzh/archive/2010/06/24/1764725.html

https://msdn.microsoft.com/en-us/library/aa973813.aspx

xss漏洞修复,待完善的更多相关文章

  1. php xss漏洞修复用手段和用到的一些函数

    php xss漏洞修复用到的一些函数 $text = '<p>"Test paragraph".</p><!-- Comment --> < ...

  2. 1.5 xss漏洞修复

    1.XSS漏洞修复 从上面XSS实例以及之前文章的介绍我们知道XSS漏洞的起因就是没有对用户提交的数据进行严格的过滤处理.因此在思考解决XSS漏洞的时候,我们应该重点把握如何才能更好的将用户提交的数据 ...

  3. Struts网站基于Filter的XSS漏洞修复

    下面的代码只支持struts2框架中的xss漏洞 第一步,创建过滤器XssFilter : package com.ulic.ulcif.filter; import java.io.IOExcept ...

  4. dedecms5.7最新漏洞修复

    最近发现织梦cms被挂马现象频繁,解决好好几个网站的问题,但是过不了多久,就又被攻击了,即使更改系统及ftp密码,也没有起到防御的作用,最后怀疑cms本身漏洞,于是采用工具扫描了一下,才发现问题的严重 ...

  5. 利用窗口引用漏洞和XSS漏洞实现浏览器劫持

    ==Ph4nt0m Security Team==                        Issue 0x03, Phile #0x05 of 0x07 |=----------------- ...

  6. (汉化改进作品)BruteXSS:Xss漏洞扫描脚本

    今天给大家进行汉化改进的事一款脚本工具:BruteXSS,这款脚本能自动进行插入XSS,而且可以自定义攻击载荷. 该脚本也同时提供包含了一些绕过各种WAF(Web应用防护系统)的语句.   0×01简 ...

  7. Web常见漏洞修复建议

    一.SQL注入修复建议 1.过滤危险字符,例如:采用正则表达式匹配union.sleep.and.select.load_file等关键字,如果匹配到则终止运行. 2.使用预编译语句,使用PDO需要注 ...

  8. Xss漏洞原理分析及简单的讲解

    感觉百度百科 针对XSS的讲解,挺不错的,转载一下~   XSS攻击全称跨站脚本攻击,是为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XS ...

  9. 教你玩转XSS漏洞

    什么是存储性XSS那? 通俗理解就是”xss“语句存在服务器上,可以一直被客户端浏览使用,所有登陆某一个存在”存储性xss“的页面的人,都会中招,可以是管理员,可以是普通的用户,所以他的危害是持续性的 ...

随机推荐

  1. ionic 发布 inoc显示不正确

    前两天因为学习的问题,把本地环境给搞崩了,然后重新安装环境之后发现生成的安装包不能使用,然后找了很多原因都不能解决,因为之前发布ios的时候使用命令 ionic resources的时候就可以将图标显 ...

  2. Web API系列(二)接口安全和参数校验

    以前简单介绍过web api 的设计,但是还是有很多朋友问我,如何合理的设计和实现web api.比如,接口安全,异常处理,统一数据返回等问题.所以有必要系统的总结总结 web api 的设计和实现. ...

  3. [01] cocos2d-x开发环境搭建

    cocos2d-x 是跨平台的游戏开发引擎,支持的平台有 ios , android , windows phone , web , tizen,windows等. 先来搭建开发环境,一般我们开发游戏 ...

  4. 利用vim查看日志,快速定位问题

    起因 在一般的情况下,如果开发过程中测试报告了一个问题,我一般会这么做: 1.在自己的开发环境下重试一下测试的操作,看看能不能重现问题.不行转2 2.数据库连接池改成测试库的地址,在自己的开发环境下重 ...

  5. python和数据科学(Anaconda)

    Python拥有着极其丰富且稳定的数据科学工具环境.遗憾的是,对不了解的人来说这个环境犹如丛林一般(cue snake joke).在这篇文章中,我会一步一步指导你怎么进入这个PyData丛林. 你可 ...

  6. 学习MySQL之数据类型(四)

    一.   整数类型: 整数类型 占用字节 最小值 最大值 TINYINT 1 有符号 -128 无符号0 有符号127 无符号255 SMALLINT 2 有符号-3 2768 无符号0 有符号3 2 ...

  7. 用R做逻辑回归之汽车贷款违约模型

    数据说明 本数据是一份汽车贷款违约数据 application_id    申请者ID account_number 账户号 bad_ind            是否违约 vehicle_year  ...

  8. [从产品角度学EXCEL 02]-EXCEL里的树形结构

    这是<从产品角度学EXCEL>系列第三篇. 前言请看: 0 为什么要关注EXCEL的本质 1 excel是怎样运作的 或者你可以去微信公众号@尾巴说数 获得连载目录. 本文仅由尾巴本人发布 ...

  9. html 杂记

    <link rel="******"  href=“****.css” type=“text/css”  media=“screen” />css样式外部链接 加个斜杠 ...

  10. hdu4405 Aeroplane chess

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...