Created
April 1, 2022 06:01
-
-
Save k3karthic/0e6e86dba1be07534099805c29e29062 to your computer and use it in GitHub Desktop.
Fetch Temporary AWS Credentials from CloudShell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Based on information from https://hackingthe.cloud/aws/post_exploitation/get_iam_creds_from_console_session/ | |
TOKEN=$( curl -s -X PUT localhost:1338/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 60" ) | |
JSON=$( curl -s localhost:1338/latest/meta-data/container/security-credentials -H "X-aws-ec2-metadata-token: $TOKEN" ) | |
if [ $? -eq 0 ]; then | |
ak=$( echo $JSON | jq .AccessKeyId ) | |
sk=$( echo $JSON | jq .SecretAccessKey ) | |
token=$( echo $JSON | jq .Token ) | |
echo "export AWS_ACCESS_KEY_ID=$ak" | |
echo "export AWS_SECRET_ACCESS_KEY=$sk" | |
echo "export AWS_SESSION_TOKEN=$token" | |
echo "export AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment