Az - Automatiseringsrekeninge

Tip

Leer & oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer & oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Leer & oefen Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Ondersteun HackTricks

Basiese Inligting

Azure Automatiseringsrekeninge is wolk-gebaseerde dienste in Microsoft Azure wat help om take te outomaties soos hulpbronbestuur, konfigurasie, en opdaterings oor Azure en plaaslike omgewings. Hulle bied Runbooks (skripte vir outomatisering wat uitgevoer word), skedules, en hibridewerkersgroepe om outomatiserings take te laat loop, wat infrastruktuur as kode (IaC) en prosesoutomatisering vir verbeterde doeltreffendheid en konsekwentheid in die bestuur van wolkbronne moontlik maak.

Instellings

  • Geloofsbriewe: Die wagwoord is slegs binne ’n runbook binne die automatiseringsrekening toeganklik, dit word gebruik om gebruikersname en wagwoorde veilig te stoor.
  • Veranderlikes: Gebruik om konfigurasiedata te stoor wat in runbooks gebruik kan word. Dit kan ook sensitiewe inligting soos API-sleutels wees. As die veranderlike versleuteld gestoor is, is dit slegs beskikbaar binne ’n runbook binne die automatiseringsrekening.
  • Sertifikate: Gebruik om sertifikate te stoor wat in runbooks gebruik kan word.
  • Verbindings: Gebruik om verbindinginligting na eksterne dienste te stoor. Dit kan sensitiewe inligting bevat.
  • Netwerktoegang: Dit kan op publiek of privaat gestel word.

Runbooks & Take

’n Runbook in Azure Automatisering is ’n skrip wat take outomaties uitvoer binne jou wolkomgewing. Runbooks kan in PowerShell, Python, of grafiese redigeerders geskryf word. Hulle help om administratiewe take soos VM-bestuur, patching, of nakomingstoetsing te outomatiseer.

In die kode wat binne Runbooks geleë is, kan sensitiewe inligting (soos geloofsbriewe) bevat.

’n Taak is ’n instansie van ’n Runbook-uitvoering. Wanneer jy ’n Runbook uitvoer, word ’n Taak geskep om daardie uitvoering te volg. Elke taak sluit in:

  • Status: In die ry, Besig, Voltooi, Misluk, Gestaak.
  • Uitset: Die resultaat van die Runbook-uitvoering.
  • Begin- en Eindtyd: Wanneer die taak begin en voltooi is.

’n Taak bevat die uitset van die Runbook-uitvoering. As jy die take kan lees, doen dit aangesien hulle die uitset van die uitvoering bevat (potensieel sensitiewe inligting).

Skedules & Webhooks

Daar is 3 hoofmaniere om ’n Runbook uit te voer:

  • Skedules: Hierdie word gebruik om Runbooks op ’n spesifieke tyd of interval te aktiveer.
  • Webhooks: Hierdie is HTTP-eindpunte wat gebruik kan word om Runbooks van eksterne dienste te aktiveer. Let daarop dat die webhook-URL nie sigbaar is na die skepping nie.
  • Handmatige Aktivering: Jy kan ’n Runbook handmatig aktiveer vanaf die Azure-portaal en vanaf die cli.

Bronbeheer

Dit maak dit moontlik om Runbooks van Github, Azure Devops (Git) en Azure Devops (TFVC) te importeer. Dit is moontlik om aan te dui om die Runbooks van die repo na die Azure Automatiseringsrekening te publiseer en dit is ook moontlik om aan te dui om die veranderings van die repo na die Azure Automatiseringsrekening te sinkroniseer.

Wanneer die sinkronisasie geaktiveer is, word daar in die Github-repo ’n webhook geskep om die sinkronisasie te aktiveer elke keer as ’n push-gebeurtenis plaasvind. Voorbeeld van ’n webhook-URL: https://f931b47b-18c8-45a2-9d6d-0211545d8c02.webhook.eus.azure-automation.net/webhooks?token=DRjQyFiOrUtz%2fw7o23XbDpOlTe1%2bUqPQm4pQH2WBfJg%3d

