I read a lot of q / a on SO about the risk of committing / capturing a session, and many people suggest changing php.ini directives like session.use_only_cookies - ON and other php.ini directives to make the server more secure ...
I wanted to see it with my own eyes if I could reproduce a simple attack scenario on my localhost server based on PHP5 + Apache.
My localhost session.use_only_cookies has OFF , so according to q / a above, my local host is basically insecure, and this is what I need to do.
I first read this simple article on how a session commit attack is performed:
To reproduce the scenario described in the article, I created two very simple PHP scripts (the code below), but the attack does not work, here is what I did:
(Pretending to be Mallory) I say to Alice: "Hi, visit http: //localhost/login.php? PHPSESSID = mysessionid "
Then (pretending to be Alice) I went to http: //localhost/login.php? PHPSESSID = mysessionid
As the administrator of my localhost server, I saw that the session is being created on the server disk (this is called a file called sess_ mysessionid ), so I thought: cool, it works !!!
Then (claiming to be Alice) I logged in to joe as credentials
Alice logs in and she is redirected to insession_ok.php , and at that moment (according to Wikipedia article above) Mallory should be able to see insession_ok.php too, because he registered the session before mysessionid , but this is not true, because when Alice registers in a new session, it is created on the server sess_vdshg238cnfb4vt7ahpnp1p522 , so I donβt understand at this stage how Mallory should record / capture the session, as explained in the article ???
login.php
<?php session_start(); //if user credentials are ok, let put him in session if( @$_POST['usr'] === 'joe' ) $_SESSION['in_session'] = TRUE; //if user is already logged in, let redirect him to the account page "insession_ok.php" if( isset($_SESSION['in_session']) ) { $webpage = 'http://' . $_SERVER['HTTP_HOST'] . '/insession_ok.php'; header("Location: " . $webpage, TRUE, 302); } ?> <form method="POST" action="login.php"> <input name="usr" type="text"> <input type="submit" value="Submit"> </form> <script type="text/javascript"> alert(document.cookie); //to view cookies </script>
insession_ok.php
<?php session_start(); if(@$_SESSION['in_session'] === TRUE) echo "in session ok"; else //user is not in session cause he did not login, let redirect him to login page { $webpage = 'http://' . $_SERVER['HTTP_HOST'] . '/login.php'; header("Location: " . $webpage, TRUE, 302); } ?>
Any hint / idea is always appreciated!
source share