SlideShare una empresa de Scribd logo
1 de 40
Descargar para leer sin conexión
Web Application Security (PHP)
Zakieh Alizadeh
zakiehalizadeh@gmail.com
APA Laboratory – Ferdowsi University of Mashhad
Session 8
Session Management
Session Management
Session Management
 Description Mechanism of Cookies
 Introducing Session Management Attacks
Strategies Of Session Storage
Session Management Testing
Strategies for Secure Session Management
Mechanism of Cookies
HTTP session token
 Problem : HTTP is stateless
o Solution : HTTP Cookies
 The client usually stores cookies and sends the token as an
o HTTP cookie
o parameter in GET or POST queries.
Mechanism of Cookies
 What is Sessions
 A session is a semi-permanent interactive information interchange, also known as
a dialogue, a conversation or a meeting, between a computer and user .
 An established communication session may involve more than one message in
each direction.
 A session is typically, but not always, stateful, meaning that at least one of the
communicating parts needs to save information.
 where the communication consists of independent requests with responses.
Such as HTTP.
Mechanism of Cookies
Session ID
 A session identifier, session ID or session token is a piece of data that is
used in network communications (often over HTTP) to identify a session.
 A session ID is often a long, randomly generated string to decrease the
brute-force search.
 The reason to use session tokens is :
o client only has to handle the identifier (a small piece of data that hasn’t
security risk) - all session data is stored on the server and is not
transmit
Mechanism of Cookies
HTTP session token
Mechanism of Cookies
HTTP session token
Mechanism of Cookies
HTTP session token
Http Cookies
HTTP Cookies
 The following is a list of the attributes that can be set for each cookie :
o secure - only send the cookie if the request is being sent over a
secure channel such as HTTPS.
o HttpOnly - it does not allow the cookie to be accessed via a client side
script such as JavaScript.
• Note that not all browsers support this functionality.
o domain - compare against the domain of the server in which the URL
is being requested
Http Cookies
HTTP Cookies
 The following is a list of the attributes that can be set for each cookie :
o path - In addition to the domain, the URL path can be specified for
which the cookie is valid. If the domain and path match, then the
cookie will be sent in the request.
o expires - This attribute is used to set persistent cookies, since the
cookie does not expire until the set date is exceeded.
Http Cookies
 HTTP Cookies : PHP function
 session_set_cookie_params() The effect of this function only lasts for the duration of
the script.
 Thus, you need to call it for every request and before session_start() is called.
 This function updates the runtime ini values of the corresponding PHP ini configuration
session_set_cookie_params ($lifetime , $path , $domain, $secure = false , $httponly = false)
Http Cookies
 HTTP Cookies : PHP function
 setcookie() defines a cookie to be sent along with the rest of the HTTP headers.
 Like other headers, cookies must be sent before any output from your script (this is a
protocol restriction).
 Once the cookies have been set, they can be accessed on the next page load with the
$_COOKIE
Setcookie ( $name , $value , $expire = 0 , $path , $domain , $secure =false , $httponly = false )
Session Management
Session management
 session management is the process of keeping track of a user's activity
across sessions of interaction with the system.
Session Management
 Description Mechanism of Cookies
 Introducing Session Management Attacks
Strategies Of Session Storage
Session Management Testing
Strategies for Secure Session Management
Session Attacks
Sessions Attack
 Session Fixation
 Session Brute-Forcing
 Session Hijacking
 Session Poisoning
Sessions Attack
Session fixation
 session fixation attacks allows one person to fixate (set) another person's
session identifier (SID).
 Hacker abtains valid session witout hijacking or sniffing, he fix valid
session for victim.
 Most rely on session identifiers being accepted from URLs (query string)
or POST data.
Sessions Attack
Session fixation
 Session fixation vulnerabilities occur when:
 A web application authenticates a user without first invalidating the
existing session ID, thereby continuing to use the session ID already
associated with the user.
 An attacker is able to force a known session ID on a user so that, once the
user authenticates, the attacker has access to the authenticated session.
Sessions Attack
Session fixation
1
3
2
4
No new
Cookie Set
In HTTP
Response
successfully authenticate request
Sessions Attack
Session fixation
Sessions Attack
Session fixation : Countermeasures
 Do not accept session identifiers from GET / POST variables
 Accept only server-generated SIDs
 Logout function
 Destroy session if Referrer is suspicious
 Time-out old SIDs
 Verify that additional information is consistent throughout session
 User Agent
