SlideShare une entreprise Scribd logo
1  sur  19
Cross Site Request Forgery


                                Obay Osman
                                 OWASP Khartoum
                                  15 Sept 2012




                                      Copyright © The OWASP Foundation
Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.
ToC
•   Definition.
•   OWASP Rating.
•   Attack Scenarios.
•   CSRF in the wiled.
•   Demo time.
•   Detection
•   Protection.
•   Summery & Discussion.
                            2
Definition
A CSRF attack is forcing a logged-on
  victim‟s browser to send a forged HTTP
  request, including the victim‟s session
  cookie and any other automatically
  included authentication information, to
  a vulnerable web application.
Synonyms: XSRF, "Sea Surf", Session Riding,
  Cross-Site Reference Forgery, Hostile
  Linking, One-Click (Microsoft).

                                              3
OWASP Risk Rating #




                      4
Attack Scenarios
User:
http://bank.com/app/transferFunds?amount=1
  500&destinationAccount=4673243243



Attacker:
<img src=
"http://bank.com/app/transferFunds?amo
unt=1500&destinationAccount=attackersA
cct#“ width="0" height="0" />



                                             5
#1




 6
#2




 7
Let us break something…




                          9
In the wield..
- Firewall web management.
- Stored CSRF flaws.(Self-vulnerable
  applications)
- Sammy Worm.
Methodologies: XSS, Social Engineering….




                                           10
Detection
Code Review:
• see if each link and form contains an
  unpredictable token for each user.
• focus on state-changing functions.
• check multistep transactions.
PenTesting:
• Manual Testing.
• OWASP‟s CSRF Tester tool.
                                          11
Protection[Developers]
• Check referrer, Really help?!(open
  redirect/HTTPS/subdomains)

• Double Submit Cookies.
• Challenge-Response. (CAPTCHA/Re-Authentication)
• Put unique token in the URL/URL
  parameter.
• Include the unique token (per
  request/session) in a hidden field.
      No XSS & Share a ‘Secret’ With The User.
                                                    12
Protection[Tokens]
Good Tokens:
Nonce:
One-time cryptographically random token
  that is returned to the client per request.
HMAC:
#(PageUrl+Session/userID+Timestamp)
(eg In .net encrypted „ViewState‟)

                                                13
Protection             [Defense in depth]


Do not use GET parameters.
Do not put the secret in the
  URL/Cookies.(log/history/referer exposure,!)
Send successful logins to a well-known
  location instead of automatic
  redirection.(Top10 A10)
Do not resubmit POST parameters if you
  need to perform redirection.

                                                 14
Protection          [Users]


Logoff immediately after using a web
  application
Do not allow your browser to save
  username/passwords, and do not allow
  sites to “remember” your login
Do not use the same browser to access
  sensitive applications and to surf freely
  the Internet.
Be careful when clicking untrusted Links.
                                              15
OWASP‟s Tools

OWASP‟s CSRF Guard can be used to
 automatically include such tokens in
 your Java EE, .NET, or PHP application.
OWASP‟s ESAPI token generators and
 validators.
+ OWASP‟s CSRF Tester.




                                           16
OWASP Top 10 2010:
A1 –Injection
A2 –Cross-Site Scripting (XSS)
A3 –Broken Authentication and Session Management
A4 –Insecure Direct Object Reference
A5 –Cross Site Request Forgery (CSRF)
A6 –Security Misconfiguration(NEW)
A7 –Insecure Cryptographic Storage
A8 –Failure to Restrict URL Access
A9 –Insufficient Transport Layer Protection
A10 –Unvalidated Redirects and Forwards (NEW)
Ref.
• https://www.owasp.org/index.php/CSRF
• https://www.owasp.org/index.php/Testing_for_CSRF_
  %28OWASP-SM-005%29
• https://www.owasp.org/index.php/Cross-
  Site_Request_Forgery_%28CSRF%29_Prevention_Ch
  eat_Sheet
• http://cwe.mitre.org/data/definitions/352.html
• https://www.trustwave.com/sae_sample/owasp-top-
  10/CourseFiles/Player.htm
20

Contenu connexe

Tendances

Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Amit Tyagi
 
