AWS - STS Persistence
Tip
Apprenez & pratiquez AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Apprenez & pratiquez GCP Hacking:HackTricks Training GCP Red Team Expert (GRTE)
Apprenez & pratiquez Az Hacking:HackTricks Training Azure Red Team Expert (AzRTE)
Soutenez HackTricks
- Consultez les subscription plans!
- Rejoignez le đŹ Discord group ou le telegram group ou suivez-nous sur Twitter đŠ @hacktricks_live.
- Partagez des hacking tricks en soumettant des PRs aux HackTricks et HackTricks Cloud github repos.
STS
Pour plus dâinformations, consultez :
Assume role token
Les jetons temporaires ne peuvent pas ĂȘtre listĂ©s, donc maintenir un jeton temporaire actif est un moyen de conserver la persistance.
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, souvent utilisĂ© pour maintenir une persistance furtive. Cela implique la capacitĂ© de assume a role which then assumes another, pouvant revenir au rĂŽle initial de maniĂšre cyclique. Chaque fois quâun rĂŽle est assumĂ©, le champ dâexpiration des identifiants est rafraĂźchi. Par consĂ©quent, si deux rĂŽles sont configurĂ©s pour sâassumer mutuellement, cette configuration permet le renouvellement perpĂ©tuel des identifiants.
Vous pouvez utiliser cet tool pour maintenir le 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
Notez que le script find_circular_trust.py de ce dĂ©pĂŽt Github ne trouve pas toutes les façons dont une chaĂźne de rĂŽles peut ĂȘtre configurĂ©e.
Code pour effectuer du Role Juggling depuis 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]
> Apprenez & pratiquez AWS Hacking:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://hacktricks-training.com/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Apprenez & pratiquez GCP Hacking: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://hacktricks-training.com/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Apprenez & pratiquez Az Hacking: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://hacktricks-training.com/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>Soutenez HackTricks</summary>
>
> - Consultez les [**subscription plans**](https://github.com/sponsors/carlospolop)!
> - **Rejoignez le** đŹ [**Discord group**](https://discord.gg/hRep4RUj7f) ou le [**telegram group**](https://t.me/peass) ou **suivez-nous** sur **Twitter** đŠ [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Partagez des hacking tricks en soumettant des PRs aux** [**HackTricks**](https://github.com/carlospolop/hacktricks) et [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
>
> </details>
HackTricks Cloud

