avatarMartin Thoma

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

3460

Abstract

lead to remote code execution or lateral movement within the target organization’s network.</p><h1 id="0926">Example Vulnerability and Attack</h1><p id="dc96">Think about a mail service like Microsoft Exchange or Gmail. You can upload attachments, but it’s annoying that you have to download an image and upload it again if you want to share it via e-mail. It would be more convenient if you could just click on a button to add the image given by the URL.</p><p id="1f73">If the code allows arbitrary file paths, the user could cat the path to <code>file:///etc/passwd</code> to get the web servers local users and password hashes. Once the local users are known,<code>file:///home/user/.ssh/id_rsa</code> can be used to get the private SSH key. <code>/home/user/.bash_history</code> might reveal interesting services that can be accessed with that key.</p><h1 id="18ca">How can I prevent SSRF attacks?</h1><p id="3816">Preventing Server-Side Request Forgery (SSRF) attacks involves a combination of secure coding practices and input validation.</p><p id="ed8a">First, ensure that your web application follows the <b>principle of least privilege</b>, meaning it only has the necessary permissions and access to required resources.</p><p id="e8f0">Next, perform strict <b>input validation and sanitization</b> on all user-supplied data to prevent malicious payloads from being injected into server-side requests. Whitelisting allowed URLs, protocols, and IP addresses can help restrict outbound requests to trusted sources only.</p><p id="a404">Other secure coding practices that can help are <b>security audits</b>, <b>code reviews</b>, and <b>educating your development team</b> about SSRF attacks. The main reason to fall for this attack is not being aware that it exists.</p><h1 id="e130">What’s next?</h1><p id="1ee1">In this series about application security (AppSec) we already explained some of the techniques of the attackers 😈 and also the techniques of the defenders πŸ˜‡:</p><ul><li>Part 1: <a href="https://readmedium.com/sql-injections-e8bc9a14c95">SQL Injections</a> 😈🐝</li><li>Part 2: <a href="https://levelup.gitconnected.com/leaking-secrets-240a3484cb80">Don’t leak Secrets</a> πŸ˜‡</li><li>Part 3: <a href="https://levelup.gitconnected.com/cross-site-scripting-xss-fd374ce71b2f">Cross-Site Scripting (XSS)</a> 😈🐝</li><li>Part 4: <a href="https://levelup.gitconnected.com/password-hashing-eb3b97684636">Password Hashing</a> πŸ˜‡</li><li>Part 5: <a href="https://readmedium.com/zip-bombs-30337a1b0112">ZIP Bombs</a> 😈</li><li>Part 6: <a href="https://readmedium.com/captcha-500991bd90a3">CAPTCHA</a> πŸ˜‡</li><li>Part 7: <a href="https://readmedium.com/email-spoofing-9da8d33406bf">Email Spoofing</a> 😈</li><li>Part 8: <a href="https://readmedium.com/software-composition-analysis-sca-7e573214a98e">Software Composition Analysis</a> (SCA) πŸ˜‡</li><li>Part 9: <a href="https://readmedium.com/xxe-attacks-750e91448e8f">XXE attacks</a> 😈🐝</li><li>Part 10: <a href="https://levelup.gitconnected.com/effective-access-control-331f883cb0ff">Effective Access Control</a> πŸ˜‡</li><li>Part 11: <a href="https://readmedium.com/dos-via-a-billion-laughs-9a79be96e139">DOS via a Billion Laughs</a> 😈</li><li>Part 12: <a href="https://readmedium.com/full-disk-encryption-2090489f9760">Full Disk Encryption</a> πŸ˜‡</li><li>Part 13: <a href="https://readmedium.com/insecure-deserialization-5c64e9943f0e">Insecure Deserialization</a> 😈</li><li>Part 14: <a href="h

Options

