Question

php session security question

Asked by: exxos_uk

After even more reading on sessions, what exactly can a user do if they get the session ID ? It is easy to do in FireBug, but does this mean they can read the session variables ? as far as I can tell the session information is encrypted ? Is there anyway to obtain session variables if someone has the session ID ? Would have thought it would be impossible for that to happen though I am not so sure anymore!

I think if I had a page which uses sessions and a simple example it just had 1 session variable called "count" that each time someone visited that page the count number would go up. So if someone got the session ID, they could in effect make the counter go up aswell ? but as far as I know, that couldn't actually know the variable was called "count" but they could maybe increase the count variable by hijacking session ID's ?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-11-04 at 11:31:20ID24872143
Topic

PHP for Windows

Participating Experts
2
Points
125
Comments
14

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. counter in php
    Hello Is there anyway I can set up a counter in php so that it initally is set to zero in a php webpage and then is incremented by one each time that webpage is opened up. I want to then reset the counter when the user clicks on a specified button. Cheers
  2. Session Cookie Hijacking
    Hi, I'm trying to demonstrate to a work colleague how Session Hijacking can be performed on one of our web applications. I use NetMon.exe to monitor traffic from his machine to the web server to retrieve the SessionID (we are using ASP/IIS). The session ID is stored in a s...
  3. hijacking an SSH session
    Hello. This is an educational question not for malicious purposes. For my assignment I was asked to discuss a method to hijack an SSH session or describe whether this is possible or not. from my google I found some saying it wasn't possible since SSH detects alterations of ...
  4. Hijacked Server
    I am running an email server on a Linux box and have gotten several hijackers using it to spam their junk now. I have tried to block these IP addresses in the sysconfig/iptables file but this has not worked. I have been getting return notices of failed emails for Viagra and...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: 930913Posted on 2009-11-04 at 11:38:15ID: 25743019

This discusses session id security: http://www.securityfocus.com/infocus/1774

 

by: exxos_ukPosted on 2009-11-04 at 11:57:32ID: 25743248

I read something similar just to that, the session ID needs to be long, I will have to check what the session length is by default... in anycase, if someone did manage to guess a session id, the could not actually obtain any data unless they knew the variable names such as "username" ?

I would presume if they got a ID and knew a variable name, they could just connect to that session and just simply echo the "username".... thinking along how SQL works now I think...

 

by: gr8gonzoPosted on 2009-11-04 at 12:09:09ID: 25743384

It doesn't quite work like that. All of your session data is stored on the server, and it's accessible while PHP is generating the HTML page. Once PHP finishes and sends the page to the user, there is no way for a user to simply request a variable from the session data (unless you happen to have created a PHP script where the user can type in a variable name, submit the form, and have the PHP script deliver the value back to the user... but that's a pretty bad idea and wouldn't really make sense to do).

Think of a world where each of us wears an ID badge on our shirt. Guessing/stealing a session ID is just like copying someone's ID badge and putting it on your own shirt. There's really nothing special except that you have access to whatever the other person had access to - nothing more.

 

by: gr8gonzoPosted on 2009-11-04 at 12:15:55ID: 25743450