Protecting Java EE Web Apps with Secure HTTP Headers
Protecting Java EE Web Apps with Secure HTTP HeadersProtecting Java EE Web Apps with Secure HTTP Headers
Protecting Java EE Web Apps with Secure HTTP HeadersFrank Kim
 
Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Ikhade Maro Igbape
 
Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)Michael Hendrickx
 
Reflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site ScriptingReflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site ScriptingInMobi Technology
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defensesMohammed A. Imran
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encodingEoin Keary
 
HTTP Security Headers Every Java Developer Must Know
HTTP Security Headers Every Java Developer Must KnowHTTP Security Headers Every Java Developer Must Know
HTTP Security Headers Every Java Developer Must KnowAyoma Wijethunga
 
Devouring Security XML Attack surface and Defences
Devouring Security XML Attack surface and DefencesDevouring Security XML Attack surface and Defences
Devouring Security XML Attack surface and Defencesgmaran23
 
MITM Attacks on HTTPS: Another Perspective
MITM Attacks on HTTPS: Another PerspectiveMITM Attacks on HTTPS: Another Perspective
MITM Attacks on HTTPS: Another PerspectiveGreenD0g
 
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolfDefeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolfdrewz lin
 
Wakanda and the top 5 security risks - JS.everyrwhere(2012) Europe
Wakanda and the top 5 security risks - JS.everyrwhere(2012) EuropeWakanda and the top 5 security risks - JS.everyrwhere(2012) Europe
Wakanda and the top 5 security risks - JS.everyrwhere(2012) EuropeAlexandre Morgaut
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionMikhail Egorov
 
Phu appsec13
Phu appsec13Phu appsec13
Phu appsec13drewz lin
 
Django (Web Applications that are Secure by Default)
Django �(Web Applications that are Secure by Default�)Django �(Web Applications that are Secure by Default�)
Django (Web Applications that are Secure by Default)Kishor Kumar
 
DEFCON 17 Presentation: CSRF - Yeah, It Still Works
DEFCON 17 Presentation: CSRF - Yeah, It Still WorksDEFCON 17 Presentation: CSRF - Yeah, It Still Works
DEFCON 17 Presentation: CSRF - Yeah, It Still WorksRuss McRee
 
Its all about CSRF - null Mumbai Meet 10 January 2015 Null/OWASP Chapter
Its all about CSRF - null Mumbai Meet 10 January 2015 Null/OWASP Chapter Its all about CSRF - null Mumbai Meet 10 January 2015 Null/OWASP Chapter
Its all about CSRF - null Mumbai Meet 10 January 2015 Null/OWASP Chapter Nilesh Sapariya
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaJim Manico
 

Tendances (20)

Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 
Beef saurabh
Beef saurabhBeef saurabh
Beef saurabh
 
Protecting Java EE Web Apps with Secure HTTP Headers
Protecting Java EE Web Apps with Secure HTTP HeadersProtecting Java EE Web Apps with Secure HTTP Headers
Protecting Java EE Web Apps with Secure HTTP Headers
 
Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation
 
Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)Owasp Top 10 A3: Cross Site Scripting (XSS)
Owasp Top 10 A3: Cross Site Scripting (XSS)
 
Reflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site ScriptingReflective and Stored XSS- Cross Site Scripting
Reflective and Stored XSS- Cross Site Scripting
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defenses
 
04. xss and encoding
04.  xss and encoding04.  xss and encoding
04. xss and encoding
 
HTTP Security Headers Every Java Developer Must Know
HTTP Security Headers Every Java Developer Must KnowHTTP Security Headers Every Java Developer Must Know
HTTP Security Headers Every Java Developer Must Know
 
Devouring Security XML Attack surface and Defences
Devouring Security XML Attack surface and DefencesDevouring Security XML Attack surface and Defences
Devouring Security XML Attack surface and Defences
 
MITM Attacks on HTTPS: Another Perspective
MITM Attacks on HTTPS: Another PerspectiveMITM Attacks on HTTPS: Another Perspective
MITM Attacks on HTTPS: Another Perspective
 
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolfDefeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
Defeating xss-and-xsrf-with-my faces-frameworks-steve-wolf
 
