Skip to content

Commit

Permalink
Land #11977, AWS EC2, S3, and IAM Enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
asoto-r7 committed Jun 27, 2019
2 parents 76f907c + 7de8d76 commit 26cd53e
Show file tree
Hide file tree
Showing 8 changed files with 661 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Gemfile.lock
Expand Up @@ -5,6 +5,9 @@ PATH
actionpack (~> 4.2.6)
activerecord (~> 4.2.6)
activesupport (~> 4.2.6)
aws-sdk-ec2
aws-sdk-iam
aws-sdk-s3
backports
bcrypt
bcrypt_pbkdf
Expand Down Expand Up @@ -111,6 +114,28 @@ GEM
arel (6.0.4)
arel-helpers (2.9.1)
activerecord (>= 3.1.0, < 7)
aws-eventstream (1.0.3)
aws-partitions (1.174.0)
aws-sdk-core (3.54.2)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-ec2 (1.91.0)
aws-sdk-core (~> 3, >= 3.53.0)
aws-sigv4 (~> 1.1)
aws-sdk-iam (1.24.0)
aws-sdk-core (~> 3, >= 3.53.0)
aws-sigv4 (~> 1.1)
aws-sdk-kms (1.21.0)
aws-sdk-core (~> 3, >= 3.53.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.42.0)
aws-sdk-core (~> 3, >= 3.53.0)
aws-sdk-kms (~> 1)
aws-sigv4 (~> 1.1)
aws-sigv4 (1.1.0)
aws-eventstream (~> 1.0, >= 1.0.2)
backports (3.15.0)
bcrypt (3.1.13)
bcrypt_pbkdf (1.0.1)
Expand Down Expand Up @@ -158,6 +183,7 @@ GEM
http_parser.rb (0.6.0)
i18n (0.9.5)
concurrent-ruby (~> 1.0)
jmespath (1.4.0)
jsobfu (0.4.2)
rkelly-remix
json (2.2.0)
Expand Down Expand Up @@ -408,3 +434,4 @@ DEPENDENCIES

BUNDLED WITH
1.17.3

117 changes: 117 additions & 0 deletions documentation/modules/auxiliary/cloud/aws/enum_ec2.md
@@ -0,0 +1,117 @@
## Vulnerable Application

Amazon Web Services (AWS) resources can be managed through an API that authenticates based on an `ACCESS_KEY_ID` and a `SECRET_ACCESS_KEY`. With these two pieces of information, an attacker can gain privileges which may include enumerating resources within the AWS account.

This module authenticates to AWS EC2 (Elastic Compute Cloud) to identify compute instances that the credentials can see. The instances themselves may be connected to the public Internet, but are likely to be protected by security groups and subnet network ACLs. In any case, knowledge of the instances is the first step in evaluating their security.

## Verification Steps

### Create or acquire the credentials

1. (If necessary) Create an AWS account. Free trials are available.
2. Login to the [AWS Console](https:\\console.aws.amazon.com\).
3. Use the dropbown menu in the top-right with your username, then click on "My Security Credentials".
4. Expand the "Access Keys" pane and click "Create New Access Key".
5. Follow the steps in the AWS console, making sure to record both the 'access key ID' and 'secret access key'. (The 'secret access key' is only shown once, then can never be retrieved.)

### Enumerate AWS resources using the credentials

1. Start msfconsole
2. `use auxiliary/cloud/aws/enum_ec2`
3. Set the `ACCESS_KEY_ID` and `SECRET_ACCESS_KEY` options.
4. Optionally, set the `REGION` and `LIMIT` options.
5. `run`

## Options

**ACCESS_KEY_ID**

This AWS credential is like a username. It uniquely identifies the user, and is paired with a 'secret access key'. The access key ID is retrievable through the AWS console.

An example `ACCESS_KEY_ID` would be `AKIA5C76TR3KXHXA5CRC`

**SECRET_ACCESS_KEY**

This AWS credential is like a password, and should be treated as such. It is paired with a 'access key ID'. The access key ID cannot be retrieved from AWS after it has been generated, but it may be discoverable through environment variables, configuration files, source code, or backups.

An example `SECRET_ACCESS_KEY` would be `EKfx3wOWWiGk1WgBTAZfF\2dq3SbDsQj4jdyOMOv`.

