Giter Site home page Giter Site logo

lmg's Introduction

Linux Memory Grabber
A script for dumping Linux memory and creating Volatility(TM) profiles.
Hal Pomeranz ([email protected]), 2016-01-12

THANKS!
=======

"If I have seen further it is by standing on the shoulders of giants."
     ~ Issac Newton

There are a lot of people who deserve thanks for making this simple
little tool possible:

-- Joe Sylve for his work on LiME

-- The entire Volatility(TM) development team for their ongoing work.
   I'd like to particularly recognize Andrew Case who answered a number
   of pesky questions from me during development of my tool.

-- David Anderson for his ongoing support of libdwarf and dwarfdump

-- Matt Suiche from MoonSols.  When I was putting my tool together,
   my design goal was "make it as easy to use as DumpIt" (if you need
   to capture Windows memory, I know of no easier to use tool).
   So thanks for the inspiration, Matt!

-- People who have provided ideas and code to make the tool better:

       Julien -- Alternate output/build directories and case ID labels, 
           abort if not running as root
       Jonathon Poling -- similar ideas to Julien's
       Jeff Bryner -- Creating volatilityrc files for each capture

The community is better for all of these efforts.  I have chosen to make
my tool available under the Creative Commons "Attribution" License (CC BY),
in order to make it as widely available as possible.

ABOUT THE TOOL
==============

To analyze Linux memory, you first need to be able to capture Linux
memory.  Joe Sylve's Linux Memory Extractor (LiME) is excellent for 
this, but you need to have a LiME module compiled for the kernel of
the system where you want to grab RAM.

Volatility(TM) is great at analyzing Linux memory images.  But it needs
a profile that matches the system where the memory was captured.
Building a profile means compiling a C program on the appropriate system
and using dwarfdump to get the addresses of important kernel data structures.
You also need a copy of the System.map file from the /boot directory.

Now if you happen to have a duplicate of your target system, you can
build LiME and compile the Volatility(TM) profile on the clone and
use them to capture and analyze memory from your target.  But there are
many situations where a duplicate of your target system is not available.
So you may have to compile LiME and build your Volatility(TM) profile
on your target machine.

And this is not for the faint of heart.  There are a number of steps,
and some fairly low-level Linux commands involved.  My goal was to
create a package that could be installed (by an expert) on a thumb drive
and distributed to agents in the field.  The user of the thumb drive
should be able to plug the thumb drive in, run a single command, 
and successfully acquire a memory image of the target machine and
a working Volatility(TM) profile.  The result is my lmg (Linux Memory
Grabber) script.

ON FORENSIC PURITY
==================

If you're a stickler for forensic purity, this is probably not the
tool for you.  Let's discuss some of the ways in which my tool interacts
with the target system:

Removable Media -- The tool is designed to be run from a portable USB
  device such as a thumb drive.  You are going to be plugging a writable
  device into your target system, where it could potentially be targeted
  by malicious users or malware on the system.  The act of plugging the
  device into the system is going to change the state of the machine
  (e.g., create log entries, mtab entries, etc).  If the device is not 
  auto-mounted by the operating system, the user must manually mount the 
  device via a root shell.

Compilation -- lmg builds a LiME kernel module for the system.
  Creating a Volatility(TM) profile also involves compiling code on
  the target machine.  So gcc will be executed, header files read,
  libraries linked, etc.  lmg tries to minimize impact on the file
  system of the target machine by setting TMPDIR to a directory on
  the USB device lmg runs from.  This means that intermediate files
  created by the compiler will be written to the thumb drive rather
  than the local file system of the target machine.

Dependencies -- In order to compile kernel code on Linux, the target
  machine needs a working development environment with gcc, make, etc 
  and all of the appropriate include files and shared libraries.
  And in particular, the kernel header files need to be present on
  the local machine.  These dependencies may not exist on the target.
  In this case, the user is faced with the choice of installing
  the appropriate dependencies (if possible) or being unable to
  acquire memory from the target.

