Injection Fundamentals: What Is SSRF?

Note: For the exercises, the course directory has changed! It's now

Assignment Command: EX_NUM=1 docker-compose up

Answer Command: EX_NUM=2 docker-compose up

Injection Fundamentals: What Is SSRF?

Table Of Contents


  • Who is this episode for?
    • Developers who have novice injection/security knowledge
  • Prerequisites:
  • At the end of this episode, you’ll be able to
    1. See how Server Side Request Forgery (SSRF) works through a live example
    2. Understand how your code (coupled with the deployment environment) can create Semantic Injection risks
    3. Review Blind Injection through a real vulnerability within New Relic
    4. Through Blind Injection, we learn why we focus on input validation (as opposed to output validation)
    5. Start reviewing mitigation strategies (whitelisting) that we’ll focus on during upcoming tutorials
  • Ready? Come join me in the next lecture!

Inject The Curl Context (Assignment Prep)

  • A host with 2 processes
    1. File server
      • Houses internal-only documents
      • Accepts traffic from the corporate network on port 8081
      • Is accessible over http://localhost:8081 on the main host
      • DevOps created this server without your knowledge
        • Aside: DevOps believes this file server is secure because
          • It’s restricted to the corporate network
          • localhost is restricted to local processes
          • Anything wrong with this thinking?
            1. The unknown unknowns are always the most dangerous
            2. Always assume there are items that you dont know
    2. Node server
      1. Is publicly accessible over port 80
      2. Houses your code

Inject The Curl Context (Assignment)

  • Hints
    • What network interface is used for “local access”

Inject The Curl Context (Answer)

  • This is an example of Server Side Request Forgery (SSRF)

Server Side Request Forgery (SSRF)

  • The attacker makes the server initiate a request
  • Categorizing SSRF
    • Is the attacker exploiting curl’s syntax?
      • Is this syntactic injection?
      • No, this is semantic injection

Semantic Injection

  • Injection that exploits a unique meaning (or situation) in the environment
    • Semantics == Meaning
    • What constitutes an environment?
      • Your code, the server and the environment that surrounds the server (AWS, DBs, etc.)
        • Your code is the door to these contexts
      • Can you think of a cloud service that exposes an introspection API on every server?
        • AWS EC2 Metadata

AWS EC2 Metadata SSRF

AWS EC2 Metadata SSRF (Takeaways)

  • SSRF can be leveraged to extract sensitive information
  • APIs in our surrounding environment pose injection risks
  • Don’t be overwhelmed by the items that you must know :)
    • By knowing that there are things you don’t know, we can create granular whitelisting strategies
      • Whitelist: A list of items that we’ll allow, and reject everything else
  • For additional EC2 Metadata information, reference the Additional Resources section in the notes
  • Potential Takeaway
    • In each of our SSRF examples, the output is clearly different from our expectations
      • “Since we know what the output should be, we could easily create a whitelist for our responses”
      • Would we be safe?

New Relic Webhook Blind SSRF

  • Reported by Tung Pun
    • See link in Additional Resources
  • Form POST that Tung leveraged

    POST /accounts/1723471/notification_channels?type=WebhookIntegration HTTP/1.1
  • Response
    • 200 if the port was open, 422 if closed

Blind Injection

  • Don’t have the full response available
    • Error messages are also turned off
  • Submit “true/false” queries to the application and observe how the application reacts
    • Ex: Is this port open? 200 if yes, 422 if no
    • Items to observe
      • Response codes, computation times, etc.
  • Whitelisting output would be incredibly difficult
    • Focus energy on whitelisting input

Course Takeaways

  • Given limited time, whitelisting input is more valuable than whitelisting output
  • Recap: Execution contexts of userDefinedUrl
    • shell context
      • Ex: Syntactic injection risk
    • curl context
      • Ex: Semantic injection risk
        • SSRF
    • javascript context
      • Coming soon :)
  • For every unique execution context, we must
    • Evaluate syntactic and semantic injection risks
    • Evaluate injection risks within the overarching environment

Next Steps

  • Additional assignments:
    • Look for SSRF within a codebase’s
      • Webhook functionality
      • File upload functionality
        • Does the API accept a URL instead of a file?
        • View Additional Resources for hackerone vulnerability
          • Make sure to review photo attachments for context
  • Review links below video
    • Additional resources
      • Specific to other languages
      • Ability to explore more in-depth

Error Log

  • None so far :)

Additional Resources

  • Please submit a PR with any additional resources

Referenced In Tutorial







Knowledge Dependency Tree