Az - Automation Accounts
Reading time: 13 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
Basic Information
Azure Automation Accounts Microsoft Azure में क्लाउड-आधारित सेवाएँ हैं जो कार्य स्वचालित करने में मदद करती हैं जैसे संसाधन प्रबंधन, कॉन्फ़िगरेशन, और Azure और ऑन-प्रिमाइसेस वातावरण में अपडेट। ये Runbooks (स्वचालन के लिए स्क्रिप्ट जो निष्पादित होती हैं), अनुसूचियाँ, और हाइब्रिड कार्यकर्ता समूह प्रदान करती हैं ताकि स्वचालन नौकरियों को चलाया जा सके, जो कोड के रूप में बुनियादी ढाँचा (IaC) और प्रक्रिया स्वचालन को सक्षम बनाता है जिससे क्लाउड संसाधनों के प्रबंधन में दक्षता और स्थिरता में सुधार होता है।
Settings
- Credentials: पासवर्ड केवल स्वचालन खाते के भीतर एक रनबुक के भीतर सुलभ है, इन्हें उपयोगकर्ता नाम और पासवर्ड को सुरक्षित रूप से स्टोर करने के लिए उपयोग किया जाता है।
- Variables: कॉन्फ़िगरेशन डेटा को स्टोर करने के लिए उपयोग किया जाता है जिसे रनबुक में उपयोग किया जा सकता है। इसमें संवेदनशील जानकारी जैसे API कुंजी भी हो सकती है। यदि वेरिएबल एन्क्रिप्टेड है, तो यह केवल स्वचालन खाते के भीतर एक रनबुक के भीतर उपलब्ध है।
- Certificates: सर्टिफिकेट को स्टोर करने के लिए उपयोग किया जाता है जिसे रनबुक में उपयोग किया जा सकता है।
- Connections: बाहरी सेवाओं के लिए कनेक्शन जानकारी को स्टोर करने के लिए उपयोग किया जाता है। इसमें संवेदनशील जानकारी हो सकती है।
- Network Access: इसे सार्वजनिक या निजी पर सेट किया जा सकता है।
Runbooks & Jobs
Azure Automation में एक Runbook एक स्क्रिप्ट है जो स्वचालित रूप से कार्य करती है आपके क्लाउड वातावरण के भीतर। Runbooks को PowerShell, Python, या ग्राफिकल संपादकों में लिखा जा सकता है। ये प्रशासनिक कार्यों जैसे VM प्रबंधन, पैचिंग, या अनुपालन जांच को स्वचालित करने में मदद करते हैं।
Runbooks के भीतर स्थित कोड में संवेदनशील जानकारी (जैसे क्रेड्स) हो सकती है।
एक Job एक Runbook निष्पादन का उदाहरण है। जब आप एक Runbook चलाते हैं, तो उस निष्पादन को ट्रैक करने के लिए एक Job बनाया जाता है। प्रत्येक नौकरी में शामिल हैं:
- Status: Queued, Running, Completed, Failed, Suspended.
- Output: Runbook निष्पादन का परिणाम।
- Start and End Time: जब नौकरी शुरू हुई और पूरी हुई।
एक नौकरी में Runbook निष्पादन का output होता है। यदि आप jobs को पढ़ सकते हैं, तो ऐसा करें क्योंकि वे run का output रखते हैं (संभावित संवेदनशील जानकारी)।
Schedules & Webhooks
Runbook निष्पादित करने के 3 मुख्य तरीके हैं:
- Schedules: इन्हें विशिष्ट समय या अवधि पर Runbooks को trigger करने के लिए उपयोग किया जाता है।
- Webhooks: ये HTTP endpoints हैं जिन्हें बाहरी सेवाओं से Runbooks को trigger करने के लिए उपयोग किया जा सकता है। ध्यान दें कि webhook URL निर्माण के बाद दिखाई नहीं देता।
- Manual Trigger: आप Azure Portal और CLI से एक Runbook को हाथ से ट्रिगर कर सकते हैं।
Source Control
यह Github, Azure Devops (Git) और Azure Devops (TFVC) से Runbooks को आयात करने की अनुमति देता है। यह संभव है कि यह स्वचालन खाते में repo के Runbooks को प्रकाशित करने के लिए इंगित किया जाए और यह भी संभव है कि repo से परिवर्तनों को Azure Automation खाते में समन्वयित करने के लिए इंगित किया जाए।
जब समन्वय सक्षम होता है, तो Github रिपॉजिटरी में एक webhook बनाया जाता है ताकि हर बार एक पुश इवेंट होने पर समन्वय को ट्रिगर किया जा सके। एक webhook URL का उदाहरण: https://f931b47b-18c8-45a2-9d6d-0211545d8c02.webhook.eus.azure-automation.net/webhooks?token=DRjQyFiOrUtz%2fw7o23XbDpOlTe1%2bUqPQm4pQH2WBfJg%3d
ध्यान दें कि ये webhooks Github repo से संबंधित runbooks में सूचीबद्ध करते समय दिखाई नहीं देंगे। यह भी ध्यान दें कि एक बार बनाए जाने के बाद source control का repo URL बदलना संभव नहीं है।
कॉन्फ़िगर किए गए स्रोत नियंत्रण के काम करने के लिए, Azure Automation Account को एक प्रबंधित पहचान (सिस्टम या उपयोगकर्ता) के साथ Contributor
भूमिका होनी चाहिए। इसके अलावा, Automation Account को उपयोगकर्ता प्रबंधित पहचान सौंपने के लिए, यह आवश्यक है कि उपयोगकर्ता MI के क्लाइंट ID को वेरिएबल AUTOMATION_SC_USER_ASSIGNED_IDENTITY_ID
में इंगित किया जाए।
Runtime Environments
जब एक Runbook बनाया जाता है तो रनटाइम वातावरण का चयन करना संभव है। डिफ़ॉल्ट रूप से, निम्नलिखित रनटाइम वातावरण उपलब्ध हैं:
- Powershell 5.1
- Powershell 7.1
- PowerShell 7.2
- Python 3.10
- Python 3.8
- Python 2.7
हालांकि, यह भी संभव है कि आप इनमें से किसी एक का उपयोग करके अपने स्वयं के वातावरण बनाएँ। Python के मामले में, यह संभव है कि आप उस वातावरण में उपयोग किए जाने वाले .whl
पैकेज अपलोड करें। PowerShell के मामले में, यह संभव है कि आप रनटाइम में रखने के लिए मॉड्यूल के साथ .zip
पैकेज अपलोड करें।
Hybrid Worker Groups
Azure Automation में, Runbooks के लिए डिफ़ॉल्ट निष्पादन वातावरण Azure Sandbox है, जो Azure द्वारा प्रबंधित एक क्लाउड-आधारित प्लेटफ़ॉर्म है, जो Azure संसाधनों से संबंधित कार्यों के लिए उपयुक्त है। हालाँकि, इस सैंडबॉक्स में सीमाएँ हैं, जैसे ऑन-प्रिमाइसेस संसाधनों तक सीमित पहुँच और निष्पादन समय और संसाधन उपयोग पर प्रतिबंध। इन सीमाओं को पार करने के लिए, हाइब्रिड कार्यकर्ता समूहों का उपयोग किया जाता है। एक हाइब्रिड कार्यकर्ता समूह में एक या एक से अधिक हाइब्रिड रनबुक कार्यकर्ता शामिल होते हैं जो आपकी मशीनों पर स्थापित होते हैं, चाहे वे ऑन-प्रिमाइसेस हों, अन्य क्लाउड वातावरण में हों या Azure VMs में। यह सेटअप Runbooks को इन मशीनों पर सीधे निष्पादित करने की अनुमति देता है, स्थानीय संसाधनों तक सीधी पहुँच प्रदान करता है, लंबे और अधिक संसाधन-गहन कार्यों को चलाने की क्षमता और Azure की तात्कालिक पहुँच से परे वातावरण के साथ बातचीत करने की लचीलापन प्रदान करता है।
जब एक हाइब्रिड कार्यकर्ता समूह बनाया जाता है, तो उपयोग करने के लिए credentials इंगित करना आवश्यक होता है। 2 विकल्प हैं:
- Default credentials: आपको क्रेडेंशियल प्रदान करने की आवश्यकता नहीं है और रनबुक VMs के भीतर System के रूप में निष्पादित की जाएगी।
- Specific credentials: आपको स्वचालन खाते के भीतर क्रेडेंशियल ऑब्जेक्ट का नाम प्रदान करने की आवश्यकता है, जिसका उपयोग VMs के भीतर रनबुक्स को निष्पादित करने के लिए किया जाएगा। इसलिए, इस मामले में, यह संभव हो सकता है कि VMs के लिए मान्य क्रेडेंशियल चुराए जाएँ।
इसलिए, यदि आप Hybrid Worker में एक Runbook चलाने का विकल्प चुनते हैं, तो आप System के रूप में एक बाहरी मशीन के भीतर मनमाने आदेश निष्पादित करेंगे (अच्छी पिवट तकनीक)।
इसके अलावा, यदि हाइब्रिड कार्यकर्ता Azure में अन्य प्रबंधित पहचानों के साथ चल रहा है, तो रनबुक रनबुक की प्रबंधित पहचान और VM की सभी प्रबंधित पहचानों तक पहुँच प्राप्त कर सकेगी जो मेटाडेटा सेवा से हैं।
tip
याद रखें कि मेटाडेटा सेवा का एक अलग URL है (http://169.254.169.254
) उस सेवा से जहाँ स्वचालन खाते की प्रबंधित पहचान टोकन प्राप्त किया जाता है (IDENTITY_ENDPOINT
)।
State Configuration (SC)
warning
जैसा कि the docs में संकेत दिया गया है, Azure Automation State Configuration 30 सितंबर, 2027 को समाप्त हो जाएगा और Azure Machine Configuration द्वारा प्रतिस्थापित किया जाएगा।
Automation Accounts भी State Configuration (SC) का समर्थन करते हैं, जो एक विशेषता है जो आपकी VMs की स्थिति को कॉन्फ़िगर और रखरखाव करने में मदद करती है। यह Windows और Linux मशीनों पर DSC कॉन्फ़िगरेशन बनाने और लागू करने की अनुमति देता है।
हमलावरों के दृष्टिकोण से यह दिलचस्प था क्योंकि यह सभी कॉन्फ़िगर की गई VMs में मनमाने PS कोड को निष्पादित करने की अनुमति देता था जिससे इन VMs की प्रबंधित पहचानों के लिए विशेषाधिकार बढ़ाने की अनुमति मिलती थी, संभावित रूप से नए नेटवर्क में पिवटिंग... इसके अलावा, कॉन्फ़िगरेशन में संवेदनशील जानकारी हो सकती है।
Enumeration
# 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>
विशेषाधिकार वृद्धि और पोस्ट एक्सप्लोइटेशन
Az - Automation Accounts Privesc
संदर्भ
- https://learn.microsoft.com/en-us/azure/automation/overview
- https://learn.microsoft.com/en-us/azure/automation/automation-dsc-overview
- https://github.com/rootsecdev/Azure-Red-Team#runbook-automation
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।