Home - XuehengWang/LiME-Volatility GitHub Wiki

LiME + Volatility2 for Linux

Prerequisites:

  • Set up Python2 environment
  • The target systems (whose memory we want to analyze) could be 32/64-bit Linux kernels 2.6.11 to 5.5 (OpenSuSE, Ubuntu, Debian, CentOS, Fedora, Mandriva, etc).
    • NOTE: This method is not suitable for later Linux versions; And for the usage on Windows and Mac, please refer to volatility's Github repo.
  • If you're trying to analyze a memory file from external machine, you need to use a host machine having same architecture as the target machine.
    • NOTE: If the architectures are different, you will need additional steps to add arguments such as ARCH= CROSS_COMPILE= to the Makefile when compiling the target kernel with $ make modules_prepare. Please read How to compile LiME for use on an Android device for more details.
  • If the above conditions are satisfied, let's start!

Description:

我们将介绍两个工具 -- LiME & Volatility;其中LiME作为内存提取工具,可以帮助我们获取目标机器的内存文件,而Volatility则用来分析获取到的内存文件。Volatility2提供了很多Linux内存分析的插件,比如查看系统进程、网络连接状态、加载的内核模块、Bash命令等等,可以帮助我们更有效率地进行内存取证。

Part 1: 在第一个使用场景中,我们将使用LiME抓取本机内存,然后使用Volatility直接在本地进行分析。此场景中我使用的试验内核是Ubuntu_4_15_0-112-generic,请参考章节Part 1: 分析本机内存的具体步骤依次安装和运行程序。

Part 2: 在第二个使用场景中,我们想要对外部测试机器进行内存取证。为了避免在测试机器上下载和编译额外的程序,或破坏测试机器的环境,我们将先在本机使用LiME编译一个内核模块(对应目标机器的内核版本),然后将编译好的内核模块放入测试机器上加载以抓取内存。之后,我们将获取的内存文件传回本机,使用Volatility进行分析。此场景中我使用的试验内核是CentOS linux-4.18.0-80.11.2.el8_0,请参考章节Part 2: 分析外部目标机器内存的具体步骤依次安装和运行程序。

Examples of Volatility2: 这页会展示Volatility一些常用的插件和功能,无论分析本机内存的场景还是外部机器的场景,这些插件都可以帮助我们进行内存取证。

Trouble Shooting: 这页总结了一些在操作过程中可能遇到的问题,如果遇到类似的问题可以参考对应的解决方案。不过,更希望整个操作过程顺利流畅,不遇到坑和问题:)


Part 1: 分析本机内存的具体步骤

1. Install Linux dependencies

  • Ubuntu/Debian可以使用apt安装:

      $ sudo apt-get install build-essential autoconf dwarfdump git subversion pcregrep libpcre++-dev python2-dev -y   
      $ sudo apt-get install automake libtool make gcc pkg-config -y
    
  • 其他使用yum/dnf的系统,例如Fedora, CentOS, RHEL,可以安装对应的依赖包:

      $ sudo yum install kernel-headers kernel-devel elfutils-libelf-devel libdwarf-tools pcre-devel python2-devel python2-setuptools -y   
      $ sudo yum install automake libtool make gcc pkgconfig -y
    

2. Install Python dependencies

NOTE: 如果默认使用Python3,一些命令可能需要明确指出安装在Python2的目录下,或者安装与Python2适配的工具,例如使用:

