Server-Side Request Forgery

Server Side Request Forgery or SSRF is a vulnerability in which an attacker forces a server to perform requests on their behalf.

Summary

  • Tools

  • Payloads with localhost

  • Bypassing filters

    • Bypass using HTTPS

    • Bypass localhost with [::]

    • Bypass localhost with a domain redirection

    • Bypass localhost with CIDR

    • Bypass using a decimal IP location

    • Bypass using octal IP

    • Bypass using IPv6/IPv4 Address Embedding

    • Bypass using malformed urls

    • Bypass using rare address

    • Bypass using URL encoding

    • Bypass using bash variables

    • Bypass using tricks combination

    • Bypass using enclosed alphanumerics

    • Bypass filter_var() php function

    • Bypass against a weak parser

    • Bypassing using jar protocol (java only)

  • SSRF exploitation via URL Scheme

    • file://

    • http://

    • dict://

    • sftp://

    • tftp://

    • ldap://

    • gopher://

    • netdoc://

  • SSRF exploiting WSGI

  • SSRF exploiting Redis

  • SSRF exploiting PDF file

  • Blind SSRF

  • SSRF to XSS

  • SSRF from XSS

  • SSRF URL for Cloud Instances

    • SSRF URL for AWS Bucket

    • SSRF URL for AWS ECS

    • SSRF URL for AWS Elastic Beanstalk

    • SSRF URL for AWS Lambda

    • SSRF URL for Google Cloud

    • SSRF URL for Digital Ocean

    • SSRF URL for Packetcloud

    • SSRF URL for Azure

    • SSRF URL for OpenStack/RackSpace

    • SSRF URL for HP Helion

    • SSRF URL for Oracle Cloud

    • SSRF URL for Kubernetes ETCD

    • SSRF URL for Alibaba

    • SSRF URL for Docker

    • SSRF URL for Rancher

Tools

Payloads with localhost

Basic SSRF v1

Basic SSRF - Alternative version

Bypassing filters

Bypass using HTTPS

Bypass localhost with [::]

Bypass localhost with a domain redirection

The service nip.io is awesome for that, it will convert any ip address as a dns.

Bypass localhost with CIDR

It's a /8

Bypass using a decimal IP location

Bypass using octal IP

Implementations differ on how to handle octal format of ipv4.

Ref:

Bypass using IPv6/IPv4 Address Embedding

IPv6/IPv4 Address Embedding

Bypass using malformed urls

Bypass using rare address

You can short-hand IP addresses by dropping the zeros

Bypass using URL encoding

Single or double encode a specific URL to bypass blacklist

Bypass using bash variables

(curl only)

Bypass using tricks combination

Bypass using enclosed alphanumerics

@EdOverflow

Bypass using unicode

In some languages (.NET, Python 3) regex supports unicode by default. \d includes 0123456789 but also ๐๑๒๓๔๕๖๗๘๙.

Bypass filter_var() php function

Bypass against a weak parser

by Orange Tsai (Blackhat A-New-Era-Of-SSRF-Exploiting-URL-Parser-In-Trending-Programming-Languages.pdf)

https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Server%20Side%20Request%20Forgery/Images/WeakParser.png?raw=true

Bypassing using a redirect

using a redirect

Bypassing using type=url

Bypassing using DNS Rebinding (TOCTOU)

Bypassing using jar protocol (java only)

Blind SSRF

SSRF exploitation via URL Scheme

File

Allows an attacker to fetch the content of a file on the server

HTTP

Allows an attacker to fetch any content from the web, it can also be used to scan ports.

SSRF stream

The following URL scheme can be used to probe the network

Dict

The DICT URL scheme is used to refer to definitions or word lists available using the DICT protocol:

SFTP

A network protocol used for secure file transfer over secure shell

TFTP

Trivial File Transfer Protocol, works over UDP

LDAP

Lightweight Directory Access Protocol. It is an application protocol used over an IP network to manage and access the distributed directory information service.

Gopher

Gopher HTTP

Gopher SMTP - Back connect to 1337

Gopher SMTP - send a mail

Netdoc

Wrapper for Java when your payloads struggle with "\n" and "\r" characters.

SSRF exploiting WSGI

Exploit using the Gopher protocol, full exploit script available at https://github.com/wofeiwo/webcgi-exploits/blob/master/python/uwsgi_exp.py.

Header

modifier1

(1 byte)

0 (%00)

datasize

(2 bytes)

26 (%1A%00)

modifier2

(1 byte)

0 (%00)

Variable (UWSGI_FILE)

key length

(2 bytes)

10

