AWS - STS Persistence
Tip
Impara e pratica il hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
STS
Per maggiori informazioni consulta:
Assume role token
I token temporanei non possono essere elencati, quindi mantenere un token temporaneo attivo è un modo per mantenere la persistence.
aws sts get-session-token --duration-seconds 129600
# With MFA
aws sts get-session-token \
--serial-number \
--token-code
# Hardware device name is usually the number from the back of the device, such as GAHT12345678
# SMS device name is the ARN in AWS, such as arn:aws:iam::123456789012:sms-mfa/username
# Vritual device name is the ARN in AWS, such as arn:aws:iam::123456789012:mfa/username
Role Chain Juggling
Role chaining is an acknowledged AWS feature, spesso utilizzata per mantenere la stealth persistence. Coinvolge la possibilitĂ di assumere un ruolo che poi ne assume un altro, potenzialmente ritornando al ruolo iniziale in modo ciclico. Ogni volta che un ruolo viene assunto, il campo di scadenza delle credenziali viene aggiornato. Di conseguenza, se due ruoli sono configurati per assumersi reciprocamente, questa impostazione consente il rinnovo perpetuo delle credenziali.
Puoi usare questo tool per mantenere attivo il role chaining:
./aws_role_juggler.py -h
usage: aws_role_juggler.py [-h] [-r ROLE_LIST [ROLE_LIST ...]]
optional arguments:
-h, --help show this help message and exit
-r ROLE_LIST [ROLE_LIST ...], --role-list ROLE_LIST [ROLE_LIST ...]
Caution
Nota che lo script find_circular_trust.py di quel repository Github non trova tutti i modi in cui una role chain può essere configurata.
Codice per eseguire Role Juggling con PowerShell
```bash
# PowerShell script to check for role juggling possibilities using AWS CLI
Check for AWS CLI installation
if (-not (Get-Command âawsâ -ErrorAction SilentlyContinue)) {
Write-Error âAWS CLI is not installed. Please install it and configure it with âaws configureâ.â
exit
}
Function to list IAM roles
function List-IAMRoles {
aws iam list-roles âquery âRoles[*].{RoleName:RoleName, Arn:Arn}â âoutput json
}
Initialize error count
$errorCount = 0
List all roles
$roles = List-IAMRoles | ConvertFrom-Json
Attempt to assume each role
foreach ($role in $roles) {
$sessionName = âRoleJugglingTest-â + (Get-Date -Format FileDateTime)
try {
$credentials = aws sts assume-role ârole-arn $role.Arn ârole-session-name $sessionName âquery âCredentialsâ âoutput json 2>$null | ConvertFrom-Json
if ($credentials) {
Write-Host âSuccessfully assumed role: $($role.RoleName)â
Write-Host âAccess Key: $($credentials.AccessKeyId)â
Write-Host âSecret Access Key: $($credentials.SecretAccessKey)â
Write-Host âSession Token: $($credentials.SessionToken)â
Write-Host âExpiration: $($credentials.Expiration)â
Set temporary credentials to assume the next role
$env:AWS_ACCESS_KEY_ID = $credentials.AccessKeyId
$env:AWS_SECRET_ACCESS_KEY = $credentials.SecretAccessKey
$env:AWS_SESSION_TOKEN = $credentials.SessionToken
Try to assume another role using the temporary credentials
foreach ($nextRole in $roles) {
if ($nextRole.Arn -ne $role.Arn) {
$nextSessionName = âRoleJugglingTest-â + (Get-Date -Format FileDateTime)
try {
$nextCredentials = aws sts assume-role ârole-arn $nextRole.Arn ârole-session-name $nextSessionName âquery âCredentialsâ âoutput json 2>$null | ConvertFrom-Json
if ($nextCredentials) {
Write-Host âAlso successfully assumed role: $($nextRole.RoleName) from $($role.RoleName)â
Write-Host âAccess Key: $($nextCredentials.AccessKeyId)â
Write-Host âSecret Access Key: $($nextCredentials.SecretAccessKey)â
Write-Host âSession Token: $($nextCredentials.SessionToken)â
Write-Host âExpiration: $($nextCredentials.Expiration)â
}
} catch {
$errorCount++
}
}
}
Reset environment variables
Remove-Item Env:\AWS_ACCESS_KEY_ID
Remove-Item Env:\AWS_SECRET_ACCESS_KEY
Remove-Item Env:\AWS_SESSION_TOKEN
} else {
$errorCount++
}
} catch {
$errorCount++
}
}
Output the number of errors if any
if ($errorCount -gt 0) {
Write-Host â$errorCount error(s) occurred during role assumption attempts.â
} else {
Write-Host âNo errors occurred. All roles checked successfully.â
}
Write-Host âRole juggling check complete.â
</details>
> [!TIP]
> Impara e pratica il hacking AWS:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Impara e pratica il hacking GCP: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Impara e pratica il hacking Azure: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>Supporta HackTricks</summary>
>
> - Controlla i [**piani di abbonamento**](https://github.com/sponsors/carlospolop)!
> - **Unisciti al** đŹ [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo telegram**](https://t.me/peass) o **seguici** su **Twitter** đŚ [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Condividi trucchi di hacking inviando PR ai** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos su github.
>
> </details>
HackTricks Cloud

