mirror of
https://github.com/mgeeky/Penetration-Testing-Tools.git
synced 2024-11-21 18:11:37 +01:00
Added get-session-creds-in-config-format.sh
This commit is contained in:
parent
ea7701a590
commit
da866502ac
34
clouds/aws/get-session-creds-in-config-format.sh
Normal file
34
clouds/aws/get-session-creds-in-config-format.sh
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# This script simply calls `aws sts assume-role` using hardcoded parameters, in order
|
||||||
|
# to retrieve set of session credentials and reformat it into ~/.aws/credentials file format.
|
||||||
|
#
|
||||||
|
# Mariusz B., mgeeky '19
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Configure below variables.
|
||||||
|
#
|
||||||
|
PROFILE_NAME=your-profile-name
|
||||||
|
SERIAL_MFA=arn:aws:iam::<NUMBER>:mfa/<USER-NAME>
|
||||||
|
ROLE_NAME=Your_Role_Name
|
||||||
|
ROLE_ARN=arn:aws:iam::<NUMBER>:role/$ROLE_NAME
|
||||||
|
DURATION=42000
|
||||||
|
|
||||||
|
#
|
||||||
|
# ------------------------
|
||||||
|
#
|
||||||
|
|
||||||
|
read -p "Type your AWS MFA Code: " code
|
||||||
|
echo
|
||||||
|
|
||||||
|
out=$(aws sts assume-role --serial-number $SERIAL_MFA --role-arn $ROLE_ARN --role-session-name $ROLE_NAME --duration-seconds $DURATION --token-code $code)
|
||||||
|
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "[$PROFILE_NAME]"
|
||||||
|
echo "$out" | python3 -c 'import sys,json; foo=json.loads(sys.stdin.read()); print("aws_access_key_id={}\naws_secret_access_key={}\naws_session_token={}".format(foo["Credentials"]["AccessKeyId"],foo["Credentials"]["SecretAccessKey"],foo["Credentials"]["SessionToken"]))'
|
||||||
|
echo
|
||||||
|
else
|
||||||
|
echo $out
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user