2.30 이전의 az cli의 accessTokens.json 파일 - 2022년 1월 - 액세스 토큰을 평문으로 저장
azureProfile.json 파일은 로그인한 사용자에 대한 정보를 포함
**az logout**은 토큰을 제거합니다.
이전 버전의 **Az PowerShell**은 **TokenCache.dat**에 액세스 토큰을 평문으로 저장했습니다. 또한 **AzureRmContext.json**에 ServicePrincipalSecret를 평문으로 저장합니다. Save-AzContext cmdlet을 사용하여 토큰을 저장할 수 있습니다.
Disconnect-AzAccount를 사용하여 제거합니다.
Az - AzureAD 섹션에서 az cli, AzureAD 및 Az PowerShell을 설치하는 방법을 배우세요.
알아야 할 첫 번째 사항 중 하나는 누구인지(어떤 환경에 있는지)를 알아야 합니다:
azaccountlistazaccounttenantlist# Current tenant infoazaccountsubscriptionlist# Current subscription infoazadsigned-in-usershow# Current signed-in userazadsigned-in-userlist-owned-objects# Get owned objects by current userazaccountmanagement-grouplist#Not allowed by default
AzureAD Security Best Practices ==============================
AzureAD is a critical component of many organizations' cloud infrastructure. Ensuring its security is paramount to protect sensitive data and resources. Here are some best practices to enhance AzureAD security:
Enable Multi-Factor Authentication (MFA): Require users to provide additional verification beyond their password to access AzureAD.
Regularly Review User Permissions: Periodically review and update user permissions to ensure least privilege access.
Monitor Sign-In Logs: Keep track of sign-in logs and set up alerts for any suspicious activities.
Enable Conditional Access Policies: Implement policies based on conditions like user location, device health, etc., to control access to AzureAD.
Use Secure Password Policies: Enforce strong password policies, including password complexity and expiration.
Enable Identity Protection: Utilize AzureAD Identity Protection to detect and respond to potential identity risks.
Regularly Update and Patch: Keep AzureAD and associated systems up to date with the latest security patches.
Educate Users: Train users on security best practices, such as recognizing phishing attempts and protecting their credentials.
By following these best practices, organizations can significantly improve the security of their AzureAD environment and reduce the risk of unauthorized access and data breaches.
#Get the current session stateGet-AzureADCurrentSessionInfo#Get details of the current tenantGet-AzureADTenantDetail
Azure PowerShell은 Azure 리소스를 관리하고 제어하기 위한 강력한 도구입니다. Azure PowerShell을 사용하면 스크립트를 작성하여 Azure 리소스를 자동화하고 구성할 수 있습니다. Azure PowerShell을 사용하면 Azure의 다양한 기능을 활용할 수 있으며, 특히 대규모 또는 반복적인 작업을 수행할 때 매우 유용합니다.
Azure PowerShell을 사용하면 가상 머신, 네트워크, 웹 앱, 데이터베이스 등과 같은 다양한 Azure 서비스를 관리할 수 있습니다. Azure PowerShell은 Azure Resource Manager(ARM)을 기반으로 하며, Azure의 모든 기능을 PowerShell 스크립트로 제어할 수 있습니다.
Azure PowerShell을 사용하면 Azure 환경을 효율적으로 관리하고 보안을 강화할 수 있습니다. PowerShell을 통해 Azure 리소스를 프로비저닝하고 모니터링하며, 보안 설정을 자동화하여 Azure 환경을 안전하게 유지할 수 있습니다.
Azure PowerShell은 다양한 운영 체제에서 사용할 수 있으며, Azure CLI와 함께 사용하여 Azure 환경을 효율적으로 관리할 수 있습니다.
# Get the information about the current context (Account, Tenant, Subscription etc.)Get-AzContext# List all available contextsGet-AzContext-ListAvailable# Enumerate subscriptions accessible by the current userGet-AzSubscription#Get Resource groupGet-AzResourceGroup# Enumerate all resources visible to the current userGet-AzResource# Enumerate all Azure RBAC role assignmentsGet-AzRoleAssignment# For all usersGet-AzRoleAssignment-SignInName test@corp.onmicrosoft.com # For current user
Azure를 열거하는 데 가장 중요한 명령 중 하나는 Az PowerShell의 **Get-AzResource**이며, 현재 사용자가 볼 수 있는 리소스를 알려줍니다.
이제 자격 증명에 대한 일부 정보를 가지고 있으므로 (그리고 레드팀인 경우 감지되지 않았으면 좋겠습니다). 환경에서 사용되는 서비스를 확인해야 합니다.
다음 섹션에서는 일반적인 서비스를 열거하는 몇 가지 방법을 확인할 수 있습니다.
서비스 주체 및 액세스 정책
Azure 서비스는 시스템 ID(서비스 자체)를 가질 수도 있고 사용자 지정 관리 ID를 사용할 수도 있습니다. 이 ID는 예를 들어 KeyVault에 액세스 정책을 가질 수 있어 비밀을 읽을 수 있습니다. 이러한 액세스 정책은 제한되어야 하지만 필요한 것보다 더 많은 권한을 가질 수도 있습니다. 일반적으로 App Service는 비밀과 인증서를 검색하기 위해 KeyVault를 사용합니다.
따라서 이러한 ID를 탐색하는 것이 유용합니다.
App Service SCM
App Service '컨테이너'에 로그인하기 위한 Kudu 콘솔.
웹 쉘
portal.azure.com을 사용하여 쉘을 선택하거나 bash 또는 powershell을 위해 shell.azure.com을 사용합니다. 이 쉘의 '디스크'는 저장소 계정에 이미지 파일로 저장됩니다.
Azure DevOps
Azure DevOps는 Azure와 별도입니다. 저장소, 파이프라인 (yaml 또는 릴리스), 보드, 위키 등이 있습니다. 변수 그룹은 변수 값과 비밀을 저장하는 데 사용됩니다.
Import-Module monkey365Get-HelpInvoke-Monkey365Get-HelpInvoke-Monkey365-DetailedInvoke-Monkey365-IncludeAzureActiveDirectory -ExportTo HTML -Verbose -Debug -InformationAction ContinueInvoke-Monkey365- Instance Azure -Analysis All -ExportTo HTML
# Start Backendcd stormspotter\backend\pipenv shellpython ssbackend.pyz# Start Front-endcd stormspotter\frontend\dist\spa\quasar.cmd serve -p 9091--history# Run Stormcollectorcd stormspotter\stormcollector\pipenv shellaz login -u test@corp.onmicrosoft.com -p Welcome2022!python stormspotter\stormcollector\sscollector.pyz cli# This will generate a .zip file to upload in the frontend (127.0.0.1:9091)
# You need to use the Az PowerShell and Azure AD modules:$passwd =ConvertTo-SecureString"Welcome2022!"-AsPlainText -Force$creds =New-Object System.Management.Automation.PSCredential ("test@corp.onmicrosoft.com", $passwd)Connect-AzAccount-Credential $credsImport-Module AzureAD\AzureAD.psd1Connect-AzureAD-Credential $creds# Launch AzureHound. AzureHound\AzureHound.ps1Invoke-AzureHound-Verbose# Simple queries## All Azure UsersMATCH (n:AZUser) return n.name## All Azure ApplicationsMATCH (n:AZApp) return n.objectid## All Azure DevicesMATCH (n:AZDevice) return n.name## All Azure GroupsMATCH (n:AZGroup) return n.name## All Azure Key VaultsMATCH (n:AZKeyVault) return n.name## All Azure Resource GroupsMATCH (n:AZResourceGroup) return n.name## All Azure Service PrincipalsMATCH (n:AZServicePrincipal) return n.objectid## All Azure Virtual MachinesMATCH (n:AZVM) return n.name## All Principals with the ‘Contributor’ roleMATCH p = (n)-[r:AZContributor]->(g) RETURN p# Advanced queries## Get Global AdminsMATCH p =(n)-[r:AZGlobalAdmin*1..]->(m) RETURN p## Owners of Azure GroupsMATCH p = (n)-[r:AZOwns]->(g:AZGroup) RETURN p## All Azure Users and their GroupsMATCH p=(m:AZUser)-[r:MemberOf]->(n) WHERE NOT m.objectid CONTAINS 'S-1-5'RETURN p## Privileged Service PrincipalsMATCH p = (g:AZServicePrincipal)-[r]->(n) RETURN p## Owners of Azure ApplicationsMATCH p = (n)-[r:AZOwns]->(g:AZApp) RETURN p## Paths to VMsMATCH p = (n)-[r]->(g: AZVM) RETURN p## Paths to KeyVaultMATCH p = (n)-[r]->(g:AZKeyVault) RETURN p## Paths to Azure Resource GroupMATCH p = (n)-[r]->(g:AZResourceGroup) RETURN p## On-Prem users with edges to AzureMATCH p=(m:User)-[r:AZResetPassword|AZOwns|AZUserAccessAdministrator|AZContributor|AZAddMembers|AZGlobalAdmin|AZVMContributor|AZOwnsAZAvereContributor]->(n) WHERE m.objectid CONTAINS 'S-1-5-21' RETURN p
## All Azure AD Groups that are synchronized with On-Premise ADMATCH (n:Group) WHERE n.objectid CONTAINS 'S-1-5' AND n.azsyncid IS NOT NULL RETURN n
# You should use an account with at least read-permission on the assets you want to accessgitclonehttps://github.com/nccgroup/azucar.gitPS>Get-ChildItem-Recursec:\Azucar_V10|Unblock-FilePS>.\Azucar.ps1-AuthModeUseCachedCredentials-Verbose-WriteLog-Debug-ExportToPRINTPS> .\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
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
# resolve the TenantID for an specific usernamePS>.\Azucar.ps1-ResolveTenantUserNameuser@company.com