AWS - STS Post Exploitation

Tip

学习并练习 AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

STS

更多信息:

AWS - IAM, Identity Center & SSO Enum

从 IAM 凭证 到 控制台

如果你已经设法获取了一些 IAM 凭证,你可能想使用下面的工具访问 web 控制台.\ 注意,用户/角色必须拥有权限 sts:GetFederationToken

自定义脚本

下面的脚本将使用默认 profile 和默认的 AWS 区域(不是 gov,也不是 cn)为你生成一个签名 URL,可用于登录 web 控制台:

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

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 凭证。

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 来获取一个 浏览器控制台会话

从 Web Console 到 IAM 凭证

该浏览器扩展 https://github.com/AI-redteam/clier 能够在浏览器将 IAM 凭证保护到内存之前,从网络中拦截这些 IAM 凭证。

从 Python 绕过 User-Agent 限制

如果存在基于所使用的 user agent 执行某些操作的限制(例如根据 user agent 限制使用 python boto3 库),可以使用前述技术通过浏览器连接到 web console,或者你也可以直接通过如下方式修改 boto3 的 user-agent

# 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

拥有此权限可以为执行该操作的用户创建一个联合身份,且该身份的权限被限制为该用户本身已有的权限。

aws sts get-federation-token --name <username>

由 sts:GetFederationToken 返回的令牌属于调用用户的联合身份,但权限受限。即使该用户具有管理员权限,通过该联合令牌也无法执行某些操作,例如列出 IAM 用户或附加策略。

此外,该方法在一定程度上更为隐蔽,因为联合用户不会出现在 AWS Portal 中,只能通过 CloudTrail 日志或监控工具观察到。

Tip

学习并练习 AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学习并练习 GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学习并练习 Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks