Laboratory3-ITT557-2020878252-SITI FARHANA
Laboratory3-ITT557-2020878252-SITI FARHANA
Laboratory3-ITT557-2020878252-SITI FARHANA
ITT 557
SESSION HIJACKING PART 1
REQUIREMENTS
For this laboratory session, students are required to have the following:
i. A running web server installation (WAMP or XAMPP)
ii. Code Editor (Notepad++, Sublime Text or Visual Studio)
iii. 2 Different types of browser (Chrome, Firefox or Edge, either 2) iv.
Postman
INSTRUCTIONS (PART I)
1. Download your preferred Apache and PHP package installation (MAMP or XAMPP)
and install.
2. Once the installation is completed and you have verified that the webserver is up
and running, create a phpinfo() page to see the PHP configuration.
a. Create a file called akurindukucingku.php
b. Insert the following code inside the file, and save.
<?php
phpinfo();
?>
c. Access the file created using a web browser, you should get page like the
following:
2 | Mohd Ali Mohd Isa © 2022
d. Scroll down through the page until you reach the section for Session. Look
for the following settings session.use_only_cookies and
session.use_strict_mode.
e. For this lab, the setting for both parameters needs to be:
Session.use_only_cookies = 0
Session.use_strict_mode = 0
3. Download the sessionfixation.php file from Google Classroom and save it inside your
web home folder. This is normally a folder called htdocs or www in some cases.
4. Open up a browser (Let us call it Browser 1) and access the file via URL:
http://localhost/sessionfixation.php
6. Now we need to find the complete session ID. By using your knowledge learnt in
Laboratory session 1, find the complete Session ID in the Request Headers.
7. Once you have the session ID, copy the session ID.
PHPSESSID=lhco3v2ld8ucjqghaje6f35v41
8. Open a new browser (Browser 2) other than the one you are using now. (For
example, if now you are using Chrome, open Edge or Firefox)
9. Type in the following URL:
http://localhost/sessionfixation.php?PHPSESSID=<session id>
10. Make sure to replace <session id> with the complete session id that you have found.
11. You should get the following:
16. Now since both user and attacker is sharing the same session ID, when the user log
in then the attacker should get logged in too. Go back to Browser 1 and hit refresh.
You should see that Browser 1 will also change to logged in without the need for the
attacker to insert the password. And this my friend is what we called Session
Fixation attack.
17. Clap 5 times so that I know you have completed the first part of the lab! :D
session_regenerate_id();
3. The function will generate a new session ID for user , when they logged in.
4. The code should look like the following:
5. Save the file, and try to carried out the attack again. You will notice that this time the
attack will fail.
6. This is how to defense against the attack via code.
7. Comment out the line session_regenerate_id(), and verify that the attack can be
carried out again.
8. Now we are going to see how to defense from the attack via server configuration.
9. Open php.ini using editor.
10. Search for the following variable:
Session.use_only_cookies
Session.use_only_cookies = 1
12. Restart webserver and try to carried out the Session Fixation attack again. You
should get that the user Session ID will always be different than the attacker Session
ID.
13. Well Done! Clap 7 times so that I know you have completed part 1B.
PART 2: ADVANCED SESSION ATTACK
In part 1 we have seen that attack can be stop if we set the variables session.use_only_cookies
= 1 in our configuration file. Since this will stop the attacker from forcing the client to use the
same session ID as the attacker.
But what if the attacker manages to get the user session ID, can the attacker hijack the user
session?
1. Open the phpinfo() page and verified that the settings for variable
session.use_only_cookies is set to 1.
2. Download the zip file session-hijack.zip from Google Classroom. Unzip the file and place it
inside your webserver root folder. This is normally a folder called htdocs.
3. Open the index page which can be access via the following URL:
http://localhost/session-hijacking/
Answer: No
6. Let us try to access the admin page directly to see if the session has been implemented
correctly. Access the following URL:
http://localhost/session-hijacking/admin.php
7. We should get a message saying that we are not authorized to view the admin page.
8. Now go back to the login page, and login using admin/admin as the username and
password combination.
9. You should get access to the admin page. Once you have login, does the session ID
change to a new one?
Answer:No
10. We are now going to mimic another request by attacker by using a software called
Postman. Postman is a tool normally used by web developer to test out their
websites request/response and API.
11. Head over to https://www.postman.com/downloads/ and download version
compatibles with your computer.
12. Once the files have been downloaded, run Postman.
13. You will need to have an account before you can start using Postman, so sign up for
an account.
18. Try to also access the admin page via Postman to verify that we are unable to access
the admin page.
9 | Mohd Ali Mohd Isa © 2022
19. Click on the Cookies tab, it will show the current session ID of the attacker.
20. Let’s assume that the attacker has managed to steal the admin session ID via other
attacks, such as Cross Site Scripting (which we will cover later). Can the attacker log in
as admin, only by knowing the Session ID? Let us try.
21. Copy the Session ID obtained from the admin page.
22. Replace the Session ID value inside Postman with the admin Session ID. How?
23. Click on the Cookies button.
24. On the resulting Cookies panel, click on PHPSESSID and then modify the value so that
the Session ID is the same as the admin Session ID.