So far, we have covered Linux binaries and memory as it pertains to userland. This book won't be complete, however, if we don't spend a chapter on the Linux kernel. This is because it is actually an ELF binary as well. Similar to how a program is loaded into memory, the Linux kernel image, also known as vmlinux, is loaded into memory at boot time. It has a text segment and a data segment, overlaid with many section headers that are very specific to the kernel, and which you won't see in userland executables. We will also briefly cover LKMs in this chapter, as they are ELF files too.
It is important to learn the layout of the Linux kernel image if you want to be a true master of kernel forensics in Linux. Attackers can modify the kernel memory to create very sophisticated kernel rootkits. There are quite a number of techniques out there for infecting a kernel at runtime. To list a few, we have the following:
sys_call_table infectionThe techniques listed here are the primary methods that are most commonly used by a kernel rootkit, which usually infects the kernel in the form of an LKM (short for Loadable Kernel Module). Getting an understanding of each technique and knowing where each infection resides within the Linux kernel and where to look in the memory are paramount to being able to detect this insidious class of Linux malware. Firstly, however, let's take a step back and see what we have to work with. Currently, there are a number of tools in the market and in the open source world that are capable of detecting kernel rootkits and help in searches for memory infections. We will not be discussing those. We will, however, be discussing methods that are taken from kernel Voodoo. Kernel Voodoo is a project of mine that is still mostly private, with the exception of releasing a few components of it to the public, such as taskverse. This will be discussed later in this chapter, with a link to download it from. It uses some very practical techniques for detecting almost any type of kernel infection. The software is based on ideas from my original work, named Kernel Detective, which was designed in 2009, and for the curious, it can still be found on my website at http://www.bitlackeys.org/#kerneldetective.
This software works on older 32-bit Linux kernels (2.6.0 to 2.6.32) only; 64-bit support was only partially completed. Some of the ideas from this project were timeless, however, and I extracted them recently and coupled them with some new ideas. The result is Kernel Voodoo, a host intrusion detection system, and kernel forensics software that relies on /proc/kcore for advanced memory acquisition and analysis. In this chapter, we are going to discuss some of the fundamental techniques that it uses, and in some cases, we will employ them manually with GDB and /proc/kcore.