Xss talk, attack and defense
Xss talk, attack and defenseXss talk, attack and defense
Xss talk, attack and defense
 
Wakanda and the top 5 security risks - JS.everyrwhere(2012) Europe
Wakanda and the top 5 security risks - JS.everyrwhere(2012) EuropeWakanda and the top 5 security risks - JS.everyrwhere(2012) Europe
Wakanda and the top 5 security risks - JS.everyrwhere(2012) Europe
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
 
Phu appsec13
Phu appsec13Phu appsec13
Phu appsec13
 
Django (Web Applications that are Secure by Default)
Django �(Web Applications that are Secure by Default�)Django �(Web Applications that are Secure by Default�)
Django (Web Applications that are Secure by Default)
 
DEFCON 17 Presentation: CSRF - Yeah, It Still Works
DEFCON 17 Presentation: CSRF - Yeah, It Still WorksDEFCON 17 Presentation: CSRF - Yeah, It Still Works
DEFCON 17 Presentation: CSRF - Yeah, It Still Works
 
Its all about CSRF - null Mumbai Meet 10 January 2015 Null/OWASP Chapter
Its all about CSRF - null Mumbai Meet 10 January 2015 Null/OWASP Chapter Its all about CSRF - null Mumbai Meet 10 January 2015 Null/OWASP Chapter
Its all about CSRF - null Mumbai Meet 10 January 2015 Null/OWASP Chapter
 
Cross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with JavaCross Site Scripting (XSS) Defense with Java
Cross Site Scripting (XSS) Defense with Java
 

En vedette

Synesis Embedded Video Analytics
Synesis Embedded Video AnalyticsSynesis Embedded Video Analytics
Synesis Embedded Video AnalyticsNikolai Ptitsyn
 
A5: Security Misconfiguration
A5: Security Misconfiguration A5: Security Misconfiguration
A5: Security Misconfiguration Tariq Islam
 
Sensitive Data Exposure
Sensitive Data ExposureSensitive Data Exposure
Sensitive Data Exposureabodiford
 
Forgery by Shukun Karthika
Forgery by Shukun KarthikaForgery by Shukun Karthika
Forgery by Shukun KarthikaShukun Karthika
 
OWASP Top 10 A4 – Insecure Direct Object Reference
OWASP Top 10 A4 – Insecure Direct Object ReferenceOWASP Top 10 A4 – Insecure Direct Object Reference
OWASP Top 10 A4 – Insecure Direct Object ReferenceNarudom Roongsiriwong, CISSP
 
WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE
WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSEWEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE
WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSEAjith Kp
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011photomatt
 

En vedette (7)

Synesis Embedded Video Analytics
Synesis Embedded Video AnalyticsSynesis Embedded Video Analytics
Synesis Embedded Video Analytics
 
A5: Security Misconfiguration
A5: Security Misconfiguration A5: Security Misconfiguration
A5: Security Misconfiguration
 
Sensitive Data Exposure
Sensitive Data ExposureSensitive Data Exposure
Sensitive Data Exposure
 
Forgery by Shukun Karthika
Forgery by Shukun KarthikaForgery by Shukun Karthika
Forgery by Shukun Karthika
 
OWASP Top 10 A4 – Insecure Direct Object Reference
OWASP Top 10 A4 – Insecure Direct Object ReferenceOWASP Top 10 A4 – Insecure Direct Object Reference
OWASP Top 10 A4 – Insecure Direct Object Reference
 
WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE
WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSEWEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE
WEB APPLICATION VULNERABILITIES: DAWN, DETECTION, EXPLOITATION AND DEFENSE
 
State of the Word 2011
State of the Word 2011State of the Word 2011
State of the Word 2011
 

Similaire à OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery

OWASP Serbia - A5 cross-site request forgery
OWASP Serbia - A5 cross-site request forgeryOWASP Serbia - A5 cross-site request forgery
OWASP Serbia - A5 cross-site request forgeryNikola Milosevic
 
OWASP App Sec US - 2010
OWASP App Sec US - 2010OWASP App Sec US - 2010
OWASP App Sec US - 2010Aditya K Sood
 