Malware -- lmg uses /bin/bash, gcc, zip, and a host of other programs from
  the target machine.  If the system has been compromised, the applications
  lmg uses may not be trustworthy.  A more complete solution would be
  to create a secure execution environment for lmg on the portable USB
  device, but was beyond the scope of this initial proof of concept.

Memory -- All of the commands being run will cause the memory of the
  target system to change.  The act of capturing RAM will always create
  artifacts, but in this case there is extensive compilation, file system
  access, etc in addition to running a RAM dumper.

All of that being said, lmg is a very convenient tool for allowing
less-skilled agents to capture useful memory analysis data from
target systems.

Note that lmg will look for an already existing LiME module on the
USB device that matches the kernel version and processor architecture
of the target machine.  If found, lmg will not bother to recompile.
Similarly, you may choose to not have lmg create the Volatility(TM)
profile for the target in order to minimize the impact on the target system.

lmg uses relative path names when invoking programs like gcc and zip.
So if you wish to run these programs from alternate media, simply update
$PATH as appropriate before running lmg.


USING LMG
=========

First, prepare a thumb drive according to the instructions in the
INSTALL document provided with lmg.

When you wish to acquire RAM, plug the thumb drive into your target
system.  On most Linux systems, new USB devices will get automatically
mounted under /media.  Let's assume yours ends up under /media/LMG.

Now, as root, run "/media/LMG/lmg".  This is interactive mode and
the user will be prompted for confirmation before lmg builds a LiME
module for the system and/or creates a Volatility(TM) profile.
If you don't want to be prompted, use "/media/LMG/lmg -y".

Everything else is automated.  After the script runs, you will have
a new directory on the thumb drive named 

   ".../capture/<hostname>-YYYY-MM-DD_hh.mm.ss"

lmg supports a -c option for specifying a case ID directory name to be
used instead of the default "<hostname>-YYYY-MM-DD_hh.mm.ss" directory.

Whatever directory name is used, the directory will contain:

   <hostname>-YYYY-MM-DD_hh.mm.ss-memory.lime  -- the RAM capture
   <hostname>-YYYY-MM-DD_hh.mm.ss-profile.zip  -- Volatility(TM) profile
   <hostname>-YYYY-MM-DD_hh.mm.ss-bash         -- copy of target's /bin/bash
   volatilityrc                                -- prototype Volatility config file

The volatilityrc file defines the appropriate locations for the captured
memory and plugin. See the USAGE EXAMPLE below for how to use this file.

The copy of /bin/bash is helpful for determining the address of the shell 
history data structure in the memory of bash processes in the memory capture.
See http://code.google.com/p/volatility/wiki/LinuxCommandReference23#linux_bash
for further details on how to use this executable (or reference the USAGE EXAMPLE
below).

Note that there may be times when you do not wish to write data to the media
that you are running lmg from-- for example if the lmg tools are on read-only
media like a DVD-ROM. lmg supports a -d option to specify a different output
directory. By default, all compilation will happen in the target directory,
but the user may specify an alternate compilation directory with -B.


USAGE EXAMPLE
=============

Here is an example of using the lmg tool, which includes using Volatility(TM)
directly off the thumb drive to analyze the captured image.  On my test
machine, the thumb drive was at /dev/sdb and it was not auto-mounted by
my operating system.  So I did everything manually.

1) Getting root and mounting the thumb drive
--------------------------------------------

caribou$ sudo -s
[sudo] password for hal: 
caribou# mkdir -p /mnt/usb
caribou# mount /dev/sdb1 /mnt/usb


2) Running lmg
--------------

caribou# /mnt/usb/lmg -y
make -C /lib/modules/3.13.0-37-generic/build M=/mnt/usb/lime/src modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-37-generic'
  CC [M]  /mnt/usb/lime/src/tcp.o
  CC [M]  /mnt/usb/lime/src/disk.o
  CC [M]  /mnt/usb/lime/src/main.o
  LD [M]  /mnt/usb/lime/src/lime.o
  Building modules, stage 2.
  MODPOST 1 modules
  CC      /mnt/usb/lime/src/lime.mod.o
  LD [M]  /mnt/usb/lime/src/lime.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-37-generic'