Let daarop dat hierdie webhooks nie sigbaar sal wees wanneer webhooks in die geassosieerde runbooks na die Github-repo gelys word nie. Let ook daarop dat dit nie moontlik is om die repo-URL van ’n bronbeheer te verander sodra dit geskep is nie.

Om te verseker dat die geconfigureerde bronbeheer werk, moet die Azure Automatiseringsrekening ’n bestuurde identiteit (stelsel of gebruiker) met die Contributor rol hê. Boonop, om ’n gebruikersbestuurde identiteit aan die Automatiseringsrekening toe te ken, is dit nodig om die kliënt-ID van die gebruikers MI in die veranderlike AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID aan te dui.

Tydslope

Wanneer ’n Runbook geskep word, is dit moontlik om die tydslope te kies. Standaard is die volgende tydslope beskikbaar:

  • Powershell 5.1
  • Powershell 7.1
  • PowerShell 7.2
  • Python 3.10
  • Python 3.8
  • Python 2.7

Dit is egter ook moontlik om jou eie omgewings te skep, met een van hierdie as ’n basis. In die geval van Python is dit moontlik om .whl pakkette na die omgewing op te laai wat gebruik sal word. In die geval van PowerShell is dit moontlik om .zip pakkette met die modules op te laai wat in die tydslope moet wees.

Hibridewerkersgroepe

In Azure Automatisering is die standaard uitvoeringsomgewing vir runbooks die Azure Sandbox, ’n wolk-gebaseerde platform wat deur Azure bestuur word, geskik vir take wat Azure-bronne betrek. Hierdie sandbox het egter beperkings, soos beperkte toegang tot plaaslike bronne en beperkings op uitvoerings tyd en hulpbronverbruik. Om hierdie beperkings te oorkom, word Hibridewerkersgroepe gebruik. ’n Hibridewerkersgroep bestaan uit een of meer Hibrid Runbook Workers wat op jou eie masjiene geïnstalleer is, of dit nou plaaslik, in ander wolkomgewings of Azure VM’s is. Hierdie opstelling laat runbooks toe om direk op hierdie masjiene uit te voer, wat direkte toegang tot plaaslike bronne bied, die vermoë om langer en meer hulpbron-intensiewe take uit te voer, en die buigsaamheid om met omgewings buite Azure se onmiddellike bereik te kommunikeer.

Wanneer ’n hibridewerkersgroep geskep word, is dit nodig om die geloofsbriewe aan te dui wat gebruik moet word. Daar is 2 opsies:

  • Standaard geloofsbriewe: Jy hoef nie die geloofsbriewe te verskaf nie en die runbooks sal binne die VM’s as Stelsel uitgevoer word.
  • Spesifieke geloofsbriewe: Jy moet die naam van die geloofsbriewe objek binne die automatiseringsrekening verskaf, wat gebruik sal word om die runbooks binne die VM’s uit te voer. Daarom kan dit in hierdie geval moontlik wees om geldige geloofsbriewe vir die VM’s te steel.

As jy dus kan kies om ’n Runbook in ’n Hibridwerker uit te voer, sal jy arbitraire opdragte binne ’n eksterne masjien as Stelsel uitvoer (nuttige pivot tegniek).

Boonop, as die hibridwerker in Azure met ander Bestuurde Identiteite aangeheg is, sal die runbook toegang hê tot die bestuurde identiteit van die runbook en al die bestuurde identiteite van die VM vanaf die metadata-diens.

Tip

