From 18cb84f727f116843fe6b0e19dcc093e5918cb79 Mon Sep 17 00:00:00 2001 From: Translator Date: Thu, 9 Jan 2025 01:06:11 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation --- .../az-authorization-privesc.md | 58 +++++++++++-------- .../gcp-source-repositories-enum.md | 41 +++++++------ 2 files changed, 58 insertions(+), 41 deletions(-) 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 c02e4dfb7..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 -Για περισσότερες πληροφορίες ελέγξτε: +Fore more information check: {{#ref}} ../az-services/az-azuread.md @@ -12,38 +12,45 @@ ### 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": "", -"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/"] } ``` -Στη συνέχεια, ενημερώστε τις άδειες ρόλου με τον προηγούμενο ορισμό καλώντας: + +Then update the role permissions with the previous definition calling: + ```bash az role definition update --role-definition role.json ``` + ### Microsoft.Authorization/elevateAccess/action -Αυτή η άδεια επιτρέπει την αναβάθμιση δικαιωμάτων και την ικανότητα ανάθεσης αδειών σε οποιονδήποτε κύριο για πόρους Azure. Προορίζεται να δοθεί στους Παγκόσμιους Διαχειριστές Entra ID ώστε να μπορούν επίσης να διαχειρίζονται άδειες για πόρους 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] -> Νομίζω ότι ο χρήστης πρέπει να είναι Παγκόσμιος Διαχειριστής στο Entra ID για να λειτουργήσει η κλήση αναβάθμισης. +> 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 -Αυτή η άδεια επιτρέπει την προσθήκη Ομοσπονδιακών διαπιστευτηρίων σε διαχειριζόμενες ταυτότητες. Π.χ. δίνει πρόσβαση σε Github Actions σε ένα repo σε μια διαχειριζόμενη ταυτότητα. Στη συνέχεια, επιτρέπει την **πρόσβαση σε οποιαδήποτε διαχειριζόμενη ταυτότητα που έχει οριστεί από τον χρήστη**. +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: -Παράδειγμα εντολής για να δώσετε πρόσβαση σε ένα repo στο Github σε μια διαχειριζόμενη ταυτότητα: ```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 a649cd2eb..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 @@ -4,34 +4,35 @@ ## Basic Information -Η Google Cloud Source Repositories είναι μια πλήρως λειτουργική, κλιμακούμενη, **ιδιωτική υπηρεσία αποθετηρίου Git**. Είναι σχεδιασμένη να **φιλοξενεί τον πηγαίο κώδικα σας σε ένα πλήρως διαχειριζόμενο περιβάλλον**, ενσωματώνοντας ομαλά με άλλα εργαλεία και υπηρεσίες GCP. Προσφέρει έναν συνεργατικό και ασφαλή χώρο για τις ομάδες να αποθηκεύουν, να διαχειρίζονται και να παρακολουθούν τον κώδικά τους. +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. -Τα κύρια χαρακτηριστικά των Cloud Source Repositories περιλαμβάνουν: +Key features of Cloud Source Repositories include: -1. **Πλήρως Διαχειριζόμενη Φιλοξενία Git**: Προσφέρει τη γνωστή λειτουργικότητα του Git, που σημαίνει ότι μπορείτε να χρησιμοποιείτε κανονικές εντολές και ροές εργασίας Git. -2. **Ενσωμάτωση με Υπηρεσίες GCP**: Ενσωματώνεται με άλλες υπηρεσίες GCP όπως Cloud Build, Pub/Sub και App Engine για πλήρη ιχνηλασιμότητα από τον κώδικα μέχρι την ανάπτυξη. -3. **Ιδιωτικά Αποθετήρια**: Διασφαλίζει ότι ο κώδικάς σας αποθηκεύεται με ασφάλεια και ιδιωτικότητα. Μπορείτε να ελέγξετε την πρόσβαση χρησιμοποιώντας ρόλους Cloud Identity and Access Management (IAM). -4. **Ανάλυση Πηγαίου Κώδικα**: Συνεργάζεται με άλλα εργαλεία GCP για να παρέχει αυτοματοποιημένη ανάλυση του πηγαίου κώδικα σας, εντοπίζοντας πιθανά προβλήματα όπως σφάλματα, ευπάθειες ή κακές πρακτικές προγραμματισμού. -5. **Εργαλεία Συνεργασίας**: Υποστηρίζει συνεργατικό προγραμματισμό με εργαλεία όπως αιτήματα συγχώνευσης, σχόλια και αναθεωρήσεις. -6. **Υποστήριξη Καθρέφτη**: Σας επιτρέπει να συνδέσετε τα Cloud Source Repositories με αποθετήρια που φιλοξενούνται στο GitHub ή Bitbucket, επιτρέποντας αυτόματη συγχρονισμό και παρέχοντας μια ενιαία εικόνα όλων των αποθετηρίων σας. +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. ### OffSec information -- Η διαμόρφωση των αποθετηρίων πηγής μέσα σε ένα έργο θα έχει έναν **Λογαριασμό Υπηρεσίας** που χρησιμοποιείται για την αποστολή μηνυμάτων Cloud Pub/Sub. Ο προεπιλεγμένος που χρησιμοποιείται είναι ο **Compute SA**. Ωστόσο, **δεν νομίζω ότι είναι δυνατόν να κλέψετε το token του** από τα Source Repositories καθώς εκτελείται στο παρασκήνιο. -- Για να δείτε τον κώδικα μέσα στην κονσόλα ιστού GCP Cloud Source Repositories ([https://source.cloud.google.com/](https://source.cloud.google.com/)), χρειάζεται ο κώδικας να είναι **μέσα στο master branch από προεπιλογή**. -- Μπορείτε επίσης να **δημιουργήσετε ένα καθρέφτη Cloud Repository** που να δείχνει σε ένα repo από **Github** ή **Bitbucket** (δίνοντας πρόσβαση σε αυτές τις πλατφόρμες). -- Είναι δυνατόν να **κωδικοποιήσετε και να αποσφαλίσετε από μέσα στο GCP**. -- Από προεπιλογή, τα Source Repositories **αποτρέπουν την αποστολή ιδιωτικών κλειδιών σε commits**, αλλά αυτό μπορεί να απενεργοποιηθεί. +- 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. ### Open In Cloud Shell -Είναι δυνατόν να ανοίξετε το αποθετήριο στο Cloud Shell, μια προτροπή όπως αυτή θα εμφανιστεί: +It's possible to open the repository in Cloud Shell, a prompt like this one will appear:
-Αυτό θα σας επιτρέψει να κωδικοποιήσετε και να αποσφαλίσετε στο Cloud Shell (το οποίο θα μπορούσε να έχει παραβιαστεί). +This will allow you to code and debug in Cloud Shell (which could get cloudshell compromised). ### Enumeration + ```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... ``` -### Ανάβαση Δικαιωμάτων & Μετά την Εκμετάλλευση + +### Privilege Escalation & Post Exploitation {{#ref}} ../gcp-privilege-escalation/gcp-sourcerepos-privesc.md {{#endref}} -### Μη Αυθεντικοποιημένη Enum +### Unauthenticated Enum {{#ref}} ../gcp-unauthenticated-enum-and-access/gcp-source-repositories-unauthenticated-enum.md {{#endref}} {{#include ../../../banners/hacktricks-training.md}} + + +