Heres the third entry in my series on abusing AWS services to provide C2 high reputation redirectors.
The first part in this series was all the way back in 2023, and in it I discussed abusing the following services to provide a trusted endpoint for C2 communications:
The second post was last week and covered AWS App Runner.
Check out those posts for more detail.
This time around, after diversions into the worlds of Azure and GCP, I’ve looped back for another look at AWS, to catch any services I missed the first time around.
In this post I will be looking at AWS Elastic Beanstalk, which is a service for easy migration, deployment and scaling of full stack applications on AWS. In this post we will see how it can instead be used to provide a trusted endpoint to receive C2 traffic and forward it to a C2 server running on an EC2 instance in a private VPC. We will do this through describing how you can setup a simple POC environment in your own AWS account.
Want more detail on why this would be useful? See this section in my first blog post on GCP service abuse.
The POC environment we will be looking at will use the following AWS resources:
For the purpose of this post I will discuss parts 1-3 in the section named The C2 Server and supporting networking
, and 4-6 in the section named Elastic Beanstalk setup
. Given a lot of this is pretty straightforward to deploy I will just provide general clickops creation instructions using the AWS web console.
The C2 service and supporting networking will use a VPC, an EC2 instance attached to that VPC and a security group associated with the EC2 instance to control network access to the instance. The steps in this section are exactly the same as the same section from post 2 in this AWS series, repeated here for ease of use.
An appropriate VPC can be deployed by visiting the VPC section of the AWS console, hitting the Create VPC
button, and using the Wizard to create VPC and more
.
In the wizard you can get away with the following minimal settings to create something functional for this POC:
This will look something like the following:
After creation, ensure all of the following resources that you create are associated with this new VPC and in the same AWS region.
We can create the EC2 instance and security group in one step. Visit the EC2 section of the console and hit Launch Instance
to start the new instance wizard.
The settings below are some simple guidelines and minimums to consider when configuring the instance in the wizard.
Machine image
Instance type
t2.nano
or t3.nano
Key Pair
Network settings
Enable
IAM instance profile
in the Advanced details
section allowing SSM access if you want to access the instance via SSM intermediated SSHConfigure storage
30GB
of storage and the gp3
volume typeAdvanced Settings
Go down to the User data - optional
and include this script. This will configure the instance as a Sliver C2 server with an Apache forwarder listening on port 80 that receives implant traffic.
Once the instance is up and running and the user data script has completed running, the environment will look something like the following:
We have a C2 server running, but at the moment we have no way to route implant traffic into the environment. This will be setup in the next section.
We need to create a security group for the Elastic Beanstalk Application we are about to create. This can be done from the AWS console here. Just make sure its created in the VPC we made earlier. We dont need to set any specific rules in the group, we will use it as a source to allow the Elastic Beanstalk Application we create to talk to the EC2 instance we created in the previous section.
The Elastic Beanstalk environment creation wizard can be started by hitting Create application
after visiting the Elastic Beanstalk section of the AWS console. The wizard has six steps, and the below will describe the important values to change for each step. Any option not specifically mentioned can be left at the default values.
Step 1: Configure environment
teststalk
teststalk-env
Heres a screenshot
Step 2: Configure service access
Step 3: Set up networking, database, and tags
Step 4: Configure instance traffic and scaling
Step 5: Configure updates, monitoring, and logging
DESTINATION
environment variable and set the value to the internal IP address of your C2 EC2 instanceStep 6: Review
Deploy
Monitor the deployment in the AWS console and once the Health
of the deployment in the Elastic Beanstalk Environment overview screen is Green you should be able to get the Domain value for you environment and visit it to ensure you can correctly visit the Sample applications web page (the value is hyperlinked in the console so just clicking will open it in a new tab).
My Domain value was teststalk-env.eba-5p3yniaa.ap-southeast-2.elasticbeanstalk.com
.
If you can see the sample app website you can now move ahead to deploying the forwarding web app that will instead route traffic to your C2.
The code we will be replacing the sample app with is available here. Clone it locally and create a deployment zip file (/tmp/dep.zip
) like so after switching to the source as your present working directory:
zip -r /tmp/dep.zip application.py requirements.txt
Use the Upload and deploy
button in the Elastic Beanstalk Environment overview section of the console, and in the following window, upload the zip file you created, and set a new version label for the app.
Once you have hit Deploy
and the Running Version section of the Beanstalks Environment page lists your new version, you should be able to access the Apache redirector on your EC2 C2 server by visiting your assigned domain using a http (NOT HTTPS!) request and see a response like the following.
$ curl http://teststalk-env.eba-5p3yniaa.ap-southeast-2.elasticbeanstalk.com/
<html>
</html>
The setup we now have is represented by the following network diagram.
You may have noticed that all instructions of how to access the Elastic Beanstalk app above specifically referenced HTTP and not HTTPS. Unlike some other fronting approaches I have discussed before, Elastic Beanstalk does NOT automatically provide HTTPS accessibility or a trusted certificate for you to use. It is however possible to get a free certificate through LetsEncrypt and use it for your app. This will involve adding some additional files to the deployment zip file you upload. Keep in mind this will get your endpoint some additional attention (and some free security scans!) as your Beanstalk app domain name will appear in the certificate transparency logs.
To enable HTTPS you can follow a process like the one described in this blog post. Just be sure to replace nginx
in the examples with apache
as we have used in this POC environment.