pax_global_header 0000666 0000000 0000000 00000000064 13552640762 0014524 g ustar 00root root 0000000 0000000 52 comment=5492e1eeed927b85193b00c00dd008688938bca0
LiME-1.9/ 0000775 0000000 0000000 00000000000 13552640762 0012163 5 ustar 00root root 0000000 0000000 LiME-1.9/.gitignore 0000664 0000000 0000000 00000000145 13552640762 0014153 0 ustar 00root root 0000000 0000000 # Dumps
*.lime
*.raw
# Objects
*.o
*.ko
Module.symvers
modules.order
*.mod.c
*.cmd
.tmp_versions/
LiME-1.9/LICENSE 0000664 0000000 0000000 00000043153 13552640762 0013176 0 ustar 00root root 0000000 0000000 GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
{description}
Copyright (C) {year} {fullname}
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
{signature of Ty Coon}, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.
LiME-1.9/README.md 0000664 0000000 0000000 00000010505 13552640762 0013443 0 ustar 00root root 0000000 0000000 # LiME ~ Linux Memory Extractor
A Loadable Kernel Module (LKM) which allows for volatile memory acquisition from Linux and Linux-based devices, such as Android. This makes LiME unique as it is the first tool that allows for full memory captures on Android devices. It also minimizes its interaction between user and kernel space processes during acquisition, which allows it to produce memory captures that are more forensically sound than those of other tools designed for Linux memory acquisition.
## Table of Contents
* [Features](#features)
* [Usage](#usage)
* [Examples](#example)
* [Presentation](#present)
## Features
* Full Android memory acquisition
* Acquisition over network interface
* Minimal process footprint
* Hash of dumped memory
## Usage
Detailed documentation on LiME's usage and internals can be found in the "doc" directory of the project.
LiME utilizes the insmod command to load the module, passing required arguments for its execution.
```
insmod ./lime.ko "path=> format= [digest=] [dio=<0|1>]"
path (required): outfile ~ name of file to write to on local system (SD Card)
tcp:port ~ network port to communicate over
format (required): padded ~ pads all non-System RAM ranges with 0s
lime ~ each range prepended with fixed-size header containing address space info
raw ~ concatenates all System RAM ranges (warning : original position of dumped memory is likely to be lost)
digest (optional): Hash the RAM and provide a .digest file with the sum.
Supports kernel version 2.6.11 and up. See below for
available digest options.
compress (optional): 1 ~ compress output with zlib
0 ~ do not compress (default)
dio (optional): 1 ~ attempt to enable Direct IO
0 ~ do not attempt Direct IO (default)
localhostonly (optional): 1 ~ restricts the tcp to only listen on localhost,
0 ~ binds on all interfaces (default)
timeout (optional): 1000 ~ max amount of milliseconds tolerated to read a page (default).
If a page exceeds the timeout all the memory region are skipped.
0 ~ disable the timeout so the slow region will be acquired.
This feature is only available on kernel versions >= 2.6.35.
```
## Examples
In this example we use adb to load LiME and then start it with acquisition performed over the network
```
$ adb push lime.ko /sdcard/lime.ko
$ adb forward tcp:4444 tcp:4444
$ adb shell
$ su
# insmod /sdcard/lime.ko "path=tcp:4444 format=lime"
```
Now on the host machine, we can establish the connection and acquire memory using netcat
```
$ nc localhost 4444 > ram.lime
```
Acquiring to sdcard
```
# insmod /sdcard/lime.ko "path=/sdcard/ram.lime format=lime"
```
## Available Digests
Really LiME will support any digest algorithm that the kernel library can.
Collecting a digest file when dumping over tcp will require 2 separate connections.
```
$ nc localhost 4444 > ram.lime
$ nc localhost 4444 > ram.sha1
```
For a quick reference here is a list of supported digests.
### All kernel versions
```
crc32c
md4, md5
sha1, sha224, sha256, sha384, sha512
wp512, wp384, wp256
```
### 4.10 and up
```
sha3-224, sha3-256, sha3-384, sha3-512
```
### 3.0 and up
```
rmd128, rmd160, rmd256, rmd320
```
## Compression
Compression can reduce significantly the time required to acquire a memory capture. It can achieve the speedup of 4x over uncompressed transfers with a few memory overhead (~ 24 KB).
The RAM file will be in the zlib format, which is different from the gzip or zip formats. The reason is that the deflate library embedded in the kernel do not support them.
To decompress it you can use [pigz](https://zlib.net/pigz/) or any zlib-compatible library.
```
$ nc localhost 4444 | unpigz > ram.lime
```
Note that only the RAM file is compressed. The digest file is not compressed, and the hash value will match the uncompressed data.
## Presentation
LiME was first presented at Shmoocon 2012 by Joe Sylve.
Youtube~ Android Mind Reading: Memory Acquisition and Analysis with DMD and Volatility
LiME-1.9/doc/ 0000775 0000000 0000000 00000000000 13552640762 0012730 5 ustar 00root root 0000000 0000000 LiME-1.9/doc/README.md 0000664 0000000 0000000 00000024154 13552640762 0014215 0 ustar 00root root 0000000 0000000 # LiME – Linux Memory Extractor
## Contents
* [Compiling](#Compile)
* [Linux](#Linux)
* [External](#External)
* [Debug](#Debug)
* [Symbols](#Symbols)
* [Android](#Android)
* [Usage](#Usage)
* [Parameters](#Params)
* [Acquisition of Memory over TCP](#TCP)
* [Acquisition of Memory to Disk (SD-Card)](#Disk)
* [LiME Memory Range Header Version 1 Specification](#Spec)
## Compiling LiME
### Linux
LiME is a Loadable Kernel Module (LKM). LiME ships with a default Makefile that should be suitable for compilation on most modern Linux systems.
For detailed instructions on using LKM see https://www.kernel.org/doc/Documentation/kbuild/modules.txt.
### External
LiME can be compiled externally from the target in order to provide a more forensically sound and secure method. Follow this [guide](./external_modules.md) to learn how.
### Debug
When compiling LiME with the default Makefile, using the command “make debug” will compile a LiME module with extra debug output. The output can be read by using the dmesg command on Linux.
### Symbols
When compiling LiME with the default Makefile, using the command “make symbols" will compile a LiME module without stripping symbols. This is useful for tools such as Volatility where one can create a profile without loading second module.
### Android
In order to cross-compile LiME for use on an Android device, additional steps are required.
#### PREREQUISITES
Disclaimer: This list may be incomplete. Please let us know if we've missed anything.
* Install the general android prerequisites found at http://source.android.com/source/initializing.html
* Download and un(zip|tar) the android NDK found at http://developer.android.com/tools/sdk/ndk/index.html.
* Download and un(zip|tar) the android SDK found at http://developer.android.com/sdk/index.html.
* Download and untar the kernel source for your device. This can usually be found on the website of your device manufacturer or by a quick Google search.
* Root your device. In order to run custom kernel modules, you must have a rooted device.
* Plug the device into computer via a USB cable.
#### SETTING UP THE ENVIRONMENT
In order to simplify the process, we will first set some environment variables. In a terminal, type the following commands.
```
export SDK_PATH=/path/to/android-sdk-linux/
export NDK_PATH=/path/to/android-ndk/
export KSRC_PATH=/path/to/kernel-source/
export CC_PATH=$NDK_PATH/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/
export LIME_SRC=/path/to/lime/src
```
#### PREPARING THE KERNEL SOURCE
We must retrieve and copy the kernel config from our device.
```
cd $SDK_PATH/platform-tools
./adb pull /proc/config.gz
gunzip ./config.gz
cp config $KSRC_PATH/.config
```
Next we have to prepare our kernel source for our module.
```
$ cd $KSRC_PATH
$ make ARCH=arm CROSS_COMPILE=$CC_PATH/arm-eabi- modules_prepare
```
#### PREPARING THE MODULE FOR COMPILATION
We need to create a Makefile to cross-compile our kernel module. A sample Makefile for cross-compiling is shipped with the LiME source. The contents of your Makefile should be similar to the following:
```
obj-m := lime.o
lime-objs := main.o tcp.o disk.o
KDIR := /path/to/kernel-source
PWD := $(shell pwd)
CCPATH := /path/to/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/
default:
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-eabi- -C $(KDIR) M=$(PWD) modules
```
#### COMPILING THE MODULE
```
cd $LIME_SRC
make
```
## Usage
To illustrate the use of LiME, we will now walk through two examples of acquiring memory from an Android device. We will first discuss the acquisition of memory over a TCP connection, followed by a discussion of acquiring a memory dump via the device’s SD card. The use of LiME on other Linux devices is similar; however, the use of the Android debug bridge (adb) is not needed.
### Parameters
Starting in version 1.1, LiME now supports multiple output formats, including a custom lime format which integrates with Volatility’s new lime address space. This means that additional parameters are needed when installing the LiME kernel module.
NOTE: There is a bug in the insmod utility on some Android devices. Multiple kernel module parameters must be wrapped in quotation marks, otherwise only the first parameter will be parsed. See sections 4.2 and 4.3 for examples.
```
path Either a filename to write on the local system (SD Card) or tcp:
format padded: Pads all non-System RAM ranges with 0s, starting from physical address 0.
lime: Each range is prepended with a fixed-sized header which contains address space information.
raw: Simply concatenates all System RAM ranges. Most memory analysis tools do not support this format, as memory position information is lost (unless System RAM is in one continuous range starting from physical address 0)
dio Optional. 1 to enable Direct IO attempt, 0 to disable (default)
localhostonly Optional. 1 restricts the tcp to only listen on localhost, 0 binds on all interfaces (default)
timeout Optional. If it takes longer than the specified timeout (in milliseconds) to read/write a page
of memory then the range is assumed to be bad and is skipped. To disable this set timeout to 0.
The default setting is 1000 (1 second).
```
### Acquisition of Memory over TCP
The first step of the process is to copy the kernel module to the device’s SD card using the Android Debug Bridge (adb), which supports a number of interactions with an Android device tethered via USB. We then use adb to setup a port-forwarding tunnel from a TCP port on the device to a TCP port on the local host. The use of adb for network transfer eliminates the need to modify the networking configuration on the device or introduce a wireless peer—all network data is transferred via USB. For the example below, we have chosen TCP port 4444. We then obtain a root shell on the device by using adb and su. To accomplish this, we run the following commands with the phone plugged into our computer and debugging enabled on the device.
```
adb push lime.ko /sdcard/lime.ko
adb forward tcp:4444 tcp:4444
adb shell
su
#
```
Memory acquisition over the TCP tunnel is then a two-part process. First, the target device must listen on a specified TCP port and then we must connect to the device from the host computer. When the socket is connected, the kernel module will automatically send the acquired RAM image to the host device.
In the adb root shell, we install our kernel module using the insmod command. To instruct the module to dump memory via TCP, we set the path parameter to “tcp”, followed by a colon and then the port number that adb is forwarding. On our host computer, we connect to this port with netcat and redirect output to a file. We also select the “lime” formatting option. When the acquisition process is complete, LiME will terminate the TCP connection.
The following command loads the kernel module via adb on the target Android device:
```
insmod /sdcard/lime.ko “path=tcp:4444 format=lime”
```
On the host, the following command captures the memory dump via TCP port 444 to the file “ram.lime”:
```
nc localhost 4444 > ram.lime
```
### Acquisition of Memory to Disk (SD-Card)
In some cases, such as when the investigator wants to make sure no network buffers are overwritten, disk-based acquisition may be preferred to network acquisition. To accommodate this situation, LiME provides the option to write memory images to the device’s file system. On Android, the logical place to write is the device’s SD card.
Since the SD card could potentially contain other relevant evidence to the case, the investigator may wish to image the SD card first in order to save unallocated space. Unfortunately, some Android phones, such as the HTC EVO 4G and the Droid series, place the removable SD card to be either under or obstructed by the phone’s battery, making it impossible to remove the SD card without powering off the phone (these phones will power down if the battery is removed, even if they are plugged into a power source!). For this reason, the investigator needs to first image the SD card, and then subsequently write the memory image to it. While this process violates the typical “order of volatility” rule of thumb in forensic acquisition, namely, obtaining the most volatile information first, it is necessary to properly preserve all evidence.
Fortunately, imaging the SD card on an Android device that will be subjected to live forensic analysis (including memory dumping) does not require removal of the SD card. Tethering the device to a Linux machine, for example, and activating USB Storage exposes a /dev/sd? device that can be imaged using traditional means (e.g., using dd on the Linux box). Activating USB Storage mode unmounts the SD card on the Android device, so a forensically valid image can be obtained.
With USB Storage mode deactivated, we copy the LiME kernel module to the device using the same steps described in the last section. When installing the module using insmod, we set the path parameter to /sdcard/ram.lime to specify the file in which to write the memory dump. We also select the “lime” format option:
```
insmod /sdcard/lime.ko “path=/sdcard/ram.lime format=lime”
```
Once the acquisition process is complete, we can power down the phone, remove the SD card from the phone, and transfer the memory dump to the examination machine. If the phone cannot be powered down, adb can also be used to transfer the memory dump to the investigator's machine.
## LiME Memory Range Header Version 1 Specification
```
typedef struct {
unsigned int magic; // Always 0x4C694D45 (LiME)
unsigned int version; // Header version number
unsigned long long s_addr; // Starting address of physical RAM range
unsigned long long e_addr; // Ending address of physical RAM range
unsigned char reserved[8]; // Currently all zeros
} __attribute__ ((__packed__)) lime_mem_range_header;
```
LiME-1.9/doc/external_modules.md 0000664 0000000 0000000 00000021413 13552640762 0016625 0 ustar 00root root 0000000 0000000 # Building External Modules
## Contents
* [Intro](#intro)
+ [How To](#howto)
+ [Required Tools](#tools)
+ [Downloading the kernel source](#download)
+ [Choosing the correct kernel release](#release)
+ [Using an old kernel config](#config)
+ [Setting the correct version](#versioncorrect)
+ [Prepare the source and compile](#compile)
+ [OS specific resources](#resources)
+ [CentOS](#centos)
+ [Fedora](#fedora)
+ [RHEL](#rhel)
+ [Ubuntu](#ubuntu)
## Introduction
There may come time in life when one would find benefit in compiling kernel modules outside of the running kernel. This is known as compiling **external** or **out of tree** modules. In the case of `LiME`, compiling outside of the running kernel is a more forensically sound and secure method, as the kernel object is not compiled on the target system. Since there is no need to compile on the target systems, Admin's do not have to alter the production systems to include gcc, linux kernel headers, among other development tools. [This link](https://www.kernel.org/doc/Documentation/kbuild/modules.txt) includes the kernel documentation on how to build an external kernel module.
**NOTE** This guide does not cover `cross compiling` external modules. If your architecture differs from your host machine you will need to cross compile your module.
## How to
The following is a step-by-step guide, using Ubuntu, in order to compile your own external module. The steps will vary from each distribution. Some distribution specifics will be covered at the end of this document.
### Required tools
You will need the following tools
- git
- build-essential package **OS specific**
### Downloading the kernel source
The first task is to find and download the correct kernel source for your distribution and version. For this I will show you examples with the Ubuntu kernel. You can read Ubuntu's fancy guide for downloading source [here](https://wiki.ubuntu.com/Kernel/Dev/KernelGitGuide).
But here is the TL;DR version
In order to determine the correct OS version of your target machine, you can run `cat /etc/os-release`.
```
$ cat /etc/os-release
NAME="Ubuntu"
VERSION="16.04.2 LTS (Xenial Xerus)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 16.04.2 LTS"
VERSION_ID="16.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
VERSION_CODENAME=xenial
UBUNTU_CODENAME=xenial
```
From the output above we can see that our release is `Xenial 16.04.2 LTS`.
Now we must go and clone the source using `git`. For our Ubuntu example the links are in the following format.
```
kernel.ubuntu.com/ubuntu/ubuntu-< release >.git
```
Following our Xenial example, we would clone the source by entering this
```
$git clone git://kernel.ubuntu.com/ubuntu/ubuntu-xenial.git
```
If you have firewall restrictions or other ridiculousness using the git protocol, you can clone via http.
```
$git clone http://kernel.ubuntu.com/git-repos/ubuntu/ubuntu-xenial.git
```
This will be a lot slower and you will not be able to set the history depth, therefore downloading far more data.
### Choosing the correct kernel release
Once the repository has finished cloning, we will need to checkout the correct kernel release. To complete this task run `uname -r` on the target machine.
```
$uname -r
4.10.0-38-generic
```
This most important take-away of the kernel release is the string after the `sublevel` digit. The Linux kernel is versioned in the following format
```
version.patchlevel.sublevel-localversion
```
From the example above we can see that our local version needs to be `-38-generic`. Once you have determined the version that you need to build, change directory into your kernel source. From this location run
```
git tag -l
```
to list all the tags. Find the tag that matches you kernel version *version.patchlevel.sublevel* and checkout that the point in history.
```
git checkout < tag >
```
Following our Ubuntu guide you would run something like the following
```
git checkout Ubuntu-lts-4.10.0-9.11_16.04.2
```
### Using an old kernel config
In order to build an external modules that will fit target running kernel, we need to know how your kernel was built. The kernel build process stores this information in a config file, storing that in `/boot/config-*`.
Copy the correct config file to your kernel working directory and then rename it to `.config`. In our Ubuntu example the correct config file is located/called
```
/boot/config-4.10.0-38-generic
```
Once you have renamed the config file `.config` run the following
```
$ make olddefconfig
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
scripts/kconfig/conf --olddefconfig Kconfig
#
# configuration written to .config
#
```
This make function will use the old kernel config and substitute the default values for options that differ in your kernel.
### Setting the correct version
This is the most important part of the entire process. If the version does not match the running kernel, your module will most likely fail to install. This is due to a kernel safety measure, enabled by default, to prevent incompatible modules from loading.
Once the config completes, we need to make sure that all the versions match before we continue. Run the following make function
```
$ make kernelrelease
4.10.0+
```
Did make complete without error? Does that match the version you want? If so continue; else checkout a different tag with git.
Did you notice that our kernel release is missing the `localversion` string? Well, let's fix that using your favorite text editor.
Find the lines that say the following
```
#
# General setup
#
CONFIG_INIT_ENV_ARG_LIMIT=32
CONFIG_CROSS_COMPILE=""
# CONFIG_COMPILE_TEST is not set
CONFIG_LOCALVERSION=""
# CONFIG_LOCALVERSION_AUTO is not set
CONFIG_HAVE_KERNEL_GZIP=y
```
Change **both** `CONFIG_LOCALVERSION` and `# CONFIG_COMPILE_TEST is not set` to match the following example
```
CONFIG_LOCALVERSION="< localversion >"
CONFIG_LOCALVERSION_AUTO=n
```
In our Ubuntu example add `-38-generic` and don't forget the hyphen.
```
CONFIG_LOCALVERSION="-38-generic"
CONFIG_LOCALVERSION_AUTO=n
```
Now! run `make kernelrelease` again
```
$ make kernelrelease
4.10.0-38-generic+
```
Is your localversion correct? If so, continue
Note the `+` at the end of the localversion string. We need to remove this
```
touch .scmversion
```
to create and empty file. Now run `make kernelrelease` once more, this time the version should be an exact match.
```
$ make kernelrelease
4.10.0-38-generic
```
### Prepare the source and compile
Now run
```
$ make modules_prepare
```
in order to prepare the kernel source tree for building external modules. We use this function in order to skip compiling an entire kernel, saving you some cycles. If this completes without error, one can proceed with compiling the module. We will use LiME as the example module. Change directory into your LiME source and run
```
make -C < path-src-tree > KVER=< kernel-version > M=$(pwd)
```
`path-to-src-tree` is the location where you cloned your kernel source. Again, following our Ubuntu example
```
make -C /home/kd8bny/ubuntu-xenial KVER=4.10.0-38-generic M=$(pwd)
```
And there you have it! A successfully compiled **external** kernel module. Now feel free to load this into the running kernel on your target machine.
## OS specific resources
### CentOS
CentOS and RHEL package source a little differently. The source is packaged as an RPM. This is a semi-helpful [link](https://wiki.centos.org/HowTos/I_need_the_Kernel_Source).
The source is located [here](http://vault.centos.org). Browse to the following location and download.
```
http://vault.centos.org/< cent version >/os/Source/SPackages/kernel-3.10.0-123.el7.src.rpm
```
Once you have downloaded the RPM extract it using `tar` or some other file archiving tool. Once extracted you will see another archive dubbed `linux-`. This is your source, extract it. You can use the config files already found in this source. Continue as stated in the guide, ignoring the use of `git`.
### Fedora
Fedora keeps kernel source off the main linux git tree. Clone it here
```
git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git
```
Follow the same process in the guide.
### RHEL
Follow the centOS section, as this is where the source is located for non-subscribers. If you are a subscriber, you can download the source from Red Hat.
### Ubuntu
Follow as shown in guide.
[kernel source](http://kernel.ubuntu.com/git/)
LiME-1.9/src/ 0000775 0000000 0000000 00000000000 13552640762 0012752 5 ustar 00root root 0000000 0000000 LiME-1.9/src/Makefile 0000664 0000000 0000000 00000003337 13552640762 0014420 0 ustar 00root root 0000000 0000000 # LiME - Linux Memory Extractor
# Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs
#
#
# Author:
# Joe Sylve - joe.sylve@gmail.com, @jtsylve
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
obj-m := lime.o
lime-objs := tcp.o disk.o main.o hash.o deflate.o
KVER ?= $(shell uname -r)
KDIR ?= /lib/modules/$(KVER)/build
PWD := $(shell pwd)
.PHONY: modules modules_install clean distclean debug
default:
$(MAKE) -C $(KDIR) M="$(PWD)" modules
strip --strip-unneeded lime.ko
mv lime.ko lime-$(KVER).ko
debug:
KCFLAGS="-DLIME_DEBUG" $(MAKE) CONFIG_DEBUG_SG=y -C $(KDIR) M="$(PWD)" modules
strip --strip-unneeded lime.ko
mv lime.ko lime-$(KVER).ko
symbols:
$(MAKE) -C $(KDIR) M="$(PWD)" modules
mv lime.ko lime-$(KVER).ko
modules: main.c disk.c tcp.c hash.c lime.h
$(MAKE) -C /lib/modules/$(KVER)/build M="$(PWD)" $@
strip --strip-unneeded lime.ko
modules_install: modules
$(MAKE) -C $(KDIR) M="$(PWD)" $@
clean:
rm -f *.o *.mod.c Module.symvers Module.markers modules.order \.*.o.cmd \.*.ko.cmd \.*.o.d
rm -rf \.tmp_versions
distclean: mrproper
mrproper: clean
rm -f *.ko
LiME-1.9/src/Makefile.sample 0000664 0000000 0000000 00000003272 13552640762 0015676 0 ustar 00root root 0000000 0000000 # LiME - Linux Memory Extractor
# Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs
#
#
# Author:
# Joe Sylve - joe.sylve@gmail.com, @jtsylve
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# This is a sample Makefile for cross-compiling the LiME LKM
obj-m := lime.o
lime-objs := tcp.o disk.o main.o
KDIR_GOLD := /usr/local/kernels/goldfish/
KVER := $(shell uname -r)
PWD := $(shell pwd)
CCPATH := /usr/local/bin/google/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin
default:
# cross-compile for Android emulator
$(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR_GOLD) M="$(PWD)" modules
$(CCPATH)/arm-linux-androideabi-strip --strip-unneeded lime.ko
mv lime.ko lime-goldfish.ko
# compile for local system
$(MAKE) -C /lib/modules/$(KVER)/build M="$(PWD)" modules
strip --strip-unneeded lime.ko
mv lime.ko lime-$(KVER).ko
$(MAKE) tidy
tidy:
rm -f *.o *.mod.c Module.symvers Module.markers modules.order \.*.o.cmd \.*.ko.cmd \.*.o.d
rm -rf \.tmp_versions
clean:
$(MAKE) tidy
rm -f *.ko
LiME-1.9/src/deflate.c 0000664 0000000 0000000 00000004722 13552640762 0014527 0 ustar 00root root 0000000 0000000 /*
* LiME - Linux Memory Extractor
* Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs
*
*
* Author:
* Joe Sylve - joe.sylve@gmail.com, @jtsylve
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef CONFIG_ZLIB_DEFLATE
#include
#include "lime.h"
/* Balance high compression level and memory footprint. */
#define DEFLATE_WBITS 11 /* 8KB */
#define DEFLATE_MEMLEVEL 5 /* 12KB */
static struct z_stream_s zstream;
static void *next_out;
static size_t avail_out;
extern int deflate_begin_stream(void *out, size_t outlen)
{
int size;
size = zlib_deflate_workspacesize(DEFLATE_WBITS, DEFLATE_MEMLEVEL);
zstream.workspace = kzalloc(size, GFP_NOIO);
if (!zstream.workspace) {
return -ENOMEM;
}
if (zlib_deflateInit2(&zstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED,
DEFLATE_WBITS,
DEFLATE_MEMLEVEL,
Z_DEFAULT_STRATEGY) != Z_OK) {
kfree(zstream.workspace);
return -EINVAL;
}
next_out = out;
avail_out = outlen;
zstream.next_out = next_out;
zstream.avail_out = avail_out;
return 0;
}
int deflate_end_stream(void)
{
zlib_deflateEnd(&zstream);
kfree(zstream.workspace);
return 0;
}
ssize_t deflate(const void *in, size_t inlen)
{
int flush, ret;
if (in && inlen > 0)
flush = Z_NO_FLUSH;
else
flush = Z_FINISH;
if (zstream.avail_out != 0) {
zstream.next_in = in;
zstream.avail_in = inlen;
}
zstream.next_out = next_out;
zstream.avail_out = avail_out;
ret = zlib_deflate(&zstream, flush);
if (ret != Z_OK && !(flush == Z_FINISH && ret == Z_STREAM_END)) {
DBG("Deflate error: %d", ret);
return -EIO;
}
return avail_out - zstream.avail_out;
}
#endif
LiME-1.9/src/disk.c 0000664 0000000 0000000 00000004457 13552640762 0014062 0 ustar 00root root 0000000 0000000 /*
* LiME - Linux Memory Extractor
* Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs
*
*
* Author:
* Joe Sylve - joe.sylve@gmail.com, @jtsylve
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lime.h"
ssize_t write_vaddr_disk(void *, size_t);
static struct file * f = NULL;
static int dio_write_test(char *path, int oflags)
{
int ok;
f = filp_open(path, oflags | O_DIRECT, 0444);
if (f && !IS_ERR(f)) {
ok = write_vaddr_disk("DIO", 3) == 3;
filp_close(f, NULL);
} else {
ok = 0;
}
return ok;
}
int setup_disk(char *path, int dio) {
mm_segment_t fs;
int oflags;
int err;
fs = get_fs();
set_fs(KERNEL_DS);
oflags = O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC | O_SYNC;
if (dio && dio_write_test(path, oflags)) {
oflags |= O_DIRECT;
} else {
DBG("Direct IO Disabled");
}
f = filp_open(path, oflags, 0444);
if (!f || IS_ERR(f)) {
DBG("Error opening file %ld", PTR_ERR(f));
set_fs(fs);
err = (f) ? PTR_ERR(f) : -EIO;
f = NULL;
return err;
}
set_fs(fs);
return 0;
}
void cleanup_disk(void) {
mm_segment_t fs;
fs = get_fs();
set_fs(KERNEL_DS);
if(f) filp_close(f, NULL);
set_fs(fs);
}
ssize_t write_vaddr_disk(void * v, size_t is) {
mm_segment_t fs;
ssize_t s;
loff_t pos;
fs = get_fs();
set_fs(KERNEL_DS);
pos = f->f_pos;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,14,0)
s = kernel_write(f, v, is, &pos);
#else
s = vfs_write(f, v, is, &pos);
#endif
if (s == is) {
f->f_pos = pos;
}
set_fs(fs);
return s;
}
LiME-1.9/src/hash.c 0000664 0000000 0000000 00000013245 13552640762 0014046 0 ustar 00root root 0000000 0000000 /*
* LiME - Linux Memory Extractor
* Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs
*
*
* Author:
* Joe Sylve - joe.sylve@gmail.com, @jtsylve
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lime.h"
// External
extern ssize_t write_vaddr_tcp(void *, size_t);
extern int setup_tcp(void);
extern void cleanup_tcp(void);
extern ssize_t write_vaddr_disk(void *, size_t);
extern int setup_disk(char *, int);
extern void cleanup_disk(void);
static u8 *output;
static int digestsize;
static char *digest_value;
extern char *digest;
extern char *path;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
static struct crypto_ahash *tfm;
static struct ahash_request *req;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
static struct crypto_hash *tfm;
static struct hash_desc desc;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
struct crypto_tfm *tfm;
#endif
int ldigest_init(void) {
DBG("Initializing Digest Transformation.");
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
tfm = crypto_alloc_ahash(digest, 0, CRYPTO_ALG_ASYNC);
if (unlikely(IS_ERR(tfm))) goto init_fail;
req = ahash_request_alloc(tfm, GFP_ATOMIC);
if (unlikely(!req)) goto init_fail;
digestsize = crypto_ahash_digestsize(tfm);
ahash_request_set_callback(req, 0, NULL, NULL);
crypto_ahash_init(req);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
tfm = crypto_alloc_hash(digest, 0, CRYPTO_ALG_ASYNC);
if (unlikely(IS_ERR(tfm)))
goto init_fail;
desc.tfm = tfm;
desc.flags = 0;
digestsize = crypto_hash_digestsize(tfm);
crypto_hash_init(&desc);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
tfm = crypto_alloc_tfm(digest, 0);
if (unlikely(tfm == NULL))
goto init_fail;
crypto_digest_init(tfm);
#else
DBG("Digest not supported for this kernel version.");
goto init_fail;
#endif
output = kzalloc(sizeof(u8) * digestsize, GFP_ATOMIC);
return LIME_DIGEST_COMPUTE;
init_fail:
DBG("Digest Initialization Failed.");
return LIME_DIGEST_FAILED;
}
int ldigest_update(void *v, size_t is) {
int ret;
struct scatterlist sg;
if (likely(virt_addr_valid((unsigned long) v))) {
sg_init_one(&sg, (u8 *) v, is);
} else {
int nbytes = is;
DBG("Invalid Virtual Address, Manually Scanning Page.");
while (nbytes > 0) {
int len = nbytes;
int off = offset_in_page(v);
if (off + len > (int)PAGE_SIZE)
len = PAGE_SIZE - off;
sg_init_table(&sg, 1);
sg_set_page(&sg, vmalloc_to_page((u8 *) v), len, off);
v += len;
nbytes -= len;
}
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
ahash_request_set_crypt(req, &sg, output, is);
ret = crypto_ahash_update(req);
if (ret < 0)
goto update_fail;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
ret = crypto_hash_update(&desc, &sg, is);
if (ret < 0)
goto update_fail;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
crypto_digest_update(tfm, &sg, is);
#endif
return LIME_DIGEST_COMPUTE;
update_fail:
DBG("Digest Update Failed.");
return LIME_DIGEST_FAILED;
}
int ldigest_final(void) {
int ret, i;
DBG("Finalizing the digest.");
digest_value = kmalloc(digestsize * 2 + 1, GFP_KERNEL);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
ret = crypto_ahash_final(req);
if (ret < 0)
goto final_fail;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
ret = crypto_hash_final(&desc, output);
if (ret < 0)
goto final_fail;
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
crypto_digest_final(tfm, output);
#endif
for (i = 0; i= KERNEL_VERSION(4, 6, 0)
crypto_free_ahash(tfm);
ahash_request_free(req);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19)
crypto_free_hash(tfm);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
crypto_free_tfm(tfm);
#endif
}
LiME-1.9/src/lime.h 0000664 0000000 0000000 00000004571 13552640762 0014060 0 ustar 00root root 0000000 0000000 /*
* LiME - Linux Memory Extractor
* Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs
*
*
* Author:
* Joe Sylve - joe.sylve@gmail.com, @jtsylve
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __LIME_H_
#define __LIME_H_
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0)
#include
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11)
#include
#endif
#define LIME_RAMSTR "System RAM"
#define LIME_MAX_FILENAME_SIZE 256
#define LIME_MAGIC 0x4C694D45 //LiME
#define LIME_MODE_RAW 0
#define LIME_MODE_LIME 1
#define LIME_MODE_PADDED 2
#define LIME_METHOD_UNKNOWN 0
#define LIME_METHOD_TCP 1
#define LIME_METHOD_DISK 2
#define LIME_DIGEST_FAILED -1
#define LIME_DIGEST_COMPLETE 0
#define LIME_DIGEST_COMPUTE 1
#ifdef LIME_DEBUG
#define DBG(fmt, args...) do { printk("[LiME] "fmt"\n", ## args); } while (0)
#else
#define DBG(fmt, args...) do {} while(0)
#endif
#define RETRY_IF_INTERRUPTED(f) ({ \
ssize_t err; \
do { err = f; } while(err == -EAGAIN || err == -EINTR); \
err; \
})
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35)
#define LIME_SUPPORTS_TIMING
#endif
#ifdef CONFIG_ZLIB_DEFLATE
#define LIME_SUPPORTS_DEFLATE
#endif
//structures
typedef struct {
unsigned int magic;
unsigned int version;
unsigned long long s_addr;
unsigned long long e_addr;
unsigned char reserved[8];
} __attribute__ ((__packed__)) lime_mem_range_header;
#endif //__LIME_H_
LiME-1.9/src/main.c 0000664 0000000 0000000 00000022236 13552640762 0014047 0 ustar 00root root 0000000 0000000 /*
* LiME - Linux Memory Extractor
* Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs
*
*
* Author:
* Joe Sylve - joe.sylve@gmail.com, @jtsylve
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "lime.h"
// This file
static ssize_t write_lime_header(struct resource *);
static ssize_t write_padding(size_t);
static void write_range(struct resource *);
static int init(void);
static ssize_t write_vaddr(void *, size_t);
static ssize_t write_flush(void);
static ssize_t try_write(void *, ssize_t);
static int setup(void);
static void cleanup(void);
// External
extern ssize_t write_vaddr_tcp(void *, size_t);
extern int setup_tcp(void);
extern void cleanup_tcp(void);
extern ssize_t write_vaddr_disk(void *, size_t);
extern int setup_disk(char *, int);
extern void cleanup_disk(void);
extern int ldigest_init(void);
extern int ldigest_update(void *, size_t);
extern int ldigest_final(void);
extern int ldigest_write_tcp(void);
extern int ldigest_write_disk(void);
extern int ldigest_clean(void);
#ifdef LIME_SUPPORTS_DEFLATE
extern int deflate_begin_stream(void *, size_t);
extern int deflate_end_stream(void);
extern ssize_t deflate(const void *, size_t);
#endif
static char * format = 0;
static int mode = 0;
static int method = 0;
static void * vpage;
#ifdef LIME_SUPPORTS_DEFLATE
static void *deflate_page_buf;
#endif
char * path = 0;
int dio = 0;
int port = 0;
int localhostonly = 0;
char * digest = 0;
int compute_digest = 0;
int no_overlap = 0;
extern struct resource iomem_resource;
module_param(path, charp, S_IRUGO);
module_param(dio, int, S_IRUGO);
module_param(format, charp, S_IRUGO);
module_param(localhostonly, int, S_IRUGO);
module_param(digest, charp, S_IRUGO);
#ifdef LIME_SUPPORTS_TIMING
long timeout = 1000;
module_param(timeout, long, S_IRUGO);
#endif
#ifdef LIME_SUPPORTS_DEFLATE
int compress = 0;
module_param(compress, int, S_IRUGO);
#endif
int init_module (void)
{
if(!path) {
DBG("No path parameter specified");
return -EINVAL;
}
if(!format) {
DBG("No format parameter specified");
return -EINVAL;
}
DBG("Parameters");
DBG(" PATH: %s", path);
DBG(" DIO: %u", dio);
DBG(" FORMAT: %s", format);
DBG(" LOCALHOSTONLY: %u", localhostonly);
DBG(" DIGEST: %s", digest);
#ifdef LIME_SUPPORTS_TIMING
DBG(" TIMEOUT: %lu", timeout);
#endif
#ifdef LIME_SUPPORTS_DEFLATE
DBG(" COMPRESS: %u", compress);
#endif
if (!strcmp(format, "raw")) mode = LIME_MODE_RAW;
else if (!strcmp(format, "lime")) mode = LIME_MODE_LIME;
else if (!strcmp(format, "padded")) mode = LIME_MODE_PADDED;
else {
DBG("Invalid format parameter specified.");
return -EINVAL;
}
method = (sscanf(path, "tcp:%d", &port) == 1) ? LIME_METHOD_TCP : LIME_METHOD_DISK;
if (digest) compute_digest = LIME_DIGEST_COMPUTE;
return init();
}
static int init() {
struct resource *p;
int err = 0;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
resource_size_t p_last = -1;
#else
__PTRDIFF_TYPE__ p_last = -1;
#endif
DBG("Initializing Dump...");
if ((err = setup())) {
DBG("Setup Error");
cleanup();
return err;
}
if (digest) {
compute_digest = ldigest_init();
no_overlap = 1;
}
vpage = (void *) __get_free_page(GFP_NOIO);
#ifdef LIME_SUPPORTS_DEFLATE
if (compress) {
deflate_page_buf = kmalloc(PAGE_SIZE, GFP_NOIO);
err = deflate_begin_stream(deflate_page_buf, PAGE_SIZE);
if (err < 0) {
DBG("ZLIB begin stream failed");
return err;
}
no_overlap = 1;
}
#endif
for (p = iomem_resource.child; p ; p = p->sibling) {
if (strcmp(p->name, LIME_RAMSTR))
continue;
if (mode == LIME_MODE_LIME && write_lime_header(p) < 0) {
DBG("Error writing header 0x%lx - 0x%lx", (long) p->start, (long) p->end);
break;
} else if (mode == LIME_MODE_PADDED && write_padding((size_t) ((p->start - 1) - p_last)) < 0) {
DBG("Error writing padding 0x%lx - 0x%lx", (long) p_last, (long) p->start - 1);
break;
}
write_range(p);
p_last = p->end;
}
write_flush();
DBG("Memory Dump Complete...");
cleanup();
if (compute_digest == LIME_DIGEST_COMPUTE) {
DBG("Writing Out Digest.");
compute_digest = ldigest_final();
if (compute_digest == LIME_DIGEST_COMPLETE) {
if (method == LIME_METHOD_TCP)
err = ldigest_write_tcp();
else
err = ldigest_write_disk();
DBG("Digest Write %s.", (err == 0) ? "Complete" : "Failed");
}
}
if (digest)
ldigest_clean();
#ifdef LIME_SUPPORTS_DEFLATE
if (compress) {
deflate_end_stream();
kfree(deflate_page_buf);
}
#endif
free_page((unsigned long) vpage);
return 0;
}
static ssize_t write_lime_header(struct resource * res) {
lime_mem_range_header header;
memset(&header, 0, sizeof(lime_mem_range_header));
header.magic = LIME_MAGIC;
header.version = 1;
header.s_addr = res->start;
header.e_addr = res->end;
return write_vaddr(&header, sizeof(lime_mem_range_header));
}
static ssize_t write_padding(size_t s) {
size_t i = 0;
ssize_t r;
memset(vpage, 0, PAGE_SIZE);
while(s -= i) {
i = min((size_t) PAGE_SIZE, s);
r = write_vaddr(vpage, i);
if (r != i) {
DBG("Error sending zero page: %zd", r);
return r;
}
}
return 0;
}
static void write_range(struct resource * res) {
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
resource_size_t i, is;
#else
__PTRDIFF_TYPE__ i, is;
#endif
struct page * p;
void * v;
ssize_t s;
#ifdef LIME_SUPPORTS_TIMING
ktime_t start,end;
#endif
DBG("Writing range %llx - %llx.", res->start, res->end);
for (i = res->start; i <= res->end; i += is) {
#ifdef LIME_SUPPORTS_TIMING
start = ktime_get_real();
#endif
p = pfn_to_page((i) >> PAGE_SHIFT);
is = min((size_t) PAGE_SIZE, (size_t) (res->end - i + 1));
if (is < PAGE_SIZE) {
// We can't map partial pages and
// the linux kernel doesn't use them anyway
DBG("Padding partial page: vaddr %p size: %lu", (void *) i, (unsigned long) is);
write_padding(is);
} else {
v = kmap(p);
/*
* If we need to compute the digest or compress the output
* take a snapshot of the page. Otherwise save some cycles.
*/
if (no_overlap) {
copy_page(vpage, v);
s = write_vaddr(vpage, is);
} else {
s = write_vaddr(v, is);
}
kunmap(p);
if (s < 0) {
DBG("Failed to write page: vaddr %p. Skipping Range...", v);
break;
}
}
#ifdef LIME_SUPPORTS_TIMING
end = ktime_get_real();
if (timeout > 0 && ktime_to_ms(ktime_sub(end, start)) > timeout) {
DBG("Reading is too slow. Skipping Range...");
write_padding(res->end - i + 1 - is);
break;
}
#endif
}
}
static ssize_t write_vaddr(void * v, size_t is) {
ssize_t ret;
if (compute_digest == LIME_DIGEST_COMPUTE)
compute_digest = ldigest_update(v, is);
#ifdef LIME_SUPPORTS_DEFLATE
if (compress) {
/* Run deflate() on input until output buffer is not full. */
do {
ret = try_write(deflate_page_buf, deflate(v, is));
if (ret < 0)
return ret;
} while (ret == PAGE_SIZE);
return is;
}
#endif
ret = try_write(v, is);
return ret;
}
static ssize_t write_flush(void) {
#ifdef LIME_SUPPORTS_DEFLATE
if (compress) {
try_write(deflate_page_buf, deflate(NULL, 0));
}
#endif
return 0;
}
static ssize_t try_write(void * v, ssize_t is) {
ssize_t ret;
if (is <= 0)
return is;
ret = RETRY_IF_INTERRUPTED(
(method == LIME_METHOD_TCP) ? write_vaddr_tcp(v, is) : write_vaddr_disk(v, is)
);
if (ret < 0) {
DBG("Write error: %zd", ret);
} else if (ret != is) {
DBG("Short write %zu instead of %zu.", ret, is);
ret = -1;
}
return ret;
}
static int setup(void) {
return (method == LIME_METHOD_TCP) ? setup_tcp() : setup_disk(path, dio);
}
static void cleanup(void) {
return (method == LIME_METHOD_TCP) ? cleanup_tcp() : cleanup_disk();
}
void cleanup_module(void) {
}
MODULE_LICENSE("GPL");
LiME-1.9/src/tcp.c 0000664 0000000 0000000 00000007260 13552640762 0013711 0 ustar 00root root 0000000 0000000 /*
* LiME - Linux Memory Extractor
* Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs
*
*
* Author:
* Joe Sylve - joe.sylve@gmail.com, @jtsylve
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "lime.h"
ssize_t write_vaddr_tcp(void *, size_t);
int setup_tcp(void);
void cleanup_tcp(void);
extern int port;
extern int localhostonly;
static struct socket *control;
static struct socket *accept;
int setup_tcp() {
struct sockaddr_in saddr;
int r, opt;
mm_segment_t fs;
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
r = sock_create_kern(&init_net, AF_INET, SOCK_STREAM, IPPROTO_TCP, &control);
#elif LINUX_VERSION_CODE > KERNEL_VERSION(2,6,5)
r = sock_create_kern(AF_INET, SOCK_STREAM, IPPROTO_TCP, &control);
#else
r = sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &control);
#endif
if (r < 0) {
DBG("Error creating control socket");
return r;
}
memset(&saddr, 0, sizeof(saddr));
saddr.sin_family = AF_INET;
saddr.sin_port = htons(port);
if (localhostonly) {
saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
} else {
saddr.sin_addr.s_addr = htonl(INADDR_ANY);
}
fs = get_fs();
set_fs(KERNEL_DS);
opt = 1;
r = kernel_setsockopt(control, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof (opt));
if (r < 0) {
DBG("Error setting socket options");
return r;
}
set_fs(fs);
r = kernel_bind(control,(struct sockaddr*) &saddr,sizeof(saddr));
if (r < 0) {
DBG("Error binding control socket");
return r;
}
r = kernel_listen(control,1);
if (r) {
DBG("Error listening on socket");
return r;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0)
r = sock_create_kern(&init_net, PF_INET, SOCK_STREAM, IPPROTO_TCP, &accept);
#elif LINUX_VERSION_CODE > KERNEL_VERSION(2,6,5)
r = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &accept);
#else
r = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &accept);
#endif
if (r < 0) {
DBG("Error creating accept socket");
return r;
}
r = kernel_accept(control, &accept, 0);
if (r < 0) {
DBG("Error accepting socket");
return r;
}
return 0;
}
void cleanup_tcp() {
if (accept) {
kernel_sock_shutdown(accept, SHUT_RDWR);
sock_release(accept);
accept = NULL;
}
if (control) {
kernel_sock_shutdown(control, SHUT_RDWR);
sock_release(control);
control = NULL;
}
}
ssize_t write_vaddr_tcp(void * v, size_t is) {
ssize_t s;
struct kvec iov;
struct msghdr msg;
memset(&iov, 0, sizeof(struct iovec));
memset(&msg, 0, sizeof(struct msghdr));
iov.iov_base = v;
iov.iov_len = is;
s = kernel_sendmsg(accept, &msg, &iov, 1, is);
return s;
}