A10:2021 – Server-Side Request Forgery (SSRF)
Share
Description
The 'Server-Side Request Forgery' (SSRF) attack is a type of attack in which an attacker abuses the functionality of a server to make HTTP requests to unauthorized internal or external resources. In essence, the server is tricked into performing unwanted actions on behalf of the attacker.
Impact
This type of attack can have serious consequences for the security of a web application and the underlying infrastructure. Some of the potential impacts include:
- Unauthorized access to internal resources: The attacker can access systems and data that are normally protected by firewalls or network restrictions.
- Bypassing security controls: SSRF can allow attackers to bypass security measures such as firewalls and access control lists.
- Sensitive data exfiltration: Attackers can use SSRF to extract sensitive information from internal systems.
- Internal port scanning: SSRF can be used to map the internal network and discover vulnerable services.
- Remote Code Execution: In extreme cases, SSRF can lead to arbitrary code execution on the compromised server.
Given the severity of these impacts, it is crucial that developers implement robust security measures to prevent and mitigate SSRF attacks on their web applications.
Practical Examples
1. Access to internal services
This can allow the attacker to access systems and data normally protected by firewalls or network restrictions, such as internal databases or administration panels.
http://vulnerable-app.com/fetch?url=http://localhost:8080/admin
In this example, if the application does not properly validate the provided URL, it could make a request to the internal administration panel on port 8080.
Summary
- Detect a query that makes a request to an external resource using HTTP.
- Modify the request so that the web server makes a request to the loopback interface and thus access functions or services not published abroad.
Example
After analyzing the operation of the audited web page, it can be observed that requests are made to external resources using HTTP.
Mitigations
- Validate and sanitize all user input, especially URLs.
- Implement whitelists of domains and allowed IP addresses.
- Use web application firewalls (WAF) to filter malicious requests.
- Correctly configure network firewalls to limit access to internal resources.
- Implement the principle of least privilege on servers and services.
- Use VPNs or virtual private networks to isolate critical resources.
- Disable HTTP redirects when they are not necessary.
- Implement strong authentication and authorization for all internal endpoints.
- Use internal DNS to resolve host names, avoiding the use of direct IP addresses.
- Monitor and log all network requests to detect suspicious patterns.
2. Internal port scanning
Summary
- Detect a query that makes a request to an external resource using HTTP.
- Modify the request so that the web server makes a request to internal IP addresses and ports that are not exposed to the outside.
- Observe different responses from the server to be able to discern when there is an IP address with an open port and when there is not.
Example
Mitigations
- Implement whitelists of IP addresses and allowed ranges for internal requests.
- Use web application firewalls (WAFs) configured to detect and block suspicious request patterns.
- Segment the internal network to limit the scope of possible scans.
- Implement the principle of least privilege on internal servers and services.
- Use strong authentication and authorization for all internal endpoints.
- Monitor and log all network requests to detect scanning patterns.
- Implement rate limiting to prevent rapid and automated scans.
- Use Virtual Private Cloud (VPC) in cloud environments to isolate critical resources.
- Correctly configure security groups and access control lists (ACLs) on the network.
- Educate developers on security best practices and the risks associated with SSRF.
3. Access to metadata in cloud environments
- Temporary AWS Credentials
- IAM roles associated with the instance
- Network configuration data
- Custom initialization scripts
Summary
- Detect a query that makes a request to an external resource using HTTP.
- Modify the original request so that the web server makes a request to cloud server resources that may be limited by WhiteList so that only the server can access it.
- Observe different responses from the server to be able to discern when it has been possible to access resources stored in the Cloud and when not.
Example
Scenery
Steps of exploitation
- The attacker discovers that the application is hosted on Amazon Web Services (AWS).
- The attacker enters the following URL in the application input field: http://169.254.169.254/latest/meta-data/
- The application makes a request to this internal AWS IP address, which is the EC2 instance metadata endpoint.
- As a result, the application returns sensitive information about the EC2 instance, such as:
1. Instance ID2. Region3. Internal Hostname4. MAC address
5.The attacker can drill down further using specific paths, such as: http://169.254.169.254/latest/meta-data/iam/security-credentials/ to obtain the temporary security credentials of the IAM role associated with the instance.
Mitigation
- Implement a whitelist of allowed URLs
- Use a reverse proxy for outgoing requests
- Configure firewalls to block traffic to internal IP addresses
- Implement the principle of least privilege in IAM roles
- Use IMDSv2 (Instance Metadata Service version 2) which requires session tokens
4. Information exfiltration (Cypher injection)
Summary
- Detect a query through which it is possible to inject code into the queries made to the database.
- Perform queries to the database to obtain information stored in it.
- Exfiltrate the information obtained through the CSV upload function over HTTP, thus performing an SSRF technique.
Example
Mitigation
- Use Parameters: Prevent Cypher injection by using parameters instead of directly concatenating user input into queries.
- Parameterize queries: Compile queries into executable plans that cannot be modified by parameter data.
- Use APOC procedures safely: When using APOC, continue passing parameters to avoid string concatenation vulnerabilities.
- Sanitize inputs: When parameterization is not possible (for example, for node labels), sanitize user inputs by escaping special characters.
- Avoid returning database errors: Use generic error messages to prevent information disclosure through error-based injection.
- Implement proper escaping: Use appropriate escape sequences for different Cypher types (string literals, identifiers).
- Validate inputs: Check user inputs against specific criteria, but be aware of possible bypass techniques.
- Be careful with second-order injections: Continue to sanitize stored data when used in subsequent queries.
- Apply the principle of least privilege: Use role-based access control to limit the potential impact of successful injections.
- Carefully handle data imports: Be aware of potential vulnerabilities when importing data from external sources such as CSV files.