## Scenarios

### Provided a valid 'access key ID' and 'secret access key' with sufficient privileges

```
msf5 auxiliary(cloud/aws/enum_iam) > run
[+] Found 3 users.
[+] User Name: test1
[+] User ID: AIDA5C76TR3KTTO3PTAJ7
[+] Creation Date: 2019-06-14 18:18:23 UTC
[+] Tags: []
[+] Groups: []
[+] SSH Pub Keys: []
[+] Policies: IAMUserChangePassword
[+] Signing certs: []
[+] Password Used: 2019-06-17 19:55:57 UTC
[+] AWS Access Keys: AKIA5C76TR3K3JN3FYUE (Active)
[+] Console login: Enabled
[+] Two-factor auth: Enabled on 2019-06-17 20:01:05 UTC
[*]
[+] User Name: test2
[+] User ID: AIDA5C76TR3KVHWFEQSDL
[+] Creation Date: 2019-06-14 18:18:35 UTC
[+] Tags: []
[+] Groups: ["mygroup", "mygroup2"]
[+] SSH Pub Keys: []
[+] Policies: IAMUserChangePassword
[+] Signing certs: []
[+] Password Used: (Never)
[+] AWS Access Keys: AKIA5C76TR3KXHXA5CRC (Inactive)
[+] Console login: Enabled
[+] Two-factor auth: Disabled
[*]
[+] User Name: test3
[+] User ID: AIDA5C76TR3KYI2HC4MOL
[+] Creation Date: 2019-06-14 18:18:44 UTC
[+] Tags: []
[+] Groups: ["mygroup"]
[+] SSH Pub Keys: []
[+] Policies: []
[+] Signing certs: []
[+] Password Used: (Never)
[+] AWS Access Keys: AKIA5C76TR3KWWADYZNB (Active)
[+] Console login: Disabled
[+] Two-factor auth: Disabled
[*]
[*] Auxiliary module execution completed
```

### Provided an invalid or inactive 'access key ID'

```
msf5 auxiliary(cloud/aws/enum_iam) > run
[-] Auxiliary aborted due to failure: unexpected-reply: The security token included in the request is invalid.
[*] Auxiliary module execution completed
msf5 auxiliary(cloud/aws/enum_iam) >
```

### Provided an invalid 'secret access key'

```
msf5 auxiliary(cloud/aws/enum_iam) > run
[-] Auxiliary aborted due to failure: unexpected-reply: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.
[*] Auxiliary module execution completed
msf5 auxiliary(cloud/aws/enum_iam) >
```

### Provided an 'access key ID' or 'secret access key' with insufficient privileges

```
msf5 auxiliary(cloud\aws\enum_ec2) > run
[-] Auxiliary aborted due to failure: unexpected-reply: User: arn:aws:iam::899712345657:user/test1 is not authorized to perform: iam:ListUsers on resource: arn:aws:iam::899712345657:user/
[*] Auxiliary module execution completed
msf5 auxiliary(cloud\aws\enum_ec2) >
```
102 changes: 102 additions & 0 deletions documentation/modules/auxiliary/cloud/aws/enum_iam.md
@@ -0,0 +1,102 @@
## Vulnerable Application

Amazon Web Services (AWS) resources can be managed through an API that authenticates based on an `ACCESS_KEY_ID` and a `SECRET_ACCESS_KEY`. With these two pieces of information, an attacker can gain privileges which may include enumerating resources within the AWS account.

This module authenticates to AWS IAM (Identify Access Module) to identify user accounts that the credentials can see. The users themselves are likely protected with different credentials, including passwords or MFA tokens. In any case, knowledge of the users is the first step in evaluating their security.

## Verification Steps

### Create or acquire the credentials

1. (If necessary) Create an AWS account. Free trials are available.
2. Login to the [AWS Console](https:\\console.aws.amazon.com\).
3. Use the dropbown menu in the top-right with your username, then click on "My Security Credentials".
4. Expand the "Access Keys" pane and click "Create New Access Key".
5. Follow the steps in the AWS console, making sure to record both the 'access key ID' and 'secret access key'. (The 'secret access key' is only shown once, then can never be retrieved.)

### Enumerate AWS resources using the credentials