Web security for developers
Web security for developersWeb security for developers
Web security for developersSunny Neo
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)Stormpath
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Jim Manico
 
Security Ninjas: An Open Source Application Security Training Program
Security Ninjas: An Open Source Application Security Training ProgramSecurity Ninjas: An Open Source Application Security Training Program
Security Ninjas: An Open Source Application Security Training ProgramOpenDNS
 
OWASP Serbia - A3 broken authentication and session management
OWASP Serbia - A3 broken authentication and session managementOWASP Serbia - A3 broken authentication and session management
OWASP Serbia - A3 broken authentication and session managementNikola Milosevic
 
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 2008abhijitapatil
 
Securing your AngularJS Application
Securing your AngularJS ApplicationSecuring your AngularJS Application
Securing your AngularJS ApplicationPhilippe De Ryck
 
Browser Security 101
Browser Security 101 Browser Security 101
Browser Security 101 Stormpath
 
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)Brian Huff
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJSrobertjd
 
OWASP_Top_10_Introduction_and_Remedies_2017.ppt
OWASP_Top_10_Introduction_and_Remedies_2017.pptOWASP_Top_10_Introduction_and_Remedies_2017.ppt
OWASP_Top_10_Introduction_and_Remedies_2017.pptjangomanso
 
OWASP Khartoum Top 10 A4 - 7th meeting
OWASP Khartoum   Top 10 A4 - 7th meetingOWASP Khartoum   Top 10 A4 - 7th meeting
OWASP Khartoum Top 10 A4 - 7th meetingOWASP Khartoum
 

Similaire à OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery (20)

WebApps_Lecture_15.ppt
WebApps_Lecture_15.pptWebApps_Lecture_15.ppt
WebApps_Lecture_15.ppt
 
OWASP Serbia - A5 cross-site request forgery
OWASP Serbia - A5 cross-site request forgeryOWASP Serbia - A5 cross-site request forgery
OWASP Serbia - A5 cross-site request forgery
 
OWASP App Sec US - 2010
OWASP App Sec US - 2010OWASP App Sec US - 2010
OWASP App Sec US - 2010
 
Spa Secure Coding Guide
Spa Secure Coding GuideSpa Secure Coding Guide
Spa Secure Coding Guide
 
Web security for developers
Web security for developersWeb security for developers
Web security for developers
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)
 
OWASP Top10 2010
OWASP Top10 2010OWASP Top10 2010
OWASP Top10 2010
 
Cross site scripting
Cross site scriptingCross site scripting
Cross site scripting
 
Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12Top Ten Web Application Defenses v12
Top Ten Web Application Defenses v12
 
Security Ninjas: An Open Source Application Security Training Program
Security Ninjas: An Open Source Application Security Training ProgramSecurity Ninjas: An Open Source Application Security Training Program
Security Ninjas: An Open Source Application Security Training Program
 
OWASP Serbia - A3 broken authentication and session management
OWASP Serbia - A3 broken authentication and session managementOWASP Serbia - A3 broken authentication and session management
OWASP Serbia - A3 broken authentication and session management
 
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
 
Securing your AngularJS Application
Securing your AngularJS ApplicationSecuring your AngularJS Application
Securing your AngularJS Application
 
Browser Security 101
Browser Security 101 Browser Security 101
Browser Security 101
 
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)
 
JWT Authentication with AngularJS
JWT Authentication with AngularJSJWT Authentication with AngularJS
JWT Authentication with AngularJS
 
OWASP_Top_10_Introduction_and_Remedies_2017.ppt
OWASP_Top_10_Introduction_and_Remedies_2017.pptOWASP_Top_10_Introduction_and_Remedies_2017.ppt
OWASP_Top_10_Introduction_and_Remedies_2017.ppt
 
4.Xss
4.Xss4.Xss
4.Xss
 
OWASP Khartoum Top 10 A4 - 7th meeting
OWASP Khartoum   Top 10 A4 - 7th meetingOWASP Khartoum   Top 10 A4 - 7th meeting
OWASP Khartoum Top 10 A4 - 7th meeting
 
