mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-04 11:07:37 -08:00
Translated ['src/pentesting-cloud/kubernetes-security/kubernetes-pivotin
This commit is contained in:
@@ -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"]
|
||||
|
||||
@@ -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('<title>(.*?)</title>', 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('<title>(.*?)</title>', 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("/"):
|
||||
|
||||
@@ -46,7 +46,7 @@ iam.gke.io/gcp-service-account=<gcp-service-account-email>
|
||||
|
||||
Dzięki Workload Identity możemy skonfigurować [konto usługi Kubernetes](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/), aby działało jako [konto usługi Google](https://cloud.google.com/iam/docs/understanding-service-accounts). Podsy działające z kontem usługi Kubernetes będą automatycznie uwierzytelniane jako konto usługi Google podczas uzyskiwania dostępu do interfejsów API Google Cloud.
|
||||
|
||||
**Pierwsza seria kroków** w celu włączenia tego zachowania to **włączenie Workload Identity w GCP** ([**kroki**](https://medium.com/zeotap-customer-intelligence-unleashed/gke-workload-identity-a-secure-way-for-gke-applications-to-access-gcp-services-f880f4e74e8c)) i utworzenie SA GCP, które chcesz, aby k8s naśladowało.
|
||||
**Pierwsza seria kroków** w celu włączenia tego zachowania to **włączenie Workload Identity w GCP** ([**kroki**](https://medium.com/zeotap-customer-intelligence-unleashed/gke-workload-identity-a-secure-way-for-gke-applications-to-access-gcp-services-f880f4e74e8c)) i utworzenie GCP SA, które chcesz, aby k8s udawało.
|
||||
|
||||
- **Włącz Workload Identity** na nowym klastrze
|
||||
```bash
|
||||
@@ -124,9 +124,9 @@ gcloud auth activate-service-account --key-file=/var/run/secrets/google/service-
|
||||
```
|
||||
> [!WARNING]
|
||||
> Jako atakujący wewnątrz K8s powinieneś **szukać SAs** z **adnotacją `iam.gke.io/gcp-service-account`**, ponieważ wskazuje to, że SA może uzyskać dostęp do czegoś w GCP. Inną opcją byłoby spróbować wykorzystać każdy KSA w klastrze i sprawdzić, czy ma dostęp.\
|
||||
> Z GCP zawsze warto enumerować powiązania i wiedzieć **jakie uprawnienia przyznajesz SA wewnątrz Kubernetes**.
|
||||
> Z GCP zawsze warto enumerować powiązania i wiedzieć **jakie uprawnienia przyznajesz SAs wewnątrz Kubernetes**.
|
||||
|
||||
To jest skrypt do łatwego **iterowania po wszystkich definicjach podów** **w poszukiwaniu** tej **adnotacji**:
|
||||
To jest skrypt do łatwego **iterowania po wszystkich definicjach podów** **szukając** tej **adnotacji**:
|
||||
```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
|
||||
@@ -143,7 +143,7 @@ done | grep -B 1 "gcp-service-account"
|
||||
|
||||
Jednym (przestarzałym) sposobem na przyznanie ról IAM Podom jest użycie [**Kiam**](https://github.com/uswitch/kiam) lub [**Kube2IAM**](https://github.com/jtblin/kube2iam) **serwera.** W zasadzie musisz uruchomić **daemonset** w swoim klastrze z **rodzajem uprzywilejowanej roli IAM**. Ten daemonset będzie tym, który przyzna dostęp do ról IAM podom, które tego potrzebują.
|
||||
|
||||
Przede wszystkim musisz skonfigurować **które role mogą być dostępne w obrębie przestrzeni nazw**, a robisz to za pomocą adnotacji wewnątrz obiektu przestrzeni nazw:
|
||||
Przede wszystkim musisz skonfigurować **które role mogą być dostępne wewnątrz przestrzeni nazw**, a robisz to za pomocą adnotacji wewnątrz obiektu przestrzeni nazw:
|
||||
```yaml:Kiam
|
||||
kind: Namespace
|
||||
metadata:
|
||||
@@ -199,7 +199,7 @@ To jest **zalecany sposób przez AWS**.
|
||||
1. Przede wszystkim musisz [utworzyć dostawcę OIDC dla klastra](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html).
|
||||
2. Następnie tworzysz rolę IAM z uprawnieniami, które będą wymagane przez SA.
|
||||
3. Utwórz [relację zaufania między rolą IAM a SA](https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html) (lub przestrzeniami nazw, które dają dostęp do roli wszystkim SA w przestrzeni nazw). _Relacja zaufania będzie głównie sprawdzać nazwę dostawcy OIDC, nazwę przestrzeni nazw i nazwę SA_.
|
||||
4. Na koniec **utwórz SA z adnotacją wskazującą ARN roli**, a podsy działające z tą SA będą miały **dostęp do tokena roli**. **Token** jest **zapisywany** w pliku, a ścieżka jest określona w **`AWS_WEB_IDENTITY_TOKEN_FILE`** (domyślnie: `/var/run/secrets/eks.amazonaws.com/serviceaccount/token`)
|
||||
4. Na koniec **utwórz SA z adnotacją wskazującą ARN roli**, a podsy działające z tą SA będą miały **dostęp do tokena roli**. **Token** jest **zapisany** w pliku, a ścieżka jest określona w **`AWS_WEB_IDENTITY_TOKEN_FILE`** (domyślnie: `/var/run/secrets/eks.amazonaws.com/serviceaccount/token`)
|
||||
```bash
|
||||
# Create a service account with a role
|
||||
cat >my-service-account.yaml <<EOF
|
||||
@@ -221,12 +221,12 @@ Aby **uzyskać aws za pomocą tokena** z `/var/run/secrets/eks.amazonaws.com/ser
|
||||
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]
|
||||
> Jako atakujący, jeśli możesz enumerować klaster K8s, sprawdź **kontrola serwisowe z tym adnotacją**, aby **eskalować do AWS**. Aby to zrobić, po prostu **exec/create** **pod** używając jednego z **uprzywilejowanych kont serwisowych IAM** i ukradnij token.
|
||||
> Jako atakujący, jeśli możesz enumerować klaster K8s, sprawdź **konta serwisowe z tym adnotacją**, aby **eskalować do AWS**. Aby to zrobić, po prostu **exec/create** **pod** używając jednego z **uprzywilejowanych kont serwisowych IAM** i ukradnij token.
|
||||
>
|
||||
> Ponadto, jeśli jesteś wewnątrz pod, sprawdź zmienne środowiskowe takie jak **AWS_ROLE_ARN** i **AWS_WEB_IDENTITY_TOKEN.**
|
||||
> Ponadto, jeśli jesteś wewnątrz poda, sprawdź zmienne środowiskowe takie jak **AWS_ROLE_ARN** i **AWS_WEB_IDENTITY_TOKEN.**
|
||||
|
||||
> [!CAUTION]
|
||||
> Czasami **Polityka Zaufania roli** może być **źle skonfigurowana** i zamiast dawać dostęp AssumeRole do oczekiwanego konta serwisowego, daje go do **wszystkich kont serwisowych**. Dlatego, jeśli możesz napisać adnotację na kontrolowanym koncie serwisowym, możesz uzyskać dostęp do roli.
|
||||
> Czasami **Polityka Zaufania roli** może być **źle skonfigurowana** i zamiast dawać dostęp AssumeRole do oczekiwanego konta serwisowego, daje go do **wszystkich kont serwisowych**. Dlatego, jeśli masz możliwość zapisania adnotacji na kontrolowanym koncie serwisowym, możesz uzyskać dostęp do roli.
|
||||
>
|
||||
> Sprawdź **następującą stronę po więcej informacji**:
|
||||
|
||||
@@ -234,9 +234,9 @@ aws sts assume-role-with-web-identity --role-arn arn:aws:iam::123456789098:role/
|
||||
../aws-security/aws-basic-information/aws-federation-abuse.md
|
||||
{{#endref}}
|
||||
|
||||
### Znajdź Podsy i SAs z rolami IAM w klastrze
|
||||
### Znajdź Pody i Konta Serwisowe z Rolami IAM w Klastrze
|
||||
|
||||
To jest skrypt do łatwego **iterowania po wszystkich podach i definicjach sas** **szukając** tej **adnotacji**:
|
||||
To jest skrypt do łatwego **iterowania po wszystkich podach i definicjach sas**, **szukając** tej **adnotacji**:
|
||||
```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
|
||||
|
||||
@@ -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 = /(?:(?:\/)+(?<lang>[a-z]{2}(?=\/|$)))?(?<path>(?:\/)*.*)?/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; }
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -144,34 +144,60 @@
|
||||
|
||||
<div class="right-buttons">
|
||||
<div id="menubar-collapse">
|
||||
<a class="menu-bar-link" href="https://training.hacktricks.xyz" target="_blank">
|
||||
Hacktricks Training
|
||||
</a>
|
||||
<a class="menu-bar-link" href="https://twitter.com/hacktricks_live" target="_blank">
|
||||
Twitter
|
||||
</a>
|
||||
<a class="menu-bar-link" href="https://www.linkedin.com/company/hacktricks" target="_blank">
|
||||
Linkedin
|
||||
</a>
|
||||
<a class="menu-bar-link" href="https://github.com/sponsors/carlospolop" target="_blank">
|
||||
Sponsor
|
||||
</a>
|
||||
</div>
|
||||
<button id="menubar-collapse-toggle" class="icon-button" type="button" title="Toggle menu bar" aria-label="Toggle Menu bar" aria-expanded="false" aria-controls="collapse">
|
||||
<i class="fa fa-ellipsis-h"></i>
|
||||
</button>
|
||||
<div id="menubar-collapse-popup" class="menubar-collapse-popup" aria-label="Menu" role="menu">
|
||||
<a href="https://training.hacktricks.xyz" target="_blank" role="menuitem" class="menu-bar-link">Hacktricks Training</a>
|
||||
<a href="https://twitter.com/hacktricks_live" target="_blank" role="menuitem" class="menu-bar-link">Twitter</a>
|
||||
<a href="https://www.linkedin.com/company/hacktricks" target="_blank" role="menuitem" class="menu-bar-link">Linkedin</a>
|
||||
<a href="https://github.com/sponsors/carlospolop" target="_blank" role="menuitem" class="menu-bar-link">Sponsor</a>
|
||||
<a class="menu-bar-link" href="https://training.hacktricks.xyz" target="_blank">
|
||||
Hacktricks Training
|
||||
</a>
|
||||
<a class="menu-bar-link" href="https://twitter.com/hacktricks_live" target="_blank">
|
||||
Twitter
|
||||
</a>
|
||||
<a class="menu-bar-link" href="https://www.linkedin.com/company/hacktricks" target="_blank">
|
||||
Linkedin
|
||||
</a>
|
||||
<a class="menu-bar-link" href="https://github.com/sponsors/carlospolop" target="_blank">
|
||||
Sponsor
|
||||
</a>
|
||||
</div>
|
||||
<div class="icons">
|
||||
<div id="menubar-collapse-toggle" class="icon-button" type="button" title="Toggle menu bar" aria-label="Toggle Menu bar" aria-expanded="false" aria-controls="collapse">
|
||||
<i class="fa fa-ellipsis-h"></i>
|
||||
<div id="menubar-collapse-popup" class="menubar-collapse-popup" aria-label="Menu" role="menu">
|
||||
<a href="https://training.hacktricks.xyz" target="_blank" role="menuitem" class="menu-bar-link">Hacktricks Training</a>
|
||||
<a href="https://twitter.com/hacktricks_live" target="_blank" role="menuitem" class="menu-bar-link">Twitter</a>
|
||||
<a href="https://www.linkedin.com/company/hacktricks" target="_blank" role="menuitem" class="menu-bar-link">Linkedin</a>
|
||||
<a href="https://github.com/sponsors/carlospolop" target="_blank" role="menuitem" class="menu-bar-link">Sponsor</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#if search_enabled}}
|
||||
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
|
||||
<i class="fa fa-search"></i>
|
||||
</button>
|
||||
{{/if}}
|
||||
{{#if search_enabled}}
|
||||
<button id="search-toggle" class="icon-button" type="button" title="Search. (Shortkey: s)" aria-label="Toggle Searchbar" aria-expanded="false" aria-keyshortcuts="S" aria-controls="searchbar">
|
||||
<i class="fa fa-search"></i>
|
||||
</button>
|
||||
{{/if}}
|
||||
|
||||
<div id="menubar-languages-toggle" class="icon-button" type="button" title="Translations" aria-label="Toggle Tanslations" aria-expanded="false" aria-controls="translations">
|
||||
<i class="fa fa-globe"></i>
|
||||
|
||||
<div id="menubar-languages-popup" class="menubar-languages-popup" aria-label="Language menu" role="language menu">
|
||||
<button id="en" role="menuitem" class="menu-bar-link">English</button>
|
||||
<button id="es" role="menuitem" class="menu-bar-link">Spanish</button>
|
||||
<button id="fr" role="menuitem" class="menu-bar-link">French</button>
|
||||
<button id="de" role="menuitem" class="menu-bar-link">German</button>
|
||||
<button id="el" role="menuitem" class="menu-bar-link">Greek</button>
|
||||
<button id="hi" role="menuitem" class="menu-bar-link">Hindi</button>
|
||||
<button id="it" role="menuitem" class="menu-bar-link">Italian</button>
|
||||
<button id="ja" role="menuitem" class="menu-bar-link">Japanese</button>
|
||||
<button id="ko" role="menuitem" class="menu-bar-link">Korean</button>
|
||||
<button id="pl" role="menuitem" class="menu-bar-link">Polish</button>
|
||||
<button id="pt" role="menuitem" class="menu-bar-link">Portuguese</button>
|
||||
<button id="sr" role="menuitem" class="menu-bar-link">Serbian</button>
|
||||
<button id="sw" role="menuitem" class="menu-bar-link">Swahili</button>
|
||||
<button id="tr" role="menuitem" class="menu-bar-link">Turkish</button>
|
||||
<button id="uk" role="menuitem" class="menu-bar-link">Ukrainian</button>
|
||||
<button id="af" role="menuitem" class="menu-bar-link">Afrikaans</button>
|
||||
<button id="zh" role="menuitem" class="menu-bar-link">Chinese</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{{#if print_enable}}
|
||||
<a href="{{ path_to_root }}print.html" title="Print this book" aria-label="Print this book">
|
||||
|
||||
@@ -19,13 +19,11 @@
|
||||
try {
|
||||
const response = await fetch(url, { method: "GET" })
|
||||
if (!response.ok) {
|
||||
console.log(response)
|
||||
throw new Error(`Response status: ${response.status}`)
|
||||
}
|
||||
|
||||
const json = await response.json()
|
||||
var sponsor = json.sponsor
|
||||
console.log("boop", sponsor)
|
||||
sponsorImg.src = sponsor.image_url
|
||||
sponsorTitle.textContent = sponsor.name
|
||||
sponsorDescription.innerHTML = sponsor.description
|
||||
|
||||
Reference in New Issue
Block a user