From c4875c421f77cc16e48df894eead52469b5da0d7 Mon Sep 17 00:00:00 2001 From: Translator Date: Thu, 2 Jan 2025 21:34:52 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/kubernetes-security/kubernetes-pivotin --- book.toml | 1 + hacktricks-preprocessor.py | 18 +++-- .../kubernetes-pivoting-to-clouds.md | 18 ++--- theme/book.js | 56 +++++++++++++ theme/css/chrome.css | 53 ++++++++++++- theme/index.hbs | 78 ++++++++++++------- theme/sponsor.js | 2 - 7 files changed, 178 insertions(+), 48 deletions(-) diff --git a/book.toml b/book.toml index e3330d5e6..f20e2d2a2 100644 --- a/book.toml +++ b/book.toml @@ -22,6 +22,7 @@ after = ["links"] [preprocessor.hacktricks] command = "python3 ./hacktricks-preprocessor.py" +env = "prod" [output.html] additional-css = ["theme/pagetoc.css", "theme/tabs.css"] diff --git a/hacktricks-preprocessor.py b/hacktricks-preprocessor.py index 37f549101..8e67ab77b 100644 --- a/hacktricks-preprocessor.py +++ b/hacktricks-preprocessor.py @@ -30,14 +30,16 @@ def ref(matchobj): href = matchobj.groups(0)[0].strip() title = href if href.startswith("http://") or href.startswith("https://"): - # pass - try: - raw_html = str(urlopen(Request(href, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0'})).read()) - match = re.search('(.*?)', raw_html) - title = match.group(1) if match else href - except Exception as e: - logger.debug(f'Error opening URL {href}: {e}') - pass #nDont stop on broken link + if context['config']['preprocessor']['hacktricks']['env'] == 'dev': + pass + else: + try: + raw_html = str(urlopen(Request(href, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:124.0) Gecko/20100101 Firefox/124.0'})).read()) + match = re.search('(.*?)', raw_html) + title = match.group(1) if match else href + except Exception as e: + logger.debug(f'Error opening URL {href}: {e}') + pass #nDont stop on broken link else: try: if href.endswith("/"): diff --git a/src/pentesting-cloud/kubernetes-security/kubernetes-pivoting-to-clouds.md b/src/pentesting-cloud/kubernetes-security/kubernetes-pivoting-to-clouds.md index 5b94566e5..0c277c6e3 100644 --- a/src/pentesting-cloud/kubernetes-security/kubernetes-pivoting-to-clouds.md +++ b/src/pentesting-cloud/kubernetes-security/kubernetes-pivoting-to-clouds.md @@ -34,19 +34,19 @@ Copy codegcloud iam service-accounts keys create .json \ kubectl create secret generic \ --from-file=key.json=.json ``` -- Collega il Secret di Kubernetes all'account di servizio di Kubernetes utilizzando il seguente comando: +- Collega il Kubernetes Secret all'account di servizio Kubernetes utilizzando il seguente comando: ```bash Copy codekubectl annotate serviceaccount \ iam.gke.io/gcp-service-account= ``` > [!WARNING] -> Nel **secondo passo** sono state impostate le **credenziali del GSA come segreto del KSA**. Quindi, se puoi **leggere quel segreto** dall'**interno** del cluster **GKE**, puoi **escalare a quel servizio account GCP**. +> Nel **secondo passaggio** sono state impostate le **credenziali del GSA come segreto del KSA**. Quindi, se puoi **leggere quel segreto** dall'**interno** del cluster **GKE**, puoi **escalare a quel servizio account GCP**. ### Identità del Carico di Lavoro GKE -Con l'Identità del Carico di Lavoro, possiamo configurare un[ account di servizio Kubernetes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/) per agire come un[ account di servizio Google](https://cloud.google.com/iam/docs/understanding-service-accounts). I pod che girano con l'account di servizio Kubernetes si autenticheranno automaticamente come l'account di servizio Google quando accedono alle API di Google Cloud. +Con l'Identità del Carico di Lavoro, possiamo configurare un [Kubernetes service account](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/) per agire come un [Google service account](https://cloud.google.com/iam/docs/understanding-service-accounts). I pod che girano con il Kubernetes service account si autenticheranno automaticamente come il Google service account quando accedono alle API di Google Cloud. -La **prima serie di passi** per abilitare questo comportamento è **abilitare l'Identità del Carico di Lavoro in GCP** ([**passi**](https://medium.com/zeotap-customer-intelligence-unleashed/gke-workload-identity-a-secure-way-for-gke-applications-to-access-gcp-services-f880f4e74e8c)) e creare il SA GCP che vuoi che k8s impersoni. +La **prima serie di passaggi** per abilitare questo comportamento è **abilitare l'Identità del Carico di Lavoro in GCP** ([**passaggi**](https://medium.com/zeotap-customer-intelligence-unleashed/gke-workload-identity-a-secure-way-for-gke-applications-to-access-gcp-services-f880f4e74e8c)) e creare il GCP SA che vuoi che k8s impersoni. - **Abilita l'Identità del Carico di Lavoro** su un nuovo cluster ```bash @@ -126,7 +126,7 @@ gcloud auth activate-service-account --key-file=/var/run/secrets/google/service- > Come attaccante all'interno di K8s dovresti **cercare SAs** con l'**annotazione `iam.gke.io/gcp-service-account`** poiché indica che l'SA può accedere a qualcosa in GCP. Un'altra opzione sarebbe cercare di abusare di ogni KSA nel cluster e controllare se ha accesso.\ > Da GCP è sempre interessante enumerare i binding e sapere **quale accesso stai dando agli SAs all'interno di Kubernetes**. -Questo è uno script per **iterare facilmente su tutte le definizioni dei pod** **cercando** quella **annotazione**: +Questo è uno script per **iterare facilmente su tutte le definizioni dei pod** **cercando** quell'**annotazione**: ```bash for ns in `kubectl get namespaces -o custom-columns=NAME:.metadata.name | grep -v NAME`; do for pod in `kubectl get pods -n "$ns" -o custom-columns=NAME:.metadata.name | grep -v NAME`; do @@ -161,7 +161,7 @@ iam.amazonaws.com/allowed-roles: | ["role-arn"] name: default ``` -Una volta che il namespace è configurato con i ruoli IAM che i Pods possono avere, puoi **indicare il ruolo che desideri in ciascuna definizione del pod con qualcosa come**: +Una volta che lo spazio dei nomi è configurato con i ruoli IAM che i Pod possono avere, puoi **indicare il ruolo che desideri in ciascuna definizione del pod con qualcosa come**: ```yaml:Kiam & Kube2iam kind: Pod metadata: @@ -194,7 +194,7 @@ args: ["-c", "sleep 100000"]' | kubectl apply -f - ``` ### IAM Role per gli Account di Servizio K8s tramite OIDC -Questo è il **metodo raccomandato da AWS**. +Questo è il **modo raccomandato da AWS**. 1. Prima di tutto, è necessario [creare un provider OIDC per il cluster](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html). 2. Poi si crea un ruolo IAM con i permessi di cui avrà bisogno l'SA. @@ -234,7 +234,7 @@ aws sts assume-role-with-web-identity --role-arn arn:aws:iam::123456789098:role/ ../aws-security/aws-basic-information/aws-federation-abuse.md {{#endref}} -### Trova Pods e SAs con Ruoli IAM nel Cluster +### Trova Pods e SAs con IAM Roles nel Cluster Questo è uno script per **iterare facilmente su tutti i pod e le definizioni di sas** **cercando** quella **annotazione**: ```bash @@ -263,7 +263,7 @@ kubectl run NodeIAMStealer --restart=Never -ti --rm --image lol --overrides '{"s ``` ### Rubare il Token del Ruolo IAM -In precedenza abbiamo discusso di come **allegare i Ruoli IAM ai Pod** o addirittura di come **fuggire al Nodo per rubare il Ruolo IAM** che l'istanza ha allegato ad esso. +In precedenza abbiamo discusso di come **allegare i Ruoli IAM ai Pod** o addirittura di come **fuggire al Nodo per rubare il Ruolo IAM** che l'istanza ha ad esso allegato. Puoi utilizzare il seguente script per **rubare** le tue nuove e faticosamente guadagnate **credenziali del ruolo IAM**: ```bash diff --git a/theme/book.js b/theme/book.js index 1c8d77287..b11674b5a 100644 --- a/theme/book.js +++ b/theme/book.js @@ -590,6 +590,62 @@ function playground_text(playground, hidden = true) { }); })(); + + +(function menubarLanguage() { + var menubarLanguageToggleButton = document.getElementById('menubar-languages-toggle'); + var menubarLanguagePopup = document.getElementById('menubar-languages-popup'); + var languageButtons = menubarLanguagePopup.querySelectorAll('.menu-bar-link'); + + function showLanguage() { + menubarLanguagePopup.style.display = 'flex'; + menubarLanguageToggleButton.setAttribute('aria-expanded', true); + } + + function hideLanguage() { + menubarLanguagePopup.style.display = 'none'; + menubarLanguageToggleButton.setAttribute('aria-expanded', false); + menubarLanguageToggleButton.focus(); + } + + menubarLanguageToggleButton.addEventListener('click', function () { + if (menubarLanguagePopup.style.display === 'flex') { + hideLanguage(); + } else { + showLanguage(); + } + }); + + menubarLanguagePopup.addEventListener('focusout', function(e) { + // e.relatedTarget is null in Safari and Firefox on macOS (see workaround below) + if (!!e.relatedTarget && !menubarLanguageToggleButton.contains(e.relatedTarget) && !menubarLanguagePopup.contains(e.relatedTarget)) { + hideLanguage(); + } + }); + + // Should not be needed, but it works around an issue on macOS & iOS: https://github.com/rust-lang/mdBook/issues/628 + document.addEventListener('click', function(e) { + if (menubarLanguagePopup.style.display === 'block' && !menubarLanguageToggleButton.contains(e.target) && !menubarLanguagePopup.contains(e.target)) { + hideLanguage(); + } + }); + + languageButtons.forEach((btn) => { + btn.addEventListener('click', function(e) { + const regex = /(?:(?:\/)+(?[a-z]{2}(?=\/|$)))?(?(?:\/)*.*)?/g + var match = regex.exec(window.location.pathname) + + var path = match.groups.path + console.log(`Path: ${path} ${typeof path}`) + + const lang = match.groups.lang + console.log(`Lang: ${lang}`) + + window.location = `/${e.target.id}${path}${window.location.hash}` + }); + }) +})(); + (function chapterNavigation() { document.addEventListener('keydown', function (e) { if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; } diff --git a/theme/css/chrome.css b/theme/css/chrome.css index 8cbda7c69..17e541163 100644 --- a/theme/css/chrome.css +++ b/theme/css/chrome.css @@ -83,6 +83,13 @@ body.sidebar-visible #menu-bar { } } +.right-buttons .icons { + display: flex; + flex-direction: row; + flex-wrap: wrap; + column-gap: 0.5rem; +} + .icon-button { border: none; background: var(--bg); @@ -138,11 +145,13 @@ body.sidebar-visible #menu-bar { } /* Collapse Menu Popup */ - +#menubar-collapse-toggle { + position: relative; +} #menubar-collapse-popup { position: absolute; - right: 30px; - top: var(--menu-bar-height); + right: 0px; + top: 35px; z-index: 105; border-radius: 5px; font-size: 14px; @@ -172,6 +181,44 @@ body.sidebar-visible #menu-bar { background-color: var(--theme-hover); } +/* Languages Menu Popup */ +#menubar-languages-toggle { + position: relative; +} + +#menubar-languages-popup { + position: absolute; + right: 0px; + top: 35px; + z-index: 105; + border-radius: 5px; + font-size: 14px; + color: var(--fg); + background: var(--bg); + border: 1px solid var(--table-border-color); + margin: 0; + padding: 0px; + display: none; + flex-direction: column; + max-height: 300px; + width: 150px; + overflow: scroll; +} +#menubar-languages-popup .menu-bar-link { + border: 0; + margin: 0; + padding: 8px 20px; + line-height: 25px; + white-space: nowrap; + text-align: start; + cursor: pointer; + color: inherit; + background: inherit; + font-size: inherit; +} +#menubar-languages-popup .menu-bar-link:hover { + background-color: var(--theme-hover); +} .left-buttons { display: flex; diff --git a/theme/index.hbs b/theme/index.hbs index 049bc3ea7..419bb6e7a 100644 --- a/theme/index.hbs +++ b/theme/index.hbs @@ -144,34 +144,60 @@