strip --strip-unneeded lime.ko
mv lime.ko lime-3.13.0-37-generic-x86_64.ko
make tidy
make[1]: Entering directory `/mnt/usb/lime/src'
rm -f *.o *.mod.c Module.symvers Module.markers modules.order \.*.o.cmd \.*.ko.cmd \.*.o.d
rm -rf \.tmp_versions
make[1]: Leaving directory `/mnt/usb/lime/src'
LiME module is /mnt/usb/lime/src/lime-3.13.0-37-generic-x86_64.ko
Dumping memory in "lime" format to /mnt/usb/capture/caribou-2016-01-12_14.32.41
This could take a while...Done!
Cleaning up...Done!
Grabbing a copy of /bin/bash...Done!
Writing volatilityrc to /mnt/usb/capture/caribou-2016-01-12_14.32.41...Done!
make -C //lib/modules/3.13.0-37-generic/build M="/mnt/usb/volatility-2.4/tools/linux" clean
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-37-generic'
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-37-generic'
rm -f module.dwarf
make -C //lib/modules/3.13.0-37-generic/build CONFIG_DEBUG_INFO=y M="/mnt/usb/volatility-2.4/tools/linux" modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-37-generic'
  CC [M]  /mnt/usb/volatility-2.4/tools/linux/module.o
  CC      /mnt/usb/volatility-2.4/tools/linux/module.mod.o
  LD [M]  /mnt/usb/volatility-2.4/tools/linux/module.ko
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-37-generic'
dwarfdump -di module.ko > module.dwarf
make -C //lib/modules/3.13.0-37-generic/build M="/mnt/usb/volatility-2.4/tools/linux" clean
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-37-generic'
  CLEAN   /mnt/usb/volatility-2.4/tools/linux/.tmp_versions
  CLEAN   /mnt/usb/volatility-2.4/tools/linux/Module.symvers
make[1]: Leaving directory `/usr/src/linux-headers-3.13.0-37-generic'
  adding: module.dwarf (deflated 90%)
  adding: boot/System.map-3.13.0-37-generic (deflated 79%)


3) Running linux_banner plugin to test capture, leveraging the prototype volatilityrc
-------------------------------------------------------------------------------------

caribou# /mnt/usb/volatility-2.4/vol.py --conf-file=/mnt/usb/capture/caribou-2016-01-12_14.32.41/volatilityrc linux_banner
Volatility Foundation Volatility Framework 2.4
Linux version 3.13.0-37-generic (buildd@kapok) (gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1) ) #64-Ubuntu SMP Mon Sep 22 21:28:38 UTC 2014 (Ubuntu 3.13.0-37.64-generic 3.13.11.7)


4) Use the captured copy of /bin/bash to dump shell history with linux_bash
---------------------------------------------------------------------------

caribou# gdb /mnt/usb/capture/caribou-2016-01-12_14.32.41/caribou-2016-01-12_14.32.41-bash 
GNU gdb (Ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from /mnt/usb/capture/caribou-2016-01-12_14.32.41/caribou-2016-01-12_14.32.41-bash...(no debugging symbols found)...done.
(gdb) disassemble history_list
Dump of assembler code for function history_list:
   0x00000000004aedb0 <+0>:	mov    0x24e861(%rip),%rax        # 0x6fd618
   0x00000000004aedb7 <+7>:	retq   
End of assembler dump.
(gdb) quit
caribou# /mnt/usb/volatility-2.4/vol.py --conf-file=/mnt/usb/capture/caribou-2016-01-12_14.32.41/volatilityrc linux_bash -H 0x6fd618 | head
Volatility Foundation Volatility Framework 2.4
Pid      Name                 Command Time                   Command
-------- -------------------- ------------------------------ -------
    4157 bash                 2016-01-12 17:42:55 UTC+0000   cd vss
    4157 bash                 2016-01-12 17:42:55 UTC+0000   unzip Security_evtx.csv.zip 
[... more output not shown ...]

lmg's People

Contributors

halpomeranz avatar jeffbryner avatar

Watchers

CrazyKID avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.