TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-04-2008, 06:30 PM   #1 (permalink)
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default Stopping session hijacking

Would this work?

PHP Code:
session_start();
session_regenerate_id();
if (
session_regenerate_id() != $_SERVER['HTTP_USER_AGENT'])
{
$_SESSION = array(); 
session_unset();
session_destroy();
header('Location: index.php');

9three is offline  
Reply With Quote
Old 12-04-2008, 10:58 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

One thing I used to do back in the days when I didn't use a framework, was to store items in the session data. I would create a fingerprint and then check that fingerprint was valid on every page load.

You could store the IP address, but some ISPs -- I think AOL, to name one, changed the user's IP address randomly so you can't rely on that, because an AOL user would be continually logged out. One thing I used was the browser data -- such as browser identifier, language, etcetera. Whilst these are not always present, what I assumed when I did it was that if they didn't exist, it wasn't a valid user -- perhaps a bot or something like that.

So whilst HTTP_USER_AGENT doesn't always exist, you could do the same as me and assume if there isn't a HTTP_USER_AGENT then it's not a user, and therefore throw an error instead. If there is a HTTP_USER_AGENT then create a fingerprint (perhaps with MD5() or SHA1()) and then check to ensure they match on every page load. Although this is not absolute hack-proof, it makes it even harder than it already is in requiring the hacker to know the user's browser details as well when attempting to hijack a session.

There are, of course, plenty of other ways to ensure your session layer isn't compromised, which are well documented. However, at least in my opinion, your approach is certainly correct in theory.

Further reading:


__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
9three (12-04-2008)
Old 12-04-2008, 11:12 PM   #3 (permalink)
The Contributor
 
Join Date: Oct 2008
Posts: 75
Thanks: 4
9three is on a distinguished road
Default

Thanks for the info.

Yes I figured in theory that the method was a good way to go. But, sometimes you miss out something so it's always good to a 2nd opinion.
9three is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Huge Session Problem Killswitch General 1 11-17-2008 02:36 AM
storing class instance into session nizzy Advanced PHP Programming 3 10-02-2008 06:49 AM
Storing Session data in $_COOKIE as well shownomercy General 8 08-21-2008 02:00 PM
Session security Blackbrain Absolute Beginners 3 01-07-2008 11:19 PM
Understanding the Life of a Session Wildhoney General 6 10-27-2007 02:34 AM


All times are GMT. The time now is 03:20 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design