May 19, 2020
In the last post of this series, we discussed the basic principles of command and control (C2) channels and traffic. Hopefully it served as a decent primer for today’s topic – PowerShell Empire. If you missed the last post or need a refresher on command and control basics, you can check out part one here: Command and Control with PowerShell Empire.
It’ll probably also be helpful to have an instance up Empire up and running to follow along and try things out yourself. You can grab it off of GitHub here: https://github.com/EmpireProject/Empire.
Empire is a PowerShell based post exploitation framework that supports various methods of command and control as well as a host of external modules to perform tasks on compromised hosts. There are a lot of these types of frameworks out there. We chose to focus on Empire because it’s open sourced, widely adopted, and we use it ourselves a fair bit. It’s also developed and maintained by an incredibly talented group of people including: @harmjoy, @sixdub, @enigma0x3, @rvrsh3ll, @xorrior etc.
There are four main pieces of Empire that work together to bring you all the functionality the framework has to offer that we’ll be going over:
The first three work in tandem to establish the command and control channel. Modules are used after the C2 channel has been established to perform post exploitation tasks.
A listener is a process that runs on your attacking server which “listens” for incoming connections from compromised hosts. There are a number of listener types, but probably the most popular of them is the HTTP listener. Using an HTTP listeners specifies to Empire that the C2 traffic will be established and managed using the HTTP protocol. Empire has a default profile which defines specifically how the communication will happen. Unfortunately, a lot of defensive tools are going to catch the default Empire HTTP traffic. You can define your own profile for a listener to change the behavior and increase the chances of your C2 traffic going undetected, but that’s a bit out of the scope of this blog post. To start up your Empire HTTP listener you need to do a few things: use the appropriate listener, set mandatory options, and execute.
Most of the default options will already be set, but there are a few especially important options to take note of.
You can see all the options by typing “info”.
After setting all the options we need, you can finally execute the listener with the “execute” command.
Launchers and stagers, while technically two different parts of the Empire framework, serve the same purpose: downloading and executing the agent on the compromised host.
Empire comes with two different options for launchers: PowerShell and Python. Both types of launchers execute encoded commands which will reach out to the Empire server to download and then launch the agent. Choosing the right launcher depends on your compromised host, and whether it’s likely to have either PowerShell or Python installed. It’s likely PowerShell will be available on most Windows targets, so the PowerShell launcher is usually a safe bet. To use a launcher for a listener you’ve configured, you can run the following from the listeners menu:
launcher powershell http
This will specify to output a PowerShell launcher for the “http” listener and look like this:
The launcher starts a PowerShell process and executes a big blob of encoded commands. Stagers are slightly different in that they are dedicated payloads that must be run on the compromised host in order to establish an agent. Otherwise, they are nearly identical. Most of the time a stager is simply a file that will run the same PowerShell/Python launcher via a VBA Macro, .bat file, or other supported method. Since they are so similar in nature to launchers we won’t go into too much detail on them here, but to show a quick example the options for a macro stager look like this:
You now have everything you need to establish an agent on a compromised host! After the agent is established, you’ll have a fully functional command and control channel that you can use to further compromise the network.
Agents are the processes which run on compromised hosts and perform actions on those hosts and the network. It will periodically check in with your Empire server to see if there are any commands available, and if so run them and return the output. You can perform some basic functionality with the vanilla Empire agent including: running shell commands, injecting shellcode, and gather metadata about your agent and compromised host. To see all the built-in agent commands, you can simply type “help”.
Now that you have a basic understanding of C2 principles and the PowerShell Empire pieces required to establish a C2 channel, you can start to fully leverage Empire for post-exploitation tasks. Network enumeration/situational awareness, privilege escalation, credential gathering, and lateral movement are all accomplished via Empire modules. In the next post we’ll cover a number of these modules in detail and explain how to use them to further compromise a network.