Sessions Attack
Session fixation : Defense in Depth
 Enable HTTPS (to protect against other problems)
 Correct configuration (do not accept external SIDs, set time-out, etc.)
o Ini_set(“session_use_only_cookie”,1)
 Perform session_regeneration, support log-out, etc.
Sessions Attack
Session hijacking
 session hijacking is the exploitation of a valid sessionID to gain unauthorized
access to information or services in a computer system.
Sessions Attack
Session hijacking : Methods
 Session fixation
 Session sidejacking
o where the attacker uses packet sniffing
o Many web sites use SSL encryption for login pages to prevent
attackers from seeing the password, but do not use encryption for the
rest of the site once authenticated.

Sessions Attack
Session hijacking : Methods
 obtaining the file or memory contents of the appropriate part of either
the user's computer or the server.
 Cross-site scripting, where the attacker tricks the user's computer into
running code which is treated as trustworthy because it appears to
belong to the server, allowing the attacker to obtain a copy of the cookie
or perform other operations.
Sessions Attack
Session hijacking : Countermeasures
 Provide a method for users to log out of the application.
o Logging out button should clear
o all session state and remove or invalidate any residual cookies.
 Set short expiry times on persistent cookies, no more than a day.
 Do not store session tokens in the URL or other trivially modified data
entry point.
Sessions Attack
Brute Force Session Identifier
 Session tokens are generated in
o a predictable fashion
o key space that is too small to prevent guessing a token in reasonable
time.
o The application does not detect and prevent session brute forcing
attempts.
 A session ID must not be valid over two currently active SSL connections
at the same time.
Sessions Attack
Brute Force SessionID: Countermeasures
 Session identifiers should be at least 128 bits(32byte) long to prevent
brute-force session guessing attacks.
 Limit the number of unique session tokens you see from the same IP
address (ie 20 in thelast five minutes).
 Use Strong Session Cryptographic Algorithms
o Use Framework session management impelemention
Sessions Attack
Session poisoning
 This should actually be called session injection, as it is just one more
variable injection type of attack. If you allow user input into session
variables, make sure you validate the data.
 Typically a server application that is vulnerable to this type of exploit will
copy user input into session variables.
Sessions Attack
Session poisoning :Example
 Exploiting ambiguous or dual use of same session variable
 Exploiting scripts allowing writes to arbitrary session variables
$var = $_GET["something"];
$_SESSION["$var"] = $var2;
vulnerable.php?something=SESSION_VAR_TO_POISON
Sessions Attack
Session poisoning :Example
 Session poisoning attacks enabled by php.ini: register_globals = on
 It is possible for attacker to cause both conditions to be false.
 php.ini is misconfigured (register_globals = on), which allows $var default
value to be controlled by GPC (GET, POST, or COOKIE) input.
if ($condition1) { $var = 'SOMETHING'; };
if ($condition2) { $var = 'OTHER'; };
$_SESSION["$var"] = $var2;
Session Storage
Session Storage
 Sessions data can Store in :
o Files (on server)
o database.
 Sessions data that Storage in Files
o Better performance ,But weak security
 Sessions data that Storage in Database
o Better security,But weak performance
Session Management
 Description Mechanism of Cookies
 Introducing Session Management Attacks
Strategies Of Session Storage
Session Management Testing
Strategies for Secure Session Management
Session Management Testing
Session Management Testing
Test Desc
Testing for Session
Management Schema
 1-cookie collection: 2-cookie reverse engineering 3- cookie
manipulation
 The session tokens tested for their randomness, uniqueness,
resistance to statistical and cryptographic analysis
Testing for Cookies
attributes
Testing for secure or httponly setting
Are all Set-Cookie directives tagged as Secure?
What Expires= times are used on persistent cookies
Testing for Session
Fixation  no new cookie has been issued upon a successful authentication
Session Management Testing
Session Management Testing
Test Desc
Testing for Exposed
Session Variables
How are Session IDs transferred? E.g., GET, POST, Form Field
Are Session IDs always sent over encrypted transport by default?
Testing for CSRF
URL being tested; for example
 u = http://www.example.com/action
