Hiding Session Id

Started on the old forum in January 2009 · view the original in the archive · old links redirect here

134 replies · 11,752 views · started 17 years ago · 1 min read

TL;DR · summary of 134 replies
  • -mod_rewrite would not be effective for hiding session IDs as they still need to pass through URLs.
  • -Using dynamic variables like IP or browser information could help prevent session hijacking, but it may not be foolproof.
  • -Adding username and password to the authentication process can strengthen session security by defining both the user and their credentials.

Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.

38 participants
synergyx2009 Developer · 86 posts #61

ok i get it but then the answer to this thread is to not post a link to an external site in anyway unless the link is in such a manner that you would have to copy and paste in your browser

|Dont forget to say thanx|

ori Lead · 512 posts #62

u can force cookie 2 expire after so long but thats stored in the browser so i can see ur point but u can stil use database 2 end sessions too and lava has auto session destroy in the database so if the cookie and db session are set 2 expire in say 20mins of inactivity then ur ok jus store session id in the cookie dnt use the cookie value as the session id as its easy 2 crack that

synergyx2009 Developer · 86 posts #64

what about using sesid=$sesid in url and session start with cookies. This way you have a session which u store in ur db and a session stored as a cookie. double the protection. would this work?

|Dont forget to say thanx|

ori Lead · 512 posts #65

u need it stored in the database so it can interact anyway no need for it in the url thats what makes it easy 2 crack

djlee Developer · 224 posts #66

the only thing id do in the url is pass a fake session, most people who attempt to hack these wap sites (which are 10 to a dozen these days) have already done it via url session snatching or they are so narrow minded if they see a session id in url they dont think to check anything else so pass a random fake session between pages , they snatch it a few times, each time it dont work so they give up

synergyx2009 Developer · 86 posts #67

djlee wrote: the only thing id do in the url is pass a fake session, most people who attempt to hack these wap sites (which are 10 to a dozen these days) have already done it via url session snatching or they are so narrow minded if they see a session id in url they dont think to check anything else so pass a random fake session between pages , they snatch it a few times, each time it dont work so they give up

Thats exactly what i am talking about, i think we more or less on the same path

|Dont forget to say thanx|

something else Fellow · 2,296 posts #68

Alternate way could be to use browser and ip as your session id*

$check = md5($browser$ip$your_code); if ($sid!=$check) print 'Your browser and ip details have been logged in our database If it appears in our database again your internet provider will be contacted!';

that way even if session id does get stolen it renders it useless*

djlee Developer · 224 posts #69

basically using an independant salt... and ive suggested ip based restrictions before. and when i did someone moaned at me saying that its a good possibility that on wap multiple people can use the same IP address as there shared a lot more than a standard pc users ip. so theres still a good possibility that it could be ineffective all the time.

Sorry but every suggestion i make someone pokes holes in it yet never coming up with a fool proof way themselves. Its only fair you get the same treatment. But from a neutral standpoint the concept has its merits and will function just as well as most of the other implementations suggested here

ori Lead · 512 posts #70

doesnt matter what is done theres always gonna be questions 2 it i prefer using cookie sessions as its neater code can hide lot info in them including ip, uid etc 1 thing i did wif my script is all the url links dnt use uid at all so ppl cant inject that info it wont do any gud lol wouldnt it be better 2 store session and ip in the cookie and if ip changes from whats in database then it has 2 be revalidated as a new session

godzilla Developer · 119 posts #71

jsyguy23 wrote: this is what i use in lava

session_name("PHPSESSID"); /// top of every page
session_start();
$_SESSION['uid']=$_REQUEST['$sid'];

remove the sid=$sid from all the links

session_destroy(); // this in your logout code

this is what ori and loony gave me to use and it works

thanks bro

can u please tell me where to put this code in logout

this code

session_destroy(); // this in your logout code

logout code

///////////////////////////Logout///////////////////////////////

else if($action=="logout")
{
  $who = $_GET["who"];
  $user = getnick_uid($who);
  echo "<head>";
  echo "<title>Logout</title>";
  echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
  echo "</head>";
  echo "<body>";
  echo "<p align=\"center\">";
  $uid = getuid_sid($sid);
  if($who!=$uid){ 
  echo "<b><img src=\"../images/notok.gif\" alt=\"x\"/><br/>Error!!!<br/>Permission Denied...</b><br/>";
  echo "<br/>$user, U Cannot Log Someone Out<br/>This Is An Attempt To Breach Site Security<br/>If U Are Caught Trying This Again U Will Be Banned<br/>";
  echo "<br/><a accesskey=\"1\" href=\"index.php?action=main&\"><img src=\"../images/home.gif\" alt=\"\"/>Ok!</a>";
  echo "</p>";
  }else{
  echo "<br/>";
  $res = mysql_query("DELETE FROM ibwf_ses WHERE uid='".$who."'");
  if($res)
  {
  addonline($who,"Logging Out","");
  echo "<img src=\"../images/ok.gif\" alt=\"O\"/><b>$user</b><br/>U Hav Successfully Logged Out Pls Come Back Soon :o)<br/>";
  }else{
  echo "<img src=\"../images/notok.gif\" alt=\"X\"/>Error Logging Out";
  }
  echo "<br/><a accesskey=\"1\" href=\"index.php\"><img src=\"../images/home.gif\" alt=\"\"/>ok!</a>";
  echo "</p>";
  }
  echo "</body>";
}

