Linux-Forensics

Linux Live Analysis Knowledge Base, Tips & Tricks

  1. System Infos and Settings
  2. Users, User Groups and Authentication (SSH)
  3. Files, Directories and Binaries
  4. System Logs
  5. Processes
  6. Persistence, overview
  7. General Velociraptor artifacts

1. System Infos and Settings

General System Overview

Command Output
System Information  
#ls Note: timestamps can easily be manipulated. Don’t trust ‘ls’ timestamps.
#date Date, time, timezone
#uname -a System hostname, OS and Kernel versions
#uname -r Kernel version
#uname -n System hostname
#uname -m Kernel architecture
#cat /etc/*-release Distribution information
#cat /proc/stat | grep btime System boot time
Users and Groups  
see  
Networking  
#ifconfig -a Network interfaces
#netstat -nalp Current connections, routing table, net. int. stats
Processes  
see  
File system  
#df -a File system information
#mount File system information
Kernel  
#cat /proc/version Kernel information
#lsmod Lists installed kernel modules

Velociraptor Artifacts

2. Users, User Groups and Authentication (SSH)

User config files: /etc/passwd (Users), /etc/shadow (hashed passwords), check for:

/etc/group

Logins
Search for suspicious logins or failed attempts.

SSH Keys
Check for suspicious authorized keys, unprotected private keys, suspicous SSH configs, suspicious creation/modification timestamps.

Velociraptor Artifacts

3. Files, Directories and Binaries

Search for suspicious files, directories and creation/modification timestamps.

Velociraptor Artifacts

4. System Logs

Syslog
Check for tampered or missing logs.

Systemd Journal

Sysmon for Linux

Velociraptor Artifacts

5. Processes

Suspicious processes:

Commands:

Velociraptor Artifacts

6. Persistence, overview

Linux persistence overview
Linux persistence overview - credits Pepe Berba

6.1 System boot: Sytem V, Upstart, Systemd, Run Control

Different scripts are run during system boot. These scripts can be created or modified to gain persistence.

  1. System V (SysV)
    Older init system.
    Startup, running and shutdown scripts in /etc/init.d/ and executed as root on boot (compatibility through systemd-generator).
    Scripts are often linked to runlevel directories, determining when they are run: /etc/rc0.d/, /etc/rc1.d/,/etc/rc2.d/, etc.

  2. Upstart
    Older init system.
    System-wide scripts in /etc/init/.
    User-session mode scripts in ~/.config/upstart/, ~/.init/,/etc/xdg/upstart/,/usr/share/upstart/sessions/.

  3. Systemd
    System ans service manager for Linux, replacement for SysVinit. Systemd operates with unit files, defing how services are started, stopped or managed.
    There are different types of unit files: Service (for managing long-running processes - typically deamons), Timer (similar to cron jobs).
    • Systemd Services
      System-wide services: /run/systemd/system/, /etc/systemd/system/, /etc/systemd/user/, /usr/local/lib/systemd/system/, /lib/systemd/system/, /usr/lib/systemd/system/, /usr/lib/systemd/user/
      User-specific services: ~/.config/systemd/user/, ~/.local/share/systemd/user/
    • Systemd Timers
      Each .timerfile must have a corresponding .service file with the same name. System-wide timers: /etc/systemd/system/, /usr/lib/systemd/system, User-specific timers: ~/.config/systemd/
    • Systemd Generator
      Generators are executables run by systemd at bootup or during configuration reloads.
      System-wide generators: /etc/systemd/system-generators/. /usr/local/lib/systemd/system-generators/. /lib/systemd/system-generators/. /etc/systemd/user-generators/. /usr/local/lib/systemd/user-generators/. /usr/lib/systemd/user-generators/
      systemd-rc-local-generator, rc-local.service: Compatibility generator and service to start /etc/rc.local during boot.
  4. rc.common, rc.local
    Deprecated and replaced by Systemd (compatibility through systemd-generator).
    The rc.local, rc.common files can start customer apps, services, scripts or commands at start-up. Config file /etc/rc.*local*

  5. initrd and initramfs
    See virtualization

