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
Exchange.Linux.Collection.SysConfig
: collects system configurationsLinux.Mounts
: lists mounted filesystems by reading /proc/mount
Exchange.Linux.Collection.NetworkConfig
: collects network config filesExchange.Linux.Network.Netstat
: parses /proc
and reveal information about current network connectionsLinux.Network.NetstatEnriched
: reports network connections, and enrich with process informationExchange.Linux.Network.NM.Connections
: lists the NetworkManager state, configured connections and settingsLinux.Proc.Arp
: collects ARP table via /proc/net/arp
Linux.Sys.CPUTime
: displays information from /proc/stat
about the time the cpu cores spent in different parts of the systemUser config files: /etc/passwd
(Users), /etc/shadow
(hashed passwords), check for:
root
should have UID 0~/.hiddendir
nologin
or false
)/etc/shadow
check for password hashes for users without a shell/etc/group
Logins
Search for suspicious logins or failed attempts.
#w
: currently logged in users#last
: last successful logins#lastb
: last failed login#lastlog
: list last login for all users#utmpdump /var/run/utmp
: all current logins, check type (0 is not valid)#utmpdump /var/log/btmp
: raw dump of btmp (possible to find pw, if a user accidentaly typed pw at the user login prompt)nologin
or false
binary integritySSH Keys
Check for suspicious authorized keys, unprotected private keys, suspicous SSH configs, suspicious creation/modification timestamps.
~/.ssh/
: private keys~/.ssh/authorized_keys
: authorized keys file (check for user email address)~/.ssh/known_hosts
: list of hosts accessed previously/etc/ssh/ssh_config
, /etc/ssh/ssh_config.d
, ~/.ssh/config
: ssh client configVelociraptor Artifacts
Linux.Sys.Users
: retrieve UsersLinux.Users.RootUsers
: retrieve Users in sudo GroupLinux.Users.InteractiveUsers
: gets the interactive usersLinux.Sys.LastUserLogin
: retrieve wtmp file content (successful logins and logouts)Linux.Users.InteractiveUsers
: retrieve the interactive users (shell login)Linux.Ssh.AuthorizedKeys
: retrieve authorized SSH keysLinux.Ssh.PrivateKeys
: retrieve private keys + checks if encrypted or notLinux.Ssh.KnownHosts
: parses ssh known hosts filesExchange.Linux.Detection.SSHKeyFileCmd
: parse ~/.ssh/authorizedkey
and ~/.ssh/id*.pub
looking for the command optionExchange.Linux.System.PAM
: enumerates applicable lines from the files that reside in /etc/PAM.d/
Search for suspicious files, directories and creation/modification timestamps.
.
, ..
, ...
/tmp
, /var/tmp
, /dev/shm
: world-writable directories (often used to drop malicious files)#ls -alp
: lists element with a / at the end (allows to see empty spaces)#lsattr
: list attributes of a File or Dir (see if immutable flag is set)#file /path/to/file
: basic file summary#ldd /path/to/binary
: ! never run ldd
on a suspicious binary (could execute malicious code) ! lists shared objects#objdump -p /path/to/binary | grep NEEDED
: lists required shared objects#strings /path/to/bianary
: search for suspicious content like listen()
, bind()
and/or accept()
, IP addresses, etc.#find /<dir> -perm 4000
: look for suspicious setuid files#find -nouser
#find -nogroup
: files without assigned UID/GID (may indicate deleted user/group)Velociraptor Artifacts
Linux.Detection.AnomalousFiles
: hidden, large or SUID bit setExchange.Linux.Detection.IncorrectPermissions
: verify files/dirs and checks whether they have the expected owner, group owner and modeLinux.Search.FileFinder
: Find files on the filesystem using the name or contentExchange.Linux.Forensics.RecentlyUsed
: retrieves a list of recent files accessed by applicationsSyslog
Check for tampered or missing logs.
/var/log/*
wtmp
, lastlog
, btmp
, utmp
auth.log
/var/log/<application>/*
/var/log/audit/audit.log
#ausearch --input audit.log --format <csv/text>
: export audit.log file to another format#aureport --input audit.log --login --start YYYY-MM-DD HH:mm:ss --end YYYY-MMM-DD HH:mm:ss
: generate a report of audit.logSystemd Journal
/var/log/journal/*
/run/log/jounral/*
(volatile)
Anlaysis of Journal File Contents#journalctl --file <filename>
#journalctl --file system.journal -o json > sytem.journal.json
: export journal to json format (other format available)#journalctl --file system.journal _SYSTEMD_UNIT=sshd.service
: Search logs from sshd.service#journalctl --file user-1000.journal _TRANSPORT=stdout
: stdout logs of deamons and unit files#journalctl --file user-1000.journal --verify
: If journal file contains FSS information → verify integrity#journalctl --file user-1000.journal -S "YYYY-MM-DD HH:mm:ss" -U "YYYY-MM-DD HH:mm:ss"
: Search logs since (-S) until (-U)Sysmon for Linux
Velociraptor Artifacts
Exchange.Linux.Collection.SysLogs
: Collects system logsSuspicious processes:
Commands:
#ps auxwf
: Check for process running from /dev
, /root
, /temp
, high PID (process started manually after OS boot) process masquerading as a kthread#pstree
: List a tree view of processes with parent-child relations#pstree -p -s <PID>
: Process tree of a running process#top
: List processes according their ressource usage#htop
: List processes according their ressource usage#netstat -nalp
: High port or raw socket open?#ls -al /proc/*/fd | grep deleted
: Search for running processes spawened from a file deleted from disk (very suspicious)#cat /proc/<PID>/comm
: Shows the executable’s name#cat /proc/<PID>/cmdline
: Shows the full command line that was used to start the process#cat /proc/<PID>/environ
: Shows environment variables that were set when the process was started#cat /proc/<PID>/map
: Shows the memory map#cat /proc/<PID>/stack
: Shows the process stack#cat /proc/<PID>/status
: Shows the process status (check if a process is masquerading as a kernel process: if process name in brackets [NAME] → Kthread must be 1 - True, kernel thread)#ls -al /proc/<PID>
:
cwd -> /$DIR
: Shows the process working directoryexe -> /$DIR/$FILE
: Shows where the binary was stored#awk '{print $22}' /proc/<PID>/stat
: Prints the process start time#stat /proc/<PID>
: General process information#lsof -i -P
: Lists open connections → drill down on PID (/proc/<PID>
) → drill donw with ‘strings’#strings /path/to/binary
: Outputs the strings from a binary (listen()
, bind()
, accept()
, IP addresses, etc)/proc/<pid>/comm
, /proc/<pid>/cmdline
additionnaly check symbolic link mismatch #ls -l /proc/<pid>/exe
Velociraptor Artifacts
Linux.Sys.Pslist
: lists processes and their running binariesLinux.Detection.Yara.Process
: runs YARA over processes in memoryExchange.Linux.PrivilegeEscalationDetection
: identifies processes running as root that were spawned by non-priviledged processesLinux.Events.ProcessExecutions
: collects process execution logs from the Linux kernel (requires auditctl
)Exchange.Linux.Detection.MemFD
: parses /proc/*/exe
files and look for processes that have been executed from memory via memfd_create()
Linux.Triage.ProcessMemory
: dumps process memory
Linux persistence overview - credits Pepe Berba
Different scripts are run during system boot. These scripts can be created or modified to gain persistence.
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.
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/
.
unit files
, defing how services are started, stopped or managed.unit files
: Service
(for managing long-running processes - typically deamons), Timer
(similar to cron jobs).
/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/
~/.config/systemd/user/
, ~/.local/share/systemd/user/
.timer
file 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/
/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.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*
Velociraptor Artifacts
Linux.Sys.Services
: parses services from systemctlroot
every time a user connects to a Linux system.
These scripts can be modified to gain persistence.
Config files in /etc/update-motd.d/
/etc/xdg/autostart/
, /usr/share/autostart/
~/.config/autostart/
, ~/.local/share/autostart/
, ~/.config/autostart-scripts/
/root/.config/autostart/
, /root/.local/share/autostart/
, /root/.config/autostart-scripts/
/var/spool/cron/atjobs/
/var/spool/cron/atspool/
/var/spool/cron/
, /var/spool/cron/crontabs/
/etc/crontab
, /etc/cron.d/
, /etc/cron.daily/
, /etc/cron.hourly/
, /etc/cron.monthly/
, /etc/cron.weekly/
/etc/udev/rules.d/
, /run/udev/rules.d/
, /usr/lib/udev/rules.d/
, /usr/local/lib/udev/rules.d/
, /lib/udev/
Anacron
, Fcron
, Task Spooler
, Batch
.Velociraptor Artifacts
Linux.Sys.Crontab
: parses information from crontabExchange.Linux.Collection.Autoruns
: collects various autorun filesExchange.Linux.Sys.SystemdTimer
: parses content of Systemd timersLD_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.
/proc/<pid>/comm
and /proc/<pid>/cmdline
) inherits that of a legitimate executable/proc/<pid>/exe
points to the legitimate binaryptrace
systeem call for process injectionLD_PRELOAD
environment variable#ps eaux | cat | grep LD_PRELOAD | grep -v grep
#lsof -p <pid>
#ls /etc/ld.so.preload
(system-wide config)Velociraptor Artifacts
Linux.Sys.Maps
: parses the /proc/*/maps
to link mapped files into the processFiles | 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 |
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
Exchange.Linux.Collection.History
: Collects history filesExchange.Linux.Collection.UserConfig
: Collects user configurationsExchange.Linux.System.BashLogout
: capture Bash logout files/bin/false
with /bin/bash
(usefull to hide a shell-login in /etc/passwd
)#sha256sum <file>
)#rpm -Va
(Red Hat), #dpkg --verify
/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
Linux.Debian.AptSources
: parses Debian apt sourcesExchange.Linux.Sys.APTHistory
: parses the apt history.log
, as well as archived history logsLinux.Debian.Packages
: parses dpkg status fileLinux.RHEL.Packages
: parses packages installed from dnfLoadable 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
#insmod
, #rmmod
, #modprobe
, #lsmod
#cat /proc/modules
: Currently loaded kernel modules.#cat /proc/modules | grep OE
: Find unsigned or out-of-tree loaded modules./sys/module/
: inforamtion about currently loaded kernel modules.#cat /proc/sys/kernel/tainted
, #dmesg | grep taint
See external tools and Velociraptor artifacts under the “Rootkit” part.
/boot
directory where initramfs is stored is not monitored against integrity and makes it a perfect place to hide malicious code.
/proc/<pid>/ns
linksRootkits 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:
/etc/passwd
and /etc/shadow
)#grep . <file>
(will stream the file content)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
Linux.Proc.Modules
:lists loaded modules via /proc/modules
Exchange.Linux.Detection.BPF
: parses /proc/*/exe
files and looks for processes that have been executed from memory via memfd_create()Exchange.Linux.Detection.BPFmaps
: parses /proc/fd/
files and looks for processes that have been created by bpf-mapsRootkit 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) |
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 |