Linux Malware
Linux Malware
Marc-Etienne M.Léveillé
Senior Malware Researcher
ESET
@marc_etienne_
#RSAC
#RSAC
2
#RSAC
Workshop overview
You only need a web browser, an OpenVPN client and an SSH client to start hunting
3
#RSAC
6
#RSAC
Why care?
Bad IP reputation
– Prevents sending legitimate email messages
Slows down legitimate software and services
Servers often host the most critical data in the enterprise1
Risk of data exfiltration
– Passwords
– E-mail addresses
– Credit card numbers
– Etc.
1 Jon Amato, Mario de Boer, Gartner Technical Professional Advice – Solution Criteria for Endpoint Protection Platforms, 2020-01-09
7
#RSAC
8
#RSAC
Artifacts
Filesystem
– Logs
– Malware persistence (if any)
Memory
– Process memory and state
– Kernel memory
Network
– Configuration
– Packet capture (in-band and out-of-band)
10
#RSAC
Filesystem
#RSAC
12
#RSAC
Basic filesystem
# ls -lat | head
total 44
-rw------- 1 root root 4322 Oct 29 11:21 .bash_history
drwx------ 1 root root 22 Oct 28 23:52 .aptitude
-rw------- 1 root root 81 Oct 28 22:44 .lesshst
drwx------ 1 root root 240 Oct 28 21:59 .
-rw------- 1 root root 5726 Oct 28 21:59 .viminfo
13
#RSAC
Basic filesystem
# stat .viminfo
File: '.viminfo'
Size: 5726 Blocks: 16 IO Block: 4096
regular file
Device: 11h/17d Inode: 63052 Links: 1
Access: (0600/-rw-------) Uid: (0/root) Gid: (0/root)
Access: 2015-10-28 21:59:36.283368614 -0400
Modify: 2015-10-28 21:59:36.283368614 -0400
Change: 2015-10-28 21:59:36.283368614 -0400
Birth: -
14
#RSAC
Basic filesystem
15
#RSAC
Basic filesystem
file $FILE
– Identify file type
# file .viminfo
ELF 64-bit LSB executable, x86-64, version 1 (SYSV),
dynamically linked, interpreter /lib64/ld-linux-x86-
64.so.2, for GNU/Linux 2.6.32, stripped
16
#RSAC
Package integrity
debsums
– Dpkg-based distributions (Debian, Ubuntu)
rpm -Va
– RPM-based distributions (RHEL, CentOS, Fedora)
17
#RSAC
Malicious or not?
# rpm --verify keyutils-libs
(no error)
# rpm -qi keyutils-libs
Name : keyutils-libs Relocations: (not relocatable)
Version : 1.4 Vendor: CentOS
Release : 4.el6 Build Date: Fri 22 Jun 2012 02:20:38
Install Date: Mon 27 Jan 2014 06:08:43 Build Host: c6b10.bsys.dev.centos.org
Group : System Environment/Base Source RPM: keyutils-1.4-
4.el6.src.rpm
Size : 59320 License: GPLv2+ and LGPLv2+
Signature : RSA/SHA1, Sun 24 Jun 2012 06:18:51, Key ID 21efc4bf71fbfe7b
URL : http://people.redhat.com/~dhowells/keyutils/
Summary : Key utilities library
Description :
This package provides a wrapper library for the key management facility
system
calls.
18
#RSAC
Logs
/var/log
– auth.log
– HTTP logs
– messages, syslog, etc.
systemd’s journalctl
auditd log
19
#RSAC
Using auditd
Using auditd
21
#RSAC
Offline filesystem
22
#RSAC
System memory
#RSAC
# ps auxw
root 7673 0.0 0.0 55164 5292 ? Ss Oct19 0:01 /usr/sbin/sshd -D
root 7718 0.0 0.3 200676 127160 ? Ss Oct21 2:29 /lib/systemd/systemd
root 7948 0.0 0.0 248844 25032 ? Ss Oct20 0:18 /usr/sbin/apache2 -k
webuser 7953 0.0 0.0 141732 4188 ? S Oct20 0:06 /usr/sbin/apache2 -k
webuser 5023 6.2 0.0 39764 8936 ? Ss Oct28 66:08 /tmp/.ICE-A5BF7
[...]
24
#RSAC
25
#RSAC
procfs
26
#RSAC
27
#RSAC
procfs environ
28
#RSAC
Process stalling
29
#RSAC
Acquisition
– gcore $PID and cp /proc/$PID/exe malware.elf
Alternative acquisition tool
– memfetch from http://lcamtuf.coredump.cx
Analysis (simple)
– strings
Analysis (in-depth)
– gdb malware.elf $PID.core
30
#RSAC
Kernel memory
Acquisition
– VM snapshot
– LiME (Linux Memory Extractor)
Analysis
– Volatility Framework
Only helpful if kernel is compromised via malicious kernel
module (rootkit)
31
#RSAC
Network
#RSAC
Network configuration
33
#RSAC
Network capture
Acquisition
– tcpdump -i eth0 -s 0 -w capture.pcap
Analysis
– tshark -r capture.pcap
– Wireshark
– bro -r capture.pcap
34
#RSAC
Malware analysis
#RSAC
Two approaches
Script-based malware
– PHP
– Perl
– Python
Compiled malware
– ELF executables
36
#RSAC
Script-based malware
#RSAC
Script-based malware
Can be obfuscated
– Removed whitespace
– Variables renamed
<?php function
PXN1YnN0ci($a,$b){$c=array(139,164,40,72);if($b==62)
{$d=substr($a,$c[0]+$c[1],$c[2]);}elseif($b==12){$d=sub
str($a,$c[0],$c[1]);
}elseif($b=92){$d=trim(substr($a,$c[0]+$c[1]+$c[2]));}r
eturn$d;} ?>
38
#RSAC
39
#RSAC
Script-based malware
40
#RSAC
41
#RSAC
Compiled malware
#RSAC
Compiled malware
43
#RSAC
Statically
– strings
– radare2
– IDA Pro ($)
44
#RSAC
Dynamically
– strace
– ltrace for dynamically linked binaries
– gdb, or any other debugger you like
– gcore
Always work in an isolated environment
when playing with malware
45
#RSAC
47
#RSAC
48
#RSAC
1 Jon Amato, Mario de Boer, Gartner Technical Professional Advice – Solution Criteria for Endpoint Protection Platforms, 2020-01-09
49
#RSAC
50