# Inicio

Apuntes sobre pentesting cloud.


# Enumeración no autenticada

## General

Obtener Tenant ID.

```shell
https://login.microsoftonline.com/<tenant-name>.onmicrosoft.com.onmicrosoft.com/.well-known/openid-configuration
```

## Azure services

### MicroBurst

```powershell
Invoke-EnumerateAzureSubDomains -Base "<base-name>" -Verbose
```

## Azure Blob Storage

### MicroBurst

```powershell
Invoke-EnumerateAzureBlobs -Base "<base-name>" -Verbose
```


# Enumeración autenticada

## Credenciales de usuario

### Az PowerShell <a href="#credenciales-de-usuario-az-powershell" id="credenciales-de-usuario-az-powershell"></a>

Conexión inicial.

```powershell
$UserPassword = ConvertTo-SecureString '<password>' -AsPlainText -Force
$UserCredential = New-Object System.Management.Automation.PSCredential ("<user>@<tenant-name>.onmicrosoft.com", $UserPassword)
Connect-AzAccount -Credential $UserCredential -Tenant "<tenant>"
```

Enumeración general.

```powershell
Get-AzResource
Get-AzResourceGroup
Get-AzWebApp
Get-AzFunctionApp
Get-AzKeyVault
Get-AzStorageAccount
Get-AzRoleAssignment -SignInName <user>
```

Enumeración de SQL Server.

```powershell
Get-AzSqlServer

$SQLServers = Get-AzSqlServer
foreach($SQLServer in $SQLServers){
    Get-AzSqlDatabase -ServerName $SQLServer.ServerName –ResourceGroupName $SQLServer.ResourceGroupName
} 
```

Enumeración Cosmo DB.

```powershell
$ResourceGroups = (Get-AzResourceGroup).ResourceGroupName
foreach($ResourceGroup in $ResourceGroups){
    Get-AzCosmosDBAccount -ResourceGroupName $ResourceGroup -ErrorAction SilentlyContinue
}
```

### AzureAD

Obtener Tenant ID.

```powershell
$UserPassword = ConvertTo-SecureString '<password>' -AsPlainText -Force
$UserCredential = New-Object System.Management.Automation.PSCredential ("<user>@<tenant>.onmicrosoft.com", $UserPassword)
Connect-AzureAD -Credential $UserCredential
```

Enumeración general.

```powershell
Get-AzureADUser
Get-AzureADUser -SearchString "<search-string>"
```

## Credenciales de service principal <a href="#credenciales-de-service-principal-az-powershell" id="credenciales-de-service-principal-az-powershell"></a>

### Az PowerShell <a href="#credenciales-de-service-principals-az-powershell" id="credenciales-de-service-principals-az-powershell"></a>

Conexión inicial.

```powershell
$Password = ConvertTo-SecureString '<client-secret>' -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential("<service-principal-application-ID>", $Password)
Connect-AzAccount -ServicePrincipal -Credential $Credential -Tenant "<tenant>"
```

Enumeración general.

```powershell
Get-AzADApplication
Get-AzADServicePrincipal -ApplicationId "<application-ID>"
```

Enumerar todos los objetos sobre los que service principal tiene derechos de propietario.

```powershell
$GraphToken = (Get-AzAccessToken -ResourceUrl https://graph.microsoft.com).Token
$Params = @{
    "URI"     = "https://graph.microsoft.com/v1.0/servicePrincipals/<service-principal-object-ID>/ownedObjects"
    "Method"  = "GET"
    "Headers" = @{
        "Authorization" = "Bearer $GraphToken"
        "Content-Type"  = "application/json"
        }
    }

$Result = Invoke-RestMethod @Params -UseBasicParsing
$Result.value
```

Enumerer todos los roles de aplicación asignados a un service principal.

```powershell
$GraphToken = (Get-AzAccessToken -ResourceUrl https://graph.microsoft.com).Token
$Params = @{
    "URI" = "https://graph.microsoft.com/v1.0/servicePrincipals/<service-principal-object-ID>/appRoleAssignments"
    "Method" = "GET"
    "Headers" = @{
    "Authorization" = "Bearer $GraphToken"
    "Content-Type" = "application/json"
    }
}
$RoleAssignments = Invoke-RestMethod @Params -UseBasicParsing
$RoleAssignments.value
```


# Key Vault

### MicroBurst

```powershell
Invoke-EnumerateAzureSubDomains -Base "<base-name>" -Verbose
```

### Az PowerShell <a href="#credenciales-de-usuario-az-powershell" id="credenciales-de-usuario-az-powershell"></a>

Conexión inicial.

```powershell
$UserPassword = ConvertTo-SecureString '<password>' -AsPlainText -Force
$UserCredential = New-Object System.Management.Automation.PSCredential ("<user>@<tenant-name>.onmicrosoft.com", $UserPassword)
Connect-AzAccount -Credential $UserCredential
```

Enumeración general.

```powershell
Get-AzResource
Get-AzKeyVault -VaultName "<vault-name>"
Get-AzKeyVaultSecret -VaultName "<vault-name>"
Get-AzKeyVaultSecret -VaultName "<vault-name>" -Name "<name>" -AsPlainText
```

Enumerar los permisos que el usuario actual tiene sobre el Key Vault.

```powershell
$KeyVault = Get-AzKeyVault
$Token = (Get-AzAccessToken).Token
$SubscriptionID = (Get-AzSubscription).Id
$ResourceGroupName = $KeyVault.ResourceGroupName
$KeyVaultName = $KeyVault.VaultName
$URI = "https://management.azure.com/subscriptions/$SubscriptionID/resourceGroups/$ResourceGroupName/providers/Microsoft.KeyVault/vaults/$KeyVaultName/providers/Microsoft.Authorization/permissions?api-version=2015-07-01"
$RequestParams = @{
    Method  = 'GET'
    Uri     = $URI
    Headers = @{
        'Authorization' = "Bearer $Token"
    }
}
(Invoke-RestMethod @RequestParams).value
```


# Azure Storage

### MicroBurst

```powershell
Invoke-EnumerateAzureBlobs -Permutations <path>\permutations.txt
```


# Herramientas

## AzureAD

* <https://www.powershellgallery.com/packages/AzureAD>

```powershell
Install-Module -Name AzureAD
```

## Az PowerShell

* <https://github.com/Azure/azure-powershell>

## MicroBurst

* <https://github.com/NetSPI/MicroBurst>

```powershell
Import-Module .\MicroBurst.psm1 -Verbose
```

## Microsoft Azure Storage Account Explorer

* <https://azure.microsoft.com/es-es/products/storage/storage-explorer>


