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

Merged
merged 8 commits into from
Jan 23, 2025
Merged

Conversation

j0eblow
Copy link
Contributor

@j0eblow j0eblow commented May 9, 2023

have fun

Copy link
Contributor

@jdearmas jdearmas left a comment

Choose a reason for hiding this comment

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

I'm blocked on completing the scenario. Can you add more detail/commands to the cheat sheet?

@@ -0,0 +1,13 @@
---
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 a single comment at the top of the file that explains what this file does in plain English?

For example:
# This 'manifest.yml' file provides configuration variables for the Cloudgoat scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -0,0 +1,2 @@
#!/bin/bash
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 a single comment at the almost top of the file that explains what this file does in plain English?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

unnecessary file for my scenario so I deleted it.

@@ -0,0 +1,51 @@
locals {
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 a single comment at the top of the file that explains what this file does in plain English?

Copy link
Contributor

Choose a reason for hiding this comment

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

Example:

# This is a Terraform file that creates three resources:
# 1. An AWS DynamoDB Table
# 2. An AWS DynamoDB Entry (for the Access ID)
# 3. An AWS DynamoDB Entry (for the Secret Key)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,95 @@
data "aws_ami" "amazon_linux_2" {
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 a single comment at the top of the file that explains what this file does in plain English?

Copy link
Contributor

Choose a reason for hiding this comment

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

Example:

# This is a Terraform file that creates several AWS EC2 resources:
# 1. A Data Source for an AWS Amazon Machine Image.
# 2. A TLS Private Key Resource
# 3. An AWS Key Pair Resource
# 4. An AWS Instance Resource
# 5. An AWS Security Group Resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,199 @@
resource "aws_iam_user" "low_priv_user" {
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 a single comment at the top of the file that explains what this file does in plain English?

Copy link
Contributor

Choose a reason for hiding this comment

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

Example:

# This Terraform file creates several resources for AWS Identity and Access Management (IAM):
# - An IAM User 
# - An IAM Access Key 
#
#   For AWS Simple Storage Service (S3):
#     - An IAM Policy 
#     - An IAM User Policy Attachment 
#
#   For AWS Lambda:
#     - An IAM Policy 
#     - An IAM User Policy Attachment 
#     - An IAM Role Policy
#
#   For AWS DynamoDB:
#     - An IAM Policy 
#     - An IAM Role
#     - An IAM Role Policy Attachment
#     - An IAM Instance Profile
#
#   For AWS Secrets Manager:
#     - An IAM User 
#     - An IAM Access Key 
#     - An IAM Role 
#     - An IAM User Policy 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

resource "aws_iam_instance_profile" "ec2_instance_profile" {
name = "EC2InstanceProfile"
role = aws_iam_role.ec2_dynamodb_role.name
resource "aws_iam_instance_profile" "dynamodb_instance_profile" {
Copy link
Contributor

Choose a reason for hiding this comment

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

The example comment from my initial review should be updated to reflect this change.

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.

@@ -142,3 +137,13 @@ vault kv put secret/tylers_seekrit value='TylerTantalizingTacosTangleToucans'
vault kv put secret/brads_seekrit value='BradBefriendsBouncingBlueberryBison'
export SSH_PRIVATE_KEY="${private_key}"
vault kv put secret/id_rsa value="$SSH_PRIVATE_KEY"

# Update MOTD with a hint
Copy link
Contributor

Choose a reason for hiding this comment

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

What is MOTD?

Copy link
Contributor Author

@j0eblow j0eblow May 23, 2023

Choose a reason for hiding this comment

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

https://en.wikipedia.org/wiki/Message_of_the_day - basically the message users see when they log on.

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.

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.
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.

@j0eblow j0eblow requested a review from jdearmas May 24, 2023 09:35
jdearmas
jdearmas previously approved these changes Jun 5, 2023
Copy link
Contributor

@jdearmas jdearmas left a comment

Choose a reason for hiding this comment

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

This new scenario works.

@@ -35,12 +35,12 @@ As an IAM user with limited privileges, the attacker initiates their journey by

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.
3. While examining the admin page's HTML comments, the attacker finds information about environment variables and a HashiCorp endpoint (located on port 8200 of the EC2 instance).
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.

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.

Copy link
Contributor

@andrew-aiken andrew-aiken left a comment

Choose a reason for hiding this comment

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

Suggested some changes.

Also running a terraform fmt will cleanup some of the formatting issues.

owners = ["amazon"]
}

provider "tls" {}
Copy link
Contributor

Choose a reason for hiding this comment

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

The provider should be moved into the provider.tf file

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.


resource "aws_instance" "web_app" {
ami = data.aws_ami.amazon_linux_2.id
instance_type = "t2.micro"

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! While t3.micro is slightly cheaper, it’s not free-tier eligible in most regions, unlike t2.micro, which might be better for CloudGoat’s learning and testing use cases.

filename = "lambda_function_payload.zip"
source_code_hash = filebase64sha256("lambda_function_payload.zip")

runtime = "python3.8"
Copy link
Contributor

Choose a reason for hiding this comment

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

Python version should be updated to latest (python3.13)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

Copy link
Contributor

Choose a reason for hiding this comment

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

The Terraform should manage the zipping of the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -0,0 +1,6 @@
# This Terraform file initializes the Terraform AWS provider (aka plugin).
Copy link
Contributor

Choose a reason for hiding this comment

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

Default AWS tags and provider versions should be defined

Example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

# - An AWS S3 Bucket
# - An AWS S3 Object

locals {
Copy link
Contributor

Choose a reason for hiding this comment

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

Merge local blocks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -0,0 +1,165 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional
Move to a templates directory like how ansible does it

@@ -0,0 +1,42 @@
# This Terraform file creates the following variables:
Copy link
Contributor

Choose a reason for hiding this comment

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

Add variable description and types.
You can probably copy this from another scenario that has then updated

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@nobodynate nobodynate added the new scenario A new vulnerable Cloudgoat scenario label Jan 16, 2025
@j0eblow
Copy link
Contributor Author

j0eblow commented Jan 21, 2025

Hi all, I ran into an issue while working on this pull request. I accidentally synced my fork with the upstream repository, which caused the branch originally associated with this PR to lose the changes. To recover, I created a new branch (restore-changes) and pushed all the updated changes there.

You can find the updated branch here: https://github.com/j0eblow/cloudgoat/tree/restore-changes

Please let me know how you’d prefer to proceed, whether I should update this pull request with the recovered changes or create a new pull request.

@jdearmas jdearmas force-pushed the secrets_in_the_cloud branch from 9096961 to 3d7b2af Compare January 23, 2025 19:57
Copy link
Contributor

@jdearmas jdearmas left a comment

Choose a reason for hiding this comment

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

Hello Mr. Backus,

I sincerely hope this finds you well! I've reviewed, tested, and approve your pull request to create the new Cloudgoat scenario "Secrets in the cloud". Thank you very much for your time, effort, and patience!

@jdearmas jdearmas merged commit c5a5abc into RhinoSecurityLabs:master Jan 23, 2025
@j0eblow
Copy link
Contributor Author

j0eblow commented Jan 24, 2025

Hello Mr. Backus,

I sincerely hope this finds you well! I've reviewed, tested, and approve your pull request to create the new Cloudgoat scenario "Secrets in the cloud". Thank you very much for your time, effort, and patience!

Thank you, Mr. De Armas! I truly appreciate your time and effort in reviewing and approving the pull request. It means a lot and I’m glad to have contributed to CloudGoat!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new scenario A new vulnerable Cloudgoat scenario
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants