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 b23c229c7..066fa960a 100644 --- a/src/pentesting-cloud/kubernetes-security/kubernetes-pivoting-to-clouds.md +++ b/src/pentesting-cloud/kubernetes-security/kubernetes-pivoting-to-clouds.md @@ -48,7 +48,7 @@ Workload Identity를 사용하면 [Kubernetes 서비스 계정](https://kubernet 이 동작을 활성화하기 위한 **첫 번째 일련의 단계**는 **GCP에서 Workload Identity를 활성화**하는 것 ([**단계**](https://medium.com/zeotap-customer-intelligence-unleashed/gke-workload-identity-a-secure-way-for-gke-applications-to-access-gcp-services-f880f4e74e8c))과 k8s가 가장하고자 하는 GCP SA를 생성하는 것입니다. -- 새 클러스터에서 **Workload Identity 활성화** +- **새 클러스터에서 Workload Identity 활성화** ```bash gcloud container clusters update \ --region=us-central1 \ @@ -80,7 +80,7 @@ kubectl create namespace testing # Create the KSA kubectl create serviceaccount ksa2gcp -n testing ``` -- **GSA를 KSA에 바인딩하기** +- **GSA를 KSA와 연결하기** ```bash # Allow the KSA to access the GSA in GCP IAM gcloud iam service-accounts add-iam-policy-binding gsa2ksa@ +### Kiam & Kube2IAM (Pods를 위한 IAM 역할) -Pods에 IAM 역할을 부여하는 (구식) 방법은 [**Kiam**](https://github.com/uswitch/kiam) 또는 [**Kube2IAM**](https://github.com/jtblin/kube2iam) **서버**를 사용하는 것입니다. 기본적으로 클러스터에서 **특권 IAM 역할**의 **데몬셋**을 실행해야 합니다. 이 데몬셋이 필요한 Pods에 IAM 역할에 대한 액세스를 제공합니다. +Pods에 IAM 역할을 부여하는 (구식) 방법은 [**Kiam**](https://github.com/uswitch/kiam) 또는 [**Kube2IAM**](https://github.com/jtblin/kube2iam) **서버**를 사용하는 것입니다. 기본적으로 클러스터에서 **특권 IAM 역할**의 **데몬셋**을 실행해야 합니다. 이 데몬셋이 필요한 Pods에 IAM 역할에 대한 접근을 제공합니다. 우선 **네임스페이스 내에서 어떤 역할에 접근할 수 있는지** 구성해야 하며, 이는 네임스페이스 객체 내의 주석을 통해 수행합니다: ```yaml:Kiam @@ -171,7 +171,7 @@ annotations: iam.amazonaws.com/role: reportingdb-reader ``` > [!WARNING] -> 공격자로서, 만약 당신이 **이 주석들**을 pods나 namespaces에서 발견하거나 실행 중인 kiam/kube2iam 서버(아마 kube-system에서)에서 발견한다면, 당신은 **pods**에 의해 이미 **사용되고 있는 모든 r**ole을 **가장할 수** 있으며, 더 많은 것들(만약 AWS 계정에 접근할 수 있다면 역할을 나열할 수 있습니다). +> 공격자로서, 만약 당신이 **이 주석들**을 pods나 namespaces에서 발견하거나 실행 중인 kiam/kube2iam 서버(아마 kube-system에서)를 발견한다면, 당신은 **pods**에 의해 이미 **사용되는 모든 r**ole을 **가장할 수** 있으며, 더 많은 것들(만약 AWS 계정에 접근할 수 있다면 역할을 나열할 수 있습니다). #### IAM 역할로 Pod 생성 @@ -198,7 +198,7 @@ args: ["-c", "sleep 100000"]' | kubectl apply -f - 1. 먼저 [클러스터에 대한 OIDC 공급자를 생성해야 합니다](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html). 2. 그런 다음 SA가 필요로 하는 권한으로 IAM 역할을 생성합니다. -3. IAM 역할과 SA 간에 [신뢰 관계를 생성합니다](https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html) (또는 역할에 대한 모든 SA에 접근을 허용하는 네임스페이스). _신뢰 관계는 주로 OIDC 공급자 이름, 네임스페이스 이름 및 SA 이름을 확인합니다_. +3. [IAM 역할과 SA 간의 신뢰 관계를 생성합니다](https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html) (또는 역할에 대한 모든 SA에 접근을 허용하는 네임스페이스). _신뢰 관계는 주로 OIDC 공급자 이름, 네임스페이스 이름 및 SA 이름을 확인합니다_. 4. 마지막으로, **역할의 ARN을 나타내는 주석이 있는 SA를 생성하고**, 해당 SA로 실행되는 파드는 **역할의 토큰에 접근할 수 있습니다**. **토큰**은 **파일에 기록되며** 경로는 **`AWS_WEB_IDENTITY_TOKEN_FILE`**에 지정됩니다 (기본값: `/var/run/secrets/eks.amazonaws.com/serviceaccount/token`) ```bash # Create a service account with a role @@ -221,7 +221,7 @@ kubectl annotate serviceaccount -n $namespace $service_account eks.amazonaws.com aws sts assume-role-with-web-identity --role-arn arn:aws:iam::123456789098:role/EKSOIDCTesting --role-session-name something --web-identity-token file:///var/run/secrets/eks.amazonaws.com/serviceaccount/token ``` > [!WARNING] -> 공격자로서 K8s 클러스터를 열거할 수 있다면, **AWS로 상승하기 위해** **해당 주석이 있는 서비스 계정**을 확인하십시오. 그렇게 하려면, IAM **특권 서비스 계정** 중 하나를 사용하여 **pod**를 **exec/create**하고 토큰을 훔치십시오. +> 공격자로서 K8s 클러스터를 열거할 수 있다면, **AWS로 상승하기 위해 해당 주석이 있는 서비스 계정**을 확인하십시오. 그렇게 하려면, IAM **특권 서비스 계정** 중 하나를 사용하여 **pod**를 **exec/create**하고 토큰을 훔치면 됩니다. > > 또한, pod 내부에 있는 경우 **AWS_ROLE_ARN** 및 **AWS_WEB_IDENTITY_TOKEN**과 같은 환경 변수를 확인하십시오. @@ -236,7 +236,7 @@ aws sts assume-role-with-web-identity --role-arn arn:aws:iam::123456789098:role/ ### 클러스터에서 IAM 역할이 있는 Pods 및 SAs 찾기 -이 스크립트는 **모든 pod와 sas** 정의를 쉽게 **반복**하여 **해당 주석**을 찾기 위한 것입니다: +이 스크립트는 **모든 pod 및 sa** 정의를 쉽게 **반복**하여 해당 **주석**을 찾습니다: ```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 @@ -255,7 +255,7 @@ done | grep -B 1 "amazonaws.com" ``` ### Node IAM Role -이전 섹션은 pods로 IAM Roles를 훔치는 방법에 대한 것이었지만, **K8s 클러스터의 Node는 클라우드 내의 인스턴스가 될 것**이라는 점에 유의해야 합니다. 이는 Node가 **훔칠 수 있는 새로운 IAM 역할을 가질 가능성이 높다는** 것을 의미합니다 (_일반적으로 K8s 클러스터의 모든 노드는 동일한 IAM 역할을 가지므로 각 노드를 확인하려고 시도하는 것이 그리 가치가 없을 수 있습니다_). +이전 섹션은 pods로 IAM Roles를 훔치는 방법에 대한 것이었지만, **K8s 클러스터의 Node는 클라우드 내의 인스턴스가 될 것**이라는 점에 유의해야 합니다. 이는 Node가 **훔칠 수 있는 새로운 IAM 역할을 가질 가능성이 높다는 것을 의미합니다** (_일반적으로 K8s 클러스터의 모든 노드는 동일한 IAM 역할을 가지므로 각 노드를 확인하려고 시도하는 것이 그다지 가치가 없을 수 있습니다_). 그러나 노드의 메타데이터 엔드포인트에 접근하기 위한 중요한 요구 사항이 있습니다. 노드에 있어야 하거나 (ssh 세션?) 최소한 동일한 네트워크에 있어야 합니다: ```bash @@ -276,7 +276,7 @@ curl "http://169.254.169.254/latest/meta-data/iam/security-credentials/$IAM_ROLE fi fi ``` -## 참고 문헌 +## 참고문헌 - [https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity](https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity) - [https://medium.com/zeotap-customer-intelligence-unleashed/gke-workload-identity-a-secure-way-for-gke-applications-to-access-gcp-services-f880f4e74e8c](https://medium.com/zeotap-customer-intelligence-unleashed/gke-workload-identity-a-secure-way-for-gke-applications-to-access-gcp-services-f880f4e74e8c) 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 @@