安全矩阵

 找回密码
 立即注册
搜索
查看: 507|回复: 0

云渗透 | Azure 渗透测试

[复制链接]

179

主题

179

帖子

630

积分

高级会员

Rank: 4

积分
630
发表于 2023-3-20 23:27:37 | 显示全部楼层 |阅读模式
原文链接:云渗透 | Azure 渗透测试



基本信息
  1. <font size="3" face="Tahoma">{% content-ref url="az-basic-information.md" %} az-basic-information.md {% endcontent-ref %}</font>
复制代码
Azure Pentester/红队方法论
为了审核 AZURE 环境,了解以下内容非常重要:正在使用哪些服务、正在公开什么、谁可以访问什么以及内部 Azure 服务和外部服务如何连接。

从红队的角度来看,破坏 Azure 环境的第一步是设法获取 Azure AD 的一些凭据。在这里,您对如何做到这一点有一些想法:

·github(或类似)中的泄漏- OSINT
·社会工程学
·密码重用(密码泄露)
·Azure 托管应用程序中的漏洞
     -/home/USERNAME/.azure
     -C:\Users\USERNAME\.azure
     -accessTokens.json2.30 之前的文件az cli- Jan2022 //以明文形式存储访问令牌
     -该文件azureProfile.json包含有关登录用户的信息
     -az logout删除令牌。
     -中以明文形式Az PowerShell存储的访问令牌的旧版本。它还将ServicePrincipalSecret以明文形式存储在. 该 cmdlet可用于存储令牌。 用于删除它们。TokenCache.datAzureRmContext.jsonSave-AzContext
     -Disconnect-AzAccount
     -****访问元数据端点的服务器端请求伪造
     -读取本地文件
·第三者违约
·内部员工
·常见网络钓鱼(凭据或 Oauth 应用程序)
     -设备代码身份验证网络钓鱼
·Azure密码喷洒

即使您没有破坏您正在攻击的 Azure 租户内的任何用户,您也可以从中收集一些信息

{% content-ref url="az-unauthenticated-enum-and-initial-entry/" %} az-unauthenticated-enum-and-initial-entry {% endcontent-ref %}

{% hint style="info" %} 在您设法获得凭据后,您需要知道这些凭据属于谁,以及他们可以访问什么,因此您需要执行一些基本的枚举:{% endhint %}

基本枚举
{% hint style="info" %} 请记住,枚举中最嘈杂的部分是登录,而不是枚举本身。 {% endhint %}

SSRF
如果您在 Azure 中的机器中发现了 SSRF,请检查此页面以获取技巧:

{% embed url=" https://book.hacktricks.xyz/pent ... -forgery/cloud-ssrf " %}

绕过登录条件


如果您拥有一些有效凭据但无法登录,这些是一些可能到位的常见保护措施:

IP白名单——你需要妥协一个有效的IP
地理限制——找到用户居住的地方或公司的办公室在哪里,并从同一个城市(或至少一个国家)获得一个IP
浏览器——可能只允许使用来自特定操作系统(Windows、Linux、Mac、Android、iOS)的浏览器。找出受害者/公司使用的操作系统。
您还可以尝试破坏服务主体凭据,因为它们通常受限较少且其登录审核较少
绕过它后,您也许可以回到初始设置,并且您仍然可以访问。

我是谁

{% hint style="danger" %}在Az - AzureAD部分了解如何安装az cli、AzureAD 和 Az PowerShell 。{% endhint %}

https://github.com/carlospolop/h ... vices/az-azuread.md


你需要知道的第一件事就是你是谁(你在哪个环境中):

{% tabs %} {% tab title="az cli" %}

az account list
az account tenant list # Current tenant info
az account subscription list # Current subscription info
az ad signed-in-user show # Current signed-in user
az ad signed-in-user list-owned-objects # Get owned objects by current user
az account management-group list #Not allowed by default

{% endtab %}

{% tab title="AzureAD" %}

#Get the current session state
Get-AzureADCurrentSessionInfo
#Get details of the current tenant
Get-AzureADTenantDetail
{% endtab %}

{% tab title="Az PowerShell" %}

# Get the information about the current context (Account, Tenant, Subscription etc.)
Get-AzContext
# List all available contexts
Get-AzContext -ListAvailable
# Enumerate subscriptions accessible by the current user
Get-AzSubscription
#Get Resource group
Get-AzResourceGroup
# Enumerate all resources visible to the current user
Get-AzResource
# Enumerate all Azure RBAC role assignments
Get-AzRoleAssignment # For all users
Get-AzRoleAssignment -SignInName test@corp.onmicrosoft.com # For current user
{% endtab %} {% endtabs %}