The most dangerous thing you can do when you steal a session ID is to log into their account without needing to know their username or password (having the session ID of a logged-in user is just like a magical key that lets you right into that user's account).

From there, you can do whatever the REAL owner of that session ID can do - steal some information from their profile page maybe (identity theft?), maybe change the password on the account, or post messages pretending to be that user. That type of thing, but again, there's really no built-in / default way for a user to simply have free access to whatever is in the session data. Some systems store secret information about the user in the session - information that even the logged-in user should not know. Since the user can't just request that information, it can be safe (in a basic sense).

 

by: exxos_ukPosted on 2009-11-04 at 12:18:46ID: 25743482

if I stole a ID and did have access to whatever that person did, then thats a really bad thing.... but if thats the case, what exatly do they have access to ?!

Of course they will not know any of the variable names, that was one question.. so if they get the ID, really it would be useless ?

The link in the first posted reply explains a lot, but using cookies, in my case im not actually using cookies, not on the clients pc anyway. My thought there was to just store the timestamp of when the person logged in, then that timestamp will be  needed along with a valid session id, which must tally with that session id.  

So my thought is there, it has to be secure as any who managed to obtain a ID could not make any valid requests to my server as the timestamps would not match. So in that case can I assume the session ID is useless to anyother users ?

all I really wanted to know if what anyone could do with the session ID is they had it.. as long as they can't read any information then there is no problem, which was really my main question that I was just double checking on...

 

by: exxos_ukPosted on 2009-11-04 at 12:21:48ID: 25743511

just read your second post gr8gonzo:..

I undertand what you say, I think my time stamp idea would prevent anyone else from faking other users though as they would never have the same timestamp as the user who actually logged in..

 

by: gr8gonzoPosted on 2009-11-04 at 12:28:09ID: 25743560

Well, technically the session ID -is- stored in cookies unless you've specifically disabled that and are forcing all your visitors to use pages where the session ID is passed along in the URL.

Regarding the timestamp - that's fine, but it's pretty hard to randomly guess a session ID. Thus, if someone else has the same session ID, it's probabyl because they stole it, and if they stole it, then they probably have access to the other data, like that timestamp. Still, every additional measure you take can only help and turn away casual hacking attempts. If someone is talented and desperate to steal a specific session, then they'll probably be looking at all the other visible data and trying to mimic stuff like the timestamps.

You should simply ask yourself, if a regular user just decided one day to be as evil as possible and do as much damage as they could, what COULD they do (using just your application) ? I wrote an article a while back on security in web applications - might help you here;

http://www.experts-exchange.com/articles/Programming/Project_Management/Security/5-Steps-to-Securing-Your-Web-Application.html





 

by: gr8gonzoPosted on 2009-11-04 at 12:33:26ID: 25743597

A note on the timestamp idea (just to clarify): you just have to think about where you're going to store the timestamp. All data has to be stored somewhere, and if that timestamp value has to "stick" with the user as they go through the application, then where is it stored for that purpose? Is it stored in a cookie? In a session variable? Inside the URL of each link and form action?

If it's in a session variable, then it doesn't really help, since stealing the session ID would basically also "steal" access to that same session data, including the correct timestamp.

Store it in a cookie, and you probably face the problem I mentioned earlier - if they stole the cookie with the session ID, then they probably also stole the cookie with the timestamp value in it.

If it's in the link, well, then you have to rewrite all the links and form actions in your application so the timestamp isn't lost along the way.

 

by: exxos_ukPosted on 2009-11-04 at 12:37:44ID: 25743632

It is remote that someone could (or want to) get a ID to hack it, but it only takes 1 person to do it, then google becomes your main evil.

It was why I asked if someone could obtain the session variables, the time stamp would be only issued on a valid login and stored in a SQL DB related to the actual user.  

So if the "Fake user" who has the valid session ID wanted to trash someones account (or whatever) , the server would just not accept requests from his "location" as the SQL timestamp would not be there in the faked users session... at least I think so anyway....

That may not work as I think about it, as if I stored the timestamp in a session, then it would be a "Clone" of the user so the timestamp would not actually matter... I guess it would work if I store the timestamp in a local cookie instead of the session ?  that way the "cloned user" using the stolen ID will not be able to make requests as they do not have the local cookie which was created during a official login....

this all makes your head spin a lot! thanks for the link, will go read that too!

 

by: exxos_ukPosted on 2009-11-04 at 12:38:50ID: 25743642

ditto! we both just covered the same issue!

 

by: exxos_ukPosted on 2009-11-04 at 13:00:13ID: 25743867

great link. will take me some time to read it all, though I can see from other articles about SQL injection, I only use POST now, though my SQL lines read such as select password where user=$user , so even if they inject values using POST, it *shouldnt* matter... they could select any username via injection, but the script will not allow them to login unless they input the correct password... bit off topic in this post though! thanks for your input!!

 

by: gr8gonzoPosted on 2009-11-04 at 13:55:41ID: 25744393

SQL injection isn't about simply changing the username that is sent to the query, or changing from $_GET to a $_POST or something. Changing data (regardless of GET or POST or whatever) is trivial to do.  

The whole big deal about SQL injection is about sending data to SQL that also changes the query itself.

Example:
$query = "SELECT * FROM users WHERE username='$user' and password='$password'";

No matter where $user came from, if you don't "clean" the value before you put it into a query, then anyone can change your query. I could go into your login form and instead of using gr8gonzo as my username, and my real password, I use:
$user = administrator
$password = blah' or 1=1

If you don't do any sort of escaping / cleaning on those values, then MySQL would end up with this query:
$query = "SELECT * FROM users WHERE username='administrator' and password='blah' or 1=1";

The result? I would be able to log into the administrator account without knowing the password. Obviously, "blah" probably isn't the right password, so "password='blah'" would be false, but the "or 1=1" would be true, so it would go ahead and return the administrator record (thus logging me in).

That's SQL injection.

 

by: exxos_ukPosted on 2009-11-04 at 14:22:03ID: 25744672

I do understand what you are saying there. I am adding your tips from your link into my code as it all helps a lot!

 I can't see how anyone could login without knowing the password in my script, as it only gets the password WHERE the username is. the only thing they can change is the username, and if its not a valid username it would never return the password, which wouldn't really help them anyway.

though I guess after reading your article that if they could pass a OR line in the username which could be used to select any username in the list, however, it may return the password of some user, but unless they enter that password the script would never allow them to login anyway.

The POSTED password from the login form has to match the one returned from the SQL line, else it will not allow a login as the passwords do not match. AFAIK, all is ok ?

 

by: gr8gonzoPosted on 2009-11-04 at 15:05:30ID: 25745065

> and if its not a valid username it would never return the password
That's very true. My example was just showing someone who actually knew a valid username or at least was guessing at a popular username. The point of it all, though, is that someone could change the ENTIRE query to something completely different. A little bit of ingenuity goes a long way in hacking. Someone could even do this:

$user = gr8gonzo'; UPDATE users SET password=''; SELECT * FROM users WHERE '1'='1
$password = whatever

And your script would end up running three queries:
$query = "SELECT * FROM users WHERE username='gr8gonzo'; UPDATE users SET password='newpassword'; SELECT * FROM users WHERE '1'='1' and password='whatever'";

Or they could simply change the query so it pulled back the first record in your users table, regardless of what the username or password were. Often times, the first user is also the top-level administrator user.

Or they could simple try to issue DROP TABLE commands to simply delete all your data.

Having any part of your site vulnerable to SQL injection is almost the same as giving them a big textbox to type their own queries that will be run on your database. The only difference is that they need to write their queries a little differently so they get exceuted properly, and getting the results back isn't quite as easy, but it can be done.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...