Home

Awesome

An awesome list with only the links is found on awesome-malware-persistence.


Collection of malware persistence information

This repository collects various currently scattered information regarding the detection, the response and the log collection of malware persistence mechanisms.

In short, we look for one of the things which is so common between different malware families: the ability to persist on a target host. Also malware associated with the misleading term "fileless" often persists on the target too, though not through regular files on the file system but through changes in configuration files like Windows Registry or cron jobs.

Unfortunately, many malware blog posts include all the various IP and hash information but only a few highlight the persistence mechanism from an attack, despite that it's one of the more static and more difficult to change information from an attacker's perspective. Using the persistence mechanism to hunt for malware is more robust than the more frequently changed IP addresses or hashes.

If you're only looking for an overview about persistence techniques and some links to useful resources then see overview of often and less often used persistence mechanisms and links and resources for detection. See section tools for some well-known persistence collection tools.

This repository is regularly updated with new detection resources and tools. If you have inputs then pull requests are more then welcome!

<!-- vim-markdown-toc GFM --> <!-- vim-markdown-toc -->

Why bothering with malware persistence?

If you are an incident responder and have to analyze compromised hosts, do a generic compromise assessment or if you do threat hunting activities in your infrastructure, then you should get into the topic of persistence mechanisms as one way to detect known or unknown malware. It's one of the pieces for looking for during IR activities.

Let's start with the persistence technique description used by MITRE:

The adversary is trying to maintain their foothold.

Persistence consists of techniques that adversaries use to keep access to systems across restarts, changed credentials, and other interruptions that could cut off their access. Techniques used for persistence include any access, action, or configuration changes that let them maintain their foothold on systems, such as replacing or hijacking legitimate code or adding startup code.

One thing in common between different malware families is that they (mostly) try to persist on the target host. Malware associated with the misleading term "fileless" often persists on the target too, though not through regular files on the file system but through changes in configuration files like Windows Registry or cron jobs.

Why use the word mostly above? Because there is rare malware which omit setting persistence mechanism on the victim's host itself but reinfect the host after reboot from another system (e.g. DC, where the system is running longtime on which no persistence is needed at all).

This gold mine of malware persistence information is a fraction of what other log sources produce. Tens to hundreds of events depending of what you looking for versus thousand to ten thousands of entries for process information. Therefore, the analysis of these events reduce the time and the effort compared to other log sources considerably. The signal to noise ratio is also much lower.

So, by becoming and being a persistent persistence hunter, you can make use of this treasury. Though not that kind of persistence hunting described in Wikipedia...

Persistence hunting (sometimes called endurance hunting) is a hunting technique in which hunters, who may be slower than their prey over short distances, use a combination of running, walking, and tracking to pursue prey until it is exhausted. A persistence hunter must be able to run a long distance over an extended period of time.

Detection

While there are many ways how malware can persist on a host, malware authors rely mostly on a handful of techniques. Beside these often used techniques some malware families and more targeted attacks use more advanced mechanisms to stay hidden on the system.

Keep in mind that for some persistence techniques escalated privileges are required and therefore malware running under normal users (and privilege escalation left out of consideration) can only set "user mode" persistence. So if the user on the infected host only use a normal user account then first focus on the user level persistence and secondly look for system level techniques.

Approach

The analysis process could involve these steps, as with other incident response and threat hunting procedures:

  1. Collect the persistence mechanisms using single commands for specific techniques (see links and resources for detection) or use tools for collection of a bunch of them at the same time, see tools.
  2. Analyse the command, file hash, file signer and file path information and enrich the information with more information from external services (AV detection rate, correlation with other files, reputation, signer information, known-bad hash check).
  3. If the output doesn't help, check the information against other clients in your infrastructure: Is this entry found on other hosts too?
  4. Look for anomalies, e.g. an exe file in startup folder where normally only .lnk files should be placed is suspicious or look for IP addresses or web request in cronjobs. See the links below for detection ideas.
  5. In the process of the analysis it is important to note too what is NOT found (evidence of absence) and not only what is found, e.g. no cron jobs were found at all.

Overview of commonly used persistence mechanisms

The used techniques varies from user land persistence mechanisms, to system level persistence, from hiding behind common binary names, to putting malware at unusual but lesser known places. Sometimes only a proxy or other network configuration (i.a. DNS settings) changes were found after infection. Retefe used the latter.

Use the information from section links and resources for detection for specific information for these techniques.

Linux

MacOS

Windows

Cloud

All OSes and developer specific changes

Overview of difficult to detect persistence mechanisms

Persistence through UEFI malware and bootkits

Links and resources for detection

The following resources cover a lot of persistence techniques and more information on how to detect these specific mechanisms.

MITRE ATT&CK tactic "TA0003 - Persistence"

One of the most comprehensive lists of persistence techniques is the list found in MITRE ATT&CK tactic "TA0003 - Persistence". Besides a description, different mitigations and a detection section is provided. Furthermore, the involved actors using these techniques are listed on the page.

