# PowerShell Empire

{% hint style="info" %}
PowerShell-Empire PowerShell Scripts Location `/usr/share/powershell-empire/empire/server/data/module_source/`
{% endhint %}

So, we have a stable shell. What now?

With a foothold in a target network, we can start looking to bring what is known as a C2 (Command and Control) Framework into play. C2 Frameworks are used to consolidate an attacker's position within a network and simplify post-exploitation steps (privesc, AV evasion, pivoting, looting, covert network tactics, etc), as well as providing red teams with extensive collaboration features. There are many C2 Frameworks available. The most famous (and expensive) is likely Cobalt Strike; however, there are many others, including the .NET based [Covenant](https://github.com/cobbr/Covenant), [Merlin](https://github.com/Ne0nd0g/merlin), [Shad0w](https://github.com/bats3c/shad0w), [PoshC2](https://github.com/nettitude/PoshC2), and many others. An excellent resource for finding (and filtering) C2 frameworks is [The C2 Matrix](https://www.thec2matrix.com/) , which provides a great list of the pros and cons of a huge number of frameworks.

We have a system shell on a Windows host, making this an ideal time to introduce the second of our three teaching topics: the C2 Framework "Empire".

Powershell Empire is, as the name suggests, a framework built primarily to attack Windows targets (although especially with the advent of dotnet core, more and more of the functionality may become usable in other systems). It provides a wide range of modules to take initial access to a network of devices, and turn it into something much bigger. In this section we will be looking at the principles of PS Empire, as well as how to use it (and its GUI interface: Starkiller) to improve our shell and perform post-exploitation techniques on the Git Server.

