Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Something I Discovered With Sessions [php]
ghostrider
post Jan 4 2008, 03:02 AM
Post #1


Super Member
*********

Group: Members
Posts: 397
Joined: 9-June 06
From: Wisconsin
Member No.: 24,924



Hello All,

I've been doing a lot of PHP programming since I last posted here. I've run across two security related things with sessions that you may or may not know about.

The first one pertains to the session id, or the id that PHP assigns each computer when a session is created. This id is either stored in a cookie (search for PHPSESSID) or through the URL as GET data. Remember that all session data is stored server side; this ID is the only thing that PHP will use to differentiate your computer from someone else's. While I was programming for Plug Computers, I decided to experiment with logging into the Admin CP I built, copying the session ID from my computer, and putting it as a cookie on the other computer. Sure enough, both computers were recognized as logged into the admin CP.

This poses a very serious threat to anyone that knows what they are doing with sessions. However, there is a system that I use to eliminate this from occurring. PHP has a bunch of functions for working with sessions. I utilize the "session_regenerate_id", which will change the session ID every time it is invoked. This way, if someone is able to capture someone's session ID, the next time that function is invoked, the ID will be useless.

CODE
<?
session_start(); // Start the session.
session_regenerate_id(); // Give the session a new id.
?>


I recommend doing that every time your user loads a new page.

The second discovery I've made pertains to using local variables and session variables. When I write PHP for people I use PHP version 5.2.2. I believe newer versions have addressed and fixed this issue. But just in case, I'll share what I've found anyway.

Firstly, let me tell you what I mean by a local variable. Look at the code below:

CODE
function some_function($var) {
$newvar = $var;
++$newvar; // This is not a local variable.
return $newvar;
}

$othervar = 7; // This is a local variable


Variables within functions are not considered local variables because when a user-defined function is invoked, PHP will create the variables within that function, and then destroy them once the function has been completed. Other variables outside of functions are considered "local variables", with the exception of superglobals ($_POST, $_GET, $_COOKIE, $_SERVER).

I am currently writing some PHP for a tenis coach in Indiana who wants a way to allow his students to keep track of work out routines, keep a blog, keep notes on opponents and other things like that. When working with the Admin CP and creating a "add user" form for the site, I noticed that the key 'username' in the session superglobal would change each time I ran the script.

Here is the code in question:
CODE
$username = $_POST['username'];


The value in $_SESSION['username'] was changed to $username. It's a bug that also caused me some difficulty with Plug Computers. I had to change all of my $id's to $id1's to avoid it.

Hope this helps someone out.
Go to the top of the page
 
+Quote Post
babyboomer
post Jan 24 2008, 01:12 PM
Post #2


Newbie [Level 3]
***

Group: Members
Posts: 40
Joined: 15-January 08
Member No.: 56,293



I never actually thought about the session variable being a security hole. Thanx for pointing that out mate.

The thing about local and global variables must be known by every php coder. I mean this is like the abc of this thing.

Keep up posting.
Go to the top of the page
 
+Quote Post
galexcd
post Jan 24 2008, 10:01 PM
Post #3


Define:EVIL PROGRAMMER (ē'vəl prō'grăm'ər)- n. An organism that converts caffeine into evil software.
***********

Group: [HOSTED]
Posts: 1,074
Joined: 25-September 05
From: Los Angeles, California
Member No.: 12,251



This is the main reason I don't use session in php. I write it myself, come up with a random string and make my own cookie this way I have more control over it. I check the IP address that was logged in with, with the one trying to get the request.
Go to the top of the page
 
+Quote Post
jlhaslip
post Feb 10 2008, 03:06 AM
Post #4


A computer once beat me at chess, but it was no match for me at kick boxing.
Group Icon

Group: [MODERATOR]
Posts: 4,085
Joined: 24-July 05
From: Linix, DOS and Windows…the good, the bad and the ugly
Member No.: 9,787
Spam Patrol



QUOTE(alex7h3pr0gr4m3r @ Jan 24 2008, 03:01 PM) *
I check the IP address that was logged in with, with the one trying to get the request.

That would work with Users that have a Static IP, but how do you handle Dynamic IP's?
Go to the top of the page
 
+Quote Post
FLaKes
post Feb 10 2008, 04:40 AM
Post #5


Trap Grand Marshal Member
***********

Group: [HOSTED]
Posts: 1,136
Joined: 19-May 05
From: Mexico
Member No.: 7,234



Nice one, I had to added it my favorites to consider it for whenever I am programming something with php. I am currently working on an admin cp for a business that sells boots. This will really come in handy. Thanks.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Get User Info True Sessions Or Cookies(0)
  2. New Security Hole Discovered In Excel(0)
  3. Gigantic Rats Discovered In Indonesia(18)
  4. The Most Beautiful Egyptian Mummy Was Discovered(9)
  5. Php Sessions And Post Variables Issues(1)
  6. New Websites Discovered...(9)
  7. Sessions(7)
  8. I've Discovered That Wrestling Is A Scam(15)
  9. <?php ?> Unique Visitors Script(2)
  10. Gigantic Cave Discovered In Venezuela(3)
  11. Sessions And Our First Project(0)
  12. Obesity Gene Discovered(3)
  13. Cool Web Applications Discovered.(3)
  14. Using Sessions Instead Of Cookies, Help Please(1)
  15. New Definition Of Planet Will Enlarge Our Solar System(6)
  1. Sessions And Login(5)
  2. Attention All Ipb Users/admin(6)
  3. Session Variables(4)
  4. Cool Photoshop Text Effects I Discovered(2)
  5. Two New Moons Of Pluto Discovered(4)
  6. Identity Hackers Discovered!(7)
  7. Sessions(0)
  8. To All Pinoys Out There..(8)
  9. Php Sessions(2)
  10. T-rex Soft Tissue Discovered(6)
  11. Sessions(8)


 



- Lo-Fi Version Time is now: 13th October 2008 - 05:36 PM