Az - Azure App Service & Function Apps

HackTricksのサポート

App Serviceの基本情報

公式ドキュメントから: Azure App Service は、Webアプリケーション、REST API、およびモバイルバックエンドをホストするためのHTTPベースのサービスです。お気に入りの言語で開発できます。.NET、.NET Core、Java、Ruby、Node.js、PHP、またはPythonです。アプリケーションは、WindowsおよびLinuxベースの環境で簡単に実行およびスケーリングできます。

各アプリはサンドボックス内で実行されますが、分離はApp Serviceプランに依存します

  • FreeおよびSharedティアのアプリは共有VM上で実行されます

  • StandardおよびPremiumティアのアプリは専用VM上で実行されます

これらの分離のいずれも、ファイルのアップロードやインジェクションなどの一般的なWeb脆弱性(例:ファイルのアップロード、インジェクション)を防ぐものではありません。また、管理アイデンティティが使用されている場合、その権限を侵害される可能性があります。

列挙

# List webapps
az webapp list

## Less information
az webapp list --query "[].{hostName: defaultHostName, state: state, name: name, resourcegroup: resourceGroup}"

# Get access restrictions
az webapp config access-restriction show --resource-group <res-group> -n <name>

# Remove access restrictions
az webapp config access-restriction remove --resource-group <res-group> -n <name> --rule-name <rule-name>

# Get snapshots
az webapp config snapshot list --resource-group <res-group> -n <name>

# Restore snapshot
az webapp config snapshot restore -g <res-group> -n <name> --time 2018-12-11T23:34:16.8388367

# Restart webapp
az webapp restart --name <name> --resource-group <res-group>
# Get App Services and Function Apps
Get-AzWebApp
# Get only App Services
Get-AzWebApp | ?{$_.Kind -notmatch "functionapp"}

#!/bin/bash

# Get all App Service and Function Apps

# Define Azure subscription ID
azure_subscription="your_subscription_id"

# Log in to Azure
az login

# Select Azure subscription
az account set --subscription $azure_subscription

# Get all App Services in the specified subscription
list_app_services=$(az appservice list --query "[].{appServiceName: name, group: resourceGroup}" -o tsv)

# Iterate over each App Service
echo "$list_app_services" | while IFS=$'\t' read -r appServiceName group; do
# Get the type of the App Service
service_type=$(az appservice show --name $appServiceName --resource-group $group --query "kind" -o tsv)

# Check if it is a Function App and print its name
if [ "$service_type" == "functionapp" ]; then
echo "Function App Name: $appServiceName"
fi
done

資格情報を取得し、Webアプリのコードにアクセスします

# Get connection strings that could contain credentials (with DBs for example)
az webapp config connection-string list --name <name> --resource-group <res-group>
## Check how to use the DBs connection strings in the SQL page

# Get credentials to access the code and DB credentials if configured.
az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>


# Get git URL to access the code
az webapp deployment source config-local-git --resource-group <res-group> -n <name>

# Access/Modify the code via git
git clone 'https://<username>:<password>@name.scm.azurewebsites.net/repo-name.git'
## In my case the username was: $nameofthewebapp and the password some random chars
## If you change the code and do a push, the app is automatically redeployed

SSHを介したWebアプリケーションのDockerコンテナへのアクセス:

# Get ssh session
az webapp create-remote-connection --subscription <SUBSCRIPTION-ID> --resource-group <RG-NAME> -n <APP-SERVICE-NAME>

## If successfull you will get a message such as:
#Verifying if app is running....
#App is running. Trying to establish tunnel connection...
#Opening tunnel on port: 39895
#SSH is available { username: root, password: Docker! }

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

関数アプリの基本情報

Azure Functionsは、サーバーレスソリューションであり、少ないコードを記述し、少ないインフラを維持し、コストを節約することができます。サーバーの展開や維持を心配する代わりに、クラウドインフラストラクチャは、アプリケーションを実行するために必要な最新のリソースをすべて提供します。

Azureポータルでは、Azure FunctionsとAzure API Managementの間の統合が容易になり、HTTPトリガー関数エンドポイントをREST APIとして公開することができます。この方法で公開されるAPIは、OpenAPI定義を使用して記述され、RESTful APIに対する標準的で言語に依存しないインターフェースを提供します。

関数アプリはマネージドアイデンティティをサポートしています。

さらに、関数アプリには、"admin"や"anonymous"などの特定レベルの認証が必要なエンドポイントがある可能性があります。 攻撃者は、匿名許可されたエンドポイントにアクセスし、制限をバイパスして機密データや機能にアクセスしようとする可能性があります。

列挙

# Get only Function Apps
Get-AzFunctionApp

参考

HackTricksのサポート

Last updated