*nix Persistence Mechanisms

There are a number of systems on Unix-like hosts that may be abused by malware to maintain persistence on a host.

MITRE maintains comprehensive lists of Linux and MacOS persistence mechanisms.

Scheduled Jobs

There are many ways to schedule a jobs on *nix systems. All of these schedulers may be abused as persistence mechanisms.

MethodOperating SystemNotes
cronallhttps://crontab.guru
atall
systemd timersLinuxhttps://wiki.archlinux.org/index.php/Systemd/Timers
https://opensource.com/article/20/7/systemd-timers
periodicFreeBSDhttps://www.freebsddiary.org/periodic.php

Startup Scripts

*nix systems provide convenient methods to execute code when a system boots. Attackers can abuse this functionality to maintain persistence on a host.

sudo

sudo is a program which enables systems administrators to grant access to users to execute commands as another user. Most often, sudo is used to allow a regular user to execute commands as root. Attackers may abuse existing sudo configurations or add their own entries to sudoers (sudo’s configuration files) as a persistent method to elevate their privileges.

ssh

ssh is the most popular method of remotely administrating Unix-like systems. As such, it is a popular choice for attackers to abuse to maintain persistence on a host.

MethodNotes
authorized_keys
Stealing private keyshttps://github.com/droberson/sshady
PAM moduleshttps://github.com/zephrax/linux-pam-backdoor
http://0x90909090.blogspot.com/2016/06/creating-backdoor-in-pam-in-5-line-of.html
https://x-c3ll.github.io/posts/PAM-backdoor-DNS/
https://github.com/mthbernardes/sshLooterC

Abusing Accounts

Attackers often abuse accounts to main access. Credentials may be obtained by an attacker in a variety of ways:

MethodNotes
Default credentialshttps://github.com/droberson/rtfm/blob/master/defaults.md
Cracking hashes
Brute force
Spraying
Sniffing
Social engineering
Creating rogue accounts

Rootkits

Rootkits are malware which maintain access to a system by hiding an attacker’s presence. This is typically done by means of a malicious kernel module, abusing the dynamic linker (LD_PRELOAD, DYLD_INSERT_LIBRARIES), or replacing userland software with malicious code.

Here are some examples of publicly available rootkits for Unix-like systems.

RootkitOperating SystemNotes
ReptileLinuxhttps://github.com/f0rb1dd3n/Reptile
vlanyLinuxhttps://github.com/mempodippy/vlany
FreeBSD RootkitFreeBSDhttps://github.com/chkyass/Freebsd-Rootkit
Nuk3Gh0stLinuxhttps://github.com/ropch4ins/Nuk3Gh0st
Jynx2Linuxhttps://github.com/chokepoint/Jynx2
rkorovaLinuxhttps://github.com/nopn0p/rkorova
AzazelLinuxhttps://github.com/chokepoint/azazel
Z34107Linuxhttps://github.com/qunxyz/Z34107
inficereMacOShttps://github.com/enzolovesbacon/inficere
VixenSolarishttps://github.com/patrobinson/Vixen

Malicious Software Modules

Many advanced pieces of software provide means to load modules which extend their functionality. This functionality can be abused to load malicious modules which provide an attacker with illicit access to a system.

Malicious ModuleSoftwareNotes
apache-rootkitApachehttps://github.com/ChristianPapathanasiou/apache-rootkit
mod-rootmeApachehttps://github.com/sajith/mod-rootme
MySQL User-Defined FunctionsMySQLhttps://www.exploit-db.com/papers/44139

Abusing Shell Functionality

Shells can be abused in a number of ways to maintain persistence on a host.

MethodNotes
profiles and rc files
trapshttps://bash.cyberciti.biz/guide/Trap_statement
PATH hijacking

External Services

Attackers often abuse functionality of legitimate services, leverage bugs in these services, add backdoor code to a service, or create their own services with an intent of maintaining access on a host.

Web Shells

Web servers allow code execution. Naturally, attackers have created web-based shells which abuse this functionality.

Traffic Signalling

Send a magic packet or sequence of packets to a host to gain access to a system.