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

Scenario | ecs_privesc_evade_protection #233

Open
wants to merge 36 commits into
base: master
Choose a base branch
from

Conversation

West-wise
Copy link
Contributor

Add a new scenario which abuses an ECS & reverse shell to escalate privileges.

@West-wise West-wise changed the title Add new scenario/ecs_privesc_evade_protection Scenario | ecs_privesc_evade_protection Oct 31, 2023
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.

Will add some more once I get the change to go through the scenario

source_arn = aws_cloudwatch_event_rule.guardduty_events.arn
}

resource "null_resource" "lambda_zip" {
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -0,0 +1 @@
cg-secret-bob12-gC9!+Xy#QJ37fa@H3D7Kd@2*a&#+Tp%
Copy link
Contributor

Choose a reason for hiding this comment

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

Assets used by the scenario should be moved to under the terraform directory. Like done here

- The attacker exploits vulnerabilities in a web service to access the EC2's credentials.
- The attacker defines and executes an ECS task with the authority of the web developer to privesc or bypass mitigations. Perform a reverse shell attack to access the container been created.
- The attacker accesses S3 at the container to bypass GuardDuty detection. Gets the Secret String and exits the scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

Create a manifest.yml file.
example

- The attacker exploits vulnerabilities in a web service to access the EC2's credentials.
- The attacker defines and executes an ECS task with the authority of the web developer to privesc or bypass mitigations. Perform a reverse shell attack to access the container been created.
- The attacker accesses S3 at the container to bypass GuardDuty detection. Gets the Secret String and exits the scenario.

Copy link
Contributor

Choose a reason for hiding this comment

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

Once we have the size & difficulty, add you scenario to the main readme file.

}

# Wait a little for ec2 be created in ASG.
resource "time_sleep" "wait_for_instance" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the resources and data to dedicated files

@@ -0,0 +1,4 @@
provider "aws" {
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -0,0 +1,4 @@
provider "aws" {
Copy link
Contributor

Choose a reason for hiding this comment

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

3iuy-prog and others added 2 commits November 2, 2023 03:20
Missing commit about user-email input for SES is reflected.
@3iuy-prog
Copy link

We have addressed all the requirements. Please let us know if there are any other requests or suggestions. :)

@3iuy-prog
Copy link

Terraform version >= 2.0 was definitely a misnomer.
According to Hasicorp, the latest version of terraform is 1.6.3.
The version has been modified accordingly.

and I added vpc.tf reflecting the feedback.
=> https://discord.com/channels/969671994599669760/1168866493451214859/1170108321819275334

```
http://<ec2_ip_address>/?url=http://[::ffff:a9fe:a9fe]/latest/meta-data/iam/security-credentials/<role>
aws configure --profile attacker
echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials`echo "aws_session_token = <token>" >> ~/.aws/credentials
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be this many echo commands?

@andrew-aiken
Copy link
Contributor

The following data sources are now unused

  • data.aws_vpc.default
  • data.aws_subnets.all_subnets

I would also recommend adding a required version for the archive & time providers

@andrew-aiken
Copy link
Contributor

Have the scenario create the CloudWatch group that the lambda will write to. Then when the scenario is destroyed it is also cleaned up

- data "aws_vpc" "default"
- data "aws_subnets" "all_subnets"
- flag.txt is now for easy path.
- secret-string.txt is for hard path.
- refresh README.md & cheat_sheet.md.
@3iuy-prog
Copy link

3iuy-prog commented Nov 9, 2023

I was thinking about adding an easy path and decided to create a separate secret-string file for each path.
S3 is now accessible with web credentials, and users can also see both secret files. However, users can only read the contents of the easy-path file.
Users must do ECS Privesc to read the Hard Path file.

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.

LGTM

@jdearmas could you review this. There also is a thread in discord about this scenario

@3iuy-prog 3iuy-prog force-pushed the scenario/ecs_privesc_evade_protection branch from 3c01de3 to 0dca220 Compare December 13, 2023 12:04
@3iuy-prog 3iuy-prog force-pushed the scenario/ecs_privesc_evade_protection branch from 0dca220 to 928ad74 Compare December 13, 2023 12:10
@@ -0,0 +1,6 @@
# Using CloudTrail for GuardDuty
resource "aws_cloudtrail" "cloudtrail" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a depends on for the bucket policy aws_s3_bucket_policy.trail_bucket_policy

provisioner "local-exec" {
when = create
on_failure = fail
command = "python ./push-dockerfile.py --dockerfile_path ../assets/ssrf-web/ --repository ${aws_ecr_repository.repository.name} --region ${var.region} --profile ${var.profile} --image_tag latest"
Copy link
Contributor

Choose a reason for hiding this comment

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

Switch out python to python3 not all systems come with python/ an alias to 3 (osx)

Python3 is already defined to be used in cloudgoat.py

The files could also be made executable and then define the env in the top of the files

provisioner "local-exec" {
when = destroy
on_failure = fail
command = "python ./pop-dockerfile.py --repository ${self.triggers.repository_name} --region ${self.triggers.region} --profile ${self.triggers.profile} --image_tag all"
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above


def docker_build_and_push(repository_uri, image_tag, path):
# Build the Docker image
subprocess.run(f"docker build -t {repository_uri}:{image_tag} {path}", shell=True, check=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Add --platform linux/amd64 to the build subprocess, I'm on a apple silicon machine which is based on arm

Logs from the ecs server

[root@ip-192-168-150-41 ~]# docker logs 6d265c0e1c35
exec /usr/local/bin/docker-php-entrypoint: exec format error

import subprocess


def get_docker_login_cmd(client, region):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this function necessary for removing the images from ecr?

@@ -227,16 +227,13 @@ Starting with access the "ruse" EC2 the user leverages the instace profile to ba

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

### glue_privesc(Large / Moderate)
### ecs_privesc_evade_protection (Medium / Moderate)
Copy link
Contributor

Choose a reason for hiding this comment

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

Overwriting glue_privesc

@@ -0,0 +1,61 @@
# Scenario: ecs_privesc_evade_protection
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you make a note that this scenario needs docker to run

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.

Submitted some changes

@3iuy-prog
Copy link

All changes are submitted. :)

@andrew-aiken
Copy link
Contributor

andrew-aiken commented Dec 24, 2023

941aa82

The change to the platform are still building as arm, the ECS tasks then fails.

I think the only thing needed to be added is the platform tag to force it to be amd64

docker_build_cmd = f"docker build --platform=linux/amd64 -t {repository_uri}:{image_tag} {path}"

Everything else looks great 🙌

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

Successfully merging this pull request may close these issues.

3 participants