# Az - PostgreSQL Databases

{{#include ../../../banners/hacktricks-training.md}}

## Azure PostgreSQL
**Azure Database for PostgreSQL** is 'n volledig bestuurde **relationele databasediens wat gebaseer is op die PostgreSQL** Gemeenskapsuitgawe. Dit is ontwerp om skaalbaarheid, sekuriteit en buigsaamheid te bied vir diverse toepassingsbehoeftes. Soos Azure MySQL, bied PostgreSQL twee ontplooiingsmodelle:

* **Enkelbediener** (op die aftreepad):
- Geoptimaliseer vir eenvoudige, kostedoeltreffende PostgreSQL-ontplooiings.
- Beskik oor outomatiese rugsteun, basiese monitering en hoë beskikbaarheid.
- Ideaal vir toepassings met voorspelbare werklas.
* **Buigsame Bediener**:
- Bied groter beheer oor databasisbestuur en konfigurasie.
- Ondersteun hoë beskikbaarheid, beide in dieselfde sone en oor sones.
- Beskik oor elastiese skaalbaarheid, outomatiese onderhoud en kostebesparende funksionaliteit.
- Laat die begin en stop van die bediener toe om koste te optimaliseer.

### Sleutelkenmerke

* **Pasgemaakte Onderhoudsvensters**: Skeduleer opdaterings om onderbrekings te minimaliseer.
* **Aktiewe Monitering**: Toegang tot gedetailleerde metrieke en logs om databasisprestasie te volg en te verbeter.
* **Stop/Begin Bediener**: Gebruikers kan die bediener stop en begin.
* **Outomatiese Rugsteun**: Ingeboude daaglikse rugsteun met retensietydperke wat tot 35 dae konfigureerbaar is.
* **Rolgebaseerde Toegang**: Beheer gebruikersregte en administratiewe toegang deur Azure Active Directory.
* **Sekuriteit en Netwerk**: kan bediener-vuurmuurreëls bestuur vir veilige databasis toegang en virtuele netwerk konfigurasies soos nodig ontkoppel.
* **Bestuurde Identiteite**: laat jou bediener toe om veilig met ander Azure-dienste te autentiseer sonder om akrediteerbesonderhede te stoor. Dit laat toegang tot ander dienste wat 'n stelselaanbestede bestuurde identiteit sou wees en deur ander dienste met ander identiteite wat 'n gebruiker aangewese bestuurde identiteit is, benader kan word.

### Enumerasie

{{#tabs }}
{{#tab name="az cli" }}
```bash
# List servers in a resource group
az postgres flexible-server list --resource-group <resource-group-name>
# List databases in a flexible-server
az postgres flexible-server db list --resource-group <resource-group-name> --server-name <server_name>
# Show specific details of a Postgre database
az postgres flexible-server db show --resource-group <resource-group-name> --server-name <server_name> --database-name <database_name>

# List firewall rules of the a server
az postgres flexible-server firewall-rule list --resource-group <resource-group-name> --name <server_name>
# List parameter values for a felxible server
az postgres flexible-server parameter list --resource-group <resource-group-name> --server-name <server_name>
# List private link
az postgres flexible-server private-link-resource list --resource-group <resource-group-name> --server-name <server_name>

# List all ad-admin in a server
az postgres flexible-server ad-admin list --resource-group <resource-group-name> --server-name <server_name>
# List all user assigned managed identities from the server
az postgres flexible-server identity list --resource-group <resource-group-name> --server-name <server_name>

# List the server backups
az postgres flexible-server backup list --resource-group <resource-group-name> --name <server_name>
# List all read replicas for a given server
az postgres flexible-server replica list --resource-group <resource-group-name> --name <server_name>
# List migrations
az postgres flexible-server migration list --resource-group <resource-group-name> --name <server_name>

# Get the server's advanced threat protection setting
az postgres flexible-server advanced-threat-protection-setting show --resource-group <resource-group-name> --name <server_name>
# List all of the maintenances of a flexible server
az postgres flexible-server maintenance list --resource-group <resource-group-name> --server-name <server_name>
# List log files for a server.
az postgres flexible-server server-logs list --resource-group <resource-group-name> --server-name <server_name>

```
{{#endtab }}

{{#tab name="Az Powershell" }}
```bash
Get-Command -Module Az.PostgreSql

# List flexible-servers in a resource group
Get-AzPostgreSqlFlexibleServer -ResourceGroupName <resource-group-name>
# List databases in a flexible-server
Get-AzPostgreSqlFlexibleServerDatabase -ResourceGroupName <resource-group-name> -ServerName <server_name>

# List firewall rules of the a flexible-server
Get-AzPostgreSqlFlexibleServerFirewallRule -ResourceGroupName <resource-group-name> -ServerName <server_name>

# List configuration settings of a flexible server
Get-AzPostgreSqlFlexibleServerConfiguration -ResourceGroupName <resource-group-name> -ServerName <server_name>
# Get the connection string for a flexible server
Get-AzPostgreSqlFlexibleServerConnectionString -ResourceGroupName <resource-group-name> -ServerName <server_name> -Client <client>

Get-AzPostgreSqlFlexibleServerLocationBasedCapability -Location <location>

# List servers in a resource group
Get-AzPostgreSqlServer -ResourceGroupName <resource-group-name>

```
{{#endtab }}
{{#endtabs }}

### Verbinding

Met die uitbreiding rdbms-connect kan jy toegang tot die databasis verkry met:
```bash
az postgres flexible-server connect -n <server-name> -u <username> -p <password> --interactive

#or execute commands
az postgres flexible-server execute \
-n <server-name> \
-u <username> \
-p "<password>" \
-d <database-name> \
--querytext "SELECT * FROM <table-name>;"

```
Of
```bash
psql -h testpostgresserver1994.postgres.database.azure.com -p 5432 -U adminuser <database-name>
```
## Verwysings

- [https://learn.microsoft.com/en-us/azure/postgresql/](https://learn.microsoft.com/en-us/azure/postgresql/)
- [https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/service-overview](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/service-overview)
- [https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/overview](https://learn.microsoft.com/en-us/azure/postgresql/flexible-server/overview)

## Privilege Escalation

{{#ref}}
../az-privilege-escalation/az-postgresql-privesc.md
{{#endref}}

## Post Exploitation

{{#ref}}
../az-post-exploitation/az-postgresql-post-exploitation.md
{{#endref}}

## ToDo

* Kyk 'n manier om toegang te verkry met ad-admin om te verifieer dat dit 'n privesc-metode is


{{#include ../../../banners/hacktricks-training.md}}
