LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 11-07-2003, 01:31 PM   #1
pnh73
Member
 
Registered: Jul 2003
Location: Birmingham, UK
Distribution: Ubuntu,Debian
Posts: 381

Rep: Reputation: 30
PHP Session ID Security


Hi,

I found have a script which I am working with that shows the SessId in the address bar and if the user doesnt log out (hence destroying the session) this session can be reopened and the "secure" page accessed. This is probably due to the session not being destroyed.

Is it possible for someone malicious to find what the variables that make up the Session ID are and then generate their own to get access to other users' areas that are deemed to be "secure"?

TIA
 
Old 11-07-2003, 02:09 PM   #2
cyph3r7
Member
 
Registered: Apr 2003
Location: Silicon Valley East, Northern Virginia
Distribution: FreeBSD,Debian, RH, ok well most of em...
Posts: 238

Rep: Reputation: 30
yes and no.......the string is difficult to match but it is possible to "massage" the session header info and gain access to an area not intended for you. The bigger worry is mismanaged session state wherein if the session isn't forced to close after a set amount of idle time and the client doesnt close the session properly, another person can simply hop on the machine and access the users data. You definately want to configure the web server to manage active and inactive http/https sessions while at the same time your code enforces session state in a reasonable manner.
 
Old 11-07-2003, 03:35 PM   #3
pnh73
Member
 
Registered: Jul 2003
Location: Birmingham, UK
Distribution: Ubuntu,Debian
Posts: 381

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by cyph3r7
yes and no.......the string is difficult to match but it is possible to "massage" the session header info and gain access to an area not intended for you.
How? I want to test out my code to see if it is exploitable... Any HOWTO's
 
Old 11-07-2003, 04:22 PM   #4
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Well what is of more importance is for instance in a virtual hosting envorinment - like at most ISP's PHP is set up with default values. EVERYBODY can list the directory which is being used for sessions - this is mostly /tmp/php. So you could just list that and give it a try.

Well honestly I have recently coded some class for secure login. It uses md5 hashes to ensure it's correctness of the data:
  • ip
  • username
  • expire (max idle time verification)
  • hashes to ensure the above are valid

This should work ... you can call that paranoid but it definately is more secure than relying on something other. Maybe I'll give you some code excerpts...
 
Old 11-08-2003, 09:31 AM   #5
pnh73
Member
 
Registered: Jul 2003
Location: Birmingham, UK
Distribution: Ubuntu,Debian
Posts: 381

Original Poster
Rep: Reputation: 30
cyph3r7 said that it was possible to massage the $_SESSION variables to get a correct hash. Is this correct?

I am trying to put myself in the position of a potential cracker... He managed to get hold of 1 Session ID but doesnt have SSH/Telnet access, so he cant get to the /tmp directory and doesnt want to hack just the account he got the Session ID for but wants to generate more... Any Ideas?
 
Old 11-08-2003, 03:17 PM   #6
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Well when you have carefully implemented my suggestions above one invalid hash will force the user to login again and erase the session data. I forgot to mention that in my particular protection there is also a secret hash which in combination with the other 2 hashes is my VERIFICATION hash.

If one of the hashes is invalid => login form.
 
Old 11-10-2003, 04:53 AM   #7
pnh73
Member
 
Registered: Jul 2003
Location: Birmingham, UK
Distribution: Ubuntu,Debian
Posts: 381

Original Poster
Rep: Reputation: 30
i noticed that after trying to check my PHP scripts on w3c.org i saw that the checking script got the raw script remotely! How does it do this. I am guessing it would be possible for a cracker to extract the contents of my PHP script and find the $_SESSION[""] values! I have not come across anything like this before. Its kind of worrying as this would enable anyone to just leech your carefully crafted PHP site :s
 
Old 11-11-2003, 02:01 PM   #8
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Well if it can get your raw script your webserver is misconfigured. However you can always encrypt your scripts using turk mmcache.
 
Old 11-12-2003, 11:15 AM   #9
pnh73
Member
 
Registered: Jul 2003
Location: Birmingham, UK
Distribution: Ubuntu,Debian
Posts: 381

Original Poster
Rep: Reputation: 30
How can I stop fix this mis-configuration then?
 
Old 11-12-2003, 11:27 AM   #10
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
Please refer to the documentation on howto enable PHP for Apache 1/Apache 2. It contains everything required.
 
Old 11-13-2003, 12:51 PM   #11
markus1982
Senior Member
 
Registered: Aug 2002
Location: Stuttgart (Germany)
Distribution: Debian/GNU Linux
Posts: 1,467

Rep: Reputation: 46
What you could do to even more secure the area around the secret hash would be setting up a hash table in the database and filling it with let's say 1000 values of different hashes; expand the script to submit the hash_id also and use the hash on a random base ... this will ensure maximum security (but will also be slower since the hash is also validated each time since it can't be known to be valid)
 
Old 11-13-2003, 01:51 PM   #12
pnh73
Member
 
Registered: Jul 2003
Location: Birmingham, UK
Distribution: Ubuntu,Debian
Posts: 381

Original Poster
Rep: Reputation: 30
cool thanks for the help guys!
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Are PHP session variables held in memory when you leave a PHP site? Locura Programming 11 11-16-2008 08:37 PM
PHP session.gc_maxlifetime j-ray Programming 1 11-07-2004 01:45 PM
php session richard22 Programming 2 10-26-2004 05:50 AM
PHP Session problem!!! AskMe Programming 9 06-03-2004 07:33 AM
PHP session control lhoff Programming 3 05-06-2002 12:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 09:19 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration