博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
在ASP.NET MVC中如何预防Cookie的窃取攻击(转载)
阅读量:5160 次
发布时间:2019-06-13

本文共 3064 字,大约阅读时间需要 10 分钟。

Cookie is a small piece of data sent by a web server to a web browser. The browser stores this data in a text file. This data is sent by the browser to the web server each time it requests a page from that server.

Cookies store information like your site preferences or history so that they can customize the page for you, every time you request it. So that information is usually not what attacker cares about. Cookies are also used to store information that uniquely identify the user such as the Authentication Ticket. That's more luring to the attacker ;) If the attacker can steal someone's authentication cookie they can simply get access to the complete account.

In order to steal the cookie, the attacker can write a script which reads all the cookies and sends it to the attacker. If you search about it on google, you can find plenty of scripts that read all the cookies and send it to a specific server. I also discussed about XSS attack in my previous blog post here. If the site is XSS vulnerable, the attacker's task is made easy. He can simply get the script executed on anyone's machine and get all the cookies.

Once the attacker gets the authentication cookie, he can copy the Session Id/ Username, etc and plug that information into his own browser and get access to the victim's account. Isn't it simple?

How to Prevent?

In order to prevent the scripts to access the cookies we need to set the flag called HttpOnly to true. This allows the scripts to be accessed only by Http and disables all kinds of script access. We can set this flag at the application level in system.web section in web.config like this:

If we need to set it at per cookie level, we can set it like this:

Response.Cookies["ImpCookie"].HttpOnly=true;

Conclusion

Cookies can store valuable information and should be protected. We should set the cookie access to HttpOnly in order to prevent their access from malicious scripts.

扩展

On the system.web/authentication/forms element:

requireSSL = true.

This requires that the cookie only be transmitted over SSL

slidingExpiration = false.

When true, an expired ticket can be reactivated.

cookieless = false.

Do not use cookieless sessions in an environment where are you trying to enforce security.

enableCrossAppRedirects = false.

When false, processing of cookies across apps is not allowed.

protection = all.

Encrypts and hashes the Forms Auth cookie using the machine key specified in the machine.config or web.config. This feature would stop someone from hacking their own cookie as this setting tells the system to generate a signature of the cookie and on each authentication request, compare the signature with the passed cookie.

If you so wanted, you could add a small bit of protection by putting some sort of authentication information in Session such as a hash of the user's username (Never the username in plain text nor their password). This would require the attacker to steal both the Session cookie and the Forms Auth cookie.

转载于:https://www.cnblogs.com/wxlevel/p/7691186.html

你可能感兴趣的文章
wcf可以返回的类型有哪些
查看>>
Android 基础Intent与Intent Filter
查看>>
Invalid AABB inAABB UnityEngine.Canvas:SendWillRenderCanvases()的解决办法
查看>>
poj1083
查看>>
500.19与500.20错误
查看>>
LUOGU P2709 小B的询问
查看>>
Python Elasticsearch api
查看>>
The Most Important Code Isn't Code
查看>>
Android-活动生命周期&Bundle回收临时数据&活动启动模式&常用技巧
查看>>
springmvc controller Date数据 400错误
查看>>
《京东峰值系统设计》有感
查看>>
网络原理以及常用工具 git Linux Maven等~
查看>>
jQuery Mobile 学习
查看>>
JavaWeb中jsp路径斜杆(/)跟没斜杆的路径映射问题
查看>>
如何强制ffmpeg编码时输出一个关键帧
查看>>
apicloud+融云实现即时通讯
查看>>
CentOS7 设置开机自启
查看>>
数塔-动态规划
查看>>
HDU 1210 Eddy's 洗牌问题(找规律,数学)
查看>>
[MySQL5.6] 最近对group commit的小优化
查看>>