URL: https://attack.mitre.org/tactics/TA0003/

Hexacorn's blog persistence category

A second gold mine for persistence information is found on Hexacorn's blog where regularly and since long time new techniques and blog posts about persistence mechanisms are published, crazy stuff. You'll also find there the legendary series "Beyond good ol’ Run key".

URL: http://www.hexacorn.com/blog/category/autostart-persistence/

theevilbit's series "Beyond the good ol' LaunchAgents"

Series about persistence on macOS beyond just the LaunchDaemons or LaunchAgents directories. In the introduction it's also refered to Pasquale Stirparo's posts (here and here) with the name Beyond the good ol' LaunchAgent from 2018.

URL: https://theevilbit.github.io/tags/beyond/

Forensic artifact repository

The forensic artifact repository covers different artifacts regarding persistence for different OSes. See yaml files for MacOS, Linux and Windows in the data directory.

URL: https://github.com/ForensicArtifacts/artifacts

Sigma rules

Sigma rules also include various rules regarding persistence. Search for persistence rules in Sigma repository or use the filter options of Sigma for either MITRE ATT&CK persistence category itself or for one specific technique:

sigmac --recurse --filter tag=attack.persistence --target splunk --config config/splunk-windows.yml rules

sigmac --recurse --filter tag=attack.t1084 --target splunk --config config/splunk-windows.yml rules

URL: https://github.com/Neo23x0/sigma/search?q=persistence&unscoped_q=persistence

Autoruns

You can learn which Windows persistence mechanisms are possible by looking at the output of Autoruns on your own client (see also tools). In the output you see the categories and the different locations where things were found. To see which entries Autoruns scans at all, you can start a disassembler and look at the strings found in the binary, this covers only a subset.

URL: http://technet.microsoft.com/en-us/sysinternals/bb963902

Another way to find Windows persistence information is to look at the PowerShell implementation of Autoruns, where the locations are found in the source code. Bonus: A history of the covered persistence locations for each version is found there too, which is awesome!

URL: https://github.com/p0w3rsh3ll/AutoRuns/blob/master/AutoRuns.psm1

KnockKnock

For macOS there's the KnockKnock persistence tool to look for persistence mechanisms: https://github.com/objective-see/KnockKnock. Specific persistence locations are found in the plugins folder, e.g. LaunchItems or StartupScripts.

PoisonApple

PoisonApple is a command-line tool to perform various persistence mechanism techniques on macOS. This tool was designed to be used by threat hunters for cyber threat emulation purposes. Learn about various macOS persistence techniques by looking at the source code of PoisonApple.

PANIX

Panix- Persistence Against *NIX - Features is a highly customizable Linux persistence tool and includes various persistence techniques.

Various blog posts

Various blog posts write about persistence mechanisms, some specific for one technique, others for a broader set of techniques. Here are some for the past years as an inspiration what to look for.

See How malware persists on macOS for macOS persistence locations, General persistence mechanisms: Common malware persistence mechanisms, Malware persistence techniques, WMI: Detecting & Removing an Attacker’s WMI Persistence, Winlogon: Windows Persistence using WinLogon, Kovter: Untangling Kovter’s persistence methods, Threat Spotlight: Kovter Malware Fileless Persistence Mechanism, GlobalFlags in Image File Execution Hijacks: Persistence using GlobalFlags in Image File Execution Options – Hidden from Autoruns.exe, Bootloader persistence: Uncovering a MyKings Variant With Bootloader Persistence via Managed Detection and Response, COM hijacking / CLSID hijacking: gdatasoftware writeup from 2014 or pentestlab writeup from 2020 or Enigma0x3 / Matt Nelson's writeup from 2016 abusing com hijacking in combination with scheduled tasks, Linux cron: Linux Malware Persistence with Cron, Microsoft Exchange and Outlook: Hunting for persistence via Microsoft Exchange Server or Outlook, Shadow Linking: The Persistence Vector of SaaS Identity Threat, Linux Detection Engineering - A primer on persistence mechanisms.

Examples

MITRE ATT&CK persistence technique called Local Job Scheduling

In the list from the tactic's page, we can navigate to the technique itself, namely T1168 - local job scheduling and get the description and the needed information about the involved tools and files:

On Linux and macOS systems, multiple methods are supported for creating pre-scheduled and periodic background jobs: cron, at, and launchd.

[...]

System-wide cron jobs are installed by modifying /etc/crontab file, /etc/cron.d/ directory or other locations supported by the Cron daemon, while per-user cron jobs are installed using crontab with specifically formatted crontab files.

Further below the detection ideas are provided. Besides the process monitoring we can spot malicious jobs by comparing the cron files and commands against other hosts or just search for unusual commands.

