I token temporanei non possono essere elencati, quindi mantenere attivo un token temporaneo è un modo per mantenere la persistenza.
awsstsget-session-token--duration-seconds129600# Con MFAawsstsget-session-token \--serial-number <mfa-device-name> \--token-code <code-from-token># Il nome del dispositivo hardware è di solito il numero sul retro del dispositivo, come GAHT12345678# Il nome del dispositivo SMS è l'ARN in AWS, come arn:aws:iam::123456789012:sms-mfa/username# Il nome del dispositivo virtuale è l'ARN in AWS, come arn:aws:iam::123456789012:mfa/username
Giocoleria con catene di ruoli
La concatenazione di ruoli è una funzionalità riconosciuta da AWS, spesso utilizzata per mantenere la persistenza in modo stealth. Coinvolge la capacità di assumere un ruolo che poi assume un altro, potenzialmente tornando al ruolo iniziale in modo ciclico. Ogni volta che viene assunto un ruolo, il campo di scadenza delle credenziali viene aggiornato. Di conseguenza, se due ruoli sono configurati per assumere reciprocamente l'uno l'altro, questa configurazione consente il rinnovo perpetuo delle credenziali.
Puoi utilizzare questo strumento per mantenere attiva la concatenazione dei ruoli:
Codice per eseguire il Role Juggling da PowerShell
# PowerShell script to check for role juggling possibilities using AWS CLI# Check for AWS CLI installationif (-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 rolesfunctionList-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 roleforeach ($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 credentialsforeach ($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 variablesRemove-Item Env:\AWS_ACCESS_KEY_IDRemove-Item Env:\AWS_SECRET_ACCESS_KEYRemove-Item Env:\AWS_SESSION_TOKEN} else {$errorCount++}} catch {$errorCount++}}# Output the number of errors if anyif ($errorCount -gt0) {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."