## SETTINGS ## $yourDomain="moemntive.onmicrosoft.com" $rgName = "RedTeamClass" $subnetName="RedTeamNet" $locName="East US" ## END OF SETTINGS ## Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope process -Force # Download and install required PowerShell modules Install-Module MSOnline -Scope CurrentUser -Force Install-Module AzureAD -Scope CurrentUser -Force Install-Module -Name Az -Scope CurrentUser -Force # Import the modules downloaded above Import-Module Az.Accounts -Force Import-Module Az.Compute -Force import-module MSOnline -force import-module azuread -force # Authenticate to Azure Connect-AzAccount # Get the Azure subscription name $subscr=( Get-AzSubscription | Sort Name | Select Name ).Name # Get the Azure resource group name Get-AzResourceGroup | Sort ResourceGroupName | Select ResourceGroupName # Create a new Azure resource group New-AzResourceGroup -Name $rgName -Location $locName # create the TestLab virtual network that will host the corporate network subnet of the simulated enterprise environment and protect it with a network security group $corpnetSubnet=New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24 New-AzVirtualNetwork -Name TestLab -ResourceGroupName $rgName -Location $locName -AddressPrefix 10.0.0.0/8 -Subnet $corpnetSubnet -DNSServer 8.8.8.8 #$rule0=New-AzNetworkSecurityRuleConfig -Name "AllowAllOutbound" -Description "Allow All Outbound" -Access Allow -Protocol * -Direction Outbound -Priority 100 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange * $rule1=New-AzNetworkSecurityRuleConfig -Name "RDPTraffic" -Description "Allow RDP to all VMs on the subnet" -Access Allow -Protocol Tcp -Direction Inbound -Priority 101 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 #New-AzNetworkSecurityGroup -Name $subnetName -ResourceGroupName $rgName -Location $locName -SecurityRules $rule0,$rule1 New-AzNetworkSecurityGroup -Name $subnetName -ResourceGroupName $rgName -Location $locName -SecurityRules $rule0,$rule1 $vnet=Get-AzVirtualNetwork -ResourceGroupName $rgName -Name TestLab $nsg=Get-AzNetworkSecurityGroup -Name $subnetName -ResourceGroupName $rgName Set-AzVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $subnetName -AddressPrefix "10.0.0.0/24" -NetworkSecurityGroup $nsg $vnet | Set-AzVirtualNetwork # create an Azure Virtual Machine for CLIENT1 $vnet=Get-AzVirtualNetwork -Name TestLab -ResourceGroupName $rgName $pip=New-AzPublicIpAddress -Name CLIENT1-PIP -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic $nic=New-AzNetworkInterface -Name CLIENT1-NIC -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id #$vm=New-AzVMConfig -VMName CLIENT1 -VMSize Standard_A2_V2 #https://azure.microsoft.com/en-us/blog/new-av2-series-vm-sizes/ $vm=New-AzVMConfig -VMName CLIENT1 -VMSize Standard_A4_V2 $cred=Get-Credential -Message "Type the name and password of the local administrator account for CLIENT1." $vm=Set-AzVMOperatingSystem -VM $vm -Windows -ComputerName CLIENT1 -Credential $cred -ProvisionVMAgent -EnableAutoUpdate #$vm=Set-AzVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter -Version "latest" # Changed to Windows 10 $vm=Set-AzVMSourceImage -VM $vm -PublisherName MicrosoftWindowsDesktop -Offer "Windows-10" -Skus "20h2-ent" -Version "latest" $vm=Add-AzVMNetworkInterface -VM $vm -Id $nic.Id $vm=Set-AzVMOSDisk -VM $vm -Name "CLIENT1-OS" -DiskSizeInGB 128 -CreateOption FromImage New-AzVM -ResourceGroupName $rgName -Location $locName -VM $vm # Display the VM's public IP address $externalIP = (get-AzPublicIpAddress -Name CLIENT1-PIP).IpAddress echo "===================================================" echo "Windows VM external IP: $externalIP" echo "==================================================="## SETTINGS ## $yourDomain="REPLACE-WITH-YOUR-SUBDOMAIN.onmicrosoft.com" $rgName = "RedTeamClass" $subnetName="RedTeamNet" $locName="East US" ## END OF SETTINGS ## Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope process -Force # Download and install required PowerShell modules Install-Module MSOnline -Scope CurrentUser -Force Install-Module AzureAD -Scope CurrentUser -Force Install-Module -Name Az -Scope CurrentUser -Force # Import the modules downloaded above Import-Module Az.Accounts -Force Import-Module Az.Compute -Force import-module MSOnline -force import-module azuread -force # Authenticate to Azure Connect-AzAccount # Get the Azure subscription name $subscr=( Get-AzSubscription | Sort Name | Select Name ).Name # Get the Azure resource group name Get-AzResourceGroup | Sort ResourceGroupName | Select ResourceGroupName # Create a new Azure resource group New-AzResourceGroup -Name $rgName -Location $locName # create the TestLab virtual network that will host the corporate network subnet of the simulated enterprise environment and protect it with a network security group $corpnetSubnet=New-AzVirtualNetworkSubnetConfig -Name $subnetName -AddressPrefix 10.0.0.0/24 New-AzVirtualNetwork -Name TestLab -ResourceGroupName $rgName -Location $locName -AddressPrefix 10.0.0.0/8 -Subnet $corpnetSubnet -DNSServer 8.8.8.8 #$rule0=New-AzNetworkSecurityRuleConfig -Name "AllowAllOutbound" -Description "Allow All Outbound" -Access Allow -Protocol * -Direction Outbound -Priority 100 -SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange * $rule1=New-AzNetworkSecurityRuleConfig -Name "RDPTraffic" -Description "Allow RDP to all VMs on the subnet" -Access Allow -Protocol Tcp -Direction Inbound -Priority 101 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389 #New-AzNetworkSecurityGroup -Name $subnetName -ResourceGroupName $rgName -Location $locName -SecurityRules $rule0,$rule1 New-AzNetworkSecurityGroup -Name $subnetName -ResourceGroupName $rgName -Location $locName -SecurityRules $rule0,$rule1 $vnet=Get-AzVirtualNetwork -ResourceGroupName $rgName -Name TestLab $nsg=Get-AzNetworkSecurityGroup -Name $subnetName -ResourceGroupName $rgName Set-AzVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $subnetName -AddressPrefix "10.0.0.0/24" -NetworkSecurityGroup $nsg $vnet | Set-AzVirtualNetwork # create an Azure Virtual Machine for CLIENT1 $vnet=Get-AzVirtualNetwork -Name TestLab -ResourceGroupName $rgName $pip=New-AzPublicIpAddress -Name CLIENT1-PIP -ResourceGroupName $rgName -Location $locName -AllocationMethod Dynamic $nic=New-AzNetworkInterface -Name CLIENT1-NIC -ResourceGroupName $rgName -Location $locName -SubnetId $vnet.Subnets[0].Id -PublicIpAddressId $pip.Id #$vm=New-AzVMConfig -VMName CLIENT1 -VMSize Standard_A2_V2 #https://azure.microsoft.com/en-us/blog/new-av2-series-vm-sizes/ $vm=New-AzVMConfig -VMName CLIENT1 -VMSize Standard_A4_V2 $cred=Get-Credential -Message "Type the name and password of the local administrator account for CLIENT1." $vm=Set-AzVMOperatingSystem -VM $vm -Windows -ComputerName CLIENT1 -Credential $cred -ProvisionVMAgent -EnableAutoUpdate #$vm=Set-AzVMSourceImage -VM $vm -PublisherName MicrosoftWindowsServer -Offer WindowsServer -Skus 2016-Datacenter -Version "latest" # Changed to Windows 10 $vm=Set-AzVMSourceImage -VM $vm -PublisherName MicrosoftWindowsDesktop -Offer "Windows-10" -Skus "20h2-ent" -Version "latest" $vm=Add-AzVMNetworkInterface -VM $vm -Id $nic.Id $vm=Set-AzVMOSDisk -VM $vm -Name "CLIENT1-OS" -DiskSizeInGB 128 -CreateOption FromImage New-AzVM -ResourceGroupName $rgName -Location $locName -VM $vm # Display the VM's public IP address $externalIP = (get-AzPublicIpAddress -Name CLIENT1-PIP).IpAddress echo "===================================================" echo "Windows VM external IP: $externalIP" echo "==================================================="