Skip to main content

Session Fixation


Session Fixation is an attack that permits an attacker to hijack a valid user session. The attack explores a limitation in the way the web application manages the session ID, more specifically the vulnerable web application. When authenticating a user, it doesn’t assign a new session ID, making it possible to use an existent session ID. The attack consists of obtaining a valid session ID (e.g. by connecting to the application), inducing a user to authenticate himself with that session ID, and then hijacking the user-validated session by the knowledge of the used session ID. The attacker has to provide a legitimate Web application session ID and try to make the victim's browser use it.



Session Fixation Protection

The idea is that, since ASP prohibits write access to the ASPSESSIONIDxxxxx cookie, and will not allow us to change it in any way, we have to use an additional cookie that we do have control over to detect any tampering. So, we set a cookie in the user's browser to a random value, and set a session variable to the same value. If the session variable and the cookie value ever don't match, then we have a potential fixation attack, and should invalidate the session, and force the user to log on again.


In the Logout function, ensure that you are removing this new Cookie “AuthCookie” as well. To remove this cookie, simply set its expiration date time to a few months earlier than the current date time

Sample Code to fix Session fixation

Step: 1 Add below code in page load even of landing page.
if (Session["AuthToken"] == null && Request.Cookies["AuthToken"] == null)
{
string guid = Guid.NewGuid().ToString();
Session["AuthToken"] = guid;
// now create a new cookie with this guid value
Response.Cookies.Add(new HttpCookie("AuthToken", guid));
}

Step: 2 Add below code in master page load event.
if (Session["AuthToken"] != null && Request.Cookies["AuthToken"] != null)
{
if (!Session["AuthToken"].ToString().Equals(Request.Cookies["AuthToken"].Value))
Response.Redirect("Logon.aspx");
}
else
Response.Redirect("Login.aspx");

Step: 3 Add below code in logout click event.
Session.Clear();
Session.Abandon();
Session.RemoveAll(); 


How to Test?

Step: 1 Load the page and get the session ID and Authtoken as shown in below screen

Step: 2 tampering the session ID and AuthToken 

Step: 3 submit the request or redirect to other page.


 It will redirect to login page as Asp.Net_SessionId and AuthToken is not valid.




Comments

Popular posts from this blog

Product/Application/ Software Security Testing

Product/Application/ Software Security Testing Application Security testing is the process to find security issues or security vulnerability in the application using automated and manual security scanner tools and share the identified issues or risk with development or application team. Process will remain mostly same in all the different types of application security scan. Before initiating security scan, its always good to identify the boundary and scope of your security testing.  Below are the few example of which we can consider as Application or software. ( Scope for Application Security Testing) Web Application, Portal. Web API. Desktop Software / Thick Client. Mobile Application. Web Services.  Plug in, Add-On The goal of application security is to secure the application and prevent the unwanted damaged. The process of performing security scan or audit is know as ASA (Application Security Assessment). Generally there are three types of ASA, SAST, DAST and PT. 

Password Protected File Validation for(.doc/.docx/.xls/.xlsx/.pdf) file types

Password Protected File Validation for(.doc/.docx/.xls/.xlsx/.pdf) file types protected void btnUpload_Click( object sender, EventArgs e)         {             //Check if File Upload control has file or not             if (FileUpload1.HasFile)             {                 //Get Uploaded file bytes                 var bytes = FileUpload1.FileBytes;                 //Get Uploaded File Extension                 FileInfo objFileInfo = new FileInfo (FileUpload1.FileName);                 string StrFileExt = objFileInfo.Extension.ToUpper();                                 //Based on the File extension call appropriate user defined method.                 //For PDF file type                 if (StrFileExt == ".PDF" )                 {                     //Upload and save file in server temp folder                     var newfilename = DateTime .Now.GetHashCode() + FileUpload1.FileName;                     FileUpload1.SaveAs(Syst

Cyber Security Best Practice for daily use

Below are some of observations and Cyber security best practices for daily use. If you are secure,  safe and healthy so you can make others as well. What we practice everyday it becomes our habit.  if you follow some basic and standard practice which may avoid some possible damage or loss. Email ID and Mobile Number:   Manage separate Email-Id and mobile number for your banking and such important activities, avoid sharing this Email-Id with anyone. Login to such email id in separate browser or use incognito mode.  Opt for second factor authentication for your personal email id, banking to add extra layer of security.  Use of basic phone for banking mobile number (SIM card).  Banking: Avoid sharing banking, bank account details.  Avoid storing card pin, card number, CVV number, banking details or banking cerdentials on insecure file or storage.  Make a habit of changing banking password more frequently.  Deactivate unused or inactive credit card, Debit Card.  Ava