xss漏洞修复,待完善
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漏洞修复,待完善的更多相关文章
- php xss漏洞修复用手段和用到的一些函数
php xss漏洞修复用到的一些函数 $text = '<p>"Test paragraph".</p><!-- Comment --> < ...
- 1.5 xss漏洞修复
1.XSS漏洞修复 从上面XSS实例以及之前文章的介绍我们知道XSS漏洞的起因就是没有对用户提交的数据进行严格的过滤处理.因此在思考解决XSS漏洞的时候,我们应该重点把握如何才能更好的将用户提交的数据 ...
- Struts网站基于Filter的XSS漏洞修复
下面的代码只支持struts2框架中的xss漏洞 第一步,创建过滤器XssFilter : package com.ulic.ulcif.filter; import java.io.IOExcept ...
- dedecms5.7最新漏洞修复
最近发现织梦cms被挂马现象频繁,解决好好几个网站的问题,但是过不了多久,就又被攻击了,即使更改系统及ftp密码,也没有起到防御的作用,最后怀疑cms本身漏洞,于是采用工具扫描了一下,才发现问题的严重 ...
- 利用窗口引用漏洞和XSS漏洞实现浏览器劫持
==Ph4nt0m Security Team== Issue 0x03, Phile #0x05 of 0x07 |=----------------- ...
- (汉化改进作品)BruteXSS:Xss漏洞扫描脚本
今天给大家进行汉化改进的事一款脚本工具:BruteXSS,这款脚本能自动进行插入XSS,而且可以自定义攻击载荷. 该脚本也同时提供包含了一些绕过各种WAF(Web应用防护系统)的语句. 0×01简 ...
- Web常见漏洞修复建议
一.SQL注入修复建议 1.过滤危险字符,例如:采用正则表达式匹配union.sleep.and.select.load_file等关键字,如果匹配到则终止运行. 2.使用预编译语句,使用PDO需要注 ...
- Xss漏洞原理分析及简单的讲解
感觉百度百科 针对XSS的讲解,挺不错的,转载一下~ XSS攻击全称跨站脚本攻击,是为不和层叠样式表(Cascading Style Sheets, CSS)的缩写混淆,故将跨站脚本攻击缩写为XS ...
- 教你玩转XSS漏洞
什么是存储性XSS那? 通俗理解就是”xss“语句存在服务器上,可以一直被客户端浏览使用,所有登陆某一个存在”存储性xss“的页面的人,都会中招,可以是管理员,可以是普通的用户,所以他的危害是持续性的 ...
随机推荐
- MVC分页
http://www.cnblogs.com/iamlilinfeng/p/4075292.html 目录 一.Contrl与View数据传递(多表数据) 二.分页控件介绍 三.MVC源码说明 四.源 ...
- centos6.5 卸载php
1.删除php,删除之前需要查看php依赖包,使用 rpm -qa|grep php [root@localhost ~]# rpm -qa |grep phpphp55w-mysql-5.5.38- ...
- JavaScript中让Html页面中循环播放文字
JavaScript中让Html页面中循环播放文字 <html> <head> <meta http-equiv="Content-Type" con ...
- UP Board 妄图启动ubilinux失败
前言 原创文章,转载引用务必注明链接. 经历了上次的上电开机失败,我们终于发现需要手动为UP板安装系统,因为没有显示器的Headless模式时,使用Linux比较方便,另外熟悉Debian系的,所以选 ...
- redis 操作 hash 的测试
1>hset setname field value hset stuSet name zhangsan:1 2>hget setname field hget stuset ...
- mysql myisam简单分表设计
一般来说,当我们的数据库的数据超过了100w记录的时候就应该考虑分表或者分区了,这次我来详细说说分表的一些方法.目前我所知道的方法都是MYISAM的,INNODB如何做分表并且保留事务和外键,我还不是 ...
- Canvas绘制时钟
①首先在HTML的body标签中添加一个canvas标签,用于绘制时钟. <canvas id="myCanvas" width="600" height ...
- CSS 7阶层叠水平
著名的7阶层叠水平(stacking level) 层叠上下文 background/border 负z-index block块状水平盒子:正常流失布局,非inline-block,无positio ...
- 使用axis开发web service服务端
一.axis环境搭建 1.安装环境 JDK.Tomcat或Resin.eclipse等. 2.到 http://www.apache.org/dyn/closer.cgi/ws/axis/1_4下载A ...
- HTML 语义化之b_i_em_strong
默认效果 i和em都是斜体.b和strong都是加粗. 语义区别: em 和 strong 分别表示句中强调和全局加重强调 搜索引擎中更受重视,一些语音阅读器也会根据它在阅读时加强语气. i 和 b ...