Ssrf on Azure
How SSRF Manifests in Azure
Server-Side Request Forgery (SSRF) in Azure environments often exploits the platform's extensive service mesh and internal networking. Azure's architecture creates unique SSRF attack surfaces that don't exist in traditional on-premises setups. The most common vector is when applications accept user-controlled URLs and make HTTP requests to them, but the request is routed through Azure's internal network fabric.
A classic Azure SSRF scenario involves Azure Instance Metadata Service (IMDS) at http://169.254.169.254. If an application accepts a URL parameter and makes a request without proper validation, an attacker can craft requests to http://169.254.169.254/metadata/instance?api-version=2021-02-01 to extract instance metadata including subscription IDs, resource groups, and network configuration. This metadata often contains sensitive information that can be used for lateral movement or privilege escalation within the Azure tenant.
Azure-specific SSRF also targets service endpoints. For example, Azure Key Vault (https://*.vault.azure.net), Azure Storage (https://*.blob.core.windows.net), and Azure SQL Database (https://*.database.windows.net) are common targets. An application that proxies requests to these services without proper authentication can expose secrets, database credentials, or allow data exfiltration through crafted requests.
Virtual Network Service Endpoints create another attack surface. Applications that accept URLs pointing to privatelink endpoints or internal Azure services can be manipulated to access resources across virtual network boundaries. For instance, a web application that proxies requests to storage accounts might be tricked into accessing a storage account in a different tenant or region, bypassing network security groups.
Azure App Service and Azure Functions have specific SSRF considerations. These services can make outbound requests to internal Azure services, and if user input is incorporated into these requests without validation, attackers can exploit the trust relationship between services. For example, an Azure Function that processes user-submitted URLs and makes HTTP requests might be able to access internal service management endpoints or administrative interfaces.
Managed identity scenarios create additional risks. When applications use Azure Managed Identities to authenticate with other Azure services, SSRF attacks can force the application to make authenticated requests to unintended services. An attacker might craft a request that causes the application to use its managed identity token to access Key Vault secrets or call Azure Resource Manager APIs, effectively hijacking the service's permissions.
Azure Container Instances and AKS (Azure Kubernetes Service) introduce container-specific SSRF vectors. Applications running in containers might have access to Docker daemon APIs or container orchestration endpoints if misconfigured. An SSRF vulnerability could allow an attacker to interact with the Docker socket or Kubernetes API server, leading to container escape or cluster compromise.
Azure Relay and Service Bus scenarios are particularly concerning. Applications that proxy requests to Azure Relay endpoints or Service Bus topics can be manipulated to send messages to unintended recipients or access queues that should be isolated. The trust relationship between Azure services means that a successful SSRF attack can often escalate to broader Azure service abuse.
Azure AD authentication endpoints are also targets. Applications that handle authentication flows might be vulnerable if they don't properly validate redirect URIs or if they proxy authentication requests. An SSRF attack could manipulate the authentication flow to steal tokens or access Azure AD-protected resources.
Storage account SSRF is particularly prevalent in Azure. Applications that generate or manipulate URLs to Azure Blob Storage, Azure Files, or Azure Data Lake Storage can be tricked into accessing storage accounts across tenant boundaries. This can lead to data exposure, unauthorized uploads, or even storage account enumeration attacks that map out an organization's Azure footprint.
Azure Cosmos DB and other database services have unique SSRF considerations. Applications that construct database connection strings or API calls based on user input might be vulnerable to SSRF attacks that target database endpoints. This can lead to unauthorized data access, database enumeration, or even data manipulation if the application has write permissions.
Azure API Management services can also be SSRF targets. If an application proxies requests to API Management endpoints or constructs API URLs dynamically, attackers might be able to access internal APIs, administrative interfaces, or services that should be isolated from the public internet.
Azure-Specific Detection
Detecting SSRF vulnerabilities in Azure requires specialized scanning that understands Azure's unique architecture and service endpoints. middleBrick's Azure-aware scanning identifies SSRF risks by testing against Azure-specific attack patterns and service endpoints.
The first detection layer involves testing against Azure Instance Metadata Service endpoints. middleBrick attempts requests to http://169.254.169.254 with various metadata paths to determine if the application will make these internal requests. The scanner also tests for Azure-specific IP ranges and service tags that might be accessible from the application's network context.
Azure service endpoint detection is critical. middleBrick maintains a comprehensive database of Azure service endpoints including Key Vault, Storage, SQL Database, Cosmos DB, and Service Bus URLs. The scanner attempts to access these services through the application's request pipeline to identify SSRF vulnerabilities that could expose these services.
Virtual network and private endpoint detection is another key capability. middleBrick tests for SSRF vulnerabilities that could access privatelink endpoints, internal Azure services, and resources across virtual network boundaries. This includes testing for SSRF attacks that could bypass Azure network security groups or access resources in peered virtual networks.
Azure App Service and Functions have specific detection patterns. middleBrick tests for SSRF vulnerabilities that could access internal App Service management endpoints, Kudu service APIs, or other administrative interfaces that are typically only accessible from within the Azure environment.
Managed identity token theft detection is a critical Azure-specific feature. middleBrick attempts to force the application to make authenticated requests to Azure services using its managed identity, then analyzes the responses to determine if tokens or credentials are being exposed through SSRF vulnerabilities.
Azure Container Instances and AKS have container-specific detection. middleBrick tests for SSRF vulnerabilities that could access Docker daemon APIs, Kubernetes API servers, or other container orchestration endpoints that might be accessible from within the container network.
Azure Relay and Service Bus detection involves testing for SSRF vulnerabilities that could access these messaging services. middleBrick attempts to send messages through Azure Relay endpoints or access Service Bus topics and queues to identify potential SSRF attack vectors.
Azure AD authentication endpoint testing is another critical detection area. middleBrick tests for SSRF vulnerabilities that could manipulate authentication flows, steal tokens, or access Azure AD-protected resources through crafted requests.
Storage account SSRF detection involves testing against Azure Storage endpoints with various account names and container paths. middleBrick attempts to enumerate storage accounts and access containers to identify SSRF vulnerabilities that could expose storage data.
Cosmos DB and database service detection involves testing against Azure database endpoints with various connection strings and API paths. middleBrick attempts to access database services to identify SSRF vulnerabilities that could lead to unauthorized data access.
Azure API Management detection involves testing for SSRF vulnerabilities that could access internal APIs, administrative interfaces, or services exposed through API Management endpoints.
middleBrick's Azure scanning also includes testing for SSRF vulnerabilities that could access Azure Resource Manager APIs, allowing attackers to enumerate resources, modify configurations, or even create new resources if the application has sufficient permissions.
The scanner provides detailed findings that include the specific Azure services that could be accessed, the potential impact of each SSRF vulnerability, and remediation guidance specific to Azure's security controls and best practices.
Azure-Specific Remediation
Remediating SSRF vulnerabilities in Azure requires a defense-in-depth approach that leverages Azure's native security features. The primary mitigation is implementing strict input validation and URL allowlisting, but Azure provides several platform-specific controls that enhance SSRF protection.
For Azure Instance Metadata Service protection, implement strict allowlisting of URLs and use Azure's network security groups to restrict outbound access to 169.254.169.254 from only trusted services. For applications that legitimately need IMDS access, use Azure Instance Metadata Service Managed Identity integration, which provides token-based access control rather than direct HTTP access to metadata endpoints.
Azure Service Endpoint protection involves implementing Azure Private Link where possible to replace public endpoints with private endpoints that are only accessible from within your virtual network. For services that must use public endpoints, implement Azure Firewall or Network Security Groups to restrict outbound access to only approved service tags and IP ranges.
For Azure Key Vault and other secret management services, implement Azure Managed Identities instead of handling credentials in application code. This eliminates the need for applications to make outbound requests to secret endpoints, reducing the SSRF attack surface. Use Azure Key Vault's firewall settings to restrict access to specific virtual networks or IP ranges.
Azure App Service and Functions SSRF protection involves using App Service Environment (ASE) or Azure Functions Premium plans with virtual network integration. This allows you to control outbound traffic through network security groups and Azure Firewall, preventing SSRF attacks from accessing internal Azure services.
For container-based SSRF protection, use Azure Container Instances with virtual network integration or Azure Kubernetes Service with network policies. Implement Azure DDoS Protection and Web Application Firewall (WAF) to filter malicious requests before they reach your applications.
Azure Relay and Service Bus protection involves using Azure Private Link to create private endpoints for these services, eliminating the need for applications to make outbound requests to public service endpoints. Implement Azure Service Bus authentication and authorization to ensure that only authorized applications can access messaging resources.
Azure AD authentication protection involves implementing proper redirect URI validation and using Azure AD's built-in security features like Conditional Access policies. For applications that proxy authentication requests, use Azure AD's token validation endpoints instead of making direct requests to authentication services.
Storage account SSRF protection involves using Azure Private Link for storage accounts, implementing Azure Storage firewall rules to restrict access to specific virtual networks or IP ranges, and using Azure Managed Identities for storage access instead of handling storage keys in application code.
For Cosmos DB and database services, use Azure Private Link to create private endpoints, implement database firewall rules to restrict access to specific IP ranges or virtual networks, and use Azure AD authentication for database access where supported.
Azure API Management protection involves using API Management's built-in security features like rate limiting, IP filtering, and authentication policies. Implement Azure Front Door or Application Gateway with WAF to filter malicious requests before they reach your API Management services.
For applications that must make outbound requests to external services, implement Azure App Service's Managed Environment (ASE) with outbound traffic restrictions, or use Azure Functions with virtual network integration to control outbound network access through network security groups and Azure Firewall.
Code-level SSRF protection in Azure involves implementing strict URL validation using regular expressions that allow only approved domains and protocols. Use Azure's DNS resolution services to verify that URLs point to legitimate endpoints before making requests. Implement timeout and retry policies to prevent SSRF attacks from causing denial of service through slow or hanging requests.
Azure Security Center and Azure Defender provide additional SSRF protection through network mapping, anomaly detection, and just-in-time access controls. Enable Azure Defender for App Service and Azure Defender for Containers to get advanced threat protection and SSRF vulnerability detection.
Implement Azure Policy to enforce security standards across your Azure environment, including restrictions on public IP addresses, requirements for Private Link usage, and controls on outbound network access. Use Azure Blueprints to deploy consistent security configurations across multiple subscriptions.
For applications that handle user-controlled URLs, implement Azure Front Door with Web Application Firewall (WAF) rules that specifically target SSRF attack patterns. Use Azure Application Gateway's URL rewriting and redirection capabilities to prevent malicious URL manipulation.
Finally, implement comprehensive logging and monitoring using Azure Monitor and Azure Security Center. Set up alerts for suspicious outbound network traffic patterns, unusual authentication attempts, or access to internal Azure services that shouldn't be publicly accessible.
Related CWEs: ssrf
| CWE ID | Name | Severity |
|---|---|---|
| CWE-918 | Server-Side Request Forgery (SSRF) | CRITICAL |
| CWE-441 | Unintended Proxy or Intermediary (Confused Deputy) | HIGH |