# Az - MySQL Databases
{% hint style="success" %}
Learn & practice AWS Hacking:
[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)
\
Learn & practice GCP Hacking:
[**HackTricks Training GCP Red Team Expert (GRTE)**
](https://training.hacktricks.xyz/courses/grte)
Support HackTricks
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
## Azure MySQL
Azure Database for MySQLは、MySQL Community Editionに基づいた完全管理型リレーショナルデータベースサービスであり、さまざまなアプリケーションニーズに対してスケーラビリティ、セキュリティ、および柔軟性を提供するように設計されています。2つの異なるデプロイメントモデルがあります:
* **Single Server** (引退の道を歩んでいます):
- コスト効率が高く、管理が容易なMySQLデプロイメントに最適化されています。
- 自動バックアップ、高可用性、基本的な監視機能が含まれています。
- 予測可能なワークロードを持つアプリケーションに最適です。
* **Flexible Server**:
- データベース管理と構成に対するより多くの制御を提供します。
- 高可用性(同ゾーンおよびゾーン冗長)をサポートします。
- 弾力的なスケーリング、パッチ管理、ワークロード最適化の機能があります。
- コスト削減のための停止/開始機能を提供します。
### Key Features
* **Server Management**: **ad-admin**機能は、MySQLサーバーのAzure Active Directory (AAD)管理者を管理することを可能にし、AAD資格情報を介して管理アクセスを制御します。一方、**identity**機能は、Azure Managed Identitiesの割り当てと管理を可能にし、Azureリソースへの安全な資格情報なしの認証を提供します。
* **Lifecycle Management**: サーバーの開始または停止、フレキシブルサーバーインスタンスの削除、構成変更を迅速に適用するためのサーバーの再起動、そして自動化スクリプトを進める前にサーバーが特定の条件を満たすことを確認するための待機オプションがあります。
* **Security and Networking**: 安全なデータベースアクセスのためにサーバーファイアウォールルールを管理し、必要に応じて仮想ネットワーク構成を切り離すことができます。
* **Data Protection and Backup**: データ回復のためのフレキシブルサーバーのバックアップを管理するオプション、異なるリージョンでサーバーを回復するためのジオリストア、外部使用のためのサーバーバックアップのエクスポート(プレビュー中)、および特定の時点にバックアップからサーバーを復元するオプションが含まれています。
### Enumeration
{% tabs %}
{% tab title="az cli" %}
{% code overflow="wrap" %}
```bash
# List all flexible-servers
az mysql flexible-server db list --resource-group
# List databases in a flexible-server
az mysql flexible-server db list --resource-group --server-name
# Show specific details of a MySQL database
az mysql flexible-server db show --resource-group --server-name --database-name
# List firewall rules of the a server
az mysql flexible-server firewall-rule list --resource-group --name
# List all ad-admin in a server
az mysql flexible-server ad-admin list --resource-group --server-name
# List all user assigned managed identities from the server
az mysql flexible-server identity list --resource-group --server-name
# List the server backups
az mysql flexible-server backup list --resource-group --name
# List all read replicas for a given server
az mysql flexible-server replica list --resource-group --name
# Get the server's advanced threat protection setting
az mysql flexible-server advanced-threat-protection-setting show --resource-group --name
# List all of the maintenances of a flexible server
az mysql flexible-server maintenance list --resource-group --server-name
# List log files for a server.
az mysql flexible-server server-logs list --resource-group --server-name
```
{% endcode %}
{% endtab %}
{% tab title="Az PowerShell" %}
{% code overflow="wrap" %}
```bash
Get-Command -Module Az.MySql
# Get all flexible servers in a resource group
Get-AzMySqlFlexibleServer -ResourceGroupName
# List databases in a specific flexible server
Get-AzMySqlFlexibleServerDatabase -ResourceGroupName -ServerName
# Get details of a specific database in a flexible server
Get-AzMySqlFlexibleServerDatabase -ResourceGroupName -ServerName -DatabaseName
# List all firewall rules for a flexible server
Get-AzMySqlFlexibleServerFirewallRule -ResourceGroupName -ServerName
# Get the identity information of a flexible server
Get-AzMySqlFlexibleServerIdentity -ResourceGroupName -ServerName
# Get the server's advanced threat protection setting
Get-AzMySqlFlexibleServerAdvancedThreatProtection -ResourceGroupName -ServerName
# List configuration settings of a flexible server
Get-AzMySqlFlexibleServerConfiguration -ResourceGroupName -ServerName
# Get the connection string for a flexible server
Get-AzMySqlFlexibleServerConnectionString -ResourceGroupName -ServerName -Client
# List all read replicas for a given server
Get-AzMySqlFlexibleServerReplica -ResourceGroupName -ServerName
# Get the maintenance window details for a flexible server
Get-AzMySqlFlexibleServerMaintenanceWindow -ResourceGroupName -ServerName
# List log files for a server
Get-AzMySqlFlexibleServerLog -ResourceGroupName -ServerName
```
{% endcode %}
{% endtab %}
{% endtabs %}
### 接続
拡張機能 rdbms-connect を使用すると、次のようにデータベースにアクセスできます:
{% code overflow="wrap" %}
```bash
az mysql flexible-server connect -n -u -p --interactive
#or execute commands
az mysql flexible-server execute \
-n \
-u \
-p "" \
-d \
--querytext "SELECT * FROM ;"
```
{% endcode %}
または MySQL ネイティブ拡張プラグインを使用して
{% code overflow="wrap" %}
```bash
mysql -h .mysql.database.azure.com -P 3306 -u -p
```
{% endcode %}
また、GitHubを使用してクエリを実行することもできますが、パスワードとユーザーも必要です。実行するクエリを含むSQLファイルを設定する必要があります。その後:
{% code overflow="wrap" %}
```bash
# Setup
az mysql flexible-server deploy setup \
-s \
-g \
-u \
-p "" \
--sql-file \
--repo \
--branch \
--action-name \
--allow-push
# Run it
az mysql flexible-server deploy run \
--action-name \
--branch
```
{% endcode %}
## 権限昇格
{% content-ref url="../az-privilege-escalation/az-mysql-privesc.md" %}
[az-mysql-privesc.md](../az-privilege-escalation/az-mysql-privesc.md)
{% endcontent-ref %}
## ポストエクスプロイト
{% content-ref url="../az-post-exploitation/az-mysql-post-exploitation.md" %}
[az-sql-mysql-exploitation.md](../az-post-exploitation/az-mysql-post-exploitation.md)
{% endcontent-ref %}
## ToDo
* mysql flexible-server ad-admin にアクセスして、権限昇格の方法であることを確認する方法を探す
{% hint style="success" %}
AWSハッキングを学び、実践する:
[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)
\
GCPハッキングを学び、実践する:
[**HackTricks Training GCP Red Team Expert (GRTE)**
](https://training.hacktricks.xyz/courses/grte)
HackTricksをサポートする
* [**サブスクリプションプラン**](https://github.com/sponsors/carlospolop)を確認してください!
* **💬 [**Discordグループ**](https://discord.gg/hRep4RUj7f)または[**テレグラムグループ**](https://t.me/peass)に参加するか、**Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks_live)**をフォローしてください。**
* **[**HackTricks**](https://github.com/carlospolop/hacktricks)および[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud)のgithubリポジトリにPRを提出してハッキングトリックを共有してください。**
{% endhint %}