Owasp top 10_-_2010 presentation
Owasp top 10_-_2010 presentationOwasp top 10_-_2010 presentation
Owasp top 10_-_2010 presentation
 

Plus de OWASP Khartoum

Cryptocurrency, a deep dive
Cryptocurrency, a deep diveCryptocurrency, a deep dive
Cryptocurrency, a deep diveOWASP Khartoum
 
Usable Security: Tips for Daily Life
Usable Security: Tips for Daily LifeUsable Security: Tips for Daily Life
Usable Security: Tips for Daily LifeOWASP Khartoum
 
SSH - From Zero to Hero
SSH - From Zero to HeroSSH - From Zero to Hero
SSH - From Zero to HeroOWASP Khartoum
 
OWASP Khartoum Cyber Security Session
OWASP Khartoum Cyber Security SessionOWASP Khartoum Cyber Security Session
OWASP Khartoum Cyber Security SessionOWASP Khartoum
 
Computer forensic 101 - OWASP Khartoum
Computer forensic 101 - OWASP KhartoumComputer forensic 101 - OWASP Khartoum
Computer forensic 101 - OWASP KhartoumOWASP Khartoum
 
Welcome to OWASP World
Welcome to OWASP WorldWelcome to OWASP World
Welcome to OWASP WorldOWASP Khartoum
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)OWASP Khartoum
 
OWASP Khartoum - Top 10 A6 - 8th meeting - Security Misconfiguration
OWASP Khartoum - Top 10 A6 - 8th meeting - Security MisconfigurationOWASP Khartoum - Top 10 A6 - 8th meeting - Security Misconfiguration
OWASP Khartoum - Top 10 A6 - 8th meeting - Security MisconfigurationOWASP Khartoum
 

Plus de OWASP Khartoum (9)

Cryptocurrency, a deep dive
Cryptocurrency, a deep diveCryptocurrency, a deep dive
Cryptocurrency, a deep dive
 
Usable Security: Tips for Daily Life
Usable Security: Tips for Daily LifeUsable Security: Tips for Daily Life
Usable Security: Tips for Daily Life
 
API IN(SECURITY)
API IN(SECURITY)API IN(SECURITY)
API IN(SECURITY)
 
SSH - From Zero to Hero
SSH - From Zero to HeroSSH - From Zero to Hero
SSH - From Zero to Hero
 
OWASP Khartoum Cyber Security Session
OWASP Khartoum Cyber Security SessionOWASP Khartoum Cyber Security Session
OWASP Khartoum Cyber Security Session
 
Computer forensic 101 - OWASP Khartoum
Computer forensic 101 - OWASP KhartoumComputer forensic 101 - OWASP Khartoum
Computer forensic 101 - OWASP Khartoum
 
Welcome to OWASP World
Welcome to OWASP WorldWelcome to OWASP World
Welcome to OWASP World
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
 
OWASP Khartoum - Top 10 A6 - 8th meeting - Security Misconfiguration
OWASP Khartoum - Top 10 A6 - 8th meeting - Security MisconfigurationOWASP Khartoum - Top 10 A6 - 8th meeting - Security Misconfiguration
OWASP Khartoum - Top 10 A6 - 8th meeting - Security Misconfiguration
 