Velociraptor Artifacts

6.2 User Accounts, Authentication

  1. User Accounts and Groups
    See
  2. SSH Keys
    See
  3. MOTD
    Message of the day (MOTD) is a message presented to a user when he/she connects via SSH or a serial connection. If activated, MOTD scripts are executed as root every time a user connects to a Linux system. These scripts can be modified to gain persistence. Config files in /etc/update-motd.d/
  4. XDG Autostart
    XDG Autostart entries can be used to execute arbitrary commands or scripts when a user logs in.
    System-wide configs: /etc/xdg/autostart/, /usr/share/autostart/
    User-specific configs: ~/.config/autostart/, ~/.local/share/autostart/, ~/.config/autostart-scripts/
    Root-specific configs: /root/.config/autostart/, /root/.local/share/autostart/, /root/.config/autostart-scripts/

6.3 Jobs, Crons, Timers, Automated actions

  1. At job (one time jobs)
    Config files in /var/spool/cron/atjobs/
    Job detail in /var/spool/cron/atspool/
  2. Cron Job (recuring jobs)
    User-specifc cron job settings:
    /var/spool/cron/, /var/spool/cron/crontabs/
    System-wide cron job settings:
    /etc/crontab, /etc/cron.d/, /etc/cron.daily/, /etc/cron.hourly/, /etc/cron.monthly/, /etc/cron.weekly/
  3. UDEV
    Device manager for the Linux kernel. When a device is added to the system (USB drive, keyboard or network interface, etc) UDEV triggers predefined actions (rules).
    These rules can be created or manipulated to gain persistence. UDEV rule files in:
    /etc/udev/rules.d/, /run/udev/rules.d/, /usr/lib/udev/rules.d/, /usr/local/lib/udev/rules.d/, /lib/udev/
  4. Additionnal persistence mechanisms: Anacron, Fcron, Task Spooler, Batch.

Velociraptor Artifacts

6.4 Shared objects/libraries

LD_PRELOAD
LD_PRELOAD is an environment variable used to specify a shared library (or multiple libraries) that should be loaded before any other shared libraries () when executing a program. This allows to override functions in the standard library or other shared libraries without modifying the original binary.

Velociraptor Artifacts

6.5 Shell configurations, Environment Variables

  1. Shell scripts
    Different scripts are executed when a shell starts or ends.
Files Working
/etc/bash.bashrc systemwide files executed at the start of interactive shell
/etc/bash_logout Systemwide files executed when we terminate the shell
~/.bashrc Widly exploited user specific startup script executed at the start of shell
~/.bash_profile, ~/.bash_login, ~/.profile User specific files , but which found first are executed first
~.bash_logout User specific files, executed when shell session closes
~/.bash_logout User-specific clean up script at the end of the session
/etc/profile Systemwide files executed at the start of login shells
/etc/profile.d all the .sh files are executed at the start of login shells
  1. Environment Variables
    Each process has en environment list, wich is a set of environment variables. When a new process is created via fork(), it inherits a copy of its parent’s environment. There are multiple use cases for environment variables. For example the env. variable SHELL defines the path to the shell that programms will use when they need a shell, or HOME that defines the home directory of a user. There are local and system-wide environment variables.

TO DO

Velociraptor Artifacts

