Attack scenarios
http://unsafe.example.com/
Mallory intends to target Alice's money from her bank.
Alice has a reasonable level of trust in Mallory, and will visit links Mallory sends her.
A simple attack scenario
Straightforward scenario: # Mallory has determined thathttp://unsafe.example.com/
accepts any session identifier, accepts session identifiers from query strings and has no security validation. http://unsafe.example.com/
is thus not secure.
# Mallory sends Alice an e-mail: "Hey, check this out, there is a cool new account summary feature on our bank, http://unsafe.example.com/?SID=I_WILL_KNOW_THE_SID
". Mallory is trying to fixate the SID to I_WILL_KNOW_THE_SID
.
# Alice is interested and visits http://unsafe.example.com/?SID=I_WILL_KNOW_THE_SID
. The usual log-on screen pops up, and Alice logs on.
# Mallory visits http://unsafe.example.com/?SID=I_WILL_KNOW_THE_SID
and now has unlimited access to Alice's account.
Attack using server generated SID
A misconception is that if a server only accepts server-generated session identifiers, it is safe from fixation. This is false. Scenario: # Mallory visitshttp://vulnerable.example.com/
and checks which SID is returned. For example, the server may respond: Set-Cookie: SID=0D6441FEA4496C2
.
# Mallory is now able to send Alice an e-mail: "Check out this new cool feature on our bank, http://vulnerable.example.com/?SID=0D6441FEA4496C2
."
# Alice logs on, with fixated session identifier SID=0D6441FEA4496C2
.
# Mallory visits http://vulnerable.example.com/?SID=0D6441FEA4496C2
and now has unlimited access to Alice's account.
Attacks using cross-subdomain cookie
This type of attack is similar to a cross-site cookie attack except that, it does not rely on the vulnerability of the user's browser. Rather, it relies on the fact that wildcard cookies can be set by a subdomain and, that those cookies may affect other subdomains. Scenario: # A web sitewww.example.com
hands out subdomains to untrusted third parties
# One such party, Mallory, who now controls evil.example.com
, lures Alice to his site
# A visit to evil.example.com
sets a session cookie with the domain .example.com
on Alice's browser
# When Alice visits www.example.com
this cookie will be sent with the request and Alice will have the session specified by Mallory's cookie.
# If Alice now logs on, Mallory can use her account.
When this attack is complete, Mallory can gain access to www.example.com
as Alice.
It is not essential that a user login to exploit session fixation attacksCountermeasures
Do not accept session identifiers from GET / POST variables
Session identifiers in URL (query string, GET variables) or POST variables are not recommended as they simplify this attack – it is easy to make links or forms that set GET / POST variables. * The SID is leaked to other people as users cut & paste "interesting links" from the address bar into chats, forums, communities, etc. * The SID is stored in many places (browser history log, web server log, proxy logs, ...) Note: Cookies are shared between tabs and popped up browser windows. If your system requires to be hit with the same domain (www.example.com/?code=site1 and www.example.com/?code=site2 ), cookies may conflict with one another between tabs. It may be required to send the session identifier on the URL in order to overcome this limitation. If possible use site1.example.com or site2.example.com so there is no domain conflicts in the cookies. This may incur costs with extra SSL certificates. This behavior can be seen on many sites by opening another tab and trying to do side by side search results. One of the sessions will become unusable.Best solution: Identity confirmation
This attack can be largely avoided by changing the session ID when users log in. If every request specific to a user requires the user to be authenticated with ("logged into") the site, an attacker would need to know the id of the victim's log-in session. When the victim visits the link with the fixed session id, however, they will need to log into their account in order to do anything "important" as themselves. At this point, their session id will change, and the attacker will not be able to do anything "important" with the anonymous session ID. A similar technique can be used to solve theSolution: Store session identifiers in HTTP cookies
The session identifier on most modern systems is stored by default in anSolution: Utilize SSL / TLS session identifier
When enablingRegenerate SID on each request
A countermeasure against session fixation is to generate a new session identifier (SID) on each request. If this is done, then even though an attacker may trick a user into accepting a known SID, the SID will be invalid when the attacker attempts to re-use the SID. Implementation of such a system is simple, as demonstrated by the following: * Get previous Session IdentifierOLD_SID
from HTTP request.
* If OLD_SID
is null, empty, or no session with SID=OLD_SID
exists, create a new session.
* Generate new session identifier NEW_SID
with a secure random number generator.
* Let session be identified by SID=NEW_SID
(and no longer by SID=OLD_SID
)
* Transmit new SID to client.
Example:
If Mallory successfully tricks Alice into visiting http://victim.example.com/?SID=I_KNOW_THE_SID
, this HTTP request is sent to victim.example.com
:
victim.example.com
accepts SID=I_KNOW_THE_SID
, which would normally be bad. However, victim.example.com
is secure because it performs session regeneration. victim.example.com
gets the following response:
SID=3134998145AB331F
that is unknown to Mallory, and SID=I_KNOW_THE_SID
is invalid. Mallory is thus unsuccessful in the session fixation attempt.
Unfortunately session regeneration is not always possible. Problems are known to occur when third-party software such as ActiveX or Java applets are used, and when browser plugins communicate with the server. Third-party software could cause logouts, or the session could be split into two separate sessions.
If the implementation of sessions includes transmitting the SID through GET or POST variables, then this might also render the "back" button in most browsers unusable, as the user would then be using an older, invalid, session identifier from a previous request.
Accept only server-generated SIDs
One way to improve security is not to accept session identifiers that were not generated by the server. However, as noted above, this does not prevent all session fixation attacks.Logout function
A logout function is useful as it allows users to indicate that a session should not allow further requests. Thus attacks can only be effective while a session is active. Note that the following code performs no Cross-site request forgery checks, potentially allowing an attacker to force users to log out of the web application.Time-out old SIDs
This defense is simple to implement and has the advantage of providing a measure of protection against unauthorized users accessing an authorized user's account by using a machine that may have been left unattended. Store a session variable containing a time stamp of the last access made by that SID. When that SID is used again, compare the current timestamp with the one stored in the session. If the difference is greater than a predefined number, say 5 minutes, destroy the session. Otherwise, update the session variable with the current timestamp.Destroy session if Referrer is suspicious
When visiting a page, most web browsers will set the Referrer header – the page that contained the link that you followed to get to this page. When the user is logged into a site that is not likely to be linked to from outside that site (e.g., banking websites, orhttp://vulnerable.example.com/
could employ the following security check:
Verify that additional information is consistent throughout session
One way to further improve security is to ensure that the user appears to be the same end user (client). This makes it a bit harder to perform session fixation and other attacks. As more and more networks begin to conform to RFC 3704 and other anti- spoofing practices, theUser Agent
Browsers identify themselves by "User-Agent" HTTP headers. This header does not normally change during use; it would be extremely suspicious if that were to happen. A web application might make use of User-Agent detection in attempt to prevent malicious users from stealing sessions. This however is trivial to bypass, as an attacker can easily capture the victim's user-agent with their own site and then spoof it during the attack. This proposed security system is relying onDefense in depth
Defense in depth is to combine several countermeasures. The idea is simple: if one obstacle is trivial to overcome, several obstacles could be very hard to overcome. A defense in depth strategy could involve: * Enable HTTPS (to protect against other problems) * Correct configuration (do not accept external SIDs, set time-out, etc.) * Perform session_regeneration, support log-out, etc. HTTP referrers are not passed with SSL/TLS (HTTPS). The following PHP script demonstrates several such countermeasures combined in a defense in depth manner:See also
* Session poisoning *References
External links