OWASP Khartoum - Top 10 A5 - 7th meeting - Cross Site Request Forgery

  • 1. Cross Site Request Forgery Obay Osman OWASP Khartoum 15 Sept 2012 Copyright © The OWASP Foundation Permission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.
  • 2. ToC • Definition. • OWASP Rating. • Attack Scenarios. • CSRF in the wiled. • Demo time. • Detection • Protection. • Summery & Discussion. 2
  • 3. Definition A CSRF attack is forcing a logged-on victim‟s browser to send a forged HTTP request, including the victim‟s session cookie and any other automatically included authentication information, to a vulnerable web application. Synonyms: XSRF, "Sea Surf", Session Riding, Cross-Site Reference Forgery, Hostile Linking, One-Click (Microsoft). 3
  • 5. Attack Scenarios User: http://bank.com/app/transferFunds?amount=1 500&destinationAccount=4673243243 Attacker: <img src= "http://bank.com/app/transferFunds?amo unt=1500&destinationAccount=attackersA cct#“ width="0" height="0" /> 5
  • 8. Let us break something… 9
  • 9. In the wield.. - Firewall web management. - Stored CSRF flaws.(Self-vulnerable applications) - Sammy Worm. Methodologies: XSS, Social Engineering…. 10
  • 10. Detection Code Review: • see if each link and form contains an unpredictable token for each user. • focus on state-changing functions. • check multistep transactions. PenTesting: • Manual Testing. • OWASP‟s CSRF Tester tool. 11
  • 11. Protection[Developers] • Check referrer, Really help?!(open redirect/HTTPS/subdomains) • Double Submit Cookies. • Challenge-Response. (CAPTCHA/Re-Authentication) • Put unique token in the URL/URL parameter. • Include the unique token (per request/session) in a hidden field. No XSS & Share a ‘Secret’ With The User. 12
  • 12. Protection[Tokens] Good Tokens: Nonce: One-time cryptographically random token that is returned to the client per request. HMAC: #(PageUrl+Session/userID+Timestamp) (eg In .net encrypted „ViewState‟) 13
  • 13. Protection [Defense in depth] Do not use GET parameters. Do not put the secret in the URL/Cookies.(log/history/referer exposure,!) Send successful logins to a well-known location instead of automatic redirection.(Top10 A10) Do not resubmit POST parameters if you need to perform redirection. 14
  • 14. Protection [Users] Logoff immediately after using a web application Do not allow your browser to save username/passwords, and do not allow sites to “remember” your login Do not use the same browser to access sensitive applications and to surf freely the Internet. Be careful when clicking untrusted Links. 15
  • 15. OWASP‟s Tools OWASP‟s CSRF Guard can be used to automatically include such tokens in your Java EE, .NET, or PHP application. OWASP‟s ESAPI token generators and validators. + OWASP‟s CSRF Tester. 16
  • 16.
  • 17. OWASP Top 10 2010: A1 –Injection A2 –Cross-Site Scripting (XSS) A3 –Broken Authentication and Session Management A4 –Insecure Direct Object Reference A5 –Cross Site Request Forgery (CSRF) A6 –Security Misconfiguration(NEW) A7 –Insecure Cryptographic Storage A8 –Failure to Restrict URL Access A9 –Insufficient Transport Layer Protection A10 –Unvalidated Redirects and Forwards (NEW)
  • 18. Ref. • https://www.owasp.org/index.php/CSRF • https://www.owasp.org/index.php/Testing_for_CSRF_ %28OWASP-SM-005%29 • https://www.owasp.org/index.php/Cross- Site_Request_Forgery_%28CSRF%29_Prevention_Ch eat_Sheet • http://cwe.mitre.org/data/definitions/352.html • https://www.trustwave.com/sae_sample/owasp-top- 10/CourseFiles/Player.htm
  • 19. 20