$ sudo apt install -y python2-dev python2-setuptools  
$ pip2 install / python2 -m pip install
  • pip for Python2

    If pip is not installed, We could first install it with Python2:

      $ wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
      $ python2 get-pip.py
    
  • Python setuptools (Skip this if you've installed python2-setuptools in Step 1)

    Once having pip, we can then install setuptools using the command:

      $ python2 -m pip install setuptools  
    
  • yara

    (a) 直接pip安装

      $ python2 -m pip install yara-python
    

    (b) 如果使用过程中报错,找不到,尝试直接在系统上安装yara👇

      $ sudo apt-get install yara -y
    

    (c) 或者从https://github.com/VirusTotal/yara/releases下载,然后安装

      $ tar -zxf yara-4.3.2.tar.gz              
      $ cd yara-4.3.2            
      $ ./bootstrap.sh             
      $ ./configure                     
      $ make             
      $ sudo make install   
    
  • pycrypto

    (a) Download source, unzip, and install

      $ wget https://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.1.tar.gz   
      $ tar -xvzf pycrypto-2.6.1.tar.gz   
      $ cd pycrypto-2.6.1   
      $ python2 setup.py build   
      $ sudo python2 setup.py build install   
    
  • distorm

    (a) 直接$ python2 -m pip install distorm3 或者 $ pip2 install distorm3

    (b) 或者从https://github.com/gdabah/distorm/releases下载,解压,然后安装:

      $ python2 setup.py build     
      $ python2 setup.py build install   
    

3. (分析本机内存) 使用LiME抓取内存

  • 安装内核头文件

      $ sudo apt install linux-headers-$(uname -r)
    
  • Download & Compile

      $ git clone https://github.com/504ensicsLabs/LiME   
      $ cd LiME/src/   
      $ make   
    
    • Here, a compiled LKM is created

  • Then use insmod to load it

      $ sudo insmod [name].ko "path=../dump.mem format=lime timeout=0"
    
    • 这里重要的是设置format=lime timeout=0
    • 等待内存转储文件dump.mem生成,就完成了
    • dump.mem是原始数据格式,尝试下面的命令,看到第一行的Emil就 表示格式是lime

    $ hexdump -C ~/LiME/dump.mem | head

4. (分析本机内存) 安装Volatility + 配置对应的profile

  • Clone from Directory

      $ git clone https://github.com/volatilityfoundation/volatility.git  
      $ cd volatility  
      $ sudo python2 setup.py build install  
    
  • Create module.dwarf

      $ cd /tools/linux  
      $ make  
    
  • Make a profile:module.dwarf + System.map

      $ sudo zip $(lsb_release -i -s)_$(uname -r)_profile.zip ./volatility/tools/linux/module.dwarf /boot/System.map-$(uname -r)  
    

    NOTE: module.dwarf是我们上一步make生成的,加上/boot目录下的System.map,组成了我们需要的配置文件

  • Copy profile zip to the Volatility plugin path

      $ cp [name].zip ./volatility/volatility/plugins/overlays/linux   
    
  • Test if installation is complete and profile is configured

      $ cd volatility  
      $ python2 vol.py --info | grep $(lsb_release -i -s)  
    
    • 这时候应该能识别到profile文件了👇

  • Volatility的一些具体功能请参考Examples of Volatility2, 可以跳过 Part 2


Part 2: 分析外部目标机器内存的具体步骤

1. Install Linux dependencies

2. Install Python dependencies

3. (分析外部机器内存) 使用LiME抓取内存

  • 下载LiME

      $ git clone https://github.com/504ensicsLabs/LiME  
    
  • 寻找并下载目标机器的kernel source

    • 参考文档中介绍了获取Ubuntu内核源码的详细步骤,还有一些其他的资源,可以参考;我试验的内核是CentOS linux-4.18.0-80.11.2.el8_0,下文会有详细步骤

    (a) CentOS

    • 例如,我使用$(uname -r)查询目标机器对应的版本号为4.18.0-80.11.2.el8_0.x86_64
    • 我以https://vault.centos.org/作为根目录开始搜索,在如下地址找到了对应的rpm文件
    • 解压rpm文件,找到linux-[version]文件夹:

        $ mkdir test  
        $ mv kernel-4.18.0-80.11.2.el8_0.src.rpm ./test  
        $ cd test  
        $ rpm2cpio kernel-4.18.0-80.11.2.el8_0.src.rpm | cpio -idmv  
        $ tar -xf linux-4.18.0-80.11.2.el8_0.tar.xz  
        $ cd linux-4.18.0-80.11.2.el8_0   
      
    • 👆linux-4.18.0-80.11.2.el8_0 就是我们的内核源码文件夹了

    (b) Ubuntu

      $ git clone http://kernel.ubuntu.com/git-repos/ubuntu/ubuntu-[release].git  
      $ git tag -l  
      $ git checkout [tag]   
    
  • 调整内核配置文件

    • 回到目标机器,先将目标机器的/boot/config-[version]文件拷贝到本机刚刚下载的kernel source文件夹内(文件夹根目录),改名为.config

    • 然后在文件夹内执行$ make olddefconfig

  • 添加正确的kernel version

    • 使用$ make kernelrelease查看当前下载的内核源码所对应的版本,这时候应该是没有local version后缀的

    比如目标机器$(uname -r)显示的版本是4.18.0-80.11.2.el8_0.x86_64,但此时$ make kernelrelease显示的只是4.18.0

    • 编辑.config文件,添加如下部分:

      CONFIG_LOCALVERSION="-80.11.2.el8_0.x86_64
      CONFIG_LOCALVERSION_AUTO=n

    • 再尝试$ make kernelrelease,显示的版本应该就全了

    • 最后执行$ make modules_prepare

  • 回到LiME/src文件夹进行编译

      $ cd LiME/src/  
      $ make -C ~/Desktop/test1/linux-4.18.0-80.el8/ KVER=4.18.0-80.11.2.el8_0.x86_64 M=$(pwd)  
    
    • 这里~/Desktop/test1/linux-4.18.0-80.el8/是下载的kernel source的文件夹
    • KVER=后面是kernel version
  • 生成了一个编译好的lime.ko,放到目标机器中加载

    • 先将上一步生成的内核模块lime.ko拷贝到目标机器中,加载:

        $ sudo insmod lime.ko "path=./dump.mem format=lime timeout=0"   
      
    • 然后等待dump.mem在当前文件夹中生成

6. (分析外部机器内存) 安装Volatility + 配置对应的profile

这步的目的是把从目标机器上获取的内存文件传输到本机,用volatility进行分析,这些步骤不需要在目标机器上执行

  • Clone from Directory

      $ git clone https://github.com/volatilityfoundation/volatility.git
      $ cd volatility
      $ sudo python setup.py build install
    
  • Create module.dwarf

      $ cd /tools/linux  
    
    • 按照下图修改Makefile,指向我们之前下载并配置的内核源码文件目录(comment掉原来的Makefile内容,然后参照下图修改drawf部分)

    • 然后执行$ make

  • Make a profile zip:module.dwarf + System.map

    • 从目标机器中找到/boot/System.map-[version]文件,复制到本机

        $ sudo zip [name]._profile.zip ./volatility/tools/linux/module.dwarf System.map  
      
    • 注:上面System.map使用的是目标机器的,module.dwarf是上一步使用make生成的

  • Copy profile zip to the Volatility plugin path

      $ cp [name].zip ./volatility/volatility/plugins/overlays/linux  
    
  • Test if installation is complete and profile is configured

      $ cd volatility  
      $ python2 vol.py --info | grep Linux  
    
  • 这时候应该就可以识别到Profile文件了,可以开始分析内存文件,Volatility的一些具体功能请参考Examples of Volatility2