% grep -r http /etc/cron.daily/*

A writeup on bleepingcomputer regarding a cryptominer on Linux shows an example of such a cron entry. IP changes but the persistence technique using the crontab and a web request stays. So hunt them down!

(Ab)use of Rundll32

A second example is the (ab)use of rundll32.exe to load a library through registery keys or other means (T1085 - Rundll32). Ursnif is one of the malware families which use a specific rundll32 command line since long time. Therefore, searching for registry keys containing "rundll32" and "DllRegisterServer" in the command line would catch it or just use "rundll32" as a more generic search pattern.

Example taken from Trendmicro's URSNIF threat encyclopedia

In HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run
    dminsenh = "rundll32 "%Application Data%\Microsoft\Appislad\devrusic.dll",DllRegisterServer"

File handler manipulation

Sneaky persistence through manipulation of exefile file handler. MITRE ATT&CK T1546.001 - Event Triggered Execution: Change Default File Association. Lokibot sample from Nov 2021. Check both HKLM and HKCU.

\REGISTRY\MACHINE\SOFTWARE\Classes\exefile\shell\open\command\ = "C:\\Windows\\svchost.com \"%1\" %*"

and malware was dropped to C:\Windows\svchost.com.

Detection Evasion

Malware authors abuse different techniques to hide their malware persistence or make the detection more difficult:

Testing

Use the descriptions and information from the resources in section detection to simulate the persistence.

Furthermore, different tools provide checks to verify if detections work.

Atomic Red Team test suite allows checking for specific MITRE ATT&CK persistence techniques, see e.g. T1044 "File System Permissions Weakness".

hasherezade published demos of various (also non standard) persistence methods used by malware, like COM hijacking.

Use PoisonApple to perform various persistence techniques on macOS.

Use PANIX to perform various persistence techniques against Linux systems, among others Debian and RHEL.

Example

As an example we use the technique T1183 - "Image File Execution Options Injection" and abuse the "sticky keys" feature for executing a command shell. This would also be triggered before a login.

To test your collection tools, the prevention mechanisms in place and your awesome detections, execute the following for adding a debugger value for the corresponding registry key:

REG ADD "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\sethc.exe" /v Debugger /t REG_SZ /d "cmd /c tasklist"

Now you can click multiple times on the shift-key on your keyboard to trigger the execution of cmd.

Response

If you respond to an incident and need to clean up malware persistence as a temporary countermeasure, you just have to remove the given information. For files and configuration changes it's mostly done using standard OS commands. Use your EDR or some other frameworks (e.g. for Windows, see PowerSponse).

In special cases like WMI the cleanup is not as straightforward as with other mechanisms, see blog post Removing Backdoors – Powershell Empire Edition:

  1. remove the binding using Get-WmiObject __FilterToConsumerBinding -Namespace root\subscription | Where-Object { $_.filter -match 'evil'} | Remove-WmiObject;
  2. remove the event consumer using Get-WmiObject CommandLineEventConsumer -Namespace root\subscription -Filter "name='evil'" | Remove-WmiObject
  3. remove the event filter using Get-WMIObject -Namespace root\Subscription -Class __EventFilter -Filter "Name='evil'" | Remove-WmiObject -Verbose

Then there were issues with null byte values in the Windows registry and attackers abused that to hide entries in e.g. run keys. Custom tools or the RegDelNull can be used to remove these entries.

Prevention

This list is in no way comprehensive and just lists some possibilities to prevent malware persistence. The most important thing would be of course to prevent the execution of unknown programs.

For macOS there's the BlockBlock tool by Patrick Wardle which provides protection by monitoring persistence locations: https://github.com/objective-see/BlockBlock.

Tools

You can either collect the needed information once on a (remote) host in case of an incident or collect the information on a regular basis for baselining and threat hunting.

One thing as a reminder and thanks to Harlan Carvey over at windowsir for pointing out similar points too in various blog posts, see Deep Knowledge, and the Pursuit Thereof and Troubleshooting and Deep Knowledge: Be cautious of the results of tools and try to cross check with different tools or check things by hand. Tools only provide you the information in their way and sometimes miss the malicious entry or some options were turned off etc. Autoruns for example can hide Microsoft signed entries, but than some LOLbin (living-of-the-land, abusing system tools so to say) commands were missing. Use it to reduce the amount of entries, but know the limits. There was a null byte issue with the registry and the entries were missing too in the collection. New version fixed the issue. One more: Persistence using GlobalFlags in Image File Execution Options – Hidden from Autoruns.exe.

For collection of specific techniques see links and resources for detection which cover detailed information about the location of different persistence mechanisms.

Linux

MacOS

Windows

Github topic search for persistence

Currently not many things are found with these topics, but if you search for #malware and #persistence the matched repositories are listed: https://github.com/search?q=%23malware+%23persistence&type=

Acknowledgement

Thanks to my previous employer Swisscom (Github) for allowing me to publish the information which was inspired by my work in the past few years at the @swisscom_csirt.