6.6 System Binaries

  1. Living of the Land Binaries See https://gtfobins.github.io/
  2. Modified or substituted system binaries
    • for example, replace /bin/false with /bin/bash (usefull to hide a shell-login in /etc/passwd)
  3. System Binary Wrapping Replace a system binary by a malicious one, executing additionnal code without breaking the functionnality of the original system binary.
    • compare binary hashes to known-good ones (#sha256sum <file>)
    • monitor file integrity with AIDE, #rpm -Va (Red Hat), #dpkg --verify
  4. Modified packet manager configurations
    • /etc/apt/apt.conf.d/*
    • /usr/lib/python*/site-packages/dnf-plugins/*
    • /etc/dnf/plugins/*
    • /usr/lib/yum-plugins/*
    • /etc/yum/pluginconf.d/*

Velociraptor Artifacts

6.7 Loadable Kernel Modules (LKM)

Loadable kernel modules can be dynamically loaded into the Linux Kernel at runtime to extend its functionality. There is no need to recompile the kernel or reboot the machine to apply the change. A malicious kernel module can hook kernel functions allowing to manipulate: Syscall table, Kprobes, Ftrace, VFS.

Hunting

See external tools and Velociraptor artifacts under the “Rootkit” part.

6.8 RAM and Virtualization

  1. initrd, initramfs
    Initramfs is a temporary file system mounted during the early boot process, before the root file system is mounted. The /boot directory where initramfs is stored is not monitored against integrity and makes it a perfect place to hide malicious code.
    • Check /proc/<pid>/ns links
    • Check Kernel threads proc entries (ppid != 0)
  2. Malicious VM or Container (tbd)
  3. RAM (tbd)

6.9 Rootkits, User- and Kernel-Space

Rootkits can be tricky to detect as they have different mechanisms to hide on an infected system. On the other hand, it is difficult to build stable kernel-rootkits in Linux and any sudden system instabilities (crash, reboot) could indicate their presence.

Rootkits can modify or hide following elements making their manual detection challenging:

For rootkits persistence mechanisms, see system boot, Shared objects/libraries, Loadable Kernel Modules (LKM), Virtualization.

There is no silver bullet to detect rootkits using common Linux system utilities. It is recommended to compare the subject machine to a known-good VM or to retrieve the same information in multiple different ways (for example compare the loaded kernel modules with lsmod, cat /proc/modules, kmod list).
Following are some external tools that can help in their detection. If it is not possible to install these tools on the subject machine (remember to modify as little as possible on a subject machine when doing a forensic analysis), then the recommended method would be to take a memory image (with LiME) and analyse it with Volatility (a separated doc for this process will follow).
Note that some of the listed tools don’t required any installation on a subject machine and are therfore very usefull for a live analysis.

Velociraptor Artifacts

Rootkit Detection Tools

Tool Details
Sunlight https://github.com/tstromberg/sunlight.git
set of powerfull bash scripts
LinuxCatScale https://github.com/WithSecureLabs/LinuxCatScale
bash script that uses live-of-the-land tools
UAC https://github.com/tclahr/uac
Use of native binaries and tools
Runs everywhere with no dependencies (no installation required)
rkhunter Rootkit, backdoor and local exploits scanner.
chrootkit Rootkit scanner.
unhide https://salsa.debian.org/pkg-security-team/unhide
(part of Kali) find processes and TCP/UDP ports hidden by rootkits
ClamAV Antivirus scanner for Linux.
bpftrace https://github.com/bpftrace
Dynamic tracing tool using eBPF. A bunch of detection scripts are available.
Tracee https://github.com/aquasecurity/tracee
Dynamic tracing tool using eBPF. A bunch of detection scripts are available.
Falco https://github.com/falcosecurity/falco
Parses system calls against rules and alerts for violations.
Velociraptor https://github.com/Velocidex/velociraptor
Powerful hunting tool.
Sandfly (licensed tool)
Will literally tear appart anything malicious on a Linux machine. Check out where its name came from.
Runs everywhere with no dependencies (no installation required)

7. General Velociraptor Artifacts

Name Details
Linux.Network.PacketCapture leverages tcpdump to natively capture packets
Exchange.Linux.Collection.CatScale Uses CatScale to collect multiple artifacts
Exchange.Generic.Collection.UAC Uses UAC to collect multiple artifacts
Exchange.Linux.CentOS.Memory.Acquisition Acquires a full memory image (LiME)
Exchange.Linux.Centos.Volatility.Create.Profile Creates Volatility profile
Exchange.Linux.Collection.BrowserHistory Collects Browser History
Linux.Applications.Chrome.Extensions Fetch Chrome extensions