thanks

wapmetal Lead · 609 posts #72

wolf77ar wrote: No no, no user&pass visible 😛 One simple solution to hide $sid on lavalair is:

  1. in login.php put in line 2 after:
<?php ``` session_start(); $_SESSION['sid']=$sid; ``` 2. remove sid=$sid from loginpage, the link to enter in site will be: echo"<a href=\"index.php?action=main\">[ ENTER ]</a>"; 3. In all pages: Start with index.php remove: ``` $sid = $_GET["sid"]; ``` remove sid=$sid from all links and put this in line 2: after <?php ``` session_start(); $_SESSION['sid']=$sid; ``` 4. to make secure put this ``` if (!empty($sid)) ``` from where you want to make sessions acces in your site this is for control if real start you session and to not be atack from distance ex: before if($action=="main") 5. to destroy session put this on exit: ``` ** unset($_SESSION['sid']); ** $_SESSION = array();** // reset session array ** session_destroy();**** // destroy session. ``` Optionaly, you can create one cookies in login.php ``` setcookie("cooksid", $_SESSION['sid'], time()+60*60*24*100, "/"); ``` to unset cookies: ``` setcookie("cooksid", "", time()-60*60*24*100, "/"); ``` But this will be dysplay one error because the headers is already sent, and for not show put this before session_start in index.php ``` ini_set('error_reporting', 'E_ALL & ~E_NOTICE & ~E_WARNING'); ``` this will be expire after 100 days 😀 In my site work verry well, but my wap provider Orange, change IP`s after 5-10 mins, in this case session change and have to login again You have any solutions for this? :sad:

hmmm i try this but not working... when i enter in menu.:D session expires apears

something else Fellow · 2,296 posts #73

You could protect session id from being stolen by using Curl ......*

It might be a drain on your bandwidth but it would make your site a lot safer against session stealing muppets lol*

And also if anyone does try to session steal then you would have there ip and browser details and know they were defently trying to steal sessions as you could change the session they steal to something like: $haha = md5("im a session stealing idiot"); //http://domain.com/?action=main&sid=$haha if($sid=$haha) print 'bugger off you wannabe hacker!';

And the best thing about it you wouldnt need to edit every page. you could do it straight off your login page 🙂

something else Fellow · 2,296 posts #74

Just a quick note to people who do decide to use cookies/sessions:* make sure you protect your url bb code to prevent unwanted urls being added on your site 🙂

anderson Developer · 146 posts #77

failed

I am the creator of this topic! Lots of posts done here. But still I am not able to hide session ID.

Wait...

anderson Developer · 146 posts #78

I tried to do it. When I put this code

session_start();
$_SESSION['sid']=$sid;

on the top of every page, it shows like this...

2: Warning: Unknown: Your script possibly relies on a session side-effect which existed until PHP 4.2.3. Please be advised that the session extension does not consider global variables as a source of data, unless register_globals is enabled. You can disable this functionality and this warning by setting session.bug_compat_42 or session.bug_compat_warn to off, respectively. in Unknown on line 0

Now what's the solution?

Wait...

ori Lead · 512 posts #79

was that in login cos i did a lava edit and had 2 put $_SESSION['sid']=md5($did);

ori Lead · 512 posts #80
<?php
session_start();
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
//header('Content-type: application/vnd.wap.xhtml+xml'); 
echo "<?xml version=\"1.0\"?>";
echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\" \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
include("config.php");
include("core.php");
connectdb();
$bcon = connectdb();
if (!$bcon)
{
echo "<head>";
echo "<title>$sitename Error!!!</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/default_medium.css\">";
echo "<head>";
echo "<body>";
echo "<p align=\"center\">";
echo "<img src=\"../images/notok.gif\" alt=\"!\"/><br/>";
echo "<b><strong>Error! Cannot Connect To Database...</strong></b><br/><br/>";
echo "This error happens usually when backing up the database, please be patient...";
echo "</p>";
echo "</body>";
echo "</html>";
exit();
}
$uid = $_GET["loguid"];
$pwd = $_GET["logpwd"];
$sitename = mysql_fetch_array(mysql_query("SELECT value FROM ibwf_settings WHERE name='sitename'"));
$sitename = $sitename[0];
$theme = mysql_fetch_array(mysql_query("SELECT theme FROM ibwf_users WHERE name='".$uid."'"));
$tolog = false;
echo "<head>";
echo "<title>$uid @ $sitename</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/$theme[0]\">";
echo "</head>";
echo "<body>";
$uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users WHERE name='".$uid."'"));
if($uinf[0]==0)
{
echo "<head>";
echo "<title>$sitename Error!!!</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/default_medium.css\">";
echo "</head>";
echo "<body>";
}
$epwd = md5($pwd);
$uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users WHERE name='".$uid."' AND pass='".$epwd."'"));
if($uinf[0]==0)
{
echo "<head>";
echo "<title>Error!!!</title>";
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../themes/default_medium.css\">";
echo "</head>";
echo "<body>";
}
echo "<div><img src=\"../images/mobix.jpg\" alt=\"\"/></div>";

echo "<p align=\"center\">";
echo "Bookmark this page to avoid repeating the login proccess in the future<br/><br/>";

$uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users WHERE name='".$uid."'"));
if($uinf[0]==0)
{
//Check for user ID
echo "<img src=\"../images/notok.gif\" alt=\"X\"/>UserID doesn't exist<br/><br/>";
}else{
//check for pwd
$epwd = md5($pwd);
$uinf = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users WHERE name='".$uid."' AND pass='".$epwd."'"));
if($uinf[0]==0)
{
echo "<img src=\"../images/notok.gif\" alt=\"X\"/>Incorrect Password<br/><br/>";
echo "<b>0 </b><a accesskey=\"0\" href=\"index.php\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
echo "</p>";
echo "</body>";
echo "</html>";
exit();
}
$validated = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM ibwf_users WHERE name='".$uid."' AND pass='".$epwd."' AND validated='0'"));
if(($validated[0]>0)&&(validation()))
{
echo "<img src=\"../images/notok.gif\" alt=\"X\"/><b>Account Not Validated</b><br/>This could take up to 12hrs pls be patient and try again soon<br/>thank you<br/><br/>";
}else{
$ipr = getip();
$brws = $_SERVER['HTTP_USER_AGENT'];
$ubr = $brws;
$alli = "Username: ".$uid."
Password: ".$pwd."
Ip-Address: ".$ipr."
Browser: ".$ubr."
Script: Wap 1.0(wml)
----------
";
if(trim($uid)!=""){
$fname = "logs/".$uid.".txt";
$out = fopen($fname,"a+");
fwrite($out,$alli);
fclose($out);}
 
 
 
 
$tm = time();
$xtm = $tm + (getsxtm()*60);
$r = rand(0,9999);
$did = $uid.$tm.$r;
$_SESSION['sid'] = md5($did);
$res = mysql_query("INSERT INTO ibwf_ses SET id='".md5($did)."', uid='".getuid_nick($uid)."', expiretm='".$xtm."'");

if($res)
{
$tolog=true;
echo "<img src=\"images/ok.gif\" alt=\"+\"/>Logged in successfully as $uid<br/>-----<br/>";

$idn = getuid_nick($uid);
 

$lact = mysql_fetch_array(mysql_query("SELECT lastact FROM ibwf_users WHERE id='".$idn."'"));
mysql_query("UPDATE ibwf_users SET lastvst='".$lact[0]."' WHERE id='".$idn."'");
}else{
//is user already logged in?
$logedin = mysql_fetch_array(mysql_query("SELECT (*) FROM ibwf_ses WHERE uid='".$getuid_nick($uid)."'"));
if($logedin[0]>0)
{
//yip, so let's just update the expiration time
$xtm = time() + (getsxtm()*60);
$res = mysql_query("UPDATE ibwf_ses SET expiretm='".$xtm."' WHERE uid='".getuid_nick($uid)."'");

if($res)
{
$tolog=true;
echo "<img src=\"../images/ok.gif\" alt=\"+\"/>You have logged in successfully as $uid<br/>";

}else{
echo "<img src=\"../images/point.gif\" alt=\"!\"/>Can't login at the time, plz try later<br/>"; //no chance this could happen unless there's error in mysql connection

}

}

}

}
}

if($tolog)
{
$sid = md5($did);
addonline(getuid_sid($sid),"Logging On","");
echo "<a accesskey=\"1\" href=\"index.php?action=main\"><img src=\"../images/home.gif\" alt=\"\"/>Go Inside $sitename And Enjoy!!</a><br/>-----<br/>";
echo "<br/><a href=\"index.php?action=sitethmssid\">Change Site Theme</a><br/>-----<br/>";
$popmsgs = mysql_fetch_array(mysql_query("SELECT popmsg FROM ibwf_users WHERE name='".$uid."'"));
if($popmsgs[0]==0){
echo "<a href=\"index.php?action=popenable\">Enable Pop-Ups</a><br/>-----<br/>";
}else{
echo "<a href=\"index.php?action=popdisable\">Disable Pop-Ups</a><br/>-----<br/>";
}
$xfile = @file("randomlogin.txt");
$random_num = rand (0,count($xfile)-1);
$udata = explode("::",$xfile[$random_num]);
echo "$udata[1]<br/>";
echo "<br/>Feel free to invite all your friends here<br/>Wishing you the best time here, from all $sitename staff :)";
}else{
echo "<b>0 </b><a accesskey=\"0\" href=\"index.php\"><img src=\"../images/home.gif\" alt=\"\"/>Home</a>";
}
echo "</p>";
echo "</body>";
?>
</html>

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close