are session safe?

This is a discussion on "are session safe?" within the PHP Forum section. This forum, and the thread "are session safe? are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Aug 26th, 2007, 20:48
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Exclamation are session safe?

Hello, I've heard an awful lot about login systems that use sessions being vulnerable to XSS.
As the user can change sessions, if the session was storing the username/id of the person logged in, could they change it to access other peoples accounts?
if so how can this be fixed? or is there another way besides sessions?
thanks guyssssss
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote

  #2 (permalink)  
Old Aug 26th, 2007, 23:07
Junior Member
Join Date: Jan 2007
Location: South Cambs, UK
Age: 18
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to afmanuk
Re: are session safe?

You could store a random string in the session aswell as the username and update the database for the user when they log in. Then on every page check that the username and the key thing match... That's what I do anyways
PHP: Select all

$key substr(md5(rand(01000)), rand(027), 5); 

This is something simple to create a key and there's like 27,000 possibilities
It probably won't take long to go through all 27,000 with a program. But the hacker will have to know how the key is generated. Use you imagination
Reply With Quote
  #3 (permalink)  
Old Aug 26th, 2007, 23:14
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: are session safe?

could use salt or something i guess.
could you show me an example of your login script?
is it something like:
PHP: Select all

   $key substr(md5(rand(01000)), rand(027), 5);
$username $mysqlquery;
$_SESSION['user'] = $username.$key;
$update "update set key='$key' where username='$username'"
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #4 (permalink)  
Old Aug 26th, 2007, 23:22
Junior Member
Join Date: Jan 2007
Location: South Cambs, UK
Age: 18
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to afmanuk
Re: are session safe?

Yeah, close.
But instead of
PHP: Select all

$_SESSION['user'] = $username.$key
Set them seperately in the session like this...
PHP: Select all

$_SESSION['user'] = $username;
$_SESSION['key'] = $key
Then you don't have to seperate the joint strings when checking
Reply With Quote
  #5 (permalink)  
Old Aug 26th, 2007, 23:27
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: are session safe?

ahh right thanks
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #6 (permalink)  
Old Aug 26th, 2007, 23:31
Junior Member
Join Date: Jan 2007
Location: South Cambs, UK
Age: 18
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to afmanuk
Re: are session safe?

No worries, glad to help
Reply With Quote
  #7 (permalink)  
Old Aug 26th, 2007, 23:35
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: are session safe?

are there any other methods or things to add to this one?
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #8 (permalink)  
Old Aug 27th, 2007, 16:37
Junior Member
Join Date: Jan 2007
Location: South Cambs, UK
Age: 18
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to afmanuk
Re: are session safe?

Wow... Appears my way of stopping illegitimate users is just as bad as storing just the username.

Quote:
A problem occurs if someone else gets hold of your session ID. All a malicious user needs to become you is your session ID - if they then send it to the server as if it were their own, the server will assign all your session data to the hacker. Effectively, they will be logged in as you. You want to ensure that the session ID you receive is the same ID as you sent out to the same user, and no one else.
Haha... Oh dear... Read this... There's a bit on session hijacking
http://www.roscripts.com/Security_in...tions-174.html
Reply With Quote
  #9 (permalink)  
Old Aug 30th, 2007, 10:45
SuperMember

SuperMember
Join Date: Apr 2007
Location: Sydney
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Re: are session safe?

apparently storing the users user-agent on log in is a good way as well. (on each page match the user-agent on record with the one sent on the original login. Would take ages to hit a match by brute force!!)

Also regenerating the session id on login.
Reply With Quote
Reply

Tags
sessions, users

Thread Tools

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

BB 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
List of Web Safe Browser Fonts ... hmm213 Web Page Design 1 Nov 30th, 2007 15:27
Help with SESSION vars, please? Donny Bahama PHP Forum 3 May 28th, 2007 15:53
Session Variables.... courtjester Classic ASP 11 Jul 6th, 2004 00:04
session php iamzoli PHP Forum 2 Apr 7th, 2004 05:49
Web Safe Colours Smokie Web Page Design 17 Sep 11th, 2003 22:10


All times are GMT. The time now is 20:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43