The Empire project was originally abandoned in early 2019; however, it was soon picked up by a company called BC-Security, who have maintained and improved it ever since. As such, there are actually two public versions of Empire -- the original (now very outdated), and the current [BC-Security](https://www.bc-security.org/) fork. Be careful to get the right one!

Note: this material was originally written for Empire 3.x, but has been updated in response to the release of Empire 4.x which has a very different way of operating. Make sure to use Empire 4.x if following along with these materials.

We will be looking into both Empire and its GUI extension: "Starkiller". Empire is the original CLI based framework but has now been split into a server mode and a client mode. Starkiller is a more recent addition to the toolbox, and can be used instead of (or as well as) the Empire client CLI program.

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FxubLFwmfQf1CAEj7uP7m%2Fimage.png?alt=media&#x26;token=777f8162-908f-4f1b-b261-1ee7968d7d79" alt=""><figcaption></figcaption></figure>

It would be more common to have an Empire server running on a separate C2 server (usually hosted locally with cloud infrastructure linking back to receive inbound connections through). Multiple pentesters or red teamers would then be able to connect to a single central server.

This is entirely overkill for our uses here -- instead we will just run both the server and the client application(s) on the single Kali instance.

With the server started, let's get the Empire CLI Client working. You are welcome to skip this if you would prefer to work exclusively in Starkiller.

Starting the Empire CLI Client is as easy as:

`$ powershell-empire client`

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FouqihwN6y3GphHS49sOA%2Fimage.png?alt=media&#x26;token=eec2a0b0-4acc-4cdb-a278-c7211472eb72" alt=""><figcaption></figcaption></figure>

With the server instance hosted locally this should connect automatically by default. If the Empire server was on a different machine then you would need to either change the connection information in the `/usr/share/powershell-empire/empire/client/config.yaml` file, or connect manually from the Empire CLI Client using `connect HOSTNAME --username=USERNAME --password=PASSWORD`

Starkiller is an Electron app which works by connecting to the REST API exposed by the Empire server

With an Empire server running, we can start Starkiller by executing `starkiller` in a new terminal window:

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FH6nxI5LwAODJBl7KctrE%2Fimage.png?alt=media&#x26;token=7223f807-a3f6-4051-9655-bde251fd0d50" alt=""><figcaption></figcaption></figure>

From here we need to sign into the REST API we deployed previously. By default this runs on `https://localhost:1337`, with a username of `empireadmin` and a password of `password123`:

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FHYjx7bFUzHMYZT6rWJHt%2Fimage.png?alt=media&#x26;token=8db22417-062e-4f58-825e-116b49300589" alt=""><figcaption></figcaption></figure>

Powershell Empire has several major sections to it, which we will be covering in the upcoming tasks.

* Listeners are fairly self-explanatory. They listen for a connection and facilitate further exploitation
* Stagers are essentially payloads generated by Empire to create a robust reverse shell in conjunction with a listener. They are the delivery mechanism for agents
* Agents are the equivalent of a Metasploit "Session". They are connections to compromised targets, and allow an attacker to further interact with the system
* Modules are used to in conjunction with agents to perform further exploitation. For example, they can work through an existing agent to dump the password hashes from the server

Empire also allows us to add in custom plugins which extend the functionality of the framework in various ways; however, we will not be covering this in the upcoming content.

In addition to these practical applications of the framework, it also has a nifty credential storage facility, automatically storing any found creds in a local database, plus many other neat features! Many of these extra features (such as the messaging functionality) are tailored for teams attacking a target; we will not be covering these collaborative features in much detail, but you are encouraged to look at them for yourself!

There is a problem though. As established previously, our target (the Git Server) does not have the ability to connect directly to our attacking machine. Due to how Empire handles pivoting, we will need to set up a special kind of listener, so before we do that, we will learn the "normal" process for setting up Empire and Starkiller using the already compromised Webserver as a target. Once we have a handle on how Empire operates, we will switch focus to our primary target: the Git Server.

In each of the following tasks, we will cover the relative section in both the Empire CLI and the Starkiller GUI. You are welcome to pick whichever one you prefer -- or follow along with both!

## Setting up the First Listener

Listeners in Empire are used to receive connections from stagers (which we'll look at in the next task). The default listener is the HTTP listener. This is what we will be using here, although there are many others available. It's worth noting that a single listener can be used more than once -- they do not die after their first usage.

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FnGFHRmSzxQjo22E50MHc%2Fimage.png?alt=media&#x26;token=8b49ace7-ede6-4cfb-9999-ce5983448b23" alt=""><figcaption></figcaption></figure>

To select a listener we would use the `uselistener` command. To see all available listeners, type `uselistener`  (making sure to include the space at the end!) -- this should bring up a dropdown menu of available listeners:

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Fqlcc1KA41jLvVD7O0O5q%2Fimage.png?alt=media&#x26;token=5852d0c1-dbf1-4751-971a-10de86869237" alt=""><figcaption></figcaption></figure>

When you've picked a listener, type `uselistener LISTENER` and press enter to select it; alternatively, the up and down arrow keys can also be used to traverse the dropdown, with the chosen listener again being selected by pressing enter. Here we will be using the `http` listener (the most common kind), so we use `uselistener http`:

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2F3HHRvzmznOxKH4i3rGGz%2Fimage.png?alt=media&#x26;token=5ed36a35-2c19-4115-9da8-548fcd5852eb" alt=""><figcaption></figcaption></figure>

This brings up a huge table of options for the listener. If we need to see an updated copy of this table (having set options, for example), we can access it again with the options command when in the context of the listener.

The syntax for setting options is identical to the Metasploit module options syntax `-- set OPTION VALUE`. Once again, a dropdown will appear showing us the available options after we type `set`.

Set a new name for the listener. This allows us to easily identify it later -- especially if we have several open. It is not essential, however, and can be left at the default `http` if preferred.

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Ff4k8anXq570dYiONYrys%2Fimage.png?alt=media&#x26;token=98611692-9d3a-4ff1-ace4-b81d715affc2" alt=""><figcaption></figcaption></figure>

Bear in mind that option names are case sensitive in Empire.

Many of the other options presented here are extremely useful, so it's well worth learning what they do and how they can be applied.

With the required options set, we can start the listener with: `execute`. We can then exit out of this menu using `back`, or exit to the main menu with `main`.

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FmeJi9fHSAGF0jYuK3hGx%2Fimage.png?alt=media&#x26;token=339d12c1-c3aa-4d5d-95bd-f5a307aafc6b" alt=""><figcaption></figcaption></figure>

When we want to stop a listener, we can use `kill LISTENER_NAME` to do so --  a dropdown menu with our active listeners will once again appear to assist.

We have a listener in the Empire CLI; now let's do the same thing in Starkiller!

## Starting the Listener in StarKiller

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FUclCeuuZDEF2WYMMrKgY%2Fimage.png?alt=media&#x26;token=e10313f8-e881-4a17-af03-a28293708b7a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FET33LyLCm2ZrBHvRHcH0%2Fimage.png?alt=media&#x26;token=50f33fbd-a247-4735-9d00-de7cc9cb30e9" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Fq6rdrAwabsIvasHdJdlD%2Fimage.png?alt=media&#x26;token=f783e30b-609f-46e6-9b1a-55b6e9ad1b1e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FLFfkaODz9icBYBTcp27f%2Fimage.png?alt=media&#x26;token=da0502c0-0123-4af2-aa60-c5f79114fdf8" alt=""><figcaption></figcaption></figure>

## Stagers

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FoSv1qx320xGhWLyOJVPQ%2Fimage.png?alt=media&#x26;token=f592289e-2fd6-440e-8b7c-c0f4ece58e4a" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FWKVd7AZhpdozVCZaSuPj%2Fimage.png?alt=media&#x26;token=6e87b742-0963-4c94-85c9-7aa952c2e584" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FfO3vHbXSZKoSGEAlYsCQ%2Fimage.png?alt=media&#x26;token=885f7100-2355-414c-b69d-7f97ce694df2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Fa1IiUhf78JnFnzP6ypc6%2Fimage.png?alt=media&#x26;token=9d8e3bc5-902f-4b42-aa6b-d2d417fd3d43" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2F25KE1Hfp2OnrXTlvxnaA%2Fimage.png?alt=media&#x26;token=65ecef46-e98c-40e0-9e11-a0646e32241d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Fn97DZvAtMepn2pRrUFD3%2Fimage.png?alt=media&#x26;token=891bf7b1-d3c0-4e91-9a58-a6d980027540" alt=""><figcaption></figcaption></figure>

## Agents

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2F1NNEaWDIsDaCAqpexX0S%2Fimage.png?alt=media&#x26;token=58f91deb-5265-4b37-ae79-227f6514a3bf" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Fe6iAaf4bIMoJmaZwWfXV%2Fimage.png?alt=media&#x26;token=71a46c99-1a2a-42b0-a5c6-06676458e86f" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FMlxAKfa92Qv7ZRvxWDGU%2Fimage.png?alt=media&#x26;token=73b8c4c2-6094-480f-91da-3c4b07ab8c5e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FsAJ8Zru6EuY3zcD4LYSx%2Fimage.png?alt=media&#x26;token=8a3683f9-84de-415f-8a97-db348694af0b" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FNuKsI53W2to55PZlHXfo%2Fimage.png?alt=media&#x26;token=a894fefb-5809-486f-b312-1cc8df350766" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FaN19P2k1r8B8J9vuWCsr%2Fimage.png?alt=media&#x26;token=3afcfd44-c0fd-4ddf-b300-68059829cc6e" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FcJITgZz3WaFM9gCOCQfy%2Fimage.png?alt=media&#x26;token=9519a26d-a48b-4dca-a859-1ab09bff2b2b" alt=""><figcaption></figcaption></figure>

## Hop Listeners

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FaIPTSDGbg8YTlidc2Vp9%2Fimage.png?alt=media&#x26;token=da790d57-e27e-484f-8c6a-0b4cac04abe2" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FttaxqJIWO9RhrQpsVT90%2Fimage.png?alt=media&#x26;token=ea7bc22a-6884-4211-8d31-fb0c0baca1b6" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FloqWFo6Nwke55C9MCaLS%2Fimage.png?alt=media&#x26;token=a37fe521-6c73-4e35-b381-3bcba21504f8" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2F6sb9Fx2S9oPwWbXAucUe%2Fimage.png?alt=media&#x26;token=86055afb-281a-4d5b-85bd-0285a7b25265" alt=""><figcaption></figcaption></figure>

## Git Server

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Fjqy5bFFPPC9f0wdizZ1K%2Fimage.png?alt=media&#x26;token=2c129970-b180-4af1-9f06-b16bde40cdf3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Fxpl4844Xc181cx3eGotr%2Fimage.png?alt=media&#x26;token=762c1e2d-777e-456b-8a7e-243edf5ffa47" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FCxWbL6IxXhEipRTe8nqP%2Fimage.png?alt=media&#x26;token=2a6c0eb4-f31d-4e92-98cb-aafead4a168c" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2F4FrYs1AQV9ujfKoFoH57%2Fimage.png?alt=media&#x26;token=6df8c728-fe2a-415b-95fd-c323bf37f265" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FxJPLAbTgNEdYvG7YDkrU%2Fimage.png?alt=media&#x26;token=674427cb-5e17-40d6-84ae-c9e0dca95c09" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FmVpU5xncusSL35CcRGw1%2Fimage.png?alt=media&#x26;token=a39ba5c6-a5f2-4f34-866e-bc60140ae7bb" alt=""><figcaption></figcaption></figure>

## Modules

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Ftuxjv9xvghtiVdQBc8tk%2Fimage.png?alt=media&#x26;token=ac5e16e9-3bab-4aff-bcff-24c841e0f503" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Ft9YRSztpxcyJeU0wNN08%2Fimage.png?alt=media&#x26;token=85eb897f-36d9-4c81-9259-c65614cb35a1" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2Fa7kkcjuUn7uHLuIEnhPk%2Fimage.png?alt=media&#x26;token=a81b7c52-5ff7-4588-b4b6-6379fe203aa3" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FR6qhTABLYFaiAtbu257y%2Fimage.png?alt=media&#x26;token=c5749648-091c-4f82-8874-ffce46356920" alt=""><figcaption></figcaption></figure>

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FLFUnXQEBVPpKlt3WmAxj%2Fimage.png?alt=media&#x26;token=fa6a1bff-06b3-4254-baeb-4d7fd9c87c4a" alt=""><figcaption></figcaption></figure>

## Interactive Shell

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FOkL2pBfl53BBwQ2jSbqC%2Fimage.png?alt=media&#x26;token=056ed963-5469-45f6-9fea-ee27cef70070" alt=""><figcaption></figcaption></figure>

## Conclusion

<figure><img src="https://537410186-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FH9oYbVb7VAsDxBfUpLeo%2Fuploads%2FFHf4Af4HsHoufYHBGJU5%2Fimage.png?alt=media&#x26;token=00359ded-6fdc-4426-9008-0340e01b46a2" alt=""><figcaption></figcaption></figure>