Onthou dat die metadata-diens ’n ander URL het (http://169.254.169.254) as die diens waarvandaan die bestuurde identiteite token van die automatiseringsrekening verkry word (IDENTITY_ENDPOINT).

Toestand Konfigurasie (SC)

Warning

Soos aangedui in die dokumentasie, sal Azure Automatisering Toestand Konfigurasie op 30 September 2027 afgeskaf word en vervang word deur Azure Masjien Konfigurasie.

Automatiseringsrekeninge ondersteun ook Toestand Konfigurasie (SC), wat ’n kenmerk is wat help om te konfigureer en die toestand van jou VM’s te onderhou. Dit is moontlik om te skep en DSC-konfigurasies toe te pas op Windows en Linux masjiene.

Vanuit ’n aanvallers perspektief was dit interessant omdat dit toegelaat het om arbitraire PS-kode in al die geconfigureerde VM’s uit te voer, wat dit moontlik maak om voorregte na die bestuurde identiteite van hierdie VM’s te eskaleer, wat potensieel na nuwe netwerke kan pivot… Ook, die konfigurasies kan sensitiewe inligting bevat.

Opname

# List Automation Accounts
az automation account list --output table

# Get Automation Account details
# Check the network access in `privateEndpointConnections` and `publicNetworkAccess`
# Check the managed identities in `identity`
az automation account show --name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>

# Get keys of automation account
## These are used for the DSC
az automation account list-keys --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>

# Get schedules of automation account
az automation schedule list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>

# Get connections of automation account
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/connections?api-version=2023-11-01"

# Get connection details
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/connections/<connection-name>?api-version=2023-11-01"

# Get credentials of automation account
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/credentials?api-version=2023-11-01"

# Get credential details
## Note that you will only be able to access the password from inside a Runbook
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/credentials/<credential-name>?api-version=2023-11-01"

# Get certificates of automation account
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/certificates?api-version=2023-11-01"

# Get certificate details
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/certificates/<certificate-name>?api-version=2023-11-01"

# Get variables of automation account
## It's possible to get the value of unencrypted variables but not the encrypted ones
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/variables?api-version=2023-11-01"

# Get variable details
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/variables/<variable-name>?api-version=2023-11-01"

# Get runbooks of an automation account
az automation runbook list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>

# Get runbook details
az automation runbook show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <RUNBOOK-NAME>

# Get runbook content
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/runbooks/<runbook-name>/content?api-version=2023-11-01"

# Get jobs of an automation account
az automation job list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>

# Get job details
az automation job show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <JOB-NAME>

# Get job output
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/jobs/<job-name>/output?api-version=2023-11-01"

# Get the Runbook content when the job was executed
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/jobs/<job-name>/runbookContent?api-version=2023-11-01"

# Get webhooks inside an automation account
## It's possible to see to which runbook it belongs in the given data
## For security reasons it's not possible to see the URL of the webhook after creating it, here is a URL example: https://f931b47b-18c8-45a2-9d6d-0211545d8c02.webhook.eus.azure-automation.net/webhooks?token=dOdnxk6z7ugAxiuyUMKgPuDMav2Jw5EJediMdiN4jLo%3d
## Generating a webhook can be useful from a persistence perspective
az rest --method GET \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/webhooks?api-version=2018-06-30"

# Get the source control setting of an automation account (if any)
## inside the output it's possible to see if the autoSync is enabled, if the publishRunbook is enabled and the repo URL
az automation source-control list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>

# Get custom runtime environments
## Check in defaultPackages for custom ones, by default Python envs won't have anything here and PS1 envs will have "az" and "azure cli"
az automation runtime-environment list \
--resource-group <res-group>> \
--automation-account-name <account-name> \
--query "[?!(starts_with(description, 'System-generated'))]"

# Get State Configurations (SC) of an automation account
az automation dsc configuration list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>

# Get State Configuration details
az automation dsc configuration show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <DSC-CONFIG-NAME>

# Get State Configuration content
az automation dsc configuration show-content --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <DSC-CONFIG-NAME>

# Get hybrid worker groups for an automation account
az automation hrwg list --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME>

# Get hybrid worker group details
az automation hrwg show --automation-account-name <AUTOMATION-ACCOUNT> --resource-group <RG-NAME> --name <HYBRID-WORKER-GROUP>

# Get more details about a hybrid worker group (like VMs inside it)
az rest --method GET --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>>/providers/Microsoft.Automation/automationAccounts/<automation-account-name>/hybridRunbookWorkerGroups/<hybrid-worker-group-name>/hybridRunbookWorkers?&api-version=2021-06-22"
# 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>

Privilege Escalation & Post Exploitation

Az - Automation Accounts Privesc

Persistence

Az - Automation Accounts Persistence

References

Tip

Leer & oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer & oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
Leer & oefen Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Ondersteun HackTricks