(%0A%00)

key data

(m bytes)

UWSGI_FILE

value length

(2 bytes)

12

(%0C%00)

value data

(n bytes)

/tmp/test.py

SSRF exploiting Redis

Redis is a database system that stores everything in RAM

SSRF exploiting PDF file

https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/Server%20Side%20Request%20Forgery/Images/SSRF_PDF.png

Example with WeasyPrint by @nahamsec

Example with PhantomJS

Blind SSRF

When exploiting server-side request forgery, we can often find ourselves in a position where the response cannot be read.

Use an SSRF chain to gain an Out-of-Band output.

From https://blog.assetnote.io/2021/01/13/blind-ssrf-chains/ / https://github.com/assetnote/blind-ssrf-chains

Possible via HTTP(s)

Possible via Gopher

SSRF to XSS

by @D0rkerDevil & @alyssa.o.herrera

SSRF from XSS

Using an iframe

The content of the file will be integrated inside the PDF as an image or text.

Using an attachment

Example of a PDF attachment using HTML

  1. use <link rel=attachment href="URL"> as Bio text

  2. use 'Download Data' feature to get PDF

  3. use pdfdetach -saveall filename.pdf to extract embedded resource

  4. cat attachment.bin

SSRF URL for Cloud Instances

SSRF URL for AWS Bucket

Docs Interesting path to look for at http://169.254.169.254 or http://instance-data

DNS record

HTTP redirect

Alternate IP encoding

More urls to include

AWS SSRF Bypasses

E.g: Jira SSRF leading to AWS info disclosure - https://help.redacted.com/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/metadata/v1/maintenance

E.g2: Flaws challenge - http://4d0cf09b9b2d761a7d87be99d17507bce8b86f3b.flaws.cloud/proxy/169.254.169.254/latest/meta-data/iam/security-credentials/flaws/

SSRF URL for AWS ECS

If you have an SSRF with file system access on an ECS instance, try extracting /proc/self/environ to get UUID.

This way you'll extract IAM keys of the attached role

SSRF URL for AWS Elastic Beanstalk

We retrieve the accountId and region from the API.

We then retrieve the AccessKeyId, SecretAccessKey, and Token from the API.

notsosecureblog-awskey

Then we use the credentials with aws s3 ls s3://elasticbeanstalk-us-east-2-[ACCOUNT_ID]/.

SSRF URL for AWS Lambda

AWS Lambda provides an HTTP API for custom runtimes to receive invocation events from Lambda and send response data back within the Lambda execution environment.

Docs: https://docs.aws.amazon.com/lambda/latest/dg/runtimes-api.html#runtimes-api-next

SSRF URL for Google Cloud

⚠️ Google is shutting down support for usage of the v1 metadata service on January 15.

Requires the header "Metadata-Flavor: Google" or "X-Google-Metadata-Request: True"

Google allows recursive pulls

Beta does NOT require a header atm (thanks Mathias Karlsson @avlidienbrunn)

Required headers can be set using a gopher SSRF with the following technique

Interesting files to pull out:

  • SSH Public Key : http://metadata.google.internal/computeMetadata/v1beta1/project/attributes/ssh-keys?alt=json

  • Get Access Token : http://metadata.google.internal/computeMetadata/v1beta1/instance/service-accounts/default/token

  • Kubernetes Key : http://metadata.google.internal/computeMetadata/v1beta1/instance/attributes/kube-env?alt=json

Add an SSH key

Extract the token

Check the scope of the token

Now push the SSH key.

SSRF URL for Digital Ocean

Documentation available at https://developers.digitalocean.com/documentation/metadata/

SSRF URL for Packetcloud

Documentation available at https://metadata.packet.net/userdata

SSRF URL for Azure

Limited, maybe more exists? https://azure.microsoft.com/en-us/blog/what-just-happened-to-my-vm-in-vm-metadata-service/

Update Apr 2017, Azure has more support; requires the header "Metadata: true" https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service

SSRF URL for OpenStack/RackSpace

(header required? unknown)

SSRF URL for HP Helion

(header required? unknown)

SSRF URL for Oracle Cloud

SSRF URL for Alibaba

SSRF URL for Kubernetes ETCD

Can contain API keys and internal ip and ports

SSRF URL for Docker

More info:

  • Daemon socket option: https://docs.docker.com/engine/reference/commandline/dockerd/#daemon-socket-option

  • Docker Engine API: https://docs.docker.com/engine/api/latest/

SSRF URL for Rancher

More info: https://rancher.com/docs/rancher/v1.6/en/rancher-services/metadata-service/

References

Last updated