build an html page containing the http request referencing URL u
Regeneration of
Session Tokens
•Note the Session ID at the start and after every significant test
transaction.
If the session ID never changes,Application be at risk
Session Management
 Description Mechanism of Cookies
 Introducing Session Management Attacks
Strategies Of Session Storage
Session Management Testing
Strategies for Secure Session Management
Session Management
Session Management : Countermeasures
 Avoid Weak Session Cryptographic Algorithms
 Use Appropriate Key Space
 Impelement Session Time-out
 Regeneration of Session Tokens
o prior to any significant transaction
o after a certain number of requests
o after as a function of time, say every 20 minutes or so.
o Problem : when using third party software
Session Management
Session Management : Countermeasures
 Using framework implementation session management.
 Authorization and role data should be stored on the server side only.
 Presentation flags (such as theme or user language) can belong in
cookies.
 Tie the session to a particular browser by using a hash of the server-side
IP address.
Session Management

Más contenido relacionado

La actualidad más candente

Owasp Top 10 And Security Flaw Root Causes
Owasp Top 10 And Security Flaw Root CausesOwasp Top 10 And Security Flaw Root Causes
Owasp Top 10 And Security Flaw Root Causes
Marco Morana
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
Haitham Raik
 
PCI security requirements secure coding and code review 2014
PCI security requirements   secure coding and code review 2014PCI security requirements   secure coding and code review 2014
PCI security requirements secure coding and code review 2014
Haitham Raik
 

La actualidad más candente (20)

Application Security Part 1 Threat Defense In Client Server Applications ...
Application Security   Part 1   Threat Defense In Client Server Applications ...Application Security   Part 1   Threat Defense In Client Server Applications ...
Application Security Part 1 Threat Defense In Client Server Applications ...
 
Owasp Top 10 And Security Flaw Root Causes
Owasp Top 10 And Security Flaw Root CausesOwasp Top 10 And Security Flaw Root Causes
Owasp Top 10 And Security Flaw Root Causes
 
OWASP Secure Coding Practices - Quick Reference Guide
OWASP Secure Coding Practices - Quick Reference GuideOWASP Secure Coding Practices - Quick Reference Guide
OWASP Secure Coding Practices - Quick Reference Guide
 
Secure code practices
Secure code practicesSecure code practices
Secure code practices
 
Intro to Web Application Security
Intro to Web Application SecurityIntro to Web Application Security
Intro to Web Application Security
 
2013 OWASP Top 10
2013 OWASP Top 102013 OWASP Top 10
2013 OWASP Top 10
 
Top 10 Web Security Vulnerabilities
Top 10 Web Security VulnerabilitiesTop 10 Web Security Vulnerabilities
Top 10 Web Security Vulnerabilities
 
Web application attacks
Web application attacksWeb application attacks
Web application attacks
 
PCI Security Requirements - secure coding
PCI Security Requirements - secure codingPCI Security Requirements - secure coding
PCI Security Requirements - secure coding
 
PCI security requirements secure coding and code review 2014
PCI security requirements   secure coding and code review 2014PCI security requirements   secure coding and code review 2014
PCI security requirements secure coding and code review 2014
 
Web application security
Web application securityWeb application security
Web application security
 
OWASP Top 10 Proactive Controls
OWASP Top 10 Proactive ControlsOWASP Top 10 Proactive Controls
OWASP Top 10 Proactive Controls
 
Introduction to Web Application Penetration Testing
Introduction to Web Application Penetration TestingIntroduction to Web Application Penetration Testing
Introduction to Web Application Penetration Testing
 
Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)Top 10 Web Security Vulnerabilities (OWASP Top 10)
Top 10 Web Security Vulnerabilities (OWASP Top 10)
 
Owasp first5 presentation
Owasp first5 presentationOwasp first5 presentation
Owasp first5 presentation
 
OWASP top 10-2013
OWASP top 10-2013OWASP top 10-2013
OWASP top 10-2013
 
ieee
ieeeieee
ieee
 
Owasp top 10 2013
Owasp top 10 2013Owasp top 10 2013
Owasp top 10 2013
 
Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008
 
Web Application Firewall: Suckseed or Succeed
Web Application Firewall: Suckseed or SucceedWeb Application Firewall: Suckseed or Succeed
Web Application Firewall: Suckseed or Succeed
 