Notes de l'éditeur

  1. Access Control Attacks
  2. A CSRF attack forces a logged-on victim’s browser to send a forged HTTP request, including the victim’s session cookie and any other automatically included authentication information, to a vulnerable web application. This allows the attacker to force the victim’s browser to generate requests the vulnerable application thinks are legitimate requests from the victim.
  3. The application allows a user to submit a state changing request that does not include anything secret. Like so:http://example.com/app/transferFunds?amount=1500&amp;destinationAccount=4673243243So, the attacker constructs a request that will transfer money from the victim’s account to their account, and then embeds this attack in an image request or iframe stored on various sites under the attacker’s control.&lt;imgsrc=&quot;http://example.com/app/transferFunds?amount=1500&amp;destinationAccount=attackersAcct#“width=&quot;0&quot; height=&quot;0&quot; /&gt;If the victim visits any of these sites while already authenticated to example.com, any forged requests will include the user’s session info, inadvertently authorizing the request.
  4. Cross-Site Request Forgery (CSRF) is an attack that tricks the victim into loading a page that contains a malicious request. It is malicious in the sense that it inherits the identity and privileges of the victim to perform an undesired function on the victim&apos;s behalf, like change the victim&apos;s e-mail address, home address, or password, or purchase something. CSRF attacks generally target functions that cause a state change on the server but can also be used to access sensitive data. For most sites, browsers will automatically include with such requests any credentials associated with the site, such as the user&apos;s session cookie, basic auth credentials, IP address, Windows domain credentials, etc. Therefore, if the user is currently authenticated to the site, the site will have no way to distinguish this from a legitimate user request. In this way, the attacker can make the victim perform actions that they didn&apos;t intend to, such as logout, purchase item, change account information, retrieve account information, or any other function provided by the vulnerable website.
  5. Because many intranets support a single sign-on environment where authentication to a site can be performed transparently, the victim need not even use the application prior to being tricked into sending the forged request. Even if the victim is not authenticated and the application does not integrate with a single sign-on system, many authentication systems will intercept a request, require authentication, and then transparently transfer a client back to the original requested location. Because of this, even unauthenticated victims are subject to such attacks.
  6. Self-vulnerable applications, i.e., applications that are used both as attack vector and target (such as web mail applications), make things worse. If such an application is vulnerable, the user is obviously logged in when he reads a message containing a CSRF attack, that can target the web mail application and have it perform actions such as deleting messages, sending messages appearing as sent by the user, etc.
  7. The easiest way to check whether an application is vulnerable is to see if each link and form contains an unpredictable token for each user. Without such an unpredictable token, attackers can forge malicious requests. Focus on the links and forms that invoke state-changing functions, since those are the most important CSRF targets.You should check multistep transactions, as they are not inherently immune. Attackers can easily forge a series of requests by using multiple tags or possibly JavaScript.Note that session cookies, source IP addresses, and other information that is automatically sent by the browser doesn’t count since this information is also included in forged requests.OWASP’s CSRF Testertool can help generate test cases to demonstrate the dangers of CSRF flaws.
  8. Preventing CSRF requires the inclusion of a unpredictable token in the body or URL of each HTTP request. Such tokens should at a minimum be unique per user session, but can also be unique per request.1.The preferred option is to include the unique token in a hidden field. This causes the value to be sent in the body of the HTTP request, avoiding its inclusion in the URL, which is subject to exposure.2.The unique token can also be included in the URL itself, or a URL parameter. However, such placement runs the risk that the URL will be exposed to an attacker, thus compromising the secret token.OWASP’s CSRF Guardcan be used to automatically include such tokens in your Java EE, .NET, or PHP application. OWASP’s ESAPIincludes token generators and validatorsthat developers can use to protect their transactions.
  9. A nonce is a one-time cryptographically random token that is returned to the client. For each request, a different nonce is created, so secrets are not reused. The nonce is sent to the client, and also saved on the server, and then compared when the operation request comes in. The downside of a nonce is that it needs to be stored on the server. If it’s stored in memory, it limits system scalability across multiple web or application servers.An HMAC is an encrypted hash or &quot;keyed hash&quot; of the page combined with the session ID. If you create an HMAC of the Page URL, plus the User ID or Session ID a comparison value can be created that will make distributed attacks very difficult. The downside is that every time the user returns to the page it is possible that the same page URL and user ID might be generated, making it possible to steal the secret and reuse it. So you should add a timestamp to the HMAC to ensure the secret value is unique for each request. The timestamp would be concatenated with the page URL and user ID. Like a salt, the timestamp plain text need not be kept secret or protected, and is most easily sent to the client in a hidden form field or placed in a state cookie. During the request, the timestamp is retrieved and added to the URL and ID to generate the comparison HMAC.
  10. Do not use GET parameters. Although it’s possible to perform CSRF attacks via POST parameters, it limits the types of manipulation a malicious user can perform on the victim to forge the request.Do not put the secret in the URL; the URL should not to contain any kind of secret. Broken authentication and session can be seen in weblogs and accessed via JavaScript.Send successful logins to a well-known location instead of automatic redirection. Do not resubmit POST parameters if you need to perform redirection.
  11. The OWASP CSRF Guard Project makes use of a unique per-session token verification pattern using a JavaEE filter to mitigate the risk of CSRF attacks. When an HttpSession is first instantiated, CSRF Guard will generate a cryptographically random token using the SecureRandom class to be stored in the session.