Session hijacking fixation in server side script – PHP

Hi Guys,

In recent days my team got stuck with a security issue called Session Hijacking in an php based web application. After deep analysis we have found a solution by forming a tweak in server side script – PHP.

The possible solutions are
1. Identify weather the request is from intruder by saving MD5(User Agent + Remote Address) in a session variable. And compare the session variable for every request from the client. If the hashed string is not matched with the session variable value then it is anonyms request.
2. When a hacker make a request with existing active session id then generate the duplicate session id and unset it.
3. In php session_regenerate_id(); – duplicate regeneration of new session id. session_regenerate_id (true); – It deletes the existing session id and creates new session id. i.e replaces the existing session id.
4. All cookies must be enabled httponly.
5. The request identification can be either only from the url or from the cookies.

//Session Hijacking code starts here
if (isset($_SESSION['YOUR_KEY'])) {
$_COOKIES['PHPSESSID'] = md5(rand(1, 1000));
$_SESSION['ERROR'] = 'Session Hijacked!';
header("Location: login.php"); //Redirect to particular location where you want to
} else {
//Session Hijacking code ends here

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s