AzureAD 枚举
默认情况下,任何用户都应该有足够的权限来枚举我们、用户、组、角色、服务主体等内容……(检查默认的 AzureAD 权限)。
您可以在这里找到指南:

{% content-ref url="az-services/az-azuread.md" %} az-azuread.md {% endcontent-ref %}

{% hint style="info" %} 现在你已经有了一些关于你的凭据的信息(如果你是红队,希望你没有被发现)。是时候弄清楚环境中正在使用哪些服务了。
在下一节中,您可以检查一些枚举一些常见服务的方法。{% endhint %}

服务主体和访问策略
Azure 服务可以具有(服务本身的)系统标识或使用用户分配的托管标识。这个身份可以有访问策略,例如,一个 KeyVault 来读取秘密。这些访问策略应该受到限制(最小特权原则),但可能具有比所需更多的权限。通常,应用服务会使用 KeyVault 来检索机密和证书。

因此探索这些身份是有用的。

应用服务供应链管理

Kudu 控制台登录到应用服务“容器”。

Webshell
使用 portal.azure.com 并选择 shell,或使用 shell.azure.com 作为 bash 或 powershell。此外壳的“磁盘”作为图像文件存储在存储帐户中。

Azure 开发运营

Azure DevOps 独立于 Azure。它有存储库、管道(yaml 或发布)、看板、wiki 等等。变量组用于存储变量值和秘密。

自动侦察工具
侦察
https://github.com/dirkjanm/ROADtools
  1. <font size="3" face="Tahoma">cd ROADTools
  2. pipenv shell
  3. roadrecon auth -u test@corp.onmicrosoft.com -p "Welcome2022!"
  4. roadrecon gather
  5. roadrecon gui
  6. </font>
复制代码
Monkey365
https://github.com/silverhack/monkey365
{% code overflow="wrap" %}
  1. <font size="3" face="Tahoma">Import-Module monkey365
  2. Get-Help Invoke-Monkey365
  3. Get-Help Invoke-Monkey365 -Detailed
  4. Invoke-Monkey365 -IncludeAzureActiveDirectory -ExportTo HTML -Verbose -Debug -InformationAction Continue
  5. Invoke-Monkey365 - Instance Azure -Analysis All -ExportTo HTML</font>
复制代码
{% endcode %}

Stormspotter
https://github.com/Azure/Stormspotter
  1. <font size="3" face="Tahoma"># Start Backend
  2. cd stormspotter\backend\
  3. pipenv shell
  4. python ssbackend.pyz

  5. # Start Front-end
  6. cd stormspotter\frontend\dist\spa\
  7. quasar.cmd serve -p 9091 --history

  8. # Run Stormcollector
  9. cd stormspotter\stormcollector\
  10. pipenv shell
  11. az login -u test@corp.onmicrosoft.com -p Welcome2022!
  12. python stormspotter\stormcollector\sscollector.pyz cli
  13. # This will generate a .zip file to upload in the frontend (127.0.0.1:9091)</font>
复制代码
AzureHound
https://github.com/BloodHoundAD/AzureHound
  1. <font size="3" face="Tahoma"># You need to use the Az PowerShell and Azure AD modules:
  2. $passwd = ConvertTo-SecureString "Welcome2022!" -AsPlainText -Force
  3. $creds = New-Object System.Management.Automation.PSCredential ("test@corp.onmicrosoft.com", $passwd)
  4. Connect-AzAccount -Credential $creds

  5. Import-Module AzureAD\AzureAD.psd1
  6. Connect-AzureAD -Credential $creds

  7. # Launch AzureHound
  8. . AzureHound\AzureHound.ps1
  9. Invoke-AzureHound -Verbose

  10. # Simple queries
  11. ## All Azure Users
  12. MATCH (n:AZUser) return n.name
  13. ## All Azure Applications
  14. MATCH (n:AZApp) return n.objectid
  15. ## All Azure Devices
  16. MATCH (n:AZDevice) return n.name
  17. ## All Azure Groups
  18. MATCH (n:AZGroup) return n.name
  19. ## All Azure Key Vaults
  20. MATCH (n:AZKeyVault) return n.name
  21. ## All Azure Resource Groups
  22. MATCH (n:AZResourceGroup) return n.name
  23. ## All Azure Service Principals
  24. MATCH (n:AZServicePrincipal) return n.objectid
  25. ## All Azure Virtual Machines
  26. MATCH (n:AZVM) return n.name
  27. ## All Principals with the ‘Contributor’ role
  28. MATCH p = (n)-[r:AZContributor]->(g) RETURN p

  29. # Advanced queries
  30. ## Get Global Admins
  31. MATCH p =(n)-[r:AZGlobalAdmin*1..]->(m) RETURN p
  32. ## Owners of Azure Groups
  33. MATCH p = (n)-[r:AZOwns]->(g:AZGroup) RETURN p
  34. ## All Azure Users and their Groups
  35. MATCH p=(m:AZUser)-[r:MemberOf]->(n) WHERE NOT m.objectid CONTAINS 'S-1-5' RETURN p
  36. ## Privileged Service Principals
  37. MATCH p = (g:AZServicePrincipal)-[r]->(n) RETURN p
  38. ## Owners of Azure Applications
  39. MATCH p = (n)-[r:AZOwns]->(g:AZApp) RETURN p
  40. ## Paths to VMs
  41. MATCH p = (n)-[r]->(g: AZVM) RETURN p
  42. ## Paths to KeyVault
  43. MATCH p = (n)-[r]->(g:AZKeyVault) RETURN p
  44. ## Paths to Azure Resource Group
  45. MATCH p = (n)-[r]->(g:AZResourceGroup) RETURN p
  46. ## On-Prem users with edges to Azure
  47. MATCH  p=(m:User)-[r:AZResetPassword|AZOwns|AZUserAccessAdministrator|AZContributor|AZAddMembers|AZGlobalAdmin|AZVMContributor|AZOwnsAZAvereContributor]->(n) WHERE m.objectid CONTAINS 'S-1-5-21' RETURN p
  48. ## All Azure AD Groups that are synchronized with On-Premise AD
  49. MATCH (n:Group) WHERE n.objectid CONTAINS 'S-1-5' AND n.azsyncid IS NOT NULL RETURN n
  50. </font>
复制代码
Azucar
https://github.com/nccgroup/azucar

  1. <font size="3" face="Tahoma"># You should use an account with at least read-permission on the assets you want to access
  2. git clone https://github.com/nccgroup/azucar.git
  3. PS> Get-ChildItem -Recurse c:\Azucar_V10 | Unblock-File

  4. PS> .\Azucar.ps1 -AuthMode UseCachedCredentials -Verbose -WriteLog -Debug -ExportTo PRINT
  5. PS> .\Azucar.ps1 -ExportTo CSV,JSON,XML,EXCEL -AuthMode Certificate_Credentials -Certificate C:\AzucarTest\server.pfx -ApplicationId 00000000-0000-0000-0000-000000000000 -TenantID 00000000-0000-0000-0000-000000000000
  6. PS> .\Azucar.ps1 -ExportTo CSV,JSON,XML,EXCEL -AuthMode Certificate_Credentials -Certificate C:\AzucarTest\server.pfx -CertFilePassword MySuperP@ssw0rd! -ApplicationId 00000000-0000-0000-0000-000000000000 -TenantID 00000000-0000-0000-0000-000000000000

  7. # resolve the TenantID for an specific username
  8. PS> .\Azucar.ps1 -ResolveTenantUserName user@company.com
  9. </font>
复制代码

MicroBurst
https://github.com/NetSPI/MicroBurst
  1. <font size="3" face="Tahoma">Import-Module .\MicroBurst.psm1
  2. Import-Module .\Get-AzureDomainInfo.ps1
  3. Get-AzureDomainInfo -folder MicroBurst -Verbose</font>
复制代码
PowerZure
https://github.com/hausec/PowerZure
  1. <font size="3" face="Tahoma">Connect-AzAccount
  2. ipmo C:\Path\To\Powerzure.psd1
  3. Get-AzureTarget

  4. # Reader
  5. $ Get-Runbook, Get-AllUsers, Get-Apps, Get-Resources, Get-WebApps, Get-WebAppDetails

  6. # Contributor
  7. $ Execute-Command -OS Windows -VM Win10Test -ResourceGroup Test-RG -Command "whoami"
  8. $ Execute-MSBuild -VM Win10Test  -ResourceGroup Test-RG -File "build.xml"
  9. $ Get-AllSecrets # AllAppSecrets, AllKeyVaultContents
  10. $ Get-AvailableVMDisks, Get-VMDisk # Download a virtual machine's disk

  11. # Owner
  12. $ Set-Role -Role Contributor -User test@contoso.com -Resource Win10VMTest

  13. # Administrator
  14. $ Create-Backdoor, Execute-Backdoor</font>
复制代码




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-3-29 14:56 , Processed in 0.016762 second(s), 19 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表