Lets be honest implementing persistence on an assessment can be hard, messy, and get you caught. Fuzzy Security did an excellent overview of some of the most common techniques used today and how to implement them. You can find that blog post here.

Some of the persistence techniques mentioned are:

  1. Persistence through the Registry
  2. Scheduled Backdoors using Scheduled Tasks
  3. Process Resource Hooking
  4. Persistence through the MSDTC Service
  5. WMI Permanent Event Subscriptions

Personally, I like to use WMI as my persistence mechanism. It is hard to detect, difficult to remove, doesn’t require payloads saved on disk, and can be implemented easily. So how does it work? Well, at a very high level to establish persistence it is a three step process.

  1. Establish an event filter to trigger on system boot
  2. Create a command line consumer to run the payload
  3. Set a Binding to active the command line consumer, when the event filter is activated

To make this process a little easier I decided to make a quick PowerShell script. The script is available on Github. Most of the code I used came from research done by Matt Graeber and some help from Andrew Luke. Specifically, here and here are two resources that I relied on heavily.

To use this script edit the Payload to match your current environment. Import the script and run Install-Persistence. Install-Persistence

To make sure it installed correctly, simply run Check-WMI. Check-Persistence

Finally, to remove persistence, ensure that the variables for $EventFilterName and $EventConsumerName match the names assigned when it was installed. By default, these values are ‘Cleanup’ and ‘DataCleanup’ Respectively. Then run Remove-Persistence to remove each element of persistence.

There are also a ton of tools that you can use to establish persistence using WMI, like PowerSploit and PowerLurk.

If you have any feedback, advice, or comments, let me know!