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. PHP安装kafka插件

    在工作中我们经常遇到需要给php安装插件,今天把php安装kafka的插件的步骤整理下,仅供大家参考 1:需要先安装librdkafka git clone https://github.com/ed ...

  2. React视角下的轮播图

    天猫购物网站最显眼的就是轮播图了.我在学习一样新js库,一个新框架或新的编程思想的时候,总是感叹"入门必做选项卡,进阶须撸轮播图."作为一个React组件,它是状态操控行为的典型, ...

  3. 调用Interop.zkemkeeper.dll无法使用解决方案

    调用Interop.zkemkeeper.dll无法使用 已经注册dll成功但是还是报错 检索 COM 类工厂中 CLSID 为 {00853A19-BD51-419B--2DABE57EB61F} ...

  4. JSP内置对象之request对象【学习笔记】

    request对象是JSP中重要的对象,每个request对象封装着一次用户的请求,并且所有的请求参数都被封装在request对象中,因此request对象是获取请求参数的重要途径. 一.获取请求头与 ...

  5. 使用axis开发web service服务端

    一.axis环境搭建 1.安装环境 JDK.Tomcat或Resin.eclipse等. 2.到 http://www.apache.org/dyn/closer.cgi/ws/axis/1_4下载A ...

  6. C/C++头文件使用 #ifndef #define #endif 的原因

    背景 在编译的时候,出现"redefine"的错误,最后检查才发现对应的头文件没有写正确的预编译信息: #ifndef _HeadFileName_H #define _HeadF ...

  7. 微信小程序与传统APP十大优劣对比

    随着微信公众平台的开放,微信端小程序涌现市场,带来很很多便利和简单的原生操作,询:微信端小程序是否会替代传统的APP应用?两者的优劣如何?我们一起来看看传统APP与微信端小程序十大优劣对比       ...

  8. Mac Pro 编译安装 Redis 的 PHP 客户端 phpredis

    1.去官网下载 redis 扩展源码包 https://github.com/phpredis/phpredis 2.安装 redis 扩展 /usr/local/src/mac-sdk/source ...

  9. HTML5 Canvas 绘图

    首先要注意: <canvas> 元素不被一些老的浏览器所支持, 但被支持于Firefox 1.5+, Opera 9+, 新版本的Safari, Chrome, 以及Internet Ex ...

  10. Wix打包技术学习笔记

    http://blog.csdn.net/duanzilin/article/details/5951709 很好的教程,有时间好好学习一下.然后自己整理笔记,暂时不打算深入研究