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“的页面的人,都会中招,可以是管理员,可以是普通的用户,所以他的危害是持续性的 ...
随机推荐
- SolrQuery的使用
查询的总结:一般查询分为以下几个步骤: 1.创建查询对象 2.创建查询条件 3.执行查询,这里注意要有返回值 4.对查询结果进行取出 public void queryDocument() throw ...
- JS中class和id的区别
class和id的区别 class用于css的,id用于js的. 1)class页面上可以重复.id页面上唯一,不能重复. 2)一个标签可以有多个class,用空格隔开.但是id只能有id.
- Web Service和WCF的区别。其实二者不属于一个范畴!!!
Web Service和WCF的区别 [1]Web Service:严格来说是行业标准,也就是Web Service 规范. 它有一套完成的规范体系标准,而且在持续不断的更新完善中. 它使用XML扩展 ...
- 入门:Java Map<String,String>遍历及修改
重点:在使用Map时注意key-value,key用于检索value的内容. 在正常情况下,可以不允许重复:在java中分为2中情况,一是内存地址重复,另一个是不同的地址但内容相等. 在使用Map是一 ...
- NFS 文件系统
NFS的安装是非常简单的,只需要两个软件包即可,而且在通常情况下,是作为系统的默认包安装的. NFS服务的主要配置文件 /etc/exports /etc/exports文件内容格式: <输出目 ...
- highcharts去掉版权|去掉水印链接(右下角)_
credits: { enabled: false }
- Java面试题总结 from Baidu 网易 阿里
参加了几场面试,小结下问题: Java 运行时内存模型,最好能画出来 Java 分代GC的原理,JVM中的集中GC 算法 基本多线程的方法和原理 HashMap ConcurrentHashMap怎 ...
- 2.2、Hibernate用注解方式实现一对多、多对多关系
一.一对多关系 1.在上一篇日志中用.xml配置文件项目基础上,再往lib目录先添加一个包-hibernate-jpa-2.0-api-1.0.0.Final.jar 2.新建一个com.st.bea ...
- rcu机制
转载自:再谈Linux内核中的RCU机制-MagicBoy2010-ChinaUnix博客 http://blog.chinaunix.net/uid-23769728-id-3080134.html ...
- 在sql语句中使用 xml for path 格式化字符串的方法总结
此方法实现的是将查询表中的某个字段,格式化成 字符串1,字符串2,字符串3...的格式 假设我们现在有两个表 分别是 分组表 grouped和分组成员表 groupuser grouped表有连个字 ...