Security of cookies generated by the ASP.net forms authentication
I did this experiment because of http://community.csdn.net/expert/topic/3927/3927012.xml?temp=.3752405.
At first I thought,. NET authentication should be relatively safe, the generated cookies should be related to the unique parameters of this computer, to get another computer should be invalid. So is a username corresponding to a cookie value? Is it possible to cheat form validation by falsifying cookie values? Do some experiments.
Web.config
<authentication mode= "Forms" >
<forms name= "Mylab" loginurl= "/login.aspx" >
<credentials passwordformat= "Clear" >
<user name= "Fancyray" password= "Fancyray"/>
</credentials>
</forms>
</authentication.
<authorization>
<deny users= "?"/>
</authorization>
Login.aspx only a username input box txtusername, a password input box txtpassword and a Submit button, click the event as follows:
if (FormsAuthentication.Authenticate (This.txtusername.text, This.txtpassword.text))
{
FormsAuthentication.RedirectFromLoginPage (This.txtusername.text, true);
else
{
Response.Write ("Login denied");
}
With the help of Iehttpheaders (http://www.blunck.info/), you can see that a cookie like this has been added after validation:
mylab= 3ff83247c29eb5d14d61f389d453eee0586b94e27609c321b017be7b88d1a94d249996428a7a18f5c2d69f3c4dd2b88c00172cafb0b4b4ed8784db62d 1d61bcc0c786b4ea7868fc6
It seems that this is the encryption of the cookie later. To change the computer below, set this value directly to a cookie to see if forms validation is required.
Add the following sentence to the Login.aspx page:
<script language=javascript>
document.cookie= "mylab= 3ff83247c29eb5d14d61f389d453eee0586b94e27609c321b017be7b88d1a94d249996428a7a18f5c2d69f3c4dd2b88c00172cafb0b4b4ed8784db62d 1d61bcc0c786b4ea7868fc6 ";
</script>
This will automatically add this cookie as soon as you open the Login.aspx page.