mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-06-12 19:11:44 -07:00
Translated ['src/pentesting-cloud/azure-security/az-privilege-escalation
This commit is contained in:
@@ -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)
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 68 KiB |
+150
-174
@@ -4,7 +4,7 @@
|
||||
|
||||
## App Services
|
||||
|
||||
For more information about Azure App services check:
|
||||
Azure App 서비스에 대한 자세한 정보는 다음을 확인하세요:
|
||||
|
||||
{{#ref}}
|
||||
../az-services/az-app-services.md
|
||||
@@ -12,17 +12,14 @@ For more information about Azure App services check:
|
||||
|
||||
### Microsoft.Web/sites/publish/Action, Microsoft.Web/sites/basicPublishingCredentialsPolicies/read, Microsoft.Web/sites/config/read, Microsoft.Web/sites/read
|
||||
|
||||
These permissions allow to get a **SSH shell** inside a web app. They also allow to **debug** the application.
|
||||
|
||||
- **SSH in single command**:
|
||||
이 권한은 웹 앱 내에서 **SSH 셸**에 접근할 수 있게 해줍니다. 또한 애플리케이션을 **디버그**할 수 있게 해줍니다.
|
||||
|
||||
- **단일 명령으로 SSH**:
|
||||
```bash
|
||||
# Direct option
|
||||
az webapp ssh --name <name> --resource-group <res-group>
|
||||
```
|
||||
|
||||
- **Create tunnel and then connect to SSH**:
|
||||
|
||||
- **터널을 생성한 후 SSH에 연결**:
|
||||
```bash
|
||||
az webapp create-remote-connection --name <name> --resource-group <res-group>
|
||||
|
||||
@@ -35,152 +32,146 @@ az webapp create-remote-connection --name <name> --resource-group <res-group>
|
||||
## So from that machine ssh into that port (you might need generate a new ssh session to the jump host)
|
||||
ssh root@127.0.0.1 -p 39895
|
||||
```
|
||||
- **애플리케이션 디버깅**:
|
||||
1. VScode에 Azure 확장을 설치합니다.
|
||||
2. Azure 계정으로 확장에 로그인합니다.
|
||||
3. 구독 내 모든 App 서비스를 나열합니다.
|
||||
4. 디버깅할 App 서비스를 선택하고, 마우스 오른쪽 버튼을 클릭한 후 "디버깅 시작"을 선택합니다.
|
||||
5. 앱에 디버깅이 활성화되어 있지 않으면, 확장이 이를 활성화하려고 시도하지만, 귀하의 계정은 이를 수행하기 위해 `Microsoft.Web/sites/config/write` 권한이 필요합니다.
|
||||
|
||||
- **Debug the application**:
|
||||
1. Install the Azure extension in VScode.
|
||||
2. Login in the extension with the Azure account.
|
||||
3. List all the App services inside the subscription.
|
||||
4. Select the App service you want to debug, right click and select "Start Debugging".
|
||||
5. If the app doesn't have debugging enabled, the extension will try to enable it but your account needs the permission `Microsoft.Web/sites/config/write` to do so.
|
||||
### SCM 자격 증명 얻기 및 기본 인증 활성화
|
||||
|
||||
### Obtaining SCM Credentials & Enabling Basic Authentication
|
||||
|
||||
To obtain the SCM credentials, you can use the following **commands and permissions**:
|
||||
|
||||
- The permission **`Microsoft.Web/sites/publishxml/action`** allows to call:
|
||||
SCM 자격 증명을 얻으려면 다음 **명령 및 권한**을 사용할 수 있습니다:
|
||||
|
||||
- 권한 **`Microsoft.Web/sites/publishxml/action`**은 호출을 허용합니다:
|
||||
```bash
|
||||
az webapp deployment list-publishing-profiles --name <app-name> --resource-group <res-group>
|
||||
# Example output
|
||||
[
|
||||
{
|
||||
"SQLServerDBConnectionString": "",
|
||||
"controlPanelLink": "https://portal.azure.com",
|
||||
"databases": null,
|
||||
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
|
||||
"hostingProviderForumLink": "",
|
||||
"msdeploySite": "happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"mySQLDBConnectionString": "",
|
||||
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Web Deploy",
|
||||
"publishMethod": "MSDeploy",
|
||||
"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443",
|
||||
"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
|
||||
"webSystem": "WebSites"
|
||||
},
|
||||
{
|
||||
"SQLServerDBConnectionString": "",
|
||||
"controlPanelLink": "https://portal.azure.com",
|
||||
"databases": null,
|
||||
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
|
||||
"ftpPassiveMode": "True",
|
||||
"hostingProviderForumLink": "",
|
||||
"mySQLDBConnectionString": "",
|
||||
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - FTP",
|
||||
"publishMethod": "FTP",
|
||||
"publishUrl": "ftps://waws-prod-yt1-067.ftp.azurewebsites.windows.net/site/wwwroot",
|
||||
"userName": "happy-bay-0d8f842ef57843c89185d452c1cede2a\\$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
|
||||
"webSystem": "WebSites"
|
||||
},
|
||||
{
|
||||
"SQLServerDBConnectionString": "",
|
||||
"controlPanelLink": "https://portal.azure.com",
|
||||
"databases": null,
|
||||
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
|
||||
"hostingProviderForumLink": "",
|
||||
"mySQLDBConnectionString": "",
|
||||
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Zip Deploy",
|
||||
"publishMethod": "ZipDeploy",
|
||||
"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443",
|
||||
"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
|
||||
"webSystem": "WebSites"
|
||||
}
|
||||
"SQLServerDBConnectionString": "",
|
||||
"controlPanelLink": "https://portal.azure.com",
|
||||
"databases": null,
|
||||
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
|
||||
"hostingProviderForumLink": "",
|
||||
"msdeploySite": "happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"mySQLDBConnectionString": "",
|
||||
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Web Deploy",
|
||||
"publishMethod": "MSDeploy",
|
||||
"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443",
|
||||
"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
|
||||
"webSystem": "WebSites"
|
||||
},
|
||||
{
|
||||
"SQLServerDBConnectionString": "",
|
||||
"controlPanelLink": "https://portal.azure.com",
|
||||
"databases": null,
|
||||
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
|
||||
"ftpPassiveMode": "True",
|
||||
"hostingProviderForumLink": "",
|
||||
"mySQLDBConnectionString": "",
|
||||
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - FTP",
|
||||
"publishMethod": "FTP",
|
||||
"publishUrl": "ftps://waws-prod-yt1-067.ftp.azurewebsites.windows.net/site/wwwroot",
|
||||
"userName": "happy-bay-0d8f842ef57843c89185d452c1cede2a\\$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
|
||||
"webSystem": "WebSites"
|
||||
},
|
||||
{
|
||||
"SQLServerDBConnectionString": "",
|
||||
"controlPanelLink": "https://portal.azure.com",
|
||||
"databases": null,
|
||||
"destinationAppUrl": "https://happy-bay-0d8f842ef57843c89185d452c1cede2a.azurewebsites.net",
|
||||
"hostingProviderForumLink": "",
|
||||
"mySQLDBConnectionString": "",
|
||||
"profileName": "happy-bay-0d8f842ef57843c89185d452c1cede2a - Zip Deploy",
|
||||
"publishMethod": "ZipDeploy",
|
||||
"publishUrl": "happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net:443",
|
||||
"userName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"userPWD": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
|
||||
"webSystem": "WebSites"
|
||||
}
|
||||
]
|
||||
```
|
||||
**사용자 이름은 항상 동일합니다** (FTP에서는 앱 이름이 앞에 추가됨) 하지만 **비밀번호는 모두 동일합니다**.
|
||||
|
||||
Note how the **username is always the same** (except in FTP which ads the name of the app at the beginning) but the **password is the same** for all of them.
|
||||
|
||||
Moreover, the **SCM URL is `<app-name>.scm.azurewebsites.net`**.
|
||||
|
||||
- The permission **`Microsoft.Web/sites/config/list/action`** allows to call:
|
||||
또한, **SCM URL은 `<app-name>.scm.azurewebsites.net`**입니다.
|
||||
|
||||
- 권한 **`Microsoft.Web/sites/config/list/action`**은 호출을 허용합니다:
|
||||
```bash
|
||||
az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>
|
||||
# Example output
|
||||
{
|
||||
"id": "/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/carlos_rg_3170/providers/Microsoft.Web/sites/happy-bay-0d8f842ef57843c89185d452c1cede2a/publishingcredentials/$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"kind": null,
|
||||
"location": "Canada Central",
|
||||
"name": "happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"publishingPassword": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
|
||||
"publishingPasswordHash": null,
|
||||
"publishingPasswordHashSalt": null,
|
||||
"publishingUserName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"resourceGroup": "carlos_rg_3170",
|
||||
"scmUri": "https://$happy-bay-0d8f842ef57843c89185d452c1cede2a:bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS@happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net",
|
||||
"type": "Microsoft.Web/sites/publishingcredentials"
|
||||
"id": "/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/carlos_rg_3170/providers/Microsoft.Web/sites/happy-bay-0d8f842ef57843c89185d452c1cede2a/publishingcredentials/$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"kind": null,
|
||||
"location": "Canada Central",
|
||||
"name": "happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"publishingPassword": "bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS",
|
||||
"publishingPasswordHash": null,
|
||||
"publishingPasswordHashSalt": null,
|
||||
"publishingUserName": "$happy-bay-0d8f842ef57843c89185d452c1cede2a",
|
||||
"resourceGroup": "carlos_rg_3170",
|
||||
"scmUri": "https://$happy-bay-0d8f842ef57843c89185d452c1cede2a:bgrMliuJayY5btkKl9vRNuit7HEqXfnL9w7iv5l2Gh2Q2mAyCdCS1LPfi3zS@happy-bay-0d8f842ef57843c89185d452c1cede2a.scm.azurewebsites.net",
|
||||
"type": "Microsoft.Web/sites/publishingcredentials"
|
||||
}
|
||||
```
|
||||
**자격 증명이 이전 명령과 동일하다는 점에 유의하세요.**
|
||||
|
||||
Note how the **credentials are the same** as in the previous command.
|
||||
|
||||
- Another option would be to **set you own creds** and use them:
|
||||
|
||||
- 또 다른 옵션은 **자신의 자격 증명을 설정하고 사용하는 것**입니다:
|
||||
```bash
|
||||
# Show if any user is configured (password won't be shown)
|
||||
az webapp deployment user show
|
||||
|
||||
# Set your own credentials
|
||||
az webapp deployment user set \
|
||||
--user-name hacktricks \
|
||||
--password 'W34kP@ssw0rd123!'
|
||||
--user-name hacktricks \
|
||||
--password 'W34kP@ssw0rd123!'
|
||||
|
||||
# To delete it, check https://stackoverflow.com/questions/45275329/remove-deployment-credentials-from-azure-webapp
|
||||
```
|
||||
그런 다음, 이 자격 증명을 사용하여 **SCM 및 FTP 플랫폼에 액세스할 수 있습니다**. 이는 지속성을 유지하는 훌륭한 방법이기도 합니다.
|
||||
|
||||
Then, you can use this credentials to **access the SCM and FTP platforms**. This is also a great way to maintain persistence.
|
||||
|
||||
Remember that to access the SCM platform from the **web you need to access to `<SCM-URL>/BasicAuth`**.
|
||||
**웹에서 SCM 플랫폼에 액세스하려면 `<SCM-URL>/BasicAuth`에 액세스해야 합니다**.
|
||||
|
||||
> [!WARNING]
|
||||
> Note that every user can configure it's own credentials calling the previous command, but if the user doesn't have enough permissions to access the SCM or FTP, the credentials won't work.
|
||||
|
||||
- If you see that those credentials are **REDACTED**, it's because you **need to enable the SCM basic authentication option** and for that you need the second permission (`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write`):
|
||||
> 모든 사용자가 이전 명령을 호출하여 자신의 자격 증명을 구성할 수 있지만, 사용자가 SCM 또는 FTP에 액세스할 수 있는 충분한 권한이 없으면 자격 증명이 작동하지 않습니다.
|
||||
|
||||
- 자격 증명이 **REDACTED**로 표시되면, 이는 **SCM 기본 인증 옵션을 활성화해야 하기 때문이며**, 이를 위해 두 번째 권한(`Microsoft.Web/sites/basicPublishingCredentialsPolicies/write`)이 필요합니다:
|
||||
```bash
|
||||
# Enable basic authentication for SCM
|
||||
az rest --method PUT \
|
||||
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \
|
||||
--body '{
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}'
|
||||
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/scm?api-version=2022-03-01" \
|
||||
--body '{
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}'
|
||||
|
||||
# Enable basic authentication for FTP
|
||||
az rest --method PUT \
|
||||
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \
|
||||
--body '{
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}'
|
||||
--uri "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/basicPublishingCredentialsPolicies/ftp?api-version=2022-03-01" \
|
||||
--body '{
|
||||
"properties": {
|
||||
"allow": true
|
||||
}
|
||||
}'
|
||||
```
|
||||
### SCM 자격 증명을 사용하여 코드 게시
|
||||
|
||||
### Publish code using SCM credentials
|
||||
유효한 SCM 자격 증명만 있으면 **코드**를 App 서비스에 **게시**할 수 있습니다. 이는 다음 명령을 사용하여 수행할 수 있습니다.
|
||||
|
||||
Just having valid SCM credentials it's possible to **publish code** to the App service. This can be done using the following command.
|
||||
|
||||
For this python example you can download the repo from https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart, do any **changes** you wish and then **zip it running: `zip -r app.zip .`**.
|
||||
|
||||
Then you can **publish the code** in a web app with the following command:
|
||||
이 파이썬 예제를 위해 https://github.com/Azure-Samples/msdocs-python-flask-webapp-quickstart에서 리포를 다운로드하고 원하는 **변경**을 한 다음 **`zip -r app.zip .`**을 실행하여 압축할 수 있습니다.
|
||||
|
||||
그런 다음 다음 명령을 사용하여 웹 앱에 **코드를 게시**할 수 있습니다:
|
||||
```bash
|
||||
curl -X POST "<SMC-URL>/api/publish?type=zip" --data-binary "@./app.zip" -u '<username>:<password>' -H "Content-Type: application/octet-stream"
|
||||
```
|
||||
### Webjobs: Microsoft.Web/sites/publish/Action | SCM 자격 증명
|
||||
|
||||
### Webjobs: Microsoft.Web/sites/publish/Action | SCM credentials
|
||||
|
||||
The mentioned Azure permission allows to perform several interesting actions that can also be performed with the SCM credentials:
|
||||
|
||||
- Read **Webjobs** logs:
|
||||
언급된 Azure 권한은 SCM 자격 증명으로 수행할 수 있는 여러 흥미로운 작업을 수행할 수 있습니다:
|
||||
|
||||
- **Webjobs** 로그 읽기:
|
||||
```bash
|
||||
# Using Azure credentials
|
||||
az rest --method GET --url "<SCM-URL>/vfs/data/jobs/<continuous | triggered>/rev5/job_log.txt" --resource "https://management.azure.com/"
|
||||
@@ -188,123 +179,108 @@ az rest --method GET --url "https://lol-b5fyaeceh4e9dce0.scm.canadacentral-01.az
|
||||
|
||||
# Using SCM username and password:
|
||||
curl "<SCM-URL>/vfs/data/jobs/continuous/job_name/job_log.txt" \
|
||||
--user '<username>:<password>' -v
|
||||
--user '<username>:<password>' -v
|
||||
```
|
||||
|
||||
- Read **Webjobs** source code:
|
||||
|
||||
- **Webjobs** 소스 코드를 읽어보세요:
|
||||
```bash
|
||||
# Using SCM username and password:
|
||||
# Find all the webjobs inside:
|
||||
curl "<SCM-URL>/wwwroot/App_Data/jobs/" \
|
||||
--user '<username>:<password>'
|
||||
--user '<username>:<password>'
|
||||
|
||||
# e.g.
|
||||
curl "https://nodewebapp-agamcvhgg3gkd3hs.scm.canadacentral-01.azurewebsites.net/wwwroot/App_Data/jobs/continuous/job_name/rev.js" \
|
||||
--user '<username>:<password>'
|
||||
--user '<username>:<password>'
|
||||
```
|
||||
|
||||
- Create **continuous Webjob**:
|
||||
|
||||
- **지속적인 Webjob** 생성:
|
||||
```bash
|
||||
# Using Azure permissions
|
||||
az rest \
|
||||
--method put \
|
||||
--uri "https://windowsapptesting-ckbrg3f0hyc8fkgp.scm.canadacentral-01.azurewebsites.net/api/Continuouswebjobs/reverse_shell" \
|
||||
--headers '{"Content-Disposition": "attachment; filename=\"rev.js\""}' \
|
||||
--body "@/Users/username/Downloads/rev.js" \
|
||||
--resource "https://management.azure.com/"
|
||||
--method put \
|
||||
--uri "https://windowsapptesting-ckbrg3f0hyc8fkgp.scm.canadacentral-01.azurewebsites.net/api/Continuouswebjobs/reverse_shell" \
|
||||
--headers '{"Content-Disposition": "attachment; filename=\"rev.js\""}' \
|
||||
--body "@/Users/username/Downloads/rev.js" \
|
||||
--resource "https://management.azure.com/"
|
||||
|
||||
# Using SCM credentials
|
||||
curl -X PUT \
|
||||
"<SCM-URL>/api/Continuouswebjobs/reverse_shell2" \
|
||||
-H 'Content-Disposition: attachment; filename=rev.js' \
|
||||
--data-binary "@/Users/carlospolop/Downloads/rev.js" \
|
||||
--user '<username>:<password>'
|
||||
"<SCM-URL>/api/Continuouswebjobs/reverse_shell2" \
|
||||
-H 'Content-Disposition: attachment; filename=rev.js' \
|
||||
--data-binary "@/Users/carlospolop/Downloads/rev.js" \
|
||||
--user '<username>:<password>'
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/write, Microsoft.Web/sites/read, Microsoft.ManagedIdentity/userAssignedIdentities/assign/action
|
||||
|
||||
These permissions allow to **assign a managed identity** to the App service, so if an App service was previously compromised this will allow the attacker to assign new managed identities to the App service and **escalate privileges** to them.
|
||||
|
||||
이 권한은 **관리형 ID**를 App 서비스에 할당할 수 있게 하므로, 만약 App 서비스가 이전에 침해되었다면 공격자는 App 서비스에 새로운 관리형 ID를 할당하고 **권한을 상승**시킬 수 있습니다.
|
||||
```bash
|
||||
az webapp identity assign --name <app-name> --resource-group <res-group> --identities /subscriptions/<subcripttion-id>/resourceGroups/<res_group>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<managed-identity-name>
|
||||
```
|
||||
|
||||
### Microsoft.Web/sites/config/list/action
|
||||
|
||||
This permission allows to list the **connection strings** and the **appsettings** of the App service which might contain sensitive information like database credentials.
|
||||
|
||||
이 권한은 데이터베이스 자격 증명과 같은 민감한 정보를 포함할 수 있는 App 서비스의 **connection strings** 및 **appsettings**를 나열할 수 있게 해줍니다.
|
||||
```bash
|
||||
az webapp config connection-string list --name <name> --resource-group <res-group>
|
||||
az webapp config appsettings list --name <name> --resource-group <res-group>
|
||||
```
|
||||
### 구성된 제3자 자격 증명 읽기
|
||||
|
||||
### 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.
|
||||
|
||||
다음 명령을 실행하면 현재 계정에 구성된 **제3자 자격 증명**을 읽을 수 있습니다. 예를 들어, 다른 사용자에 구성된 Github 자격 증명이 있는 경우, 다른 사용자에서 토큰에 접근할 수 없음을 유의하십시오.
|
||||
```bash
|
||||
az rest --method GET \
|
||||
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
|
||||
--url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"
|
||||
```
|
||||
이 명령은 Github, Bitbucket, Dropbox 및 OneDrive에 대한 토큰을 반환합니다.
|
||||
|
||||
This command returns tokens for Github, Bitbucket, Dropbox and OneDrive.
|
||||
|
||||
Here you have some command examples to check the tokens:
|
||||
|
||||
여기 토큰을 확인하기 위한 몇 가지 명령 예가 있습니다:
|
||||
```bash
|
||||
# GitHub – List Repositories
|
||||
curl -H "Authorization: token <token>" \
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
https://api.github.com/user/repos
|
||||
-H "Accept: application/vnd.github.v3+json" \
|
||||
https://api.github.com/user/repos
|
||||
|
||||
# Bitbucket – List Repositories
|
||||
curl -H "Authorization: Bearer <token>" \
|
||||
-H "Accept: application/json" \
|
||||
https://api.bitbucket.org/2.0/repositories
|
||||
-H "Accept: application/json" \
|
||||
https://api.bitbucket.org/2.0/repositories
|
||||
|
||||
# Dropbox – List Files in Root Folder
|
||||
curl -X POST https://api.dropboxapi.com/2/files/list_folder \
|
||||
-H "Authorization: Bearer <token>" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data '{"path": ""}'
|
||||
-H "Authorization: Bearer <token>" \
|
||||
-H "Content-Type: application/json" \
|
||||
--data '{"path": ""}'
|
||||
|
||||
# OneDrive – List Files in Root Folder
|
||||
curl -H "Authorization: Bearer <token>" \
|
||||
-H "Accept: application/json" \
|
||||
https://graph.microsoft.com/v1.0/me/drive/root/children
|
||||
-H "Accept: application/json" \
|
||||
https://graph.microsoft.com/v1.0/me/drive/root/children
|
||||
```
|
||||
|
||||
### Update App Code from the source
|
||||
|
||||
- If the configured source is a third-party provider like Github, BitBucket or an Azure Repository, you can **update the code** of the App service by compromising the source code in the repository.
|
||||
- If the app is configured using a **remote git repository** (with username and password), it's possible to get the **URL and basic auth credentials** to clone and push changes with:
|
||||
- Using the permission **`Microsoft.Web/sites/sourcecontrols/read`**: `az webapp deployment source show --name <app-name> --resource-group <res-group>`
|
||||
- Using the permission **`Microsoft.Web/sites/config/list/action`**:
|
||||
- `az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>`
|
||||
- `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`
|
||||
- If the app is configured to use a **local git repository**, it's possible to **clone the repository** and **push changes** to it:
|
||||
- Using the permission **`Microsoft.Web/sites/sourcecontrols/read`**: You can get the URL of the git repo with `az webapp deployment source show --name <app-name> --resource-group <res-group>`, but it's going to be the same as the the SCM URL of the app with the path `/<app-name>.git` (e.g. `https://pythonwebapp-audeh9f5fzeyhhed.scm.canadacentral-01.azurewebsites.net:443/pythonwebapp.git`).
|
||||
- To get the SCM credential you need the permission:
|
||||
- **`Microsoft.Web/sites/publishxml/action`**: Then run `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`.
|
||||
- **`Microsoft.Web/sites/config/list/action`**: Then run `az webapp deployment list-publishing-credentials --name <name> --resource-group <res-group>`
|
||||
- 만약 설정된 소스가 Github, BitBucket 또는 Azure Repository와 같은 제3자 제공업체인 경우, 리포지토리의 소스 코드를 손상시켜 **앱 서비스의 코드를 업데이트**할 수 있습니다.
|
||||
- 앱이 **원격 git 리포지토리**(사용자 이름과 비밀번호 포함)를 사용하도록 구성된 경우, **URL 및 기본 인증 자격 증명**을 얻어 클론하고 변경 사항을 푸시할 수 있습니다:
|
||||
- 권한 **`Microsoft.Web/sites/sourcecontrols/read`** 사용: `az webapp deployment source show --name <app-name> --resource-group <res-group>`
|
||||
- 권한 **`Microsoft.Web/sites/config/list/action`** 사용:
|
||||
- `az webapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>`
|
||||
- `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`
|
||||
- 앱이 **로컬 git 리포지토리**를 사용하도록 구성된 경우, **리포지토리를 클론하고** 변경 사항을 **푸시**할 수 있습니다:
|
||||
- 권한 **`Microsoft.Web/sites/sourcecontrols/read`** 사용: `az webapp deployment source show --name <app-name> --resource-group <res-group>`로 git 리포지토리의 URL을 얻을 수 있지만, 이는 앱의 SCM URL과 동일하며 경로는 `/<app-name>.git`입니다 (예: `https://pythonwebapp-audeh9f5fzeyhhed.scm.canadacentral-01.azurewebsites.net:443/pythonwebapp.git`).
|
||||
- SCM 자격 증명을 얻으려면 다음 권한이 필요합니다:
|
||||
- **`Microsoft.Web/sites/publishxml/action`**: 그런 다음 `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`을 실행합니다.
|
||||
- **`Microsoft.Web/sites/config/list/action`**: 그런 다음 `az webapp deployment list-publishing-credentials --name <name> --resource-group <res-group>`을 실행합니다.
|
||||
|
||||
> [!WARNING]
|
||||
> Note that having the permission `Microsoft.Web/sites/config/list/action` and the SCM credentials it's always possible to deploy into a webapp (even if it was configured to use a third-party provider) as mentioned in a previous section.
|
||||
> 권한 `Microsoft.Web/sites/config/list/action`과 SCM 자격 증명을 가지고 있으면, 이전 섹션에서 언급한 바와 같이 제3자 제공업체를 사용하도록 구성된 경우에도 웹앱에 배포하는 것이 항상 가능합니다.
|
||||
|
||||
> [!WARNING]
|
||||
> Note that having the permissions below it's also **possible to execute an arbitrary container** even if the webapp was configured differently.
|
||||
> 아래 권한을 가지고 있으면 웹앱이 다르게 구성되었더라도 **임의의 컨테이너를 실행하는 것이 가능**합니다.
|
||||
|
||||
### `Microsoft.Web/sites/config/Write`, `Microsoft.Web/sites/config/Read`, `Microsoft.Web/sites/config/list/Action`, `Microsoft.Web/sites/Read`
|
||||
|
||||
This is the set of permissions that allows to **modify the container used** by a webapp. An attacker could abuse it to make a webapp execute a malicious container.
|
||||
|
||||
이 권한 세트는 웹앱에서 사용되는 **컨테이너를 수정**할 수 있게 해줍니다. 공격자는 이를 악용하여 웹앱이 악성 컨테이너를 실행하도록 만들 수 있습니다.
|
||||
```bash
|
||||
az webapp config container set \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest
|
||||
--name <app-name> \
|
||||
--resource-group <res-group> \
|
||||
--docker-custom-image-name mcr.microsoft.com/appsvc/staticsite:latest
|
||||
```
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -13,24 +13,25 @@ Azure App Services는 개발자가 **웹 애플리케이션, 모바일 앱 백
|
||||
- 격리 계층은 **전용 가상 네트워크의 전용 VM**에서 실행되어 앱의 격리를 개선합니다.
|
||||
|
||||
> [!WARNING]
|
||||
> 이러한 격리 중 **어떤 것도** 다른 일반적인 **웹 취약점**(예: 파일 업로드 또는 인젝션)을 **방지하지 않습니다**. 그리고 **관리 ID**가 사용되는 경우, 이를 통해 **권한 상승**이 가능할 수 있습니다.
|
||||
> 이러한 격리 중 **어떤 것도** 다른 일반적인 **웹 취약점**(예: 파일 업로드 또는 인젝션)을 **방지하지 않습니다**. 그리고 **관리 ID**가 사용되는 경우, 이를 통해 **권한을 상승시킬 수 있습니다**.
|
||||
|
||||
앱에는 몇 가지 흥미로운 구성 옵션이 있습니다:
|
||||
|
||||
- **항상 켜짐**: 앱이 항상 실행되도록 보장합니다. 활성화되지 않은 경우, 앱은 20분 동안 비활성 상태가 되면 중지되며 요청이 수신되면 다시 시작됩니다.
|
||||
- **항상 켜짐**: 앱이 항상 실행되도록 보장합니다. 활성화되지 않은 경우, 앱은 20분의 비활동 후 중지되며 요청이 수신되면 다시 시작됩니다.
|
||||
- 웹잡이 지속적으로 실행되어야 하는 경우 필수적입니다. 앱이 중지되면 웹잡도 중지됩니다.
|
||||
- **SSH**: 활성화된 경우, 충분한 권한을 가진 사용자가 SSH를 사용하여 앱에 연결할 수 있습니다.
|
||||
- **디버깅**: 활성화된 경우, 충분한 권한을 가진 사용자가 앱을 디버깅할 수 있습니다. 그러나 이는 48시간마다 자동으로 비활성화됩니다.
|
||||
- **웹 앱 + 데이터베이스**: 웹 콘솔을 통해 데이터베이스가 있는 앱을 생성할 수 있습니다. 이 경우 사용할 데이터베이스(SQLAzure, PostgreSQL, MySQL, MongoDB)를 선택할 수 있으며, Azure Cache for Redis를 생성할 수도 있습니다.
|
||||
- 데이터베이스 및 Redis에 대한 자격 증명이 포함된 URL은 **appsettings**에 저장됩니다.
|
||||
- **컨테이너**: 컨테이너의 URL과 액세스 자격 증명을 지정하여 App Service에 컨테이너를 배포할 수 있습니다.
|
||||
- **마운트**: Azure Blob(읽기 전용) 또는 Azure Files에서 스토리지 계정으로부터 5개의 마운트를 생성할 수 있습니다. 구성은 스토리지 계정의 액세스 키를 저장합니다.
|
||||
- **컨테이너**: 컨테이너의 URL과 접근 자격 증명을 지정하여 App Service에 컨테이너를 배포할 수 있습니다.
|
||||
- **마운트**: Azure Blob(읽기 전용) 또는 Azure Files에서 스토리지 계정으로부터 5개의 마운트를 생성할 수 있습니다. 구성은 스토리지 계정에 대한 액세스 키를 저장합니다.
|
||||
- **네트워킹**: 공개적으로 사용 가능하거나 VNet의 개인 엔드포인트만 접근할 수 있습니다.
|
||||
|
||||
## Basic Authentication
|
||||
|
||||
웹 앱(및 일반적으로 Azure 함수)을 생성할 때 **기본 인증을 활성화할지 여부**를 지정할 수 있습니다(기본적으로 비활성화됨). 이는 기본적으로 **SCM(소스 제어 관리자) 및 FTP(파일 전송 프로토콜)**를 애플리케이션에 활성화하여 이러한 기술을 사용하여 애플리케이션을 배포할 수 있도록 합니다.
|
||||
웹 앱(및 일반적으로 Azure 함수)을 생성할 때 **기본 인증을 활성화할지 여부**를 지정할 수 있습니다(기본적으로 비활성화됨). 이는 기본적으로 애플리케이션에 대해 **SCM(소스 제어 관리자) 및 FTP(파일 전송 프로토콜)**를 활성화하여 이러한 기술을 사용하여 애플리케이션을 배포할 수 있도록 합니다.
|
||||
|
||||
SCM 및 FTP 서버에 액세스하려면 **사용자 이름과 비밀번호**가 필요합니다. 따라서 Azure는 이러한 플랫폼에 대한 URL과 자격 증명을 얻기 위한 **API를 제공합니다**.
|
||||
SCM 및 FTP 서버에 접근하려면 **사용자 이름과 비밀번호**가 필요합니다. 따라서 Azure는 이러한 플랫폼에 대한 URL과 자격 증명을 얻기 위한 **API를 제공합니다**.
|
||||
|
||||
**FTP 서버는 특별한 마법이 없습니다**. 유효한 URL, 사용자 이름 및 비밀번호만 있으면 연결하여 앱 환경에 대한 읽기 및 쓰기 권한을 얻을 수 있습니다.
|
||||
|
||||
@@ -41,7 +42,7 @@ SCM
|
||||
|
||||
Kudu는 **SCM과 웹 및 API 인터페이스를 관리**하여 App Service를 관리하고 Git 기반 배포, 원격 디버깅 및 파일 관리 기능을 제공합니다. 웹 앱에 정의된 SCM URL을 통해 접근할 수 있습니다.
|
||||
|
||||
Kudu가 App Services와 Function Apps에서 사용하는 버전은 다르며, Function Apps의 버전은 훨씬 더 제한적입니다.
|
||||
App Services와 Function Apps에서 사용되는 Kudu 버전은 다르며, Function Apps의 버전은 훨씬 더 제한적입니다.
|
||||
|
||||
Kudu에서 찾을 수 있는 몇 가지 흥미로운 엔드포인트는 다음과 같습니다:
|
||||
- `/BasicAuth`: Kudu에 **로그인하기 위해 이 경로에 접근해야 합니다**.
|
||||
@@ -56,28 +57,28 @@ Kudu에서 찾을 수 있는 몇 가지 흥미로운 엔드포인트는 다음
|
||||
|
||||
## Sources
|
||||
|
||||
App Services는 기본적으로 코드를 zip 파일로 업로드할 수 있지만, 타사 서비스에 연결하여 그곳에서 코드를 가져올 수도 있습니다.
|
||||
App Services는 기본적으로 코드를 zip 파일로 업로드할 수 있도록 허용하지만, 타사 서비스에 연결하여 그곳에서 코드를 가져오는 것도 허용합니다.
|
||||
|
||||
- 현재 지원되는 타사 소스는 **Github**와 **Bitbucket**입니다.
|
||||
- 인증 토큰을 얻으려면 `az rest --url "https://management.azure.com/providers/Microsoft.Web/sourcecontrols?api-version=2024-04-01"`을 실행하면 됩니다.
|
||||
- Azure는 기본적으로 코드가 업데이트될 때마다 App Service에 코드를 배포하기 위해 **Github Action**을 설정합니다.
|
||||
- 또한, 그곳에서 코드를 가져오기 위해 **원격 git 저장소**(사용자 이름 및 비밀번호 포함)를 지정할 수 있습니다.
|
||||
- 또한, 그곳에서 코드를 가져오기 위해 **원격 git 저장소**(사용자 이름 및 비밀번호 포함)를 지정할 수도 있습니다.
|
||||
- 원격 저장소에 대한 자격 증명을 얻으려면 `az webapp deployment source show --name <app-name> --resource-group <res-group>` 또는 `az rest --method POST --url "https://management.azure.com/subscriptions/<subscription-id>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/metadata/list?api-version=2022-03-01" --resource "https://management.azure.com"`을 실행하면 됩니다.
|
||||
- **Azure Repository**를 사용할 수도 있습니다.
|
||||
- **로컬 git 저장소**를 구성할 수도 있습니다.
|
||||
- `az webapp deployment source show --name <app-name> --resource-group <res-group>`로 git 저장소의 URL을 얻을 수 있으며, 이는 앱의 SCM URL이 될 것입니다.
|
||||
- 이를 클론하려면 `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`로 얻은 SCM 자격 증명이 필요합니다.
|
||||
- `az webapp deployment source show --name <app-name> --resource-group <res-group>`를 실행하여 git 저장소의 URL을 얻을 수 있으며, 이는 앱의 SCM URL이 될 것입니다.
|
||||
- 이를 클론하려면 `az webapp deployment list-publishing-profiles --resource-group <res-group> -n <name>`를 통해 얻은 SCM 자격 증명이 필요합니다.
|
||||
|
||||
## Webjobs
|
||||
|
||||
Azure WebJobs는 **Azure App Service 환경에서 실행되는 백그라운드 작업**입니다. 개발자가 웹 애플리케이션과 함께 스크립트나 프로그램을 실행할 수 있도록 하여 파일 처리, 데이터 처리 또는 예약된 작업과 같은 비동기 또는 시간 집약적인 작업을 더 쉽게 처리할 수 있게 합니다.
|
||||
웹잡에는 2가지 유형이 있습니다:
|
||||
- **지속적**: 무한 루프에서 실행되며 생성되자마자 트리거됩니다. 지속적인 처리가 필요한 작업에 이상적입니다. 그러나 Always On이 비활성화되어 있고 지난 20분 동안 요청을 받지 않으면 앱이 중지되므로 웹잡도 중지됩니다.
|
||||
- **트리거**: 필요에 따라 또는 일정에 따라 실행됩니다. 배치 데이터 업데이트 또는 유지 관리 루틴과 같은 주기적인 작업에 가장 적합합니다.
|
||||
- **지속적**: 무한 루프에서 실행되며 생성되자마자 트리거됩니다. 지속적인 처리가 필요한 작업에 이상적입니다. 그러나 Always On이 비활성화되어 있고 지난 20분 동안 요청을 받지 않으면 앱이 중지되면서 웹잡도 중지됩니다.
|
||||
- **트리거**: 필요에 따라 또는 일정에 따라 실행됩니다. 배치 데이터 업데이트나 유지 관리 루틴과 같은 주기적인 작업에 가장 적합합니다.
|
||||
|
||||
웹잡은 환경에서 **코드를 실행**하고 연결된 관리 ID에 대한 **권한 상승**에 사용할 수 있기 때문에 공격자의 관점에서 매우 흥미롭습니다.
|
||||
웹잡은 환경에서 **코드를 실행**하고 연결된 관리 ID에 대한 **권한을 상승시킬** 수 있기 때문에 공격자의 관점에서 매우 흥미롭습니다.
|
||||
|
||||
또한, 웹잡이 생성하는 **로그**를 확인하는 것도 항상 흥미롭습니다. 로그에는 **민감한 정보**가 포함될 수 있습니다.
|
||||
또한, 웹잡에서 생성된 **로그**를 확인하는 것도 항상 흥미롭습니다. 로그에는 **민감한 정보**가 포함될 수 있습니다.
|
||||
|
||||
## Slots
|
||||
|
||||
@@ -89,7 +90,7 @@ Azure App Service Slots는 **동일한 App Service에 애플리케이션의 다
|
||||
|
||||
기본적으로 **Azure Function 앱은 Azure App Service의 하위 집합**입니다. 웹 콘솔에 가서 모든 앱 서비스를 나열하거나 az cli에서 `az webapp list`를 실행하면 **Function 앱도 나열된 것을 볼 수 있습니다**.
|
||||
|
||||
따라서 두 서비스는 실제로 대부분 **같은 구성, 기능 및 옵션을 az cli에서 가지고 있으며**, 약간 다르게 구성할 수 있습니다(예: appsettings의 기본값 또는 Function 앱에서 스토리지 계정의 사용).
|
||||
따라서 두 서비스는 실제로 대부분 **같은 구성, 기능 및 옵션을 az cli에서 가지고 있으며**, 약간 다르게 구성할 수 있습니다(예: appsettings의 기본값이나 Function 앱에서 스토리지 계정의 사용).
|
||||
|
||||
## Enumeration
|
||||
|
||||
@@ -176,6 +177,10 @@ az webapp conection list --name <name> --resource-group <res-group>
|
||||
|
||||
# Get hybrid-connections of a webapp
|
||||
az webapp hybrid-connections list --name <name> --resource-group <res-group>
|
||||
|
||||
# Get configured SMC users by your account
|
||||
az webapp deployment user show
|
||||
## If any user is created, the username should appear in the "publishingUserName" field
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
@@ -295,7 +300,7 @@ SCM 포털에 로그인하거나 FTP를 통해 로그인하면 `/wwwroot`에서
|
||||
이 튜토리얼은 이전 튜토리얼을 기반으로 하지만 Github 리포지토리를 사용합니다.
|
||||
|
||||
1. Github 계정에서 msdocs-python-flask-webapp-quickstart 리포를 포크합니다.
|
||||
2. Azure에서 새로운 Python 웹 앱을 생성합니다.
|
||||
2. Azure에서 새로운 Python 웹 앱을 만듭니다.
|
||||
3. `Deployment Center`에서 소스를 변경하고, Github로 로그인한 후 포크한 리포를 선택하고 `Save`를 클릭합니다.
|
||||
|
||||
이전 경우와 마찬가지로 SCM 포털에 로그인하거나 FTP를 통해 로그인하면 `/wwwroot`에서 웹앱의 코드를 포함하는 압축 파일 `output.tar.gz`를 볼 수 있습니다.
|
||||
@@ -309,7 +314,7 @@ SCM 포털에 로그인하거나 FTP를 통해 로그인하면 `/wwwroot`에서
|
||||
../az-privilege-escalation/az-app-services-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
## 참고 문헌
|
||||
## 참조
|
||||
|
||||
- [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)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
## 기본 정보
|
||||
|
||||
**Azure Function Apps**는 **서버리스 컴퓨트 서비스**로, 기본 인프라를 관리하지 않고도 **함수**라고 불리는 작은 코드 조각을 실행할 수 있게 해줍니다. 이들은 **HTTP 요청, 타이머 또는 Blob Storage나 Event Hubs와 같은 다른 Azure 서비스의 이벤트**와 같은 다양한 트리거에 응답하여 코드를 실행하도록 설계되었습니다. Function Apps는 C#, Python, JavaScript, Java를 포함한 여러 프로그래밍 언어를 지원하여 **이벤트 기반 애플리케이션**, 워크플로 자동화 또는 서비스 통합을 구축하는 데 유용합니다. 일반적으로 코드가 실행될 때 사용된 컴퓨트 시간에 대해서만 비용을 지불하므로 비용 효율적입니다.
|
||||
**Azure Function Apps**는 **서버리스 컴퓨트 서비스**로, 기본 인프라를 관리하지 않고도 **함수**라고 불리는 작은 코드 조각을 실행할 수 있게 해줍니다. 이들은 **HTTP 요청, 타이머 또는 Blob Storage나 Event Hubs와 같은 다른 Azure 서비스의 이벤트**와 같은 다양한 트리거에 응답하여 코드를 실행하도록 설계되었습니다. Function Apps는 C#, Python, JavaScript, Java 등 여러 프로그래밍 언어를 지원하여 **이벤트 기반 애플리케이션**, 워크플로 자동화 또는 서비스 통합을 구축하는 데 유용합니다. 일반적으로 코드가 실행될 때 사용된 컴퓨트 시간에 대해서만 비용을 지불하므로 비용 효율적입니다.
|
||||
|
||||
> [!NOTE]
|
||||
> **Functions는 App Services의 하위 집합**이므로, 여기서 논의된 많은 기능은 Azure Apps(`webapp` in cli)로 생성된 애플리케이션에서도 사용됩니다.
|
||||
@@ -12,81 +12,83 @@
|
||||
### 다양한 요금제
|
||||
|
||||
- **Flex Consumption Plan**: 수요에 따라 함수 인스턴스를 추가하거나 제거하는 **동적 이벤트 기반 스케일링**을 제공하며, 사용한 만큼만 지불하는 요금제를 제공합니다. **가상 네트워킹** 및 **사전 프로비저닝된 인스턴스**를 지원하여 콜드 스타트를 줄여주며, 컨테이너 지원이 필요하지 않은 **변동 작업 부하**에 적합합니다.
|
||||
- **Traditional Consumption Plan**: 기본 서버리스 옵션으로, **함수가 실행될 때만 컴퓨트 리소스에 대해 지불**합니다. 수신 이벤트에 따라 자동으로 스케일링되며 **콜드 스타트 최적화**가 포함되어 있지만, 컨테이너 배포는 지원하지 않습니다. 자동 스케일링이 필요한 **간헐적 작업 부하**에 이상적입니다.
|
||||
- **Premium Plan**: **일관된 성능**을 위해 설계되었으며, 콜드 스타트를 없애기 위해 **사전 예열된 작업자**를 제공합니다. **연장된 실행 시간, 가상 네트워킹**을 제공하며 **사용자 정의 Linux 이미지**를 지원하여 높은 성능과 고급 기능이 필요한 **미션 크리티컬 애플리케이션**에 적합합니다.
|
||||
- **Traditional Consumption Plan**: 기본 서버리스 옵션으로, 함수가 실행될 때만 **컴퓨트 리소스에 대해 지불**합니다. 수신 이벤트에 따라 자동으로 스케일링되며 **콜드 스타트 최적화**가 포함되어 있지만, 컨테이너 배포는 지원하지 않습니다. 자동 스케일링이 필요한 **간헐적 작업 부하**에 이상적입니다.
|
||||
- **Premium Plan**: **일관된 성능**을 위해 설계되었으며, 콜드 스타트를 없애기 위해 **사전 예열된 작업자**를 제공합니다. **연장된 실행 시간, 가상 네트워킹**을 제공하며, **사용자 정의 Linux 이미지**를 지원하여 높은 성능과 고급 기능이 필요한 **미션 크리티컬 애플리케이션**에 적합합니다.
|
||||
- **Dedicated Plan**: 예측 가능한 청구가 가능한 전용 가상 머신에서 실행되며, 수동 또는 자동 스케일링을 지원합니다. 동일한 요금제에서 여러 앱을 실행할 수 있으며, **컴퓨트 격리**를 제공하고 App Service Environments를 통해 **안전한 네트워크 액세스**를 보장하여 일관된 리소스 할당이 필요한 **장기 실행 애플리케이션**에 이상적입니다.
|
||||
- **Container Apps**: 관리되는 환경에서 **컨테이너화된 함수 앱**을 배포할 수 있으며, 마이크로서비스 및 API와 함께 사용할 수 있습니다. 사용자 정의 라이브러리, 레거시 앱 마이그레이션 및 **GPU 처리**를 지원하여 Kubernetes 클러스터 관리를 없애줍니다. **이벤트 기반, 확장 가능한 컨테이너화된 애플리케이션**에 적합합니다.
|
||||
- **Container Apps**: 관리되는 환경에서 **컨테이너화된 함수 앱**을 배포할 수 있으며, 마이크로서비스 및 API와 함께 사용할 수 있습니다. 사용자 정의 라이브러리, 레거시 앱 마이그레이션 및 **GPU 처리**를 지원하여 Kubernetes 클러스터 관리를 없앱니다. **이벤트 기반, 확장 가능한 컨테이너화된 애플리케이션**에 적합합니다.
|
||||
|
||||
### **스토리지 버킷**
|
||||
### **저장소 버킷**
|
||||
|
||||
컨테이너화되지 않은 새로운 Function App을 생성할 때, **코드 및 기타 Function 관련 데이터는 스토리지 계정에 저장됩니다**. 기본적으로 웹 콘솔은 코드를 저장하기 위해 함수당 새 스토리지 계정을 생성합니다.
|
||||
컨테이너화되지 않은 새로운 Function App을 생성할 때, **코드 및 기타 Function 관련 데이터는 저장소 계정에 저장됩니다**. 기본적으로 웹 콘솔은 코드를 저장하기 위해 함수당 새 저장소 계정을 생성합니다.
|
||||
|
||||
또한, 버킷 내의 코드를 수정하면 (저장될 수 있는 다양한 형식에서) **앱의 코드가 새 코드로 수정되어 다음에 함수가 호출될 때 실행됩니다**.
|
||||
또한, 버킷 내의 코드를 수정하면 (저장될 수 있는 다양한 형식에서) **앱의 코드가 새 코드로 수정되고 다음에 함수가 호출될 때 실행됩니다**.
|
||||
|
||||
> [!CAUTION]
|
||||
> 공격자의 관점에서 매우 흥미로운 점은 **이 버킷에 대한 쓰기 권한**이 있으면 공격자가 **코드를 손상시키고 Function App 내의 관리되는 ID에 대한 권한을 상승시킬 수 있다는 점입니다.**
|
||||
> 공격자의 관점에서 매우 흥미로운 점은 **이 버킷에 대한 쓰기 권한**이 공격자가 **코드를 손상시키고 Function App 내의 관리되는 ID에 대한 권한을 상승시킬 수 있게 해준다는 것입니다.**
|
||||
>
|
||||
> 이에 대한 자세한 내용은 **권한 상승 섹션**에서 확인할 수 있습니다.
|
||||
|
||||
또한, **`azure-webjobs-secrets`** 컨테이너 내의 스토리지 계정에서 **마스터 및 함수 키**를 찾는 것도 가능합니다. 이 키는 **`<app-name>`** 폴더 내의 JSON 파일에서 찾을 수 있습니다.
|
||||
저장소 계정의 **`azure-webjobs-secrets`** 컨테이너 내에 **마스터 및 함수 키**가 저장되어 있으며, **`<app-name>`** 폴더 내의 JSON 파일에서 찾을 수 있습니다.
|
||||
|
||||
Functions는 또한 코드를 원격 위치에 저장할 수 있으며, 그 URL을 지정하기만 하면 됩니다.
|
||||
|
||||
### 네트워킹
|
||||
|
||||
HTTP 트리거를 사용하여:
|
||||
HTTP 트리거를 사용할 때:
|
||||
|
||||
- **모든 인터넷에서 함수에 대한 액세스를 제공**하거나 IAM 기반으로 액세스를 제공할 수 있습니다. 이 액세스를 제한하는 것도 가능합니다.
|
||||
- **내부 네트워크(VPC)**에서 Function App에 대한 액세스를 **제공하거나 제한**할 수 있습니다.
|
||||
- **인터넷의 모든 사용자에게 함수에 대한 액세스를 제공**하거나 IAM 기반으로 액세스를 제공할 수 있습니다. 이 액세스를 제한하는 것도 가능합니다.
|
||||
- **내부 네트워크(VPC)**에서 Function App에 대한 액세스를 **제공하거나 제한**할 수도 있습니다.
|
||||
|
||||
> [!CAUTION]
|
||||
> 공격자의 관점에서 매우 흥미로운 점은 취약한 Function이 인터넷에 노출되면 **내부 네트워크로 피벗할 수 있는 가능성이 있다는 점입니다.**
|
||||
> 공격자의 관점에서 매우 흥미로운 점은 취약한 Function이 인터넷에 노출되어 있을 경우 **내부 네트워크로 피벗할 수 있는 가능성이 있다는 것입니다.**
|
||||
|
||||
### **Function App 설정 및 환경 변수**
|
||||
|
||||
앱 내에서 환경 변수를 구성할 수 있으며, 이 변수는 민감한 정보를 포함할 수 있습니다. 또한 기본적으로 **`AzureWebJobsStorage`** 및 **`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`**(기타 포함)과 같은 env 변수가 생성됩니다. 이들은 **애플리케이션 데이터가 포함된 스토리지 계정을 완전 권한으로 제어할 수 있는 계정 키를 포함**하고 있어 특히 흥미롭습니다. 이러한 설정은 스토리지 계정에서 코드를 실행하는 데에도 필요합니다.
|
||||
앱 내에서 환경 변수를 구성할 수 있으며, 이 변수는 민감한 정보를 포함할 수 있습니다. 또한 기본적으로 **`AzureWebJobsStorage`** 및 **`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`** (기타 포함)과 같은 환경 변수가 생성됩니다. 이들은 **애플리케이션 데이터가 포함된 저장소 계정을 완전 권한으로 제어하는 계정 키를 포함하고 있기 때문에** 특히 흥미롭습니다. 이러한 설정은 저장소 계정에서 코드를 실행하는 데에도 필요합니다.
|
||||
|
||||
이러한 env 변수 또는 구성 매개변수는 함수가 코드를 실행하는 방식을 제어합니다. 예를 들어 **`WEBSITE_RUN_FROM_PACKAGE`**가 존재하면 애플리케이션 코드가 위치한 URL을 나타냅니다.
|
||||
이러한 환경 변수 또는 구성 매개변수는 Function이 코드를 실행하는 방식을 제어하며, 예를 들어 **`WEBSITE_RUN_FROM_PACKAGE`**가 존재하면 애플리케이션 코드가 위치한 URL을 나타냅니다.
|
||||
|
||||
### **Function Sandbox**
|
||||
|
||||
리눅스 샌드박스 내에서 소스 코드는 **`/home/site/wwwroot`**의 **`function_app.py`**(Python 사용 시)에 위치하며, 코드를 실행하는 사용자는 **`app`**(sudo 권한 없음)입니다.
|
||||
리눅스 샌드박스 내에서 소스 코드는 **`/home/site/wwwroot`**의 **`function_app.py`** 파일에 위치하며 (Python을 사용하는 경우), 코드를 실행하는 사용자는 **`app`**입니다 (sudo 권한 없음).
|
||||
|
||||
**Windows** 함수에서 NodeJS를 사용하는 경우 코드는 **`C:\home\site\wwwroot\HttpTrigger1\index.js`**에 위치하며, 사용자 이름은 **`mawsFnPlaceholder8_f_v4_node_20_x86`**이고, **그룹**은 `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`입니다.
|
||||
**Windows** 함수에서 NodeJS를 사용하는 경우 코드는 **`C:\home\site\wwwroot\HttpTrigger1\index.js`**에 위치하며, 사용자 이름은 **`mawsFnPlaceholder8_f_v4_node_20_x86`**이고 **그룹**은 `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`의 일부입니다.
|
||||
|
||||
### **관리되는 ID 및 메타데이터**
|
||||
|
||||
[**VMs**](vms/index.html)와 마찬가지로 Functions는 두 가지 유형의 **Managed Identities**를 가질 수 있습니다: 시스템 할당 및 사용자 할당.
|
||||
[**VMs**](vms/index.html)와 마찬가지로, Functions는 **시스템 할당** 및 **사용자 할당**의 두 가지 유형의 **Managed Identities**를 가질 수 있습니다.
|
||||
|
||||
**시스템 할당**된 ID는 **해당 함수**만 사용할 수 있는 관리되는 ID이며, **사용자 할당**된 관리되는 ID는 **다른 Azure 서비스가 사용할 수 있는 관리되는 ID**입니다.
|
||||
|
||||
> [!NOTE]
|
||||
> [**VMs**](vms/index.html)와 마찬가지로 Functions는 **1개의 시스템 할당** 관리되는 ID와 **여러 사용자 할당** 관리되는 ID를 가질 수 있으므로, 함수를 손상시키면 모든 관리되는 ID를 찾는 것이 항상 중요합니다. 하나의 Function에서 여러 관리되는 ID로 권한을 상승시킬 수 있습니다.
|
||||
> [**VMs**](vms/index.html)와 마찬가지로, Functions는 **1개의 시스템 할당** 관리되는 ID와 **여러 사용자 할당** 관리되는 ID를 가질 수 있으므로, 함수를 손상시키면 모든 관리되는 ID를 찾는 것이 항상 중요합니다. 하나의 Function에서 여러 관리되는 ID로 권한을 상승시킬 수 있습니다.
|
||||
>
|
||||
> 시스템 관리 ID가 사용되지 않고 하나 이상의 사용자 관리 ID가 함수에 연결된 경우 기본적으로 토큰을 얻을 수 없습니다.
|
||||
> 시스템 관리 ID가 사용되지 않고 하나 이상의 사용자 관리 ID가 함수에 연결된 경우, 기본적으로 토큰을 얻을 수 없습니다.
|
||||
|
||||
[**PEASS 스크립트**](https://github.com/peass-ng/PEASS-ng)를 사용하여 메타데이터 엔드포인트에서 기본 관리 ID의 토큰을 얻을 수 있습니다. 또는 다음과 같이 **수동으로** 얻을 수 있습니다:
|
||||
|
||||
{% 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}}
|
||||
|
||||
함수가 연결된 **모든 관리되는 ID를 확인하는 방법**을 찾아야 합니다. 그렇지 않으면 메타데이터 엔드포인트는 **기본 ID만 사용**합니다(자세한 내용은 이전 링크를 확인하세요).
|
||||
모든 관리되는 ID를 **확인하는 방법을 찾아야** 하며, 이를 지정하지 않으면 메타데이터 엔드포인트는 **기본 ID만 사용**합니다 (자세한 내용은 이전 링크를 참조).
|
||||
|
||||
## 액세스 키
|
||||
|
||||
> [!NOTE]
|
||||
> 함수 호출에 대한 사용자 액세스를 부여하는 RBAC 권한이 없음을 유의하세요. **함수 호출은 생성 시 선택된 트리거에 따라 달라지며, HTTP 트리거가 선택된 경우 **액세스 키**를 사용해야 할 수 있습니다.**
|
||||
> 함수 호출을 위해 사용자에게 액세스를 부여하는 RBAC 권한이 없음을 유의하십시오. **함수 호출은 생성 시 선택된 트리거에 따라 달라지며, HTTP 트리거가 선택된 경우 **액세스 키**를 사용해야 할 수 있습니다.**
|
||||
|
||||
HTTP 트리거를 사용하여 함수 내에서 엔드포인트를 생성할 때, 함수 트리거에 필요한 **액세스 키 권한 수준**을 지정할 수 있습니다. 세 가지 옵션이 있습니다:
|
||||
HTTP 트리거를 사용하여 함수 내에서 엔드포인트를 생성할 때, 함수를 트리거하는 데 필요한 **액세스 키 권한 수준**을 지정할 수 있습니다. 세 가지 옵션이 있습니다:
|
||||
|
||||
- **ANONYMOUS**: **모든 사람**이 URL을 통해 함수에 접근할 수 있습니다.
|
||||
- **ANONYMOUS**: **모든 사용자**가 URL을 통해 함수에 접근할 수 있습니다.
|
||||
- **FUNCTION**: 엔드포인트는 **함수, 호스트 또는 마스터 키**를 사용하는 사용자만 접근할 수 있습니다.
|
||||
- **ADMIN**: 엔드포인트는 **마스터 키**를 가진 사용자만 접근할 수 있습니다.
|
||||
|
||||
**키 유형:**
|
||||
|
||||
- **Function Keys:** 함수 키는 기본 또는 사용자 정의일 수 있으며, Function App 내의 **특정 함수 엔드포인트**에 대한 액세스를 독점적으로 부여하도록 설계되었습니다. 이를 통해 엔드포인트에 대한 보다 세밀한 액세스가 가능합니다.
|
||||
- **Host Keys:** 호스트 키는 기본 또는 사용자 정의일 수 있으며, **FUNCTION 액세스 수준**으로 Function App 내의 **모든 함수 엔드포인트**에 대한 액세스를 제공합니다.
|
||||
- **Master Key:** 마스터 키(`_master`)는 모든 함수 엔드포인트에 대한 액세스를 포함하여 권한이 상승된 액세스를 제공하는 관리 키입니다(ADMIN 액세스 수준 포함). 이 **키는 취소할 수 없습니다.**
|
||||
- **Host Keys:** 호스트 키는 기본 또는 사용자 정의일 수 있으며, FUNCTION 액세스 수준으로 Function App 내의 **모든 함수 엔드포인트**에 대한 액세스를 제공합니다.
|
||||
- **Master Key:** 마스터 키(`_master`)는 모든 함수 엔드포인트에 대한 액세스를 포함하여 권한이 상승된 액세스를 제공하는 관리 키입니다. 이 **키는 취소할 수 없습니다.**
|
||||
- **System Keys:** 시스템 키는 **특정 확장에 의해 관리**되며, 내부 구성 요소에서 사용하는 웹훅 엔드포인트에 접근하는 데 필요합니다. 예를 들어, Event Grid 트리거 및 Durable Functions는 시스템 키를 사용하여 해당 API와 안전하게 상호작용합니다.
|
||||
|
||||
> [!TIP]
|
||||
@@ -96,7 +98,7 @@ HTTP 트리거를 사용하여 함수 내에서 엔드포인트를 생성할 때
|
||||
|
||||
### 기본 인증
|
||||
|
||||
App Services와 마찬가지로 Functions는 **SCM** 및 **FTP**에 연결하여 코드를 배포하기 위해 Azure에서 제공하는 **사용자 이름과 비밀번호가 포함된 URL**을 사용하여 기본 인증을 지원합니다. 이에 대한 자세한 내용은:
|
||||
App Services와 마찬가지로, Functions는 **SCM** 및 **FTP**에 연결하여 코드를 배포하기 위해 Azure에서 제공하는 **사용자 이름과 비밀번호가 포함된 URL**을 사용하여 기본 인증을 지원합니다. 이에 대한 자세한 내용은 다음에서 확인할 수 있습니다:
|
||||
|
||||
{{#ref}}
|
||||
az-app-services.md
|
||||
@@ -104,7 +106,7 @@ az-app-services.md
|
||||
|
||||
### Github 기반 배포
|
||||
|
||||
함수가 Github 리포지토리에서 생성될 때 Azure 웹 콘솔은 **특정 리포지토리에서 자동으로 Github Workflow를 생성**할 수 있게 해주며, 이 리포지토리가 업데이트될 때마다 함수의 코드가 업데이트됩니다. 실제로 Python 함수에 대한 Github Action yaml은 다음과 같습니다:
|
||||
함수가 Github 리포지토리에서 생성될 때 Azure 웹 콘솔은 **특정 리포지토리에서 자동으로 Github Workflow를 생성**할 수 있도록 하여 이 리포지토리가 업데이트될 때마다 함수의 코드가 업데이트됩니다. 실제로 Python 함수에 대한 Github Action yaml은 다음과 같습니다:
|
||||
|
||||
<details>
|
||||
|
||||
@@ -195,11 +197,11 @@ package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
|
||||
또한, **Managed Identity**가 생성되어 리포지토리의 Github Action이 이를 사용하여 Azure에 로그인할 수 있습니다. 이는 **Managed Identity**에 대해 **Issuer** `https://token.actions.githubusercontent.com`와 **Subject Identifier** `repo:<org-name>/<repo-name>:ref:refs/heads/<branch-name>`를 허용하는 Federated credential을 생성함으로써 이루어집니다.
|
||||
|
||||
> [!CAUTION]
|
||||
> 따라서, 해당 리포지토리를 손상시키는 사람은 기능과 이에 연결된 Managed Identities를 손상시킬 수 있습니다.
|
||||
> 따라서, 해당 리포지토리를 손상시키는 사람은 함수와 이에 연결된 Managed Identities를 손상시킬 수 있습니다.
|
||||
|
||||
### Container Based Deployments
|
||||
|
||||
모든 요금제가 컨테이너 배포를 허용하는 것은 아니지만, 허용하는 경우 구성에는 컨테이너의 URL이 포함됩니다. API에서 **`linuxFxVersion`** 설정은 `DOCKER|mcr.microsoft.com/...`와 같은 형태를 가질 것이며, 웹 콘솔에서는 구성에 **image settings**가 표시됩니다.
|
||||
모든 요금제가 컨테이너 배포를 허용하는 것은 아니지만, 허용하는 경우에는 구성에 컨테이너의 URL이 포함됩니다. API에서 **`linuxFxVersion`** 설정은 `DOCKER|mcr.microsoft.com/...`와 같은 형태를 가지며, 웹 콘솔에서는 구성에 **image settings**가 표시됩니다.
|
||||
|
||||
또한, **소스 코드는 함수와 관련된 스토리지** 계정에 저장되지 않습니다. 필요하지 않기 때문입니다.
|
||||
|
||||
@@ -211,10 +213,10 @@ package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
|
||||
# List all the functions
|
||||
az functionapp list
|
||||
|
||||
# Get info of 1 funciton (although in the list you already get this info)
|
||||
az functionapp show --name <app-name> --resource-group <res-group>
|
||||
## If "linuxFxVersion" has something like: "DOCKER|mcr.microsoft.com/..."
|
||||
## This is using a container
|
||||
# List functions in an function-app (endpoints)
|
||||
az functionapp function list \
|
||||
--name <app-name> \
|
||||
--resource-group <res-group>
|
||||
|
||||
# Get details about the source of the function code
|
||||
az functionapp deployment source show \
|
||||
@@ -231,6 +233,9 @@ az functionapp config container show \
|
||||
# Get settings (and privesc to the sorage account)
|
||||
az functionapp config appsettings list --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get access restrictions
|
||||
az functionapp config access-restriction show --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Check if a domain was assigned to a function app
|
||||
az functionapp config hostname list --webapp-name <app-name> --resource-group <res-group>
|
||||
|
||||
@@ -240,22 +245,41 @@ az functionapp config ssl list --resource-group <res-group>
|
||||
# Get network restrictions
|
||||
az functionapp config access-restriction show --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get more info about a function (invoke_url_template is the URL to invoke and script_href allows to see the code)
|
||||
az rest --method GET \
|
||||
--url "https://management.azure.com/subscriptions/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions?api-version=2024-04-01"
|
||||
# Get acess restrictions
|
||||
az functionapp config access-restriction show --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get connection strings
|
||||
az rest --method POST --uri "https://management.azure.com/subscriptions/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/connectionstrings/list?api-version=2022-03-01"
|
||||
az rest --method GET --uri "https://management.azure.com/subscriptions/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/config/configreferences/connectionstrings?api-version=2022-03-01"
|
||||
|
||||
# Get SCM credentials
|
||||
az functionapp deployment list-publishing-credentials --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get function, system and master keys
|
||||
az functionapp keys list --name <app-name> --resource-group <res-group>
|
||||
|
||||
# Get Host key
|
||||
az rest --method POST --uri "https://management.azure.com/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/functions/<function-endpoint-name>/listKeys?api-version=2022-03-01"
|
||||
|
||||
# Get source code with Master Key of the function
|
||||
curl "<script_href>?code=<master-key>"
|
||||
## Python example
|
||||
curl "https://newfuncttest123.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=<master-key>" -v
|
||||
curl "https://<func-app-name>.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=<master-key>" -v
|
||||
|
||||
# Get source code using SCM access (Azure permissions or SCM creds)
|
||||
az rest --method GET \
|
||||
--url "https://<func-app-name>.azurewebsites.net/admin/vfs/home/site/wwwroot/function_app.py?code=<master-key>" \
|
||||
--resource "https://management.azure.com/"
|
||||
|
||||
# Get source code with Azure permissions
|
||||
az rest --url "https://management.azure.com/subscriptions/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01"
|
||||
## Another example
|
||||
az rest --url "https://management.azure.com/subscriptions/9291ff6e-6afb-430e-82a4-6f04b2d05c7f/resourceGroups/Resource_Group_1/providers/Microsoft.Web/sites/ConsumptionExample/hostruntime/admin/vfs/HttpExample/index.js?relativePath=1&api-version=2022-03-01"
|
||||
|
||||
# Get source code
|
||||
az rest --url "https://management.azure.com/<subscription>/resourceGroups/<res-group>/providers/Microsoft.Web/sites/<app-name>/hostruntime/admin/vfs/function_app.py?relativePath=1&api-version=2022-03-01"
|
||||
```
|
||||
{{#endtab }}
|
||||
|
||||
{{#tab name="Az Powershell" }}
|
||||
```powershell
|
||||
```bash
|
||||
Get-Command -Module Az.Functions
|
||||
|
||||
# Lists all Function Apps in the current subscription or in a specific resource group.
|
||||
@@ -280,7 +304,7 @@ Get-AzFunctionAppSetting -Name <FunctionAppName> -ResourceGroupName <ResourceGro
|
||||
../az-privilege-escalation/az-functions-app-privesc.md
|
||||
{{#endref}}
|
||||
|
||||
## 참고 문헌
|
||||
## 참고자료
|
||||
|
||||
- [https://learn.microsoft.com/en-us/azure/azure-functions/functions-openapi-definition](https://learn.microsoft.com/en-us/azure/azure-functions/functions-openapi-definition)
|
||||
|
||||
|
||||
Vendored
+10
File diff suppressed because one or more lines are too long
+169
-551
@@ -1,554 +1,172 @@
|
||||
/* ────────────────────────────────────────────────────────────────
|
||||
Polyfill so requestIdleCallback works everywhere (IE 11/Safari)
|
||||
─────────────────────────────────────────────────────────────── */
|
||||
if (typeof window.requestIdleCallback !== "function") {
|
||||
window.requestIdleCallback = function (cb) {
|
||||
const start = Date.now();
|
||||
return setTimeout(function () {
|
||||
cb({
|
||||
didTimeout: false,
|
||||
timeRemaining: function () {
|
||||
return Math.max(0, 50 - (Date.now() - start));
|
||||
}
|
||||
});
|
||||
}, 1);
|
||||
};
|
||||
window.cancelIdleCallback = window.clearTimeout;
|
||||
}
|
||||
|
||||
|
||||
/* ────────────────────────────────────────────────────────────────
|
||||
search.js
|
||||
─────────────────────────────────────────────────────────────── */
|
||||
|
||||
/* ht_searcher.js ────────────────────────────────────────────────
|
||||
Dual‑index Web‑Worker search (HackTricks + HackTricks‑Cloud)
|
||||
· keeps working even if one index fails
|
||||
· cloud results rendered **blue**
|
||||
· ⏳ while loading → 🔍 when ready
|
||||
*/
|
||||
|
||||
(() => {
|
||||
"use strict";
|
||||
window.search = window.search || {};
|
||||
(function search(search) {
|
||||
// Search functionality
|
||||
//
|
||||
// You can use !hasFocus() to prevent keyhandling in your key
|
||||
// event handlers while the user is typing their search.
|
||||
|
||||
if (!Mark || !elasticlunr) {
|
||||
return;
|
||||
|
||||
/* ───────────── 0. helpers (main thread) ───────────── */
|
||||
const clear = el => { while (el.firstChild) el.removeChild(el.firstChild); };
|
||||
|
||||
/* ───────────── 1. 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<len;i++) {
|
||||
if (!seg[i]) { continue; }
|
||||
s = seg[i].split('=');
|
||||
ret[s[0]] = s[1];
|
||||
}
|
||||
return ret;
|
||||
})(),
|
||||
file: (a.pathname.match(/\/([^/?#]+)$/i) || [,''])[1],
|
||||
hash: a.hash.replace('#',''),
|
||||
path: a.pathname.replace(/^([^/])/,'/$1')
|
||||
};
|
||||
}
|
||||
|
||||
// Helper to recreate a url string from its building blocks.
|
||||
function renderURL(urlobject) {
|
||||
var url = urlobject.protocol + "://" + urlobject.host;
|
||||
if (urlobject.port != "") {
|
||||
url += ":" + urlobject.port;
|
||||
}
|
||||
url += urlobject.path;
|
||||
var joiner = "?";
|
||||
for(var prop in urlobject.params) {
|
||||
if(urlobject.params.hasOwnProperty(prop)) {
|
||||
url += joiner + prop + "=" + urlobject.params[prop];
|
||||
joiner = "&";
|
||||
}
|
||||
}
|
||||
if (urlobject.hash != "") {
|
||||
url += "#" + urlobject.hash;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
// Helper to escape html special chars for displaying the teasers
|
||||
var escapeHTML = (function() {
|
||||
var MAP = {
|
||||
'&': '&',
|
||||
'<': '<',
|
||||
'>': '>',
|
||||
'"': '"',
|
||||
"'": '''
|
||||
};
|
||||
var repl = function(c) { return MAP[c]; };
|
||||
return function(s) {
|
||||
return s.replace(/[&<>'"]/g, repl);
|
||||
};
|
||||
})();
|
||||
|
||||
function formatSearchMetric(count, searchterm) {
|
||||
if (count == 1) {
|
||||
return count + " search result for '" + searchterm + "':";
|
||||
} else if (count == 0) {
|
||||
return "No search results for '" + searchterm + "'.";
|
||||
} else {
|
||||
return count + " search results for '" + searchterm + "':";
|
||||
}
|
||||
}
|
||||
|
||||
function formatSearchResult(result, searchterms) {
|
||||
var teaser = makeTeaser(escapeHTML(result.doc.body), searchterms);
|
||||
teaser_count++;
|
||||
|
||||
// The ?URL_MARK_PARAM= parameter belongs inbetween the page and the #heading-anchor
|
||||
var url = doc_urls[result.ref].split("#");
|
||||
if (url.length == 1) { // no anchor found
|
||||
url.push("");
|
||||
}
|
||||
|
||||
// encodeURIComponent escapes all chars that could allow an XSS except
|
||||
// for '. Due to that we also manually replace ' with its url-encoded
|
||||
// representation (%27).
|
||||
var searchterms = encodeURIComponent(searchterms.join(" ")).replace(/\'/g, "%27");
|
||||
|
||||
return '<a href="' + path_to_root + url[0] + '?' + URL_MARK_PARAM + '=' + searchterms + '#' + url[1]
|
||||
+ '" aria-details="teaser_' + teaser_count + '">' + result.doc.breadcrumbs
|
||||
+ '<span class="teaser" id="teaser_' + teaser_count + '" aria-label="Search Result Teaser">'
|
||||
+ teaser + '</span>' + '</a>';
|
||||
}
|
||||
|
||||
function makeTeaser(body, searchterms) {
|
||||
// The strategy is as follows:
|
||||
// First, assign a value to each word in the document:
|
||||
// Words that correspond to search terms (stemmer aware): 40
|
||||
// Normal words: 2
|
||||
// First word in a sentence: 8
|
||||
// Then use a sliding window with a constant number of words and count the
|
||||
// sum of the values of the words within the window. Then use the window that got the
|
||||
// maximum sum. If there are multiple maximas, then get the last one.
|
||||
// Enclose the terms in <em>.
|
||||
var stemmed_searchterms = searchterms.map(function(w) {
|
||||
return elasticlunr.stemmer(w.toLowerCase());
|
||||
});
|
||||
var searchterm_weight = 40;
|
||||
var weighted = []; // contains elements of ["word", weight, index_in_document]
|
||||
// split in sentences, then words
|
||||
var sentences = body.toLowerCase().split('. ');
|
||||
var index = 0;
|
||||
var value = 0;
|
||||
var searchterm_found = false;
|
||||
for (var sentenceindex in sentences) {
|
||||
var words = sentences[sentenceindex].split(' ');
|
||||
value = 8;
|
||||
for (var wordindex in words) {
|
||||
var word = words[wordindex];
|
||||
if (word.length > 0) {
|
||||
for (var searchtermindex in stemmed_searchterms) {
|
||||
if (elasticlunr.stemmer(word).startsWith(stemmed_searchterms[searchtermindex])) {
|
||||
value = searchterm_weight;
|
||||
searchterm_found = true;
|
||||
}
|
||||
};
|
||||
weighted.push([word, value, index]);
|
||||
value = 2;
|
||||
}
|
||||
index += word.length;
|
||||
index += 1; // ' ' or '.' if last word in sentence
|
||||
};
|
||||
index += 1; // because we split at a two-char boundary '. '
|
||||
};
|
||||
|
||||
if (weighted.length == 0) {
|
||||
return body;
|
||||
}
|
||||
|
||||
var window_weight = [];
|
||||
var window_size = Math.min(weighted.length, results_options.teaser_word_count);
|
||||
|
||||
var cur_sum = 0;
|
||||
for (var wordindex = 0; wordindex < window_size; wordindex++) {
|
||||
cur_sum += weighted[wordindex][1];
|
||||
};
|
||||
window_weight.push(cur_sum);
|
||||
for (var wordindex = 0; wordindex < weighted.length - window_size; wordindex++) {
|
||||
cur_sum -= weighted[wordindex][1];
|
||||
cur_sum += weighted[wordindex + window_size][1];
|
||||
window_weight.push(cur_sum);
|
||||
};
|
||||
|
||||
if (searchterm_found) {
|
||||
var max_sum = 0;
|
||||
var max_sum_window_index = 0;
|
||||
// backwards
|
||||
for (var i = window_weight.length - 1; i >= 0; i--) {
|
||||
if (window_weight[i] > max_sum) {
|
||||
max_sum = window_weight[i];
|
||||
max_sum_window_index = i;
|
||||
}
|
||||
};
|
||||
} else {
|
||||
max_sum_window_index = 0;
|
||||
}
|
||||
|
||||
// add <em/> around searchterms
|
||||
var teaser_split = [];
|
||||
var index = weighted[max_sum_window_index][2];
|
||||
for (var i = max_sum_window_index; i < max_sum_window_index+window_size; i++) {
|
||||
var word = weighted[i];
|
||||
if (index < word[2]) {
|
||||
// missing text from index to start of `word`
|
||||
teaser_split.push(body.substring(index, word[2]));
|
||||
index = word[2];
|
||||
}
|
||||
if (word[1] == searchterm_weight) {
|
||||
teaser_split.push("<em>")
|
||||
}
|
||||
index = word[2] + word[0].length;
|
||||
teaser_split.push(body.substring(word[2], index));
|
||||
if (word[1] == searchterm_weight) {
|
||||
teaser_split.push("</em>")
|
||||
}
|
||||
};
|
||||
|
||||
return teaser_split.join('');
|
||||
}
|
||||
|
||||
function init(config) {
|
||||
results_options = config.results_options;
|
||||
search_options = config.search_options;
|
||||
searchbar_outer = config.searchbar_outer;
|
||||
doc_urls = config.doc_urls;
|
||||
searchindex = elasticlunr.Index.load(config.index);
|
||||
|
||||
// Set up events
|
||||
searchicon.addEventListener('click', function(e) { searchIconClickHandler(); }, false);
|
||||
search_wrap.addEventListener('click', function(e) { searchIconClickHandler(); }, false);
|
||||
search_modal.addEventListener('click', function(e) { e.stopPropagation(); }, false);
|
||||
searchbar.addEventListener('keyup', function(e) { searchbarKeyUpHandler(); }, false);
|
||||
document.addEventListener('keydown', function(e) { globalKeyHandler(e); }, false);
|
||||
// If the user uses the browser buttons, do the same as if a reload happened
|
||||
window.onpopstate = function(e) { doSearchOrMarkFromUrl(); };
|
||||
// Suppress "submit" events so the page doesn't reload when the user presses Enter
|
||||
document.addEventListener('submit', function(e) { e.preventDefault(); }, false);
|
||||
|
||||
// If reloaded, do the search or mark again, depending on the current url parameters
|
||||
doSearchOrMarkFromUrl();
|
||||
}
|
||||
|
||||
function unfocusSearchbar() {
|
||||
// hacky, but just focusing a div only works once
|
||||
var tmp = document.createElement('input');
|
||||
tmp.setAttribute('style', 'position: absolute; opacity: 0;');
|
||||
searchicon.appendChild(tmp);
|
||||
tmp.focus();
|
||||
tmp.remove();
|
||||
}
|
||||
|
||||
// On reload or browser history backwards/forwards events, parse the url and do search or mark
|
||||
function doSearchOrMarkFromUrl() {
|
||||
// Check current URL for search request
|
||||
var url = parseURL(window.location.href);
|
||||
if (url.params.hasOwnProperty(URL_SEARCH_PARAM)
|
||||
&& url.params[URL_SEARCH_PARAM] != "") {
|
||||
showSearch(true);
|
||||
searchbar.value = decodeURIComponent(
|
||||
(url.params[URL_SEARCH_PARAM]+'').replace(/\+/g, '%20'));
|
||||
searchbarKeyUpHandler(); // -> doSearch()
|
||||
} else {
|
||||
showSearch(false);
|
||||
}
|
||||
|
||||
if (url.params.hasOwnProperty(URL_MARK_PARAM)) {
|
||||
var words = decodeURIComponent(url.params[URL_MARK_PARAM]).split(' ');
|
||||
marker.mark(words, {
|
||||
exclude: mark_exclude
|
||||
});
|
||||
|
||||
var markers = document.querySelectorAll("mark");
|
||||
function hide() {
|
||||
for (var i = 0; i < markers.length; i++) {
|
||||
markers[i].classList.add("fade-out");
|
||||
window.setTimeout(function(e) { marker.unmark(); }, 300);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < markers.length; i++) {
|
||||
markers[i].addEventListener('click', hide);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Eventhandler for keyevents on `document`
|
||||
function globalKeyHandler(e) {
|
||||
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey || e.target.type === 'textarea' || e.target.type === 'text' || !hasFocus() && /^(?:input|select|textarea)$/i.test(e.target.nodeName)) { return; }
|
||||
|
||||
if (e.keyCode === ESCAPE_KEYCODE) {
|
||||
e.preventDefault();
|
||||
searchbar.classList.remove("active");
|
||||
setSearchUrlParameters("",
|
||||
(searchbar.value.trim() !== "") ? "push" : "replace");
|
||||
if (hasFocus()) {
|
||||
unfocusSearchbar();
|
||||
}
|
||||
showSearch(false);
|
||||
marker.unmark();
|
||||
} else if (!hasFocus() && e.keyCode === SEARCH_HOTKEY_KEYCODE) {
|
||||
e.preventDefault();
|
||||
showSearch(true);
|
||||
window.scrollTo(0, 0);
|
||||
searchbar.select();
|
||||
} else if (hasFocus() && e.keyCode === DOWN_KEYCODE) {
|
||||
e.preventDefault();
|
||||
unfocusSearchbar();
|
||||
searchresults.firstElementChild.classList.add("focus");
|
||||
} else if (!hasFocus() && (e.keyCode === DOWN_KEYCODE
|
||||
|| e.keyCode === UP_KEYCODE
|
||||
|| e.keyCode === SELECT_KEYCODE)) {
|
||||
// not `:focus` because browser does annoying scrolling
|
||||
var focused = searchresults.querySelector("li.focus");
|
||||
if (!focused) return;
|
||||
e.preventDefault();
|
||||
if (e.keyCode === DOWN_KEYCODE) {
|
||||
var next = focused.nextElementSibling;
|
||||
if (next) {
|
||||
focused.classList.remove("focus");
|
||||
next.classList.add("focus");
|
||||
}
|
||||
} else if (e.keyCode === UP_KEYCODE) {
|
||||
focused.classList.remove("focus");
|
||||
var prev = focused.previousElementSibling;
|
||||
if (prev) {
|
||||
prev.classList.add("focus");
|
||||
} else {
|
||||
searchbar.select();
|
||||
}
|
||||
} else { // SELECT_KEYCODE
|
||||
window.location.assign(focused.querySelector('a'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showSearch(yes) {
|
||||
if (yes) {
|
||||
search_wrap.classList.remove('hidden');
|
||||
searchicon.setAttribute('aria-expanded', 'true');
|
||||
} else {
|
||||
search_wrap.classList.add('hidden');
|
||||
searchicon.setAttribute('aria-expanded', 'false');
|
||||
var results = searchresults.children;
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
results[i].classList.remove("focus");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showResults(yes) {
|
||||
if (yes) {
|
||||
searchresults_outer.classList.remove('hidden');
|
||||
} else {
|
||||
searchresults_outer.classList.add('hidden');
|
||||
}
|
||||
}
|
||||
|
||||
// Eventhandler for search icon
|
||||
function searchIconClickHandler() {
|
||||
if (search_wrap.classList.contains('hidden')) {
|
||||
showSearch(true);
|
||||
window.scrollTo(0, 0);
|
||||
searchbar.select();
|
||||
} else {
|
||||
showSearch(false);
|
||||
}
|
||||
}
|
||||
|
||||
// Eventhandler for keyevents while the searchbar is focused
|
||||
function searchbarKeyUpHandler() {
|
||||
var searchterm = searchbar.value.trim();
|
||||
if (searchterm != "") {
|
||||
searchbar.classList.add("active");
|
||||
doSearch(searchterm);
|
||||
} else {
|
||||
searchbar.classList.remove("active");
|
||||
showResults(false);
|
||||
removeChildren(searchresults);
|
||||
}
|
||||
|
||||
setSearchUrlParameters(searchterm, "push_if_new_search_else_replace");
|
||||
|
||||
// Remove marks
|
||||
marker.unmark();
|
||||
}
|
||||
|
||||
// Update current url with ?URL_SEARCH_PARAM= parameter, remove ?URL_MARK_PARAM and #heading-anchor .
|
||||
// `action` can be one of "push", "replace", "push_if_new_search_else_replace"
|
||||
// and replaces or pushes a new browser history item.
|
||||
// "push_if_new_search_else_replace" pushes if there is no `?URL_SEARCH_PARAM=abc` yet.
|
||||
function setSearchUrlParameters(searchterm, action) {
|
||||
var url = parseURL(window.location.href);
|
||||
var first_search = ! url.params.hasOwnProperty(URL_SEARCH_PARAM);
|
||||
if (searchterm != "" || action == "push_if_new_search_else_replace") {
|
||||
url.params[URL_SEARCH_PARAM] = searchterm;
|
||||
delete url.params[URL_MARK_PARAM];
|
||||
url.hash = "";
|
||||
} else {
|
||||
delete url.params[URL_MARK_PARAM];
|
||||
delete url.params[URL_SEARCH_PARAM];
|
||||
}
|
||||
// A new search will also add a new history item, so the user can go back
|
||||
// to the page prior to searching. A updated search term will only replace
|
||||
// the url.
|
||||
if (action == "push" || (action == "push_if_new_search_else_replace" && first_search) ) {
|
||||
history.pushState({}, document.title, renderURL(url));
|
||||
} else if (action == "replace" || (action == "push_if_new_search_else_replace" && !first_search) ) {
|
||||
history.replaceState({}, document.title, renderURL(url));
|
||||
}
|
||||
}
|
||||
|
||||
function doSearch(searchterm) {
|
||||
|
||||
// Don't search the same twice
|
||||
if (current_searchterm == searchterm) { return; }
|
||||
else { current_searchterm = searchterm; }
|
||||
|
||||
if (searchindex == null) { return; }
|
||||
|
||||
// Do the actual search
|
||||
var results = searchindex.search(searchterm, search_options);
|
||||
var resultcount = Math.min(results.length, results_options.limit_results);
|
||||
|
||||
// Display search metrics
|
||||
searchresults_header.innerText = formatSearchMetric(resultcount, searchterm);
|
||||
|
||||
// Clear and insert results
|
||||
var searchterms = searchterm.split(' ');
|
||||
removeChildren(searchresults);
|
||||
for(var i = 0; i < resultcount ; i++){
|
||||
var resultElem = document.createElement('li');
|
||||
resultElem.innerHTML = formatSearchResult(results[i], searchterms);
|
||||
searchresults.appendChild(resultElem);
|
||||
}
|
||||
|
||||
// Display results
|
||||
showResults(true);
|
||||
}
|
||||
|
||||
(async function loadSearchIndex(lang = window.lang || "en") {
|
||||
const branch = lang === "en" ? "master" : lang;
|
||||
const rawUrl =
|
||||
`https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/refs/heads/${branch}/searchindex.js`;
|
||||
const localJs = "/searchindex.js";
|
||||
const TIMEOUT_MS = 10_000;
|
||||
|
||||
const injectScript = (src) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const s = document.createElement("script");
|
||||
s.src = src;
|
||||
s.onload = () => resolve(src);
|
||||
s.onerror = (e) => reject(e);
|
||||
document.head.appendChild(s);
|
||||
if(!rawLoaded) return null; /* give up on this index */
|
||||
const data = { json:self.search.index, urls:self.search.doc_urls, cloud:isCloud };
|
||||
delete self.search.index; delete self.search.doc_urls;
|
||||
return data;
|
||||
}
|
||||
|
||||
(async () => {
|
||||
const MAIN_RAW = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/refs/heads/master/searchindex.js';
|
||||
const CLOUD_RAW = 'https://raw.githubusercontent.com/HackTricks-wiki/hacktricks-cloud/refs/heads/master/searchindex.js';
|
||||
|
||||
const indices = [];
|
||||
const main = await loadIndex(MAIN_RAW , '/searchindex-book.js', false); if(main) indices.push(main);
|
||||
const cloud= await loadIndex(CLOUD_RAW, '/searchindex.js', true ); if(cloud) indices.push(cloud);
|
||||
|
||||
if(!indices.length){ postMessage({ready:false, error:'no-index'}); return; }
|
||||
|
||||
/* build index objects */
|
||||
const built = indices.map(d => ({
|
||||
idx : elasticlunr.Index.load(d.json),
|
||||
urls: d.urls,
|
||||
cloud: d.cloud,
|
||||
base: d.cloud ? 'https://cloud.hacktricks.wiki/' : ''
|
||||
}));
|
||||
|
||||
postMessage({ready:true});
|
||||
const MAX = 30, opts = {bool:'AND', expand:true};
|
||||
|
||||
self.onmessage = ({data:q}) => {
|
||||
if(!q){ postMessage([]); return; }
|
||||
|
||||
const all = [];
|
||||
for(const s of built){
|
||||
const res = s.idx.search(q,opts);
|
||||
if(!res.length) continue;
|
||||
const max = res[0].score || 1;
|
||||
res.forEach(r => {
|
||||
const doc = s.idx.documentStore.getDoc(r.ref);
|
||||
all.push({
|
||||
norm : r.score / max,
|
||||
title: doc.title,
|
||||
body : doc.body,
|
||||
breadcrumbs: doc.breadcrumbs,
|
||||
url : s.base + s.urls[r.ref],
|
||||
cloud: s.cloud
|
||||
});
|
||||
|
||||
try {
|
||||
/* 1 — download raw JS from GitHub */
|
||||
const controller = new AbortController();
|
||||
const timer = setTimeout(() => controller.abort(), TIMEOUT_MS);
|
||||
|
||||
const res = await fetch(rawUrl, { signal: controller.signal });
|
||||
clearTimeout(timer);
|
||||
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
||||
|
||||
/* 2 — wrap in a Blob so the browser sees application/javascript */
|
||||
const code = await res.text();
|
||||
const blobUrl = URL.createObjectURL(
|
||||
new Blob([code], { type: "application/javascript" })
|
||||
);
|
||||
|
||||
/* 3 — execute it */
|
||||
await injectScript(blobUrl);
|
||||
|
||||
/* ───────────── PATCH ─────────────
|
||||
heavy parsing now deferred to idle time
|
||||
*/
|
||||
requestIdleCallback(() => init(window.search));
|
||||
return; // ✔ UI remains responsive
|
||||
} catch (eRemote) {
|
||||
console.warn("Remote JS failed →", eRemote);
|
||||
}
|
||||
|
||||
/* ───────── fallback: local copy ───────── */
|
||||
try {
|
||||
await injectScript(localJs);
|
||||
|
||||
/* ───────────── PATCH ───────────── */
|
||||
requestIdleCallback(() => init(window.search));
|
||||
return;
|
||||
} catch (eLocal) {
|
||||
console.error("Local JS failed →", eLocal);
|
||||
}
|
||||
})();
|
||||
|
||||
// Exported functions
|
||||
search.hasFocus = hasFocus;
|
||||
})(window.search);
|
||||
});
|
||||
}
|
||||
all.sort((a,b)=>b.norm-a.norm);
|
||||
postMessage(all.slice(0,MAX));
|
||||
};
|
||||
})();
|
||||
`;
|
||||
|
||||
/* ───────────── 2. spawn worker ───────────── */
|
||||
const worker = new Worker(URL.createObjectURL(new Blob([workerCode],{type:'application/javascript'})));
|
||||
|
||||
/* ───────────── 3. DOM refs ─────────────── */
|
||||
const wrap = document.getElementById('search-wrapper');
|
||||
const bar = document.getElementById('searchbar');
|
||||
const list = document.getElementById('searchresults');
|
||||
const listOut = document.getElementById('searchresults-outer');
|
||||
const header = document.getElementById('searchresults-header');
|
||||
const icon = document.getElementById('search-toggle');
|
||||
|
||||
const READY_ICON = icon.innerHTML;
|
||||
icon.textContent = '⏳';
|
||||
icon.setAttribute('aria-label','Loading search …');
|
||||
|
||||
const HOT=83, ESC=27, DOWN=40, UP=38, ENTER=13;
|
||||
let debounce, teaserCount=0;
|
||||
|
||||
/* ───────────── helpers (teaser, metric) ───────────── */
|
||||
const escapeHTML = (()=>{const M={'&':'&','<':'<','>':'>','"':'"','\'':'''};return s=>s.replace(/[&<>'"]/g,c=>M[c]);})();
|
||||
const URL_MARK='highlight';
|
||||
function metric(c,t){return c?`${c} search result${c>1?'s':''} for '${t}':`:`No search results for '${t}'.`;}
|
||||
|
||||
function makeTeaser(body,terms){
|
||||
const stem=w=>elasticlunr.stemmer(w.toLowerCase());
|
||||
const T=terms.map(stem),W_S=40,W_F=8,W_N=2,WIN=30;
|
||||
const W=[],sents=body.toLowerCase().split('. ');
|
||||
let i=0,v=W_F,found=false;
|
||||
sents.forEach(s=>{v=W_F; s.split(' ').forEach(w=>{ if(w){ if(T.some(t=>stem(w).startsWith(t))){v=W_S;found=true;} W.push([w,v,i]); v=W_N;} i+=w.length+1; }); i++;});
|
||||
if(!W.length) return body;
|
||||
const win=Math.min(W.length,WIN);
|
||||
const sums=[W.slice(0,win).reduce((a,[,wt])=>a+wt,0)];
|
||||
for(let k=1;k<=W.length-win;k++) sums[k]=sums[k-1]-W[k-1][1]+W[k+win-1][1];
|
||||
const best=found?sums.lastIndexOf(Math.max(...sums)):0;
|
||||
const out=[]; i=W[best][2];
|
||||
for(let k=best;k<best+win;k++){const [w,wt,pos]=W[k]; if(i<pos){out.push(body.substring(i,pos)); i=pos;} if(wt===W_S) out.push('<em>'); out.push(body.substr(pos,w.length)); if(wt===W_S) out.push('</em>'); i=pos+w.length;}
|
||||
return out.join('');
|
||||
}
|
||||
|
||||
function format(d,terms){
|
||||
const teaser=makeTeaser(escapeHTML(d.body),terms);
|
||||
teaserCount++;
|
||||
const enc=encodeURIComponent(terms.join(' ')).replace(/'/g,'%27');
|
||||
const parts=d.url.split('#'); if(parts.length===1) parts.push('');
|
||||
const abs=d.url.startsWith('http');
|
||||
const href=`${abs?'':path_to_root}${parts[0]}?${URL_MARK}=${enc}#${parts[1]}`;
|
||||
const style=d.cloud?" style=\"color:#1e88e5\"":"";
|
||||
const isCloud=d.cloud?" [Cloud]":" [Book]";
|
||||
return `<a href="${href}" aria-details="teaser_${teaserCount}"${style}>`+
|
||||
`${d.breadcrumbs}${isCloud}<span class="teaser" id="teaser_${teaserCount}" aria-label="Search Result Teaser">${teaser}</span></a>`;
|
||||
}
|
||||
|
||||
/* ───────────── UI control ───────────── */
|
||||
function showUI(s){wrap.classList.toggle('hidden',!s); icon.setAttribute('aria-expanded',s); if(s){window.scrollTo(0,0); bar.focus(); bar.select();} else {listOut.classList.add('hidden'); [...list.children].forEach(li=>li.classList.remove('focus'));}}
|
||||
function blur(){const t=document.createElement('input'); t.style.cssText='position:absolute;opacity:0;'; icon.appendChild(t); t.focus(); t.remove();}
|
||||
|
||||
icon.addEventListener('click',()=>showUI(wrap.classList.contains('hidden')));
|
||||
|
||||
document.addEventListener('keydown',e=>{
|
||||
if(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey) return;
|
||||
const f=/^(?:input|select|textarea)$/i.test(e.target.nodeName);
|
||||
if(e.keyCode===HOT && !f){e.preventDefault(); showUI(true);} else if(e.keyCode===ESC){e.preventDefault(); showUI(false); blur();}
|
||||
else if(e.keyCode===DOWN && document.activeElement===bar){e.preventDefault(); const first=list.firstElementChild; if(first){blur(); first.classList.add('focus');}}
|
||||
else if([DOWN,UP,ENTER].includes(e.keyCode) && document.activeElement!==bar){const cur=list.querySelector('li.focus'); if(!cur) return; e.preventDefault(); if(e.keyCode===DOWN){const nxt=cur.nextElementSibling; if(nxt){cur.classList.remove('focus'); nxt.classList.add('focus');}} else if(e.keyCode===UP){const prv=cur.previousElementSibling; cur.classList.remove('focus'); if(prv){prv.classList.add('focus');} else {bar.focus();}} else {const a=cur.querySelector('a'); if(a) window.location.assign(a.href);}}
|
||||
});
|
||||
|
||||
bar.addEventListener('input',e=>{ clearTimeout(debounce); debounce=setTimeout(()=>worker.postMessage(e.target.value.trim()),120); });
|
||||
|
||||
/* ───────────── worker messages ───────────── */
|
||||
worker.onmessage = ({data}) => {
|
||||
if(data && data.ready!==undefined){
|
||||
if(data.ready){ icon.innerHTML=READY_ICON; icon.setAttribute('aria-label','Open search (S)'); }
|
||||
else { icon.textContent='❌'; icon.setAttribute('aria-label','Search unavailable'); }
|
||||
return;
|
||||
}
|
||||
const docs=data, q=bar.value.trim(), terms=q.split(/\s+/).filter(Boolean);
|
||||
header.textContent=metric(docs.length,q);
|
||||
clear(list);
|
||||
docs.forEach(d=>{const li=document.createElement('li'); li.innerHTML=format(d,terms); list.appendChild(li);});
|
||||
listOut.classList.toggle('hidden',!docs.length);
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user