Az - PostgreSQL Post Exploitation

Reading time: 3 minutes

{% hint style="success" %} Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
{% endhint %}

PostgreSQL Database Post Exploitation

For more information about PostgreSQL Database check:

{% content-ref url="../az-services/az-postgresql.md" %} az-postgresql.md {% endcontent-ref %}

"Microsoft.DBforPostgreSQL/flexibleServers/databases/write" && "Microsoft.DBforPostgreSQL/flexibleServers/databases/read"

With this permission, you can create new databases within a Postgres Flexible Server instance on Azure. While this action itself does not modify existing resources, excessive or unauthorized creation of databases could lead to resource consumption, or potential misuse of the server.

{% code overflow="wrap" %}

bash
az postgres flexible-server db create \
  --server-name <server_name> \
  --resource-group <resource_group_name> \
  --database-name <database_name>

{% endcode %}

"Microsoft.DBforPostgreSQL/flexibleServers/backups/write"

With this permission, you can initiate the creation of backups for a Postgres Flexible Server instance on Azure. This allows users to generate on-demand backups, which can be useful for preserving data at specific points in time.

{% code overflow="wrap" %}

bash
az postgres flexible-server backup create \
  --name <server_name> \
  --resource-group <resource_group_name>
  --backup-name <backup_name>

{% endcode %}

"Microsoft.DBforPostgreSQL/flexibleServers/advancedThreatProtectionSettings/write" && "Microsoft.DBforPostgreSQL/flexibleServers/advancedThreatProtectionSettings/read"

With this permission, you can configure or update the Advanced Threat Protection (ATP) settings for a Postgres Flexible Server instance on Azure. This allows enabling or diabling security features designed to detect and respond to anomalous activities and potential threats.

{% code overflow="wrap" %}

bash
az postgres flexible-server threat-protection-policy update \
  --name <server_name> \
  --resource-group <resource_group_name> \
  --state <Enabled|Disabled>

{% endcode %}

"Microsoft.DBforPostgreSQL/flexibleServers/firewallRules/write", "Microsoft.DBforPostgreSQL/flexibleServers/read" && "Microsoft.DBforPostgreSQL/flexibleServers/firewallRules/read"

With this permission, you can create or modify firewall rules for a Postgres Flexible Server instance on Azure. This allows control over which IP addresses or ranges can access the server. Unauthorized or improper use of this permission could expose the server to unwanted or malicious access.

{% code overflow="wrap" %}

bash
# Create Rule
az postgres flexible-server firewall-rule create \
  --name <server_name> \
  --resource-group <resource_group_name> \
  --rule-name <rule_name> \
  --start-ip-address <start_ip> \
  --end-ip-address <end_ip>

# Update Rule
az postgres flexible-server firewall-rule update \
  --name <server_name> \
  --resource-group <resource_group_name> \
  --rule-name <rule_name> \
  --start-ip-address <start_ip> \
  --end-ip-address <end_ip>

{% endcode %}

"Microsoft.DBforPostgreSQL/flexibleServers/configurations/write" && "Microsoft.DBforPostgreSQL/flexibleServers/configurations/read"

With this permission, you can update the configuration settings of a Postgres Flexible Server instance on Azure. This allows customization of server parameters such as performance tuning, security configurations, or operational settings.

{% code overflow="wrap" %}

bash
az postgres flexible-server parameter set \
    --resource-group <resource_group_name> \
    --server-name <server_name> \
    --name <parameter_name> \
    --value <parameter_value>

{% endcode %}

"Microsoft.DBforPostgreSQL/flexibleServers/stop/action"

With this permission, you can stop a PostgreSQL Flexible Server instance on Azure. Stopping a server can lead to temporary service disruption, affecting applications and users dependent on the database.

{% code overflow="wrap" %}

bash
az postgres flexible-server stop \
  --name <server_name> \
  --resource-group <resource_group_name>

{% endcode %}

"Microsoft.DBforPostgreSQL/flexibleServers/start/action"

With this permission, you can start a stopped PostgreSQL Flexible Server instance on Azure. Starting a server restores its availability, enabling applications and users to reconnect and access the database.

{% code overflow="wrap" %}

az postgres flexible-server start \
  --name <server_name> \
  --resource-group <resource_group_name>

{% endcode %}

"Microsoft.DBforPostgreSQL/flexibleServers/read", "Microsoft.DBforPostgreSQL/flexibleServers/write" && "Microsoft.ManagedIdentity/userAssignedIdentities/assign/action"

With this permission, you can assign a user-assigned managed identity to postgres flexible servers.

{% code overflow="wrap" %}

az postgres flexible-server identity assign \
    --resource-group <ResourceGroupName> \
    --server-name <ServerName> \
    --identity <IdentityName>