Original by fancyf (FancyRay)
I do this experiment because http://community.9cbs.net/expert/topic/3927/3927012.xml?temp=.3752405 I originally, .NET verification should be more secure, the generated cookie should also Related to this computer's unique parameter, it should be invalid on another computer. So is a username corresponding to a cookie value? Can I defraud form verification by counterfeiting a cookie value? Do a test. Web.config is modified as follows:
Login.aspx only one username input box txtusername, a password input box txtpassword and a submission button, the Click event is as follows:
1
IF
Formsauthentication.authenticate
THIS
.txtusername.text,
THIS
.txtPassword.text)))
2
...
{3 Formsauthentication.RedirectFromLoginPage (this.txtusername.text, true); 4}
5
Else
6
...
{7 response.write ("login denied"); 8}
With IEHTTPHEADERS
http://www.blunch.info/) It can be seen that a cookie similar to this is added after verification:
MyLab = 3FF83247C29EB5D14D61F389D453EEE0586B94E27609C321B017BE7B88D1A94D249996428A7A18F5C2D69F3C4DD2B88C00172CAFB0B4B4ED8784DB62D1D61BCC0C786B4EA7868FC6
It seems that this is the cookie after encryption. Below you have to change a computer, set this value to cookie to see if Forms verification is required.
Plus such a sentence in the login.aspx page:
document.cookie = "MyLab = 3FF83247C29EB5D14D61F389D453EEE0586B94E27609C321B017BE7B88D1A94D249996428A7A18F5C2D69F3C4DD2B88C00172CAFB0B4B4ED8784DB62D1D61BCC0C786B4EA7868FC6";
script>
This will automatically join this cookie as soon as one open the login.aspx page.
Another computer: Enter another page under the same WebApplication (should automatically jump to the login.aspx page)
http://10.0.0.7/upload.aspx, then successfully jumped to http://10.0.0.7/login.aspx?returnurl=/UPLOAD.ASPX, normal. At this point, the value of cookie should have taken effect. Then let's enter the URL just now.
http://10.0.0.7/upload.aspx!
According to my guess, I will definitely jump to the login.aspx page, because the cookie is generated on another computer. Actual, there is no jump! The content of UPLOAD.ASPX is completely displayed! And we have not logged in this computer, even we don't even know the username!
I returned to 10.0.0.7 This computer added a Page_Load () first line of the UPLOAD.ASPX page: response.write (user.Identity.Name);, refresh the UPLOAD displayed on another computer. ASPX, the result also appeared in FancyRay, which is my username.
This shows that cookie's encryption does not depend on the login computer. In other words, once your cookie is obtained by others, he may get your permissions on this server.
So what is the value of cookie? Does the hacker have to get this value without the exhaustion?
Let's first take a look at what is stored in cookies, and how to encrypt. Reflactor (http://www.aisto.com/roeder/dotnet) played! public static void SetAuthCookie (string userName, bool createPersistentCookie, string strCookiePath) {FormsAuthentication.Initialize (); HttpContext.Current.Response.Cookies.Add (FormsAuthentication.GetAuthCookie (userName, createPersistentCookie, strCookiePath));}
public static HttpCookie GetAuthCookie (string userName, bool createPersistentCookie, string strCookiePath) {FormsAuthentication.Initialize (); if (userName == null) {userName = "";} if ((strCookiePath == null) || (strCookiePath.Length < 1)) {strCookiePath = FormsAuthentication.FormsCookiePath;} FormsAuthenticationTicket ticket1 = new FormsAuthenticationTicket (1, userName, DateTime.Now, createPersistentCookie DateTime.Now.AddYears (50): DateTime.Now.AddMinutes ((double?) FormsAuthentication._Timeout), createPersistentCookie, "", strCookiePath); string text1 = FormsAuthentication.Encrypt (ticket1); FormsAuthentication.Trace ( "ticket is" text1); if ((text1 == null) || (text1.Length <1)) {throw new HttpException (HttpRuntime.FormatResourceString ( "Unable_to_encrypt_cookie_ticket"));} HttpCookie cookie1 = new HttpCookie (FormsAuthentication.FormsCookieName, text1); cookie1.Path = strCookiePath; cookie1.Secure = FormsAuthentication._RequireSSL; if (ticket1.IsPersistent) {cookie1.Expires = ticket1.Expiration;} return cookie1;} inside text1 Cookie value is stored, text1 is a string text1 = FormsAuthentication.Encrypt ( Ticket1); generated, so information in TEXT1 is Ticket1. FormsAuthenticationTicket prototype constructor is: public FormsAuthenticationTicket (int version, string name, DateTime issueDate, DateTime expiration, bool isPersistent, string userData, string cookiePath) inside a username, generation time and the expiration time ticket1. I can't help but hit it here.
Ticket1 actually only uses a key information of the username, and even the password is useless! Isn't this a user's Ticket1 can be easily manufactured? Just get the value of the cookie by Formsauthentication.encrypt (Ticket1), to the assumption of any one of the users? too frightening. Now I can only hope that the encrypt function is.
See in its implementation: public static string Encrypt (FormsAuthenticationTicket ticket) {if (ticket == null) {throw new ArgumentNullException ( "ticket");} FormsAuthentication.Initialize (); byte [] buffer1 = FormsAuthentication.MakeTicketIntoBinaryBlob (ticket) ; if (buffer1 == null) {return null;} if (FormsAuthentication._Protection == FormsProtectionEnum.None) {return MachineKey.ByteArrayToHexString (buffer1, 0);} if ((FormsAuthentication._Protection == FormsProtectionEnum.All) || (FormsAuthentication._Protection == FormsProtectionEnum.Validation)) {byte [] buffer2 = MachineKey.HashData (buffer1, null, 0, buffer1.Length); if (buffer2 == null) {return null;} FormsAuthentication.Trace ( "Encrypt : Mac Length Is: " Buffer2.Length); BYTE [] Buffer3 = New Byte [Buffer2.Length Buffer1.Length]; Buffer.blockcopy (Buffer1, 0, buffer3, 0, buffer1.Length); Buffer.BlockCopy (buffer2, 0, buffer3, buffer1.Length, buffer2.Length); if (FormsAuthentication._Protection == FormsProtectionEnum.Validation) {return MachineKey.ByteArrayToHexString (buffer3, 0 );} buffer1 = buffer3;} buffer1 = MachineKey.EncryptOrDecryptData (true, buffer1, null, 0, buffer1.Length); return MachineKey.ByteArrayToHexString (buffer1, buffer1.Length);} MachineKey saw the word finally loose a Tone. It seems that the addendal process is related to the parameters of the server. That is, there is your own key on the server, only this key can be cookied. If you don't know this key, others are unable to fake cookies.
It seems that cookie is still safe, and it is not in the premise of your computer. As with any other information, the required attention is only the security in network transmission. The value of cookie is the same as SessionID, which may cause security issues once it is guess. But it is different from sessionid because sessionID is always short, and the value of cookie may be still valid. The length of the cookie value also makes us a little bit a little. There is still a problem that it is not ignored. Although the generation of cookie is related to the specific time, that is, the cookies generated after I log in again, but a legal cookie value is permanently valid, and does not change the impact of passwords and time. In other words, I will still be used on another computer after I log out, as long as the server's MachineKey does not change. It is indeed a security hazard. We can only say: "The value of cookie is very long, and it is necessary to exhaust a valid cookie to find some comfort. Passwords can further reduce the likelihood of extremely via, but legitimate cookies cannot be changed. The password is unique, but the legal cookie value is not unique. All of this always feels unassay. Maybe worry is extra, because the electronic signature, the certificate is based on "exhaustion to pay a lot of money". If you consider "happening to", you will not exist. I believe it is still enough for the security level of the Forms generated cookie in the general security field. Use it with confidence! (Another article that is worthless, when you haven't seen it well)
(Test Environment: Windows 2003, .NET Framework 1.1 SP1)