diff --git a/src/SUMMARY.md b/src/SUMMARY.md index a470914ae..17225a2e2 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) diff --git a/src/images/lasttower.png b/src/images/lasttower.png new file mode 100644 index 000000000..61b197810 Binary files /dev/null and b/src/images/lasttower.png differ diff --git a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md index 7e842933c..747f60629 100644 --- a/src/pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md +++ b/src/pentesting-cloud/azure-security/az-privilege-escalation/az-app-services-privesc.md @@ -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 --resource-group ``` - -- **Create tunnel and then connect to SSH**: - +- **टनल बनाएं और फिर SSH से कनेक्ट करें**: ```bash az webapp create-remote-connection --name --resource-group @@ -35,152 +32,146 @@ az webapp create-remote-connection --name --resource-group ## So from that machine ssh into that port (you might need generate a new ssh session to the jump host) ssh root@127.0.0.1 -p 39895 ``` +- **ऐप्लिकेशन को डिबग करें**: +1. VScode में Azure एक्सटेंशन इंस्टॉल करें। +2. एक्सटेंशन में Azure खाते से लॉगिन करें। +3. सब्सक्रिप्शन के अंदर सभी ऐप सेवाओं की सूची बनाएं। +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 --resource-group # Example output [ { - "SQLServerDBConnectionString": "", - "controlPanelLink": "https://portal.azure.com", - "databases": null, - "destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net", - "hostingProviderForumLink": "", - "msdeploySite": "happy-bay-0d8f842ef57843c89185d452c1cede2a", - "mySQLDBConnectionString": "", - "profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Web Deploy", - "publishMethod": "MSDeploy", - "publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443", - "userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a", - "userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS", - "webSystem": "WebSites" - }, - { - "SQLServerDBConnectionString": "", - "controlPanelLink": "https://portal.azure.com", - "databases": null, - "destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net", - "ftpPassiveMode": "True", - "hostingProviderForumLink": "", - "mySQLDBConnectionString": "", - "profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - FTP", - "publishMethod": "FTP", - "publishUrl": "ftps://waws-prod-yt1-067.ftp.azurewebsites.windows.net/site/wwwroot", - "userName": "happy-bay-0d8f842ef57843c89185d452c1cede2a\\$happy-bay-0d8f842ef57843c89185d452c1cede2a", - "userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS", - "webSystem": "WebSites" - }, - { - "SQLServerDBConnectionString": "", - "controlPanelLink": "https://portal.azure.com", - "databases": null, - "destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net", - "hostingProviderForumLink": "", - "mySQLDBConnectionString": "", - "profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Zip Deploy", - "publishMethod": "ZipDeploy", - "publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443", - "userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a", - "userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS", - "webSystem": "WebSites" - } +"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 `.scm.azurewebsites.net`**. - -- The permission **`Microsoft.Web/sites/config/list/action`** allows to call: +इसके अलावा, **SCM URL है `.scm.azurewebsites.net`**। +- अनुमति **`Microsoft.Web/sites/config/list/action`** कॉल करने की अनुमति देती है: ```bash az webapp deployment list-publishing-credentials --name --resource-group # Example output { - "id": "/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/carlos_rg_3170/providers/Microsoft.Web/sites/happy-bay-0d8f842ef57843c89185d452c1cede2a/publishingcredentials/$happy-bay-0d8f842ef57843c89185d452c1cede2a", - "kind": null, - "location": "Canada Central", - "name": "happy-bay-0d8f842ef57843c89185d452c1cede2a", - "publishingPassword": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS", - "publishingPasswordHash": null, - "publishingPasswordHashSalt": null, - "publishingUserName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a", - "resourceGroup": "carlos_rg_3170", - "scmUri": "https://$happy-bay-0d8f842ef57843c89185d452c1cede2a:bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS@happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net", - "type": "Microsoft.Web/sites/publishingcredentials" +"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 `/BasicAuth`**. +याद रखें कि **वेब से SCM प्लेटफार्म तक पहुँचने के लिए आपको `/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//resourceGroups//providers/Microsoft.Web/sites//basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \ - --body '{ - "properties": { - "allow": true - } - }' +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \ +--body '{ +"properties": { +"allow": true +} +}' # Enable basic authentication for FTP az rest --method PUT \ - --uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \ - --body '{ - "properties": { - "allow": true - } - }' +--uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//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 "/api/publish?type=zip" --data-binary "@./app.zip" -u ':' -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 "/vfs/data/jobs//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 "/vfs/data/jobs/continuous/job_name/job_log.txt" \ - --user ':' -v +--user ':' -v ``` - -- Read **Webjobs** source code: - +- **Webjobs** स्रोत कोड पढ़ें: ```bash # Using SCM username and password: # Find all the webjobs inside: curl "/wwwroot/App_Data/jobs/" \ - --user ':' +--user ':' # e.g. curl "https://nodewebapp-agamcvhgg3gkd3hs.scm.canadacentral-01.azurewebsites.net/wwwroot/App_Data/jobs/continuous/job_name/rev.js" \ - --user ':' +--user ':' ``` - -- 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 \ - "/api/Continuouswebjobs/reverse_shell2" \ - -H 'Content-Disposition: attachment; filename=rev.js' \ - --data-binary "@/Users/carlospolop/Downloads/rev.js" \ - --user ':' +"/api/Continuouswebjobs/reverse_shell2" \ +-H 'Content-Disposition: attachment; filename=rev.js' \ +--data-binary "@/Users/carlospolop/Downloads/rev.js" \ +--user ':' ``` - ### 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 --resource-group --identities /subscriptions//resourceGroups//providers/Microsoft.ManagedIdentity/userAssignedIdentities/ ``` - ### 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 --resource-group az webapp config appsettings list --name --resource-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 " \ - -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 " \ - -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 " \ - -H "Content-Type: application/json" \ - --data '{"path": ""}' +-H "Authorization: Bearer " \ +-H "Content-Type: application/json" \ +--data '{"path": ""}' # OneDrive – List Files in Root Folder curl -H "Authorization: Bearer " \ - -H "Accept: application/json" \ - https://graph.microsoft.com/v1.0/me/drive/root/children +-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 --resource-group ` - - Using the permission **`Microsoft.Web/sites/config/list/action`**: - - `az webapp deployment list-publishing-credentials --name --resource-group ` - - `az rest --method POST --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"` -- 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 --resource-group `, but it's going to be the same as the the SCM URL of the app with the path `/.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 -n `. - - **`Microsoft.Web/sites/config/list/action`**: Then run `az webapp deployment list-publishing-credentials --name --resource-group ` +- यदि कॉन्फ़िगर किया गया स्रोत एक तृतीय-पक्ष प्रदाता है जैसे Github, BitBucket या Azure Repository, तो आप **कोड अपडेट** कर सकते हैं App सेवा का स्रोत कोड को समझौता करके। +- यदि ऐप को **रिमोट गिट रिपॉजिटरी** (यूजरनेम और पासवर्ड के साथ) का उपयोग करके कॉन्फ़िगर किया गया है, तो **URL और बेसिक ऑथ क्रेडेंशियल्स** प्राप्त करना संभव है ताकि क्लोन और परिवर्तन पुश किए जा सकें: +- अनुमति का उपयोग करते हुए **`Microsoft.Web/sites/sourcecontrols/read`**: `az webapp deployment source show --name --resource-group ` +- अनुमति का उपयोग करते हुए **`Microsoft.Web/sites/config/list/action`**: +- `az webapp deployment list-publishing-credentials --name --resource-group ` +- `az rest --method POST --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"` +- यदि ऐप को **लोकल गिट रिपॉजिटरी** का उपयोग करने के लिए कॉन्फ़िगर किया गया है, तो **रिपॉजिटरी क्लोन करना** और **परिवर्तन पुश करना** संभव है: +- अनुमति का उपयोग करते हुए **`Microsoft.Web/sites/sourcecontrols/read`**: आप गिट रिपॉजिटरी का URL प्राप्त कर सकते हैं `az webapp deployment source show --name --resource-group `, लेकिन यह ऐप के SCM URL के समान होगा जिसमें पथ `/.git` है (जैसे `https://pythonwebapp-audeh9f5fzeyhhed.scm.canadacentral-01.azurewebsites.net:443/pythonwebapp.git`)। +- SCM क्रेडेंशियल प्राप्त करने के लिए आपको अनुमति की आवश्यकता है: +- **`Microsoft.Web/sites/publishxml/action`**: फिर चलाएँ `az webapp deployment list-publishing-profiles --resource-group -n `। +- **`Microsoft.Web/sites/config/list/action`**: फिर चलाएँ `az webapp deployment list-publishing-credentials --name --resource-group ` > [!WARNING] -> 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 \ - --resource-group \ - --docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest +--name \ +--resource-group \ +--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest ``` - {{#include ../../../banners/hacktricks-training.md}} diff --git a/src/pentesting-cloud/azure-security/az-services/az-app-services.md b/src/pentesting-cloud/azure-security/az-services/az-app-services.md index 90bb1ed37..de3fb33b9 100644 --- a/src/pentesting-cloud/azure-security/az-services/az-app-services.md +++ b/src/pentesting-cloud/azure-security/az-services/az-app-services.md @@ -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 --resource-group ` या `az rest --method POST --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"` चलाकर दूरस्थ रिपॉजिटरी के लिए क्रेडेंशियल्स प्राप्त कर सकते हैं। - एक **Azure Repository** का उपयोग करना भी संभव है। - एक **स्थानीय git रिपॉजिटरी** को कॉन्फ़िगर करना भी संभव है। @@ -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 --resource-group # Get hybrid-connections of a webapp az webapp hybrid-connections list --name --resource-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) diff --git a/src/pentesting-cloud/azure-security/az-services/az-function-apps.md b/src/pentesting-cloud/azure-security/az-services/az-function-apps.md index e916c80f5..4877aabdd 100644 --- a/src/pentesting-cloud/azure-security/az-services/az-function-apps.md +++ b/src/pentesting-cloud/azure-security/az-services/az-function-apps.md @@ -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://.azurewebsites.net/api/?code=` @@ -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 इस तरह दिखता है:
@@ -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:/:ref:refs/heads/` को अनुमति देता है। > [!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 --resource-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 \ +--resource-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 --resource-group +# Get access restrictions +az functionapp config access-restriction show --name --resource-group + # Check if a domain was assigned to a function app az functionapp config hostname list --webapp-name --resource-group @@ -240,22 +245,41 @@ az functionapp config ssl list --resource-group # Get network restrictions az functionapp config access-restriction show --name --resource-group -# Get more info about a function (invoke_url_template is the URL to invoke and script_href allows to see the code) -az rest --method GET \ ---url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//functions?api-version=2024-04-01" +# Get acess restrictions +az functionapp config access-restriction show --name --resource-group + +# Get connection strings +az rest --method POST --uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/connectionstrings/list?api-version=2022-03-01" +az rest --method GET --uri "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//config/configreferences/connectionstrings?api-version=2022-03-01" + +# Get SCM credentials +az functionapp deployment list-publishing-credentials --name --resource-group + +# Get function, system and master keys +az functionapp keys list --name --resource-group + +# Get Host key +az rest --method POST --uri "https://management.azure.com//resourceGroups//providers/Microsoft.Web/sites//functions//listKeys?api-version=2022-03-01" # Get source code with Master Key of the function curl "?code=" -## Python example -curl "https://newfuncttest123.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=" -v +curl "https://.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=" -v + +# Get source code using SCM access (Azure permissions or SCM creds) +az rest --method GET \ +--url "https://.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=" \ +--resource "https://management.azure.com/" + +# Get source code with Azure permissions +az rest --url "https://management.azure.com/subscriptions//resourceGroups//providers/Microsoft.Web/sites//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//resourceGroups//providers/Microsoft.Web/sites//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. diff --git a/theme/elasticlunr.min.js b/theme/elasticlunr.min.js new file mode 100644 index 000000000..32cb1bce1 --- /dev/null +++ b/theme/elasticlunr.min.js @@ -0,0 +1,10 @@ +/** + * elasticlunr - http://weixsong.github.io + * Lightweight full-text search engine in Javascript for browser search and offline search. - 0.9.5 + * + * Copyright (C) 2016 Oliver Nightingale + * Copyright (C) 2016 Wei Song + * MIT Licensed + * @license + */ +!function(){function e(e){if(null===e||"object"!=typeof e)return e;var t=e.constructor();for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.9.5",lunr=t,t.utils={},t.utils.warn=function(e){return function(t){e.console&&console.warn&&console.warn(t)}}(this),t.utils.toString=function(e){return void 0===e||null===e?"":e.toString()},t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var e=Array.prototype.slice.call(arguments),t=e.pop(),n=e;if("function"!=typeof t)throw new TypeError("last argument must be a function");n.forEach(function(e){this.hasHandler(e)||(this.events[e]=[]),this.events[e].push(t)},this)},t.EventEmitter.prototype.removeListener=function(e,t){if(this.hasHandler(e)){var n=this.events[e].indexOf(t);-1!==n&&(this.events[e].splice(n,1),0==this.events[e].length&&delete this.events[e])}},t.EventEmitter.prototype.emit=function(e){if(this.hasHandler(e)){var t=Array.prototype.slice.call(arguments,1);this.events[e].forEach(function(e){e.apply(void 0,t)},this)}},t.EventEmitter.prototype.hasHandler=function(e){return e in this.events},t.tokenizer=function(e){if(!arguments.length||null===e||void 0===e)return[];if(Array.isArray(e)){var n=e.filter(function(e){return null===e||void 0===e?!1:!0});n=n.map(function(e){return t.utils.toString(e).toLowerCase()});var i=[];return n.forEach(function(e){var n=e.split(t.tokenizer.seperator);i=i.concat(n)},this),i}return e.toString().trim().toLowerCase().split(t.tokenizer.seperator)},t.tokenizer.defaultSeperator=/[\s\-]+/,t.tokenizer.seperator=t.tokenizer.defaultSeperator,t.tokenizer.setSeperator=function(e){null!==e&&void 0!==e&&"object"==typeof e&&(t.tokenizer.seperator=e)},t.tokenizer.resetSeperator=function(){t.tokenizer.seperator=t.tokenizer.defaultSeperator},t.tokenizer.getSeperator=function(){return t.tokenizer.seperator},t.Pipeline=function(){this._queue=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in t.Pipeline.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[n]=e},t.Pipeline.getRegisteredFunction=function(e){return e in t.Pipeline.registeredFunctions!=!0?null:t.Pipeline.registeredFunctions[e]},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.getRegisteredFunction(e);if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._queue.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i+1,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._queue.indexOf(e);if(-1===i)throw new Error("Cannot find existingFn");this._queue.splice(i,0,n)},t.Pipeline.prototype.remove=function(e){var t=this._queue.indexOf(e);-1!==t&&this._queue.splice(t,1)},t.Pipeline.prototype.run=function(e){for(var t=[],n=e.length,i=this._queue.length,o=0;n>o;o++){for(var r=e[o],s=0;i>s&&(r=this._queue[s](r,o,e),void 0!==r&&null!==r);s++);void 0!==r&&null!==r&&t.push(r)}return t},t.Pipeline.prototype.reset=function(){this._queue=[]},t.Pipeline.prototype.get=function(){return this._queue},t.Pipeline.prototype.toJSON=function(){return this._queue.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.DocumentStore,this.index={},this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var e=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,e)},t.Index.prototype.off=function(e,t){return this.eventEmitter.removeListener(e,t)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;n._fields=e.fields,n._ref=e.ref,n.documentStore=t.DocumentStore.load(e.documentStore),n.pipeline=t.Pipeline.load(e.pipeline),n.index={};for(var i in e.index)n.index[i]=t.InvertedIndex.load(e.index[i]);return n},t.Index.prototype.addField=function(e){return this._fields.push(e),this.index[e]=new t.InvertedIndex,this},t.Index.prototype.setRef=function(e){return this._ref=e,this},t.Index.prototype.saveDocument=function(e){return this.documentStore=new t.DocumentStore(e),this},t.Index.prototype.addDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.addDoc(i,e),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));this.documentStore.addFieldLength(i,n,o.length);var r={};o.forEach(function(e){e in r?r[e]+=1:r[e]=1},this);for(var s in r){var u=r[s];u=Math.sqrt(u),this.index[n].addToken(s,{ref:i,tf:u})}},this),n&&this.eventEmitter.emit("add",e,this)}},t.Index.prototype.removeDocByRef=function(e){if(e&&this.documentStore.isDocStored()!==!1&&this.documentStore.hasDoc(e)){var t=this.documentStore.getDoc(e);this.removeDoc(t,!1)}},t.Index.prototype.removeDoc=function(e,n){if(e){var n=void 0===n?!0:n,i=e[this._ref];this.documentStore.hasDoc(i)&&(this.documentStore.removeDoc(i),this._fields.forEach(function(n){var o=this.pipeline.run(t.tokenizer(e[n]));o.forEach(function(e){this.index[n].removeToken(e,i)},this)},this),n&&this.eventEmitter.emit("remove",e,this))}},t.Index.prototype.updateDoc=function(e,t){var t=void 0===t?!0:t;this.removeDocByRef(e[this._ref],!1),this.addDoc(e,!1),t&&this.eventEmitter.emit("update",e,this)},t.Index.prototype.idf=function(e,t){var n="@"+t+"/"+e;if(Object.prototype.hasOwnProperty.call(this._idfCache,n))return this._idfCache[n];var i=this.index[t].getDocFreq(e),o=1+Math.log(this.documentStore.length/(i+1));return this._idfCache[n]=o,o},t.Index.prototype.getFields=function(){return this._fields.slice()},t.Index.prototype.search=function(e,n){if(!e)return[];var i=null;null!=n&&(i=JSON.stringify(n));var o=new t.Configuration(i,this.getFields()).get(),r=this.pipeline.run(t.tokenizer(e)),s={};for(var u in o){var a=this.fieldSearch(r,u,o),l=o[u].boost;for(var d in a)a[d]=a[d]*l;for(var d in a)d in s?s[d]+=a[d]:s[d]=a[d]}var c=[];for(var d in s)c.push({ref:d,score:s[d]});return c.sort(function(e,t){return t.score-e.score}),c},t.Index.prototype.fieldSearch=function(e,t,n){var i=n[t].bool,o=n[t].expand,r=n[t].boost,s=null,u={};return 0!==r?(e.forEach(function(e){var n=[e];1==o&&(n=this.index[t].expandToken(e));var r={};n.forEach(function(n){var o=this.index[t].getDocs(n),a=this.idf(n,t);if(s&&"AND"==i){var l={};for(var d in s)d in o&&(l[d]=o[d]);o=l}n==e&&this.fieldSearchStats(u,n,o);for(var d in o){var c=this.index[t].getTermFrequency(n,d),f=this.documentStore.getFieldLength(d,t),h=1;0!=f&&(h=1/Math.sqrt(f));var p=1;n!=e&&(p=.15*(1-(n.length-e.length)/n.length));var v=c*a*h*p;d in r?r[d]+=v:r[d]=v}},this),s=this.mergeScores(s,r,i)},this),s=this.coordNorm(s,u,e.length)):void 0},t.Index.prototype.mergeScores=function(e,t,n){if(!e)return t;if("AND"==n){var i={};for(var o in t)o in e&&(i[o]=e[o]+t[o]);return i}for(var o in t)o in e?e[o]+=t[o]:e[o]=t[o];return e},t.Index.prototype.fieldSearchStats=function(e,t,n){for(var i in n)i in e?e[i].push(t):e[i]=[t]},t.Index.prototype.coordNorm=function(e,t,n){for(var i in e)if(i in t){var o=t[i].length;e[i]=e[i]*o/n}return e},t.Index.prototype.toJSON=function(){var e={};return this._fields.forEach(function(t){e[t]=this.index[t].toJSON()},this),{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),index:e,pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(e){var t=Array.prototype.slice.call(arguments,1);t.unshift(this),e.apply(this,t)},t.DocumentStore=function(e){this._save=null===e||void 0===e?!0:e,this.docs={},this.docInfo={},this.length=0},t.DocumentStore.load=function(e){var t=new this;return t.length=e.length,t.docs=e.docs,t.docInfo=e.docInfo,t._save=e.save,t},t.DocumentStore.prototype.isDocStored=function(){return this._save},t.DocumentStore.prototype.addDoc=function(t,n){this.hasDoc(t)||this.length++,this.docs[t]=this._save===!0?e(n):null},t.DocumentStore.prototype.getDoc=function(e){return this.hasDoc(e)===!1?null:this.docs[e]},t.DocumentStore.prototype.hasDoc=function(e){return e in this.docs},t.DocumentStore.prototype.removeDoc=function(e){this.hasDoc(e)&&(delete this.docs[e],delete this.docInfo[e],this.length--)},t.DocumentStore.prototype.addFieldLength=function(e,t,n){null!==e&&void 0!==e&&0!=this.hasDoc(e)&&(this.docInfo[e]||(this.docInfo[e]={}),this.docInfo[e][t]=n)},t.DocumentStore.prototype.updateFieldLength=function(e,t,n){null!==e&&void 0!==e&&0!=this.hasDoc(e)&&this.addFieldLength(e,t,n)},t.DocumentStore.prototype.getFieldLength=function(e,t){return null===e||void 0===e?0:e in this.docs&&t in this.docInfo[e]?this.docInfo[e][t]:0},t.DocumentStore.prototype.toJSON=function(){return{docs:this.docs,docInfo:this.docInfo,length:this.length,save:this._save}},t.stemmer=function(){var e={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},t={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,u="^("+o+")?"+r+o+"("+r+")?$",a="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,d=new RegExp(s),c=new RegExp(a),f=new RegExp(u),h=new RegExp(l),p=/^(.+?)(ss|i)es$/,v=/^(.+?)([^s])s$/,g=/^(.+?)eed$/,m=/^(.+?)(ed|ing)$/,y=/.$/,S=/(at|bl|iz)$/,x=new RegExp("([^aeiouylsz])\\1$"),w=new RegExp("^"+o+i+"[^aeiouwxy]$"),I=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,D=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,_=/^(.+?)e$/,P=/ll$/,k=new RegExp("^"+o+i+"[^aeiouwxy]$"),z=function(n){var i,o,r,s,u,a,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,u=v,s.test(n)?n=n.replace(s,"$1$2"):u.test(n)&&(n=n.replace(u,"$1$2")),s=g,u=m,s.test(n)){var z=s.exec(n);s=d,s.test(z[1])&&(s=y,n=n.replace(s,""))}else if(u.test(n)){var z=u.exec(n);i=z[1],u=h,u.test(i)&&(n=i,u=S,a=x,l=w,u.test(n)?n+="e":a.test(n)?(s=y,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=I,s.test(n)){var z=s.exec(n);i=z[1],n=i+"i"}if(s=b,s.test(n)){var z=s.exec(n);i=z[1],o=z[2],s=d,s.test(i)&&(n=i+e[o])}if(s=E,s.test(n)){var z=s.exec(n);i=z[1],o=z[2],s=d,s.test(i)&&(n=i+t[o])}if(s=D,u=F,s.test(n)){var z=s.exec(n);i=z[1],s=c,s.test(i)&&(n=i)}else if(u.test(n)){var z=u.exec(n);i=z[1]+z[2],u=c,u.test(i)&&(n=i)}if(s=_,s.test(n)){var z=s.exec(n);i=z[1],s=c,u=f,a=k,(s.test(i)||u.test(i)&&!a.test(i))&&(n=i)}return s=P,u=c,s.test(n)&&u.test(n)&&(s=y,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return z}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==!0?e:void 0},t.clearStopWords=function(){t.stopWordFilter.stopWords={}},t.addStopWords=function(e){null!=e&&Array.isArray(e)!==!1&&e.forEach(function(e){t.stopWordFilter.stopWords[e]=!0},this)},t.resetStopWords=function(){t.stopWordFilter.stopWords=t.defaultStopWords},t.defaultStopWords={"":!0,a:!0,able:!0,about:!0,across:!0,after:!0,all:!0,almost:!0,also:!0,am:!0,among:!0,an:!0,and:!0,any:!0,are:!0,as:!0,at:!0,be:!0,because:!0,been:!0,but:!0,by:!0,can:!0,cannot:!0,could:!0,dear:!0,did:!0,"do":!0,does:!0,either:!0,"else":!0,ever:!0,every:!0,"for":!0,from:!0,get:!0,got:!0,had:!0,has:!0,have:!0,he:!0,her:!0,hers:!0,him:!0,his:!0,how:!0,however:!0,i:!0,"if":!0,"in":!0,into:!0,is:!0,it:!0,its:!0,just:!0,least:!0,let:!0,like:!0,likely:!0,may:!0,me:!0,might:!0,most:!0,must:!0,my:!0,neither:!0,no:!0,nor:!0,not:!0,of:!0,off:!0,often:!0,on:!0,only:!0,or:!0,other:!0,our:!0,own:!0,rather:!0,said:!0,say:!0,says:!0,she:!0,should:!0,since:!0,so:!0,some:!0,than:!0,that:!0,the:!0,their:!0,them:!0,then:!0,there:!0,these:!0,they:!0,"this":!0,tis:!0,to:!0,too:!0,twas:!0,us:!0,wants:!0,was:!0,we:!0,were:!0,what:!0,when:!0,where:!0,which:!0,"while":!0,who:!0,whom:!0,why:!0,will:!0,"with":!0,would:!0,yet:!0,you:!0,your:!0},t.stopWordFilter.stopWords=t.defaultStopWords,t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(e){if(null===e||void 0===e)throw new Error("token should not be undefined");return e.replace(/^\W+/,"").replace(/\W+$/,"")},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.InvertedIndex=function(){this.root={docs:{},df:0}},t.InvertedIndex.load=function(e){var t=new this;return t.root=e.root,t},t.InvertedIndex.prototype.addToken=function(e,t,n){for(var n=n||this.root,i=0;i<=e.length-1;){var o=e[i];o in n||(n[o]={docs:{},df:0}),i+=1,n=n[o]}var r=t.ref;n.docs[r]?n.docs[r]={tf:t.tf}:(n.docs[r]={tf:t.tf},n.df+=1)},t.InvertedIndex.prototype.hasToken=function(e){if(!e)return!1;for(var t=this.root,n=0;n0&&t.push(e);for(var i in n)"docs"!==i&&"df"!==i&&this.expandToken(e+i,t,n[i]);return t},t.InvertedIndex.prototype.toJSON=function(){return{root:this.root}},t.Configuration=function(e,n){var e=e||"";if(void 0==n||null==n)throw new Error("fields should not be null");this.config={};var i;try{i=JSON.parse(e),this.buildUserConfig(i,n)}catch(o){t.utils.warn("user configuration parse failed, will use default configuration"),this.buildDefaultConfig(n)}},t.Configuration.prototype.buildDefaultConfig=function(e){this.reset(),e.forEach(function(e){this.config[e]={boost:1,bool:"OR",expand:!1}},this)},t.Configuration.prototype.buildUserConfig=function(e,n){var i="OR",o=!1;if(this.reset(),"bool"in e&&(i=e.bool||i),"expand"in e&&(o=e.expand||o),"fields"in e)for(var r in e.fields)if(n.indexOf(r)>-1){var s=e.fields[r],u=o;void 0!=s.expand&&(u=s.expand),this.config[r]={boost:s.boost||0===s.boost?s.boost:1,bool:s.bool||i,expand:u}}else t.utils.warn("field name in user configuration not found in index instance fields");else this.addAllFields2UserConfig(i,o,n)},t.Configuration.prototype.addAllFields2UserConfig=function(e,t,n){n.forEach(function(n){this.config[n]={boost:1,bool:e,expand:t}},this)},t.Configuration.prototype.get=function(){return this.config},t.Configuration.prototype.reset=function(){this.config={}},lunr.SortedSet=function(){this.length=0,this.elements=[]},lunr.SortedSet.load=function(e){var t=new this;return t.elements=e,t.length=e.length,t},lunr.SortedSet.prototype.add=function(){var e,t;for(e=0;e1;){if(r===e)return o;e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o]}return r===e?o:-1},lunr.SortedSet.prototype.locationFor=function(e){for(var t=0,n=this.elements.length,i=n-t,o=t+Math.floor(i/2),r=this.elements[o];i>1;)e>r&&(t=o),r>e&&(n=o),i=n-t,o=t+Math.floor(i/2),r=this.elements[o];return r>e?o:e>r?o+1:void 0},lunr.SortedSet.prototype.intersect=function(e){for(var t=new lunr.SortedSet,n=0,i=0,o=this.length,r=e.length,s=this.elements,u=e.elements;;){if(n>o-1||i>r-1)break;s[n]!==u[i]?s[n]u[i]&&i++:(t.add(s[n]),n++,i++)}return t},lunr.SortedSet.prototype.clone=function(){var e=new lunr.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},lunr.SortedSet.prototype.union=function(e){var t,n,i;this.length>=e.length?(t=this,n=e):(t=e,n=this),i=t.clone();for(var o=0,r=n.toArray();o { "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. Web‑Worker 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': '>', - '"': '"', - "'": ''' - }; - 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 '' + result.doc.breadcrumbs - + '' - + teaser + '' + ''; - } - - 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 . - 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 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("") - } - index = word[2] + word[0].length; - teaser_split.push(body.substring(word[2], index)); - if (word[1] == searchterm_weight) { - teaser_split.push("") - } - }; - - 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); \ No newline at end of file + }); + } + 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={'&':'&','<':'<','>':'>','"':'"','\'':'''};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'); out.push(body.substr(pos,w.length)); if(wt===W_S) out.push(''); 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 ``+ + `${d.breadcrumbs}${isCloud}${teaser}`; + } + + /* ───────────── 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); + }; + })(); + \ No newline at end of file