1. Start msfconsole
2. `use auxiliary/cloud/aws/enum_iam`
3. Set the `ACCESS_KEY_ID` and `SECRET_ACCESS_KEY` options.
4. `run`

## Options

**ACCESS_KEY_ID**

This AWS credential is like a username. It uniquely identifies the user, and is paired with a 'secret access key'. The access key ID is retrievable through the AWS console.

An example `ACCESS_KEY_ID` would be `AKIA5C76TR3KXHXA5CRC`

**SECRET_ACCESS_KEY**

This AWS credential is like a password, and should be treated as such. It is paired with a 'access key ID'. The access key ID cannot be retrieved from AWS after it has been generated, but it may be discoverable through environment variables, configuration files, source code, or backups.

An example `SECRET_ACCESS_KEY` would be `EKfx3wOWWiGk1WgBTAZfF\2dq3SbDsQj4jdyOMOv`.

**REGION**

AWS resources are located in regions. Optionally, this module's output can be filtered based on region to minimize the query to AWS. Alternatively, `REGION` can be left blank, such that all regions will be checked.

An example region would be `us-west-2`.

**LIMIT**

Some AWS API calls support limiting output, such that the module will only reutrn the number of instances, without detailing the configuration of each instance. Optionally, this module's output can be filtered to minimize the query to AWS and the user output. Alternatively, `LIMIT` can be left blank, such that all EC2 instances will be detailed.

Note that the `LIMIT` parameter is imposed per region, so the total number of results may be higher than the user-specified limit, but the maximum number of results for a single region will not exceed `LIMIT`. This behavior is due to the AWS API.

An example `LIMIT` would be `10`.

## Scenarios

### Provided a valid 'access key ID' and 'secret access key' with sufficient privileges

```
msf5 auxiliary(cloud/aws/enum_ec2) > run
[*] Found 0 instances in eu-north-1
[*] Found 0 instances in ap-south-1
[*] Found 0 instances in eu-west-3
[*] Found 0 instances in eu-west-2
[*] Found 0 instances in eu-west-1
[*] Found 0 instances in ap-northeast-2
[*] Found 0 instances in ap-northeast-1
[*] Found 0 instances in sa-east-1
[*] Found 0 instances in ca-central-1
[*] Found 0 instances in ap-southeast-1
[*] Found 0 instances in ap-southeast-2
[*] Found 0 instances in eu-central-1
[*] Found 0 instances in us-east-1
[*] Found 0 instances in us-east-2
[*] Found 0 instances in us-west-1
[*] Found 1 instances in us-west-2
[+] i-0f8bb3bbb06faf58d (running)
[+] Creation Date: 2019-06-11 23:14:48 UTC
[+] Public IP: 18.236.87.255 (ec2-18-236-87-255.us-west-2.compute.amazonaws.com)
[+] Private IP: 18.236.87.255 (ip-172-31-30-21.us-west-2.compute.internal)
[+] Security Group: sg-0d52cc35aaf82aff5
[*] Auxiliary module execution completed
msf5 auxiliary(cloud/aws/enum_ec2) >
```

### Provided an invalid or inactive 'access key ID', or an invalid 'secret access key'

```
msf5 auxiliary(cloud\aws\enum_ec2) > run
[-] Auxiliary aborted due to failure: unexpected-reply: AWS was not able to validate the provided access credentials
[*] Auxiliary module execution completed
msf5 auxiliary(cloud\aws\enum_ec2) >
```

### Provided an 'access key ID' or 'secret access key' with insufficient privileges

```
msf5 auxiliary(cloud\aws\enum_ec2) > run
[-] Auxiliary aborted due to failure: unexpected-reply: You are not authorized to perform this operation.
[*] Auxiliary module execution completed
msf5 auxiliary(cloud\aws\enum_ec2) >
```
95 changes: 95 additions & 0 deletions documentation/modules/auxiliary/cloud/aws/enum_s3.md
@@ -0,0 +1,95 @@
## Vulnerable Application

Amazon Web Services (AWS) resources can be managed through an API that authenticates based on an `ACCESS_KEY_ID` and a `SECRET_ACCESS_KEY`. With these two pieces of information, an attacker can gain privileges which may include enumerating resources within the AWS account.