ttps://levelup.gitconnected.com/docker-security-5f4df118948c">Docker Security</a> πŸ˜‡</li><li>Part 15: <a href="https://levelup.gitconnected.com/credential-stuffing-ff58ee8c3320">Credential Stuffing</a> 😈🐝</li><li>Part 16: <a href="https://readmedium.com/multi-factor-authentication-cefff819be95">Multi-Factor Authentication</a> (MFA/2FA) πŸ˜‡</li><li>Part 17: <a href="https://infosecwriteups.com/redos-denial-of-service-by-regex-59c7ffab4880?source=user_profile---------0-------------------------------&amp;gi=bec35fb230e3">ReDoS</a> 😈</li><li>Part 18: <a href="https://infosecwriteups.com/secure-messaging-5d2fc7748c24">Secure and Private Instant Messaging</a> πŸ˜‡</li><li>Part 19: <a href="https://readmedium.com/cryptojacking-55a73622fb6d">Cryptojacking</a> 😈</li><li>Part 20: <a href="https://readmedium.com/backups-what-matters-and-how-to-do-it-right-62accf7e9800">Backups</a> πŸ˜‡</li><li>Part 21: <a href="https://levelup.gitconnected.com/csrf-cross-site-request-forgery-88d26304e5f4">CSRF</a> 😈</li><li>Part 22: <a href="https://martinthoma.medium.com/cookies-742318b821c5">Cookies</a> πŸ˜‡</li><li>Part 23: <a href="https://readmedium.com/clipboard-hijacking-50f16695ad4a">Clipboard Hijacking</a> 😈</li><li>Part 24: <a href="https://martinthoma.medium.com/the-role-of-certificates-in-secure-communication-f58810b60f97">Certificates</a> πŸ˜‡</li><li>Part 25: Server-Side Request Forgery (SSRF) 😈</li><li>Part 26: <a href="https://martinthoma.medium.com/content-security-policy-csp-dcb137a7cb09">Content Security Policy</a> (CSP) πŸ˜‡</li><li>Part 27: Race Condition Attacks in Blockchains 😈</li><li>Part 28: Network Separation πŸ˜‡</li><li>Part 29: Social Engineering (including Phishing) 😈</li><li>Part 30: Virtual Private Networks (VPNs) πŸ˜‡</li><li>Part 31: Scareware</li><li>Part 32: JSON Web Tokens (JWT) πŸ˜‡</li><li>Part 33: Clickjacking 😈</li><li>Part 34: Single-Sign-On πŸ˜‡</li><li>Part 35: Man-in-the-Middle (MITM) Attacks 😈</li><li>Part 36: Mobile Device Management (MDM) πŸ˜‡</li><li>Part 37: Insider Threats 😈</li><li>Part 38: Data Loss Prevention (DLP) πŸ˜‡</li><li>Part 39: Subdomain Takeover 😈</li><li>Part 40: Web Application Firewalls (WAF) πŸ˜‡</li><li>Part 41: Brute Force Attacks 😈</li><li>Part 42: Security Information and Event Management (SIEM) πŸ˜‡</li><li>Part 43: Cache Poisoning 😈</li><li>Part 44: HTTPS and TLS Best Practices πŸ˜‡</li><li>Part 45: Path Traversal Attacks 😈</li><li>Part 46: Application Security Testing (AST) πŸ˜‡</li><li>Part 47: DNS Rebinding 😈</li><li>Part 48: Zero Trust Architecture πŸ˜‡</li><li>Part 49: Watering Hole Attacks 😈</li><li>Part 50: Identity and Access Management (IAM) πŸ˜‡</li></ul><p id="b905">Let me know if you are interested in more articles around AppSec / InfoSec!</p><p id="702c">I love writing about software development and technology 🀩 Don’t miss updates: <a href="https://martinthoma.medium.com/subscribe"><b>Get my free email newsletter</b></a> πŸ“§ or <a href="https://martinthoma.medium.com/membership">sign up for Medium</a> ✍️ if you haven’t done it yet β€” both encourage me to write more πŸ€—</p><figure id="fb8c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/0*_ek8guchkpgoo55z.png"><figcaption></figcaption></figure><h2 id="6fe6">πŸ‘‹ If you find this helpful, please click the clap πŸ‘ button below a few times to show your support for the author πŸ‘‡</h2><h2 id="dfe5">πŸš€Join FAUN Developer Community & Get Similar Stories in your Inbox Each Week</h2></article></body>

Server-Side Request Forgery 😈

What are SSRFs, how do they work, how do they harm

Server-Side Request Forgery (SSRF) is a type of web application security vulnerability that allows attackers to manipulate server-side requests, potentially gaining unauthorized access to internal resources and sensitive data. As organizations increasingly rely on web applications for business-critical operations, understanding and mitigating the risk posed by SSRF has become increasingly important.

In this article, we will explore the mechanics of SSRF and its potential impact on affected systems. We will also discuss best practices and strategies for identifying and preventing SSRF vulnerabilities, equipping you with the knowledge and tools necessary to safeguard your web applications from this threat.

Why should I care?

  • Capital One Data Breach (2019): A hacker exploited an SSRF vulnerability in a misconfigured AWS Web Application Firewall to gain access to sensitive data of over 100 million Capital One customers. The attacker was able to access Social Security numbers, bank account numbers, and other personal information (source).
  • Grafana SSRF Vulnerability (2016 β€” 2020): An SSRF vulnerability was discovered in Grafana, an open-source analytics and monitoring platform. Attackers could exploit the vulnerability to access internal networks and steal sensitive data. Grafana released a security update to fix the issue.
  • GitLab SSRF Vulnerability (2021): GitLab, a popular web-based DevOps platform, disclosed an SSRF vulnerability that exposed orgs’ internal servers.
  • Microsoft Exchange Server (2023): The mail server allows attaching files not only from your local disk but also from an URL. This could be used for arbitrary code execution.

How are SSRF attacks executed?

Server-Side Request Forgery (SSRF) attacks are executed by exploiting vulnerabilities in a web application that allow an attacker to forge server-side requests.

Typically, the attacker manipulates user input or API calls to create malicious requests, which are then sent by the server. The server has code that executes requests on behalf of the user, but the type of request or the target is changed by the attacker. These requests executed by the server can bypass security measures, such as firewalls or IP whitelisting, as they originate from the vulnerable server itself. Consequently, attackers can access restricted resources, read sensitive files, or interact with internal services that should not be exposed to external users.

In some cases, SSRF attacks can even lead to remote code execution or lateral movement within the target organization’s network.

Example Vulnerability and Attack

Think about a mail service like Microsoft Exchange or Gmail. You can upload attachments, but it’s annoying that you have to download an image and upload it again if you want to share it via e-mail. It would be more convenient if you could just click on a button to add the image given by the URL.

If the code allows arbitrary file paths, the user could cat the path to file:///etc/passwd to get the web servers local users and password hashes. Once the local users are known,file:///home/user/.ssh/id_rsa can be used to get the private SSH key. /home/user/.bash_history might reveal interesting services that can be accessed with that key.

How can I prevent SSRF attacks?

Preventing Server-Side Request Forgery (SSRF) attacks involves a combination of secure coding practices and input validation.

First, ensure that your web application follows the principle of least privilege, meaning it only has the necessary permissions and access to required resources.

Next, perform strict input validation and sanitization on all user-supplied data to prevent malicious payloads from being injected into server-side requests. Whitelisting allowed URLs, protocols, and IP addresses can help restrict outbound requests to trusted sources only.

Other secure coding practices that can help are security audits, code reviews, and educating your development team about SSRF attacks. The main reason to fall for this attack is not being aware that it exists.

What’s next?

In this series about application security (AppSec) we already explained some of the techniques of the attackers 😈 and also the techniques of the defenders πŸ˜‡:

Let me know if you are interested in more articles around AppSec / InfoSec!

I love writing about software development and technology 🀩 Don’t miss updates: Get my free email newsletter πŸ“§ or sign up for Medium ✍️ if you haven’t done it yet β€” both encourage me to write more πŸ€—

πŸ‘‹ If you find this helpful, please click the clap πŸ‘ button below a few times to show your support for the author πŸ‘‡

πŸš€Join FAUN Developer Community & Get Similar Stories in your Inbox Each Week

Hacking
Web Development
It Security
Information Security
Software Engineering
Recommended from ReadMedium