pax_global_header00006660000000000000000000000064131203674510014514gustar00rootroot0000000000000052 comment=f30dae8a2356fa8b5720f61698316508ddc7733e LiME-1.7.8/000077500000000000000000000000001312036745100123175ustar00rootroot00000000000000LiME-1.7.8/.gitignore000066400000000000000000000001451312036745100143070ustar00rootroot00000000000000# Dumps *.lime *.raw # Objects *.o *.ko Module.symvers modules.order *.mod.c *.cmd .tmp_versions/ LiME-1.7.8/LICENSE000066400000000000000000000431531312036745100133320ustar00rootroot00000000000000GNU 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.7.8/README.md000066400000000000000000000054101312036745100135760ustar00rootroot00000000000000# 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 ## 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= [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): raw ~ concatenates all System RAM ranges padded ~ pads all non-System RAM ranges with 0s lime ~ each range prepended with fixed-size header containing address space info dio (optional): 1 ~ attempt to enable Direct IO 0 ~ default, do not attempt Direct IO 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" ``` ## 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.7.8/doc/000077500000000000000000000000001312036745100130645ustar00rootroot00000000000000LiME-1.7.8/doc/README.md000066400000000000000000000227231312036745100143510ustar00rootroot00000000000000#LiME – Linux Memory Extractor ##Contents * [Compiling](#Compile) * [Linux](#Linux) * [Debug](#Debug) * [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. ###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. ###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 ENVIORNMENT 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 raw: Simply concatenates all System RAM ranges 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. Volatility address space developed to support this format 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.7.8/src/000077500000000000000000000000001312036745100131065ustar00rootroot00000000000000LiME-1.7.8/src/Makefile000066400000000000000000000031751312036745100145540ustar00rootroot00000000000000# 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 KVER ?= $(shell uname -r) PWD := $(shell pwd) .PHONY: modules modules_install clean distclean debug default: $(MAKE) -C /lib/modules/$(KVER)/build M="$(PWD)" modules strip --strip-unneeded lime.ko mv lime.ko lime-$(KVER).ko debug: KCFLAGS="-DLIME_DEBUG" $(MAKE) -C /lib/modules/$(KVER)/build M="$(PWD)" modules strip --strip-unneeded lime.ko mv lime.ko lime-$(KVER).ko modules: main.c disk.c tcp.c lime.h $(MAKE) -C /lib/modules/$(KVER)/build M="$(PWD)" $@ strip --strip-unneeded lime.ko modules_install: modules $(MAKE) -C /lib/modules/$(KVER)/build 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.7.8/src/Makefile.sample000066400000000000000000000032721312036745100160320ustar00rootroot00000000000000# 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.7.8/src/disk.c000066400000000000000000000047751312036745100142210ustar00rootroot00000000000000/* * 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); int setup_disk(void); void cleanup_disk(void); static void disable_dio(void); static struct file * f = NULL; extern char * path; extern int dio; static int reopen = 0; static void disable_dio() { DBG("Direct IO may not be supported on this file system. Retrying."); dio = 0; reopen = 1; cleanup_disk(); setup_disk(); } int setup_disk() { mm_segment_t fs; int err; fs = get_fs(); set_fs(KERNEL_DS); if (dio && reopen) { f = filp_open(path, O_WRONLY | O_CREAT | O_LARGEFILE | O_SYNC | O_DIRECT, 0444); } else if (dio) { f = filp_open(path, O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC | O_SYNC | O_DIRECT, 0444); } if(!dio || (f == ERR_PTR(-EINVAL))) { DBG("Direct IO Disabled"); f = filp_open(path, O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC, 0444); dio = 0; } 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() { 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; s = vfs_write(f, v, is, &pos); if (s == is) { f->f_pos = pos; } set_fs(fs); if (s != is && dio) { disable_dio(); f->f_pos = pos; return write_vaddr_disk(v, is); } return s; } LiME-1.7.8/src/lime.h000066400000000000000000000036001312036745100142040ustar00rootroot00000000000000/* * 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 #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 #ifdef LIME_DEBUG #define DBG(fmt, args...) do { printk("[LiME] "fmt"\n", ## args); } while (0) #else #define DBG(fmt, args...) do {} while(0) #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35) #define LIME_SUPPORTS_TIMING #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.7.8/src/main.c000066400000000000000000000147261312036745100142100ustar00rootroot00000000000000/* * 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 int write_lime_header(struct resource *); static ssize_t write_padding(size_t); static void write_range(struct resource *); static ssize_t write_vaddr(void *, size_t); static int setup(void); static void cleanup(void); static int init(void); // External extern int write_vaddr_tcp(void *, size_t); extern int setup_tcp(void); extern void cleanup_tcp(void); extern int write_vaddr_disk(void *, size_t); extern int setup_disk(void); extern void cleanup_disk(void); static char * format = 0; static int mode = 0; static int method = 0; static char zero_page[PAGE_SIZE]; char * path = 0; int dio = 0; int port = 0; int localhostonly = 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); #ifdef LIME_SUPPORTS_TIMING long timeout = 1000; module_param(timeout, long, S_IRUGO); #endif #define RETRY_IF_INTURRUPTED(f) ({ \ ssize_t err; \ do { err = f; } while(err == -EAGAIN || err == -EINTR); \ err; \ }) 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); #ifdef LIME_SUPPORTS_TIMING DBG(" TIMEOUT: %lu", timeout); #endif memset(zero_page, 0, sizeof(zero_page)); 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; 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; } for (p = iomem_resource.child; p ; p = p->sibling) { if (strcmp(p->name, LIME_RAMSTR)) continue; if (mode == LIME_MODE_LIME && (err = write_lime_header(p))) { DBG("Error writing header 0x%lx - 0x%lx", (long) p->start, (long) p->end); break; } else if (mode == LIME_MODE_PADDED && (err = write_padding((size_t) ((p->start - 1) - p_last)))) { DBG("Error writing padding 0x%lx - 0x%lx", (long) p_last, (long) p->start - 1); break; } write_range(p); p_last = p->end; } DBG("Memory Dump Complete..."); cleanup(); return err; } static int write_lime_header(struct resource * res) { ssize_t s; 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; s = write_vaddr(&header, sizeof(lime_mem_range_header)); if (s != sizeof(lime_mem_range_header)) { DBG("Error sending header %zd", s); return (int) s; } return 0; } static ssize_t write_padding(size_t s) { size_t i = 0; ssize_t r; while(s -= i) { i = min((size_t) PAGE_SIZE, s); r = write_vaddr(zero_page, 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); s = write_vaddr(v, is); kunmap(p); if (s < 0) { DBG("Error writing page: vaddr %p ret: %zd. Null padding.", v, s); write_padding(is); } else if (s != is) { DBG("Short Read %zu instead of %lu. Null padding.", s, (unsigned long) is); write_padding(is - s); } } #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) { return RETRY_IF_INTURRUPTED( (method == LIME_METHOD_TCP) ? write_vaddr_tcp(v, is) : write_vaddr_disk(v, is) ); } static int setup(void) { return (method == LIME_METHOD_TCP) ? setup_tcp() : setup_disk(); } static void cleanup(void) { return (method == LIME_METHOD_TCP) ? cleanup_tcp() : cleanup_disk(); } void cleanup_module(void) { } MODULE_LICENSE("GPL"); LiME-1.7.8/src/tcp.c000066400000000000000000000074611312036745100140500ustar00rootroot00000000000000/* * 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; mm_segment_t fs; int buffsize = PAGE_SIZE; #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); sock_setsockopt(control, SOL_SOCKET, SO_SNDBUF, (void *) &buffsize, sizeof (int)); set_fs(fs); if (r < 0) { DBG("Error setting buffsize %d", r); return r; } r = control->ops->bind(control,(struct sockaddr*) &saddr,sizeof(saddr)); if (r < 0) { DBG("Error binding control socket"); return r; } r = control->ops->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; } #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,11,0) r = accept->ops->accept(control,accept,0,true); #else r = accept->ops->accept(control,accept,0); #endif if (r < 0) { DBG("Error accepting socket"); return r; } return 0; } void cleanup_tcp() { if (accept && accept->ops) { accept->ops->shutdown(accept, 0); accept->ops->release(accept); } if (control && control->ops) { control->ops->shutdown(control, 0); control->ops->release(control); } } 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; }