This module authenticates to AWS S3 (Simple Storage Service), to identify buckets that the credentials can see. The files contained within buckets may be publicly readable and/or writable, or they may be locked down. In any case, knowledge of the buckets is the first step in evaluating their security.

## Verification Steps

### Create or acquire the credentials

1. (If necessary) Create an AWS account. Free trials are available.
2. Login to the [AWS Console](https://console.aws.amazon.com/).
3. Use the dropbown menu in the top-right with your username, then click on "My Security Credentials".
4. Expand the "Access Keys" pane and click "Create New Access Key".
5. Follow the steps in the AWS console, making sure to record both the 'access key ID' and 'secret access key'. (The 'secret access key' is only shown once, then can never be retrieved.)

### Enumerate AWS resources using the credentials

1. Start msfconsole
2. `use auxiliary/cloud/aws/enum_s3`
3. Set the `ACCESS_KEY_ID` and `SECRET_ACCESS_KEY` options.
4. Optionally, set the `REGION` option.
5. `run`

## Options

**ACCESS_KEY_ID**

This AWS credential is like a username. It uniquely identifies the user, and is paired with a 'secret access key'. The access key ID is retrievable through the AWS console.

An example `ACCESS_KEY_ID` would be `AKIA5C76TR3KXHXA5CRC`

**SECRET_ACCESS_KEY**

This AWS credential is like a password, and should be treated as such. It is paired with a 'access key ID'. The access key ID cannot be retrieved from AWS after it has been generated, but it may be discoverable through environment variables, configuration files, source code, or backups.

An example `SECRET_ACCESS_KEY` would be `EKfx3wOWWiGk1WgBTAZfF/2dq3SbDsQj4jdyOMOv`.

**REGION**

AWS resources are located in regions. Optionally, this module's output can be filtered based on region to minimize the query to AWS. Alternatively, `REGION` can be left blank, such that all regions will be checked.

An example region would be `us-west-2`.

## Scenarios

### Provided a valid 'access key ID' and 'secret access key' with sufficient privileges

```
msf5 auxiliary(cloud/aws/enum_s3) > run
[+] Found 1 buckets.
[+] Name: asoto-secret-demo-bucket
[+] Creation Date: 2019-06-13 23:30:26 UTC
[+] # of Objects: 0
[+] Region: us-west-2
[+] Website: /index.html
[+] Owner: asoto
[+] Permissions:
[+] User 'asoto' granted FULL_CONTROL
[+] Group '' (http://acs.amazonaws.com/groups/s3/LogDelivery) granted READ
[*]
[*] Done.
[*] Auxiliary module execution completed
msf5 auxiliary(cloud/aws/enum_s3) > exit
```

### Provided an invalid or inactive 'access key ID'

```
msf5 auxiliary(cloud/aws/enum_s3) > run
[-] Auxiliary aborted due to failure: unexpected-reply: The AWS Access Key Id you provided does not exist in our records.
[*] Auxiliary module execution completed
msf5 auxiliary(cloud/aws/enum_s3) >
```

### Provided an invalid 'secret access key'

```
msf5 auxiliary(cloud/aws/enum_s3) > run
[-] Auxiliary aborted due to failure: unexpected-reply: The request signature we calculated does not match the signature you provided. Check your key and signing method.
[*] Auxiliary module execution completed
msf5 auxiliary(cloud/aws/enum_s3) >
```

### Provided an 'access key ID' or 'secret access key' with insufficient privileges

```
msf5 auxiliary(cloud/aws/enum_s3) > run
[-] Auxiliary aborted due to failure: unexpected-reply: Access Denied
[*] Auxiliary module execution completed
msf5 auxiliary(cloud/aws/enum_s3) >
```
5 changes: 5 additions & 0 deletions metasploit-framework.gemspec
Expand Up @@ -198,4 +198,9 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency 'faker'
# Pinned as a dependency of i18n to the last working version
spec.add_runtime_dependency 'concurrent-ruby','1.0.5'

# AWS enumeration modules
spec.add_runtime_dependency 'aws-sdk-s3'
spec.add_runtime_dependency 'aws-sdk-ec2'
spec.add_runtime_dependency 'aws-sdk-iam'
end

0 comments on commit 26cd53e

Please sign in to comment.