> For the complete documentation index, see [llms.txt](https://cloud.mrw0l05zyn.cl/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cloud.mrw0l05zyn.cl/microsoft-azure/enumeracion-autenticada.md).

# 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
```