Similar a S8-Session Managment

Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
Harit Kothari
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
Satish b
 

Similar a S8-Session Managment (20)

Cookies and Session
Cookies and SessionCookies and Session
Cookies and Session
 
Mobile Application Security - Broken Authentication & Management
Mobile Application Security - Broken Authentication & ManagementMobile Application Security - Broken Authentication & Management
Mobile Application Security - Broken Authentication & Management
 
Owasp top 10_openwest_2019
Owasp top 10_openwest_2019Owasp top 10_openwest_2019
Owasp top 10_openwest_2019
 
Session Management & Cookies In Php
Session Management & Cookies In PhpSession Management & Cookies In Php
Session Management & Cookies In Php
 
Php ssession - cookies -introduction
Php ssession - cookies -introductionPhp ssession - cookies -introduction
Php ssession - cookies -introduction
 
Proxy Caches and Web Application Security
Proxy Caches and Web Application SecurityProxy Caches and Web Application Security
Proxy Caches and Web Application Security
 
Lecture8 php page control by okello erick
Lecture8 php page control by okello erickLecture8 php page control by okello erick
Lecture8 php page control by okello erick
 
Session management
Session management  Session management
Session management
 
06 application security fundamentals - part 2 - security mechanisms - sessi...
06   application security fundamentals - part 2 - security mechanisms - sessi...06   application security fundamentals - part 2 - security mechanisms - sessi...
06 application security fundamentals - part 2 - security mechanisms - sessi...
 
Security in php
Security in phpSecurity in php
Security in php
 
Magento security best practices magento's approach to pci compliance
Magento security best practices  magento's approach to pci complianceMagento security best practices  magento's approach to pci compliance
Magento security best practices magento's approach to pci compliance
 
Web security for developers
Web security for developersWeb security for developers
Web security for developers
 
season management in php (WT)
season management in php (WT)season management in php (WT)
season management in php (WT)
 
Security In PHP Applications
Security In PHP ApplicationsSecurity In PHP Applications
Security In PHP Applications
 
Cookie
CookieCookie
Cookie
 
Bitrix Software Security
Bitrix Software SecurityBitrix Software Security
Bitrix Software Security
 
Rest API Security - A quick understanding of Rest API Security
Rest API Security - A quick understanding of Rest API SecurityRest API Security - A quick understanding of Rest API Security
Rest API Security - A quick understanding of Rest API Security
 
Pentesting web applications
Pentesting web applicationsPentesting web applications
Pentesting web applications
 
Cm2 secure code_training_1day_data_protection
Cm2 secure code_training_1day_data_protectionCm2 secure code_training_1day_data_protection
Cm2 secure code_training_1day_data_protection
 
Sessions n cookies
Sessions n cookiesSessions n cookies
Sessions n cookies
 

Más de zakieh alizadeh (8)

Session11-NoSQL InjectionPHP Injection
Session11-NoSQL InjectionPHP Injection Session11-NoSQL InjectionPHP Injection
Session11-NoSQL InjectionPHP Injection
 
Session6-Protecct Sensetive Data
Session6-Protecct Sensetive DataSession6-Protecct Sensetive Data
Session6-Protecct Sensetive Data
 
Session1-Introduce Http-HTTP Security headers
Session1-Introduce Http-HTTP Security headers Session1-Introduce Http-HTTP Security headers
Session1-Introduce Http-HTTP Security headers
 
yii framework
yii frameworkyii framework
yii framework
 
Web security Contents
Web security ContentsWeb security Contents
Web security Contents
 
Validating and Sanitizing User Data
Validating and Sanitizing  User DataValidating and Sanitizing  User Data
Validating and Sanitizing User Data
 
Session3 data-validation
Session3 data-validationSession3 data-validation
Session3 data-validation
 
Introduce Yii
Introduce YiiIntroduce Yii
Introduce Yii
 

Último

AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 

S8-Session Managment

  • 1. Web Application Security (PHP) Zakieh Alizadeh zakiehalizadeh@gmail.com APA Laboratory – Ferdowsi University of Mashhad
  • 4. Session Management  Description Mechanism of Cookies  Introducing Session Management Attacks Strategies Of Session Storage Session Management Testing Strategies for Secure Session Management
  • 5. Mechanism of Cookies HTTP session token  Problem : HTTP is stateless o Solution : HTTP Cookies  The client usually stores cookies and sends the token as an o HTTP cookie o parameter in GET or POST queries.
  • 6. Mechanism of Cookies  What is Sessions  A session is a semi-permanent interactive information interchange, also known as a dialogue, a conversation or a meeting, between a computer and user .  An established communication session may involve more than one message in each direction.  A session is typically, but not always, stateful, meaning that at least one of the communicating parts needs to save information.  where the communication consists of independent requests with responses. Such as HTTP.
  • 7. Mechanism of Cookies Session ID  A session identifier, session ID or session token is a piece of data that is used in network communications (often over HTTP) to identify a session.  A session ID is often a long, randomly generated string to decrease the brute-force search.  The reason to use session tokens is : o client only has to handle the identifier (a small piece of data that hasn’t security risk) - all session data is stored on the server and is not transmit
  • 11. Http Cookies HTTP Cookies  The following is a list of the attributes that can be set for each cookie : o secure - only send the cookie if the request is being sent over a secure channel such as HTTPS. o HttpOnly - it does not allow the cookie to be accessed via a client side script such as JavaScript. • Note that not all browsers support this functionality. o domain - compare against the domain of the server in which the URL is being requested
  • 12. Http Cookies HTTP Cookies  The following is a list of the attributes that can be set for each cookie : o path - In addition to the domain, the URL path can be specified for which the cookie is valid. If the domain and path match, then the cookie will be sent in the request. o expires - This attribute is used to set persistent cookies, since the cookie does not expire until the set date is exceeded.
  • 13. Http Cookies  HTTP Cookies : PHP function  session_set_cookie_params() The effect of this function only lasts for the duration of the script.  Thus, you need to call it for every request and before session_start() is called.  This function updates the runtime ini values of the corresponding PHP ini configuration session_set_cookie_params ($lifetime , $path , $domain, $secure = false , $httponly = false)
  • 14. Http Cookies  HTTP Cookies : PHP function  setcookie() defines a cookie to be sent along with the rest of the HTTP headers.  Like other headers, cookies must be sent before any output from your script (this is a protocol restriction).  Once the cookies have been set, they can be accessed on the next page load with the $_COOKIE Setcookie ( $name , $value , $expire = 0 , $path , $domain , $secure =false , $httponly = false )
  • 15. Session Management Session management  session management is the process of keeping track of a user's activity across sessions of interaction with the system.
  • 16. Session Management  Description Mechanism of Cookies  Introducing Session Management Attacks Strategies Of Session Storage Session Management Testing Strategies for Secure Session Management
  • 17. Session Attacks Sessions Attack  Session Fixation  Session Brute-Forcing  Session Hijacking  Session Poisoning
  • 18. Sessions Attack Session fixation  session fixation attacks allows one person to fixate (set) another person's session identifier (SID).  Hacker abtains valid session witout hijacking or sniffing, he fix valid session for victim.  Most rely on session identifiers being accepted from URLs (query string) or POST data.
  • 19. Sessions Attack Session fixation  Session fixation vulnerabilities occur when:  A web application authenticates a user without first invalidating the existing session ID, thereby continuing to use the session ID already associated with the user.  An attacker is able to force a known session ID on a user so that, once the user authenticates, the attacker has access to the authenticated session.
  • 20. Sessions Attack Session fixation 1 3 2 4 No new Cookie Set In HTTP Response successfully authenticate request
  • 22. Sessions Attack Session fixation : Countermeasures  Do not accept session identifiers from GET / POST variables  Accept only server-generated SIDs  Logout function  Destroy session if Referrer is suspicious  Time-out old SIDs  Verify that additional information is consistent throughout session  User Agent
  • 23. Sessions Attack Session fixation : Defense in Depth  Enable HTTPS (to protect against other problems)  Correct configuration (do not accept external SIDs, set time-out, etc.) o Ini_set(“session_use_only_cookie”,1)  Perform session_regeneration, support log-out, etc.
  • 24. Sessions Attack Session hijacking  session hijacking is the exploitation of a valid sessionID to gain unauthorized access to information or services in a computer system.
  • 25. Sessions Attack Session hijacking : Methods  Session fixation  Session sidejacking o where the attacker uses packet sniffing o Many web sites use SSL encryption for login pages to prevent attackers from seeing the password, but do not use encryption for the rest of the site once authenticated. 
  • 26. Sessions Attack Session hijacking : Methods  obtaining the file or memory contents of the appropriate part of either the user's computer or the server.  Cross-site scripting, where the attacker tricks the user's computer into running code which is treated as trustworthy because it appears to belong to the server, allowing the attacker to obtain a copy of the cookie or perform other operations.
  • 27. Sessions Attack Session hijacking : Countermeasures  Provide a method for users to log out of the application. o Logging out button should clear o all session state and remove or invalidate any residual cookies.  Set short expiry times on persistent cookies, no more than a day.  Do not store session tokens in the URL or other trivially modified data entry point.
  • 28. Sessions Attack Brute Force Session Identifier  Session tokens are generated in o a predictable fashion o key space that is too small to prevent guessing a token in reasonable time. o The application does not detect and prevent session brute forcing attempts.  A session ID must not be valid over two currently active SSL connections at the same time.
  • 29. Sessions Attack Brute Force SessionID: Countermeasures  Session identifiers should be at least 128 bits(32byte) long to prevent brute-force session guessing attacks.  Limit the number of unique session tokens you see from the same IP address (ie 20 in thelast five minutes).  Use Strong Session Cryptographic Algorithms o Use Framework session management impelemention
  • 30. Sessions Attack Session poisoning  This should actually be called session injection, as it is just one more variable injection type of attack. If you allow user input into session variables, make sure you validate the data.  Typically a server application that is vulnerable to this type of exploit will copy user input into session variables.
  • 31. Sessions Attack Session poisoning :Example  Exploiting ambiguous or dual use of same session variable  Exploiting scripts allowing writes to arbitrary session variables $var = $_GET["something"]; $_SESSION["$var"] = $var2; vulnerable.php?something=SESSION_VAR_TO_POISON
  • 32. Sessions Attack Session poisoning :Example  Session poisoning attacks enabled by php.ini: register_globals = on  It is possible for attacker to cause both conditions to be false.  php.ini is misconfigured (register_globals = on), which allows $var default value to be controlled by GPC (GET, POST, or COOKIE) input. if ($condition1) { $var = 'SOMETHING'; }; if ($condition2) { $var = 'OTHER'; }; $_SESSION["$var"] = $var2;
  • 33. Session Storage Session Storage  Sessions data can Store in : o Files (on server) o database.  Sessions data that Storage in Files o Better performance ,But weak security  Sessions data that Storage in Database o Better security,But weak performance
  • 34. Session Management  Description Mechanism of Cookies  Introducing Session Management Attacks Strategies Of Session Storage Session Management Testing Strategies for Secure Session Management
  • 35. Session Management Testing Session Management Testing Test Desc Testing for Session Management Schema  1-cookie collection: 2-cookie reverse engineering 3- cookie manipulation  The session tokens tested for their randomness, uniqueness, resistance to statistical and cryptographic analysis Testing for Cookies attributes Testing for secure or httponly setting Are all Set-Cookie directives tagged as Secure? What Expires= times are used on persistent cookies Testing for Session Fixation  no new cookie has been issued upon a successful authentication
  • 36. Session Management Testing Session Management Testing Test Desc Testing for Exposed Session Variables How are Session IDs transferred? E.g., GET, POST, Form Field Are Session IDs always sent over encrypted transport by default? Testing for CSRF URL being tested; for example  u = http://www.example.com/action build an html page containing the http request referencing URL u Regeneration of Session Tokens •Note the Session ID at the start and after every significant test transaction. If the session ID never changes,Application be at risk
  • 37. Session Management  Description Mechanism of Cookies  Introducing Session Management Attacks Strategies Of Session Storage Session Management Testing Strategies for Secure Session Management
  • 38. Session Management Session Management : Countermeasures  Avoid Weak Session Cryptographic Algorithms  Use Appropriate Key Space  Impelement Session Time-out  Regeneration of Session Tokens o prior to any significant transaction o after a certain number of requests o after as a function of time, say every 20 minutes or so. o Problem : when using third party software
  • 39. Session Management Session Management : Countermeasures  Using framework implementation session management.  Authorization and role data should be stored on the server side only.  Presentation flags (such as theme or user language) can belong in cookies.  Tie the session to a particular browser by using a hash of the server-side IP address.