├── .gitignore ├── src ├── Makefile.sample ├── Makefile ├── lime.h ├── deflate.c ├── disk.c ├── tcp.c ├── hash.c └── main.c ├── README.md ├── doc ├── external_modules.md └── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | # Dumps 2 | *.lime 3 | *.raw 4 | 5 | # Objects 6 | *.o 7 | *.ko 8 | 9 | Module.symvers 10 | modules.order 11 | *.mod 12 | *.mod.c 13 | *.cmd 14 | .tmp_versions/ 15 | 16 | -------------------------------------------------------------------------------- /src/Makefile.sample: -------------------------------------------------------------------------------- 1 | # LiME - Linux Memory Extractor 2 | # Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs 3 | # 4 | # 5 | # Author: 6 | # Joe Sylve - joe.sylve@gmail.com, @jtsylve 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation; either version 2 of the License, or (at 11 | # your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | # 22 | 23 | # This is a sample Makefile for cross-compiling the LiME LKM 24 | 25 | obj-m := lime.o 26 | lime-objs := tcp.o disk.o main.o 27 | 28 | KDIR_GOLD := /usr/local/kernels/goldfish/ 29 | 30 | KVER := $(shell uname -r) 31 | 32 | PWD := $(shell pwd) 33 | CCPATH := /usr/local/bin/google/android-ndk-r6b/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin 34 | 35 | default: 36 | # cross-compile for Android emulator 37 | $(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-linux-androideabi- -C $(KDIR_GOLD) M="$(PWD)" modules 38 | $(CCPATH)/arm-linux-androideabi-strip --strip-unneeded lime.ko 39 | mv lime.ko lime-goldfish.ko 40 | 41 | # compile for local system 42 | $(MAKE) -C /lib/modules/$(KVER)/build M="$(PWD)" modules 43 | strip --strip-unneeded lime.ko 44 | mv lime.ko lime-$(KVER).ko 45 | 46 | $(MAKE) tidy 47 | 48 | tidy: 49 | rm -f *.o *.mod.c Module.symvers Module.markers modules.order \.*.o.cmd \.*.ko.cmd \.*.o.d 50 | rm -rf \.tmp_versions 51 | 52 | clean: 53 | $(MAKE) tidy 54 | rm -f *.ko 55 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | # LiME - Linux Memory Extractor 2 | # Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs 3 | # 4 | # 5 | # Author: 6 | # Joe Sylve - joe.sylve@gmail.com, @jtsylve 7 | # 8 | # This program is free software; you can redistribute it and/or modify 9 | # it under the terms of the GNU General Public License as published by 10 | # the Free Software Foundation; either version 2 of the License, or (at 11 | # your option) any later version. 12 | # 13 | # This program is distributed in the hope that it will be useful, but 14 | # WITHOUT ANY WARRANTY; without even the implied warranty of 15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | # General Public License for more details. 17 | # 18 | # You should have received a copy of the GNU General Public License 19 | # along with this program; if not, write to the Free Software 20 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 | 22 | 23 | obj-m := lime.o 24 | lime-objs := tcp.o disk.o main.o hash.o deflate.o 25 | 26 | KVER ?= $(shell uname -r) 27 | 28 | KDIR ?= /lib/modules/$(KVER)/build 29 | 30 | PWD := $(shell pwd) 31 | 32 | .PHONY: modules modules_install clean distclean debug 33 | 34 | default: 35 | $(MAKE) -C $(KDIR) M="$(PWD)" modules 36 | strip --strip-unneeded lime.ko 37 | mv lime.ko lime-$(KVER).ko 38 | 39 | debug: 40 | KCFLAGS="-DLIME_DEBUG" $(MAKE) CONFIG_DEBUG_SG=y -C $(KDIR) M="$(PWD)" modules 41 | strip --strip-unneeded lime.ko 42 | mv lime.ko lime-$(KVER).ko 43 | 44 | symbols: 45 | $(MAKE) -C $(KDIR) M="$(PWD)" modules 46 | mv lime.ko lime-$(KVER).ko 47 | 48 | modules: main.c disk.c tcp.c hash.c lime.h 49 | $(MAKE) -C /lib/modules/$(KVER)/build M="$(PWD)" $@ 50 | strip --strip-unneeded lime.ko 51 | 52 | modules_install: modules 53 | $(MAKE) -C $(KDIR) M="$(PWD)" $@ 54 | 55 | clean: 56 | rm -f *.o *.mod.c Module.symvers Module.markers modules.order \.*.o.cmd \.*.ko.cmd \.*.o.d 57 | rm -rf \.tmp_versions 58 | 59 | distclean: mrproper 60 | mrproper: clean 61 | rm -f *.ko 62 | -------------------------------------------------------------------------------- /src/lime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * LiME - Linux Memory Extractor 3 | * Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs 4 | * 5 | * 6 | * Author: 7 | * Joe Sylve - joe.sylve@gmail.com, @jtsylve 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifndef __LIME_H_ 25 | #define __LIME_H_ 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) 42 | #include 43 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) 44 | #include 45 | #endif 46 | 47 | #define LIME_RAMSTR "System RAM" 48 | #define LIME_MAX_FILENAME_SIZE 256 49 | #define LIME_MAGIC 0x4C694D45 //LiME 50 | 51 | #define LIME_MODE_RAW 0 52 | #define LIME_MODE_LIME 1 53 | #define LIME_MODE_PADDED 2 54 | 55 | #define LIME_METHOD_UNKNOWN 0 56 | #define LIME_METHOD_TCP 1 57 | #define LIME_METHOD_DISK 2 58 | 59 | #define LIME_DIGEST_FAILED -1 60 | #define LIME_DIGEST_COMPLETE 0 61 | #define LIME_DIGEST_COMPUTE 1 62 | 63 | #ifdef LIME_DEBUG 64 | #define DBG(fmt, args...) do { printk("[LiME] "fmt"\n", ## args); } while (0) 65 | #else 66 | #define DBG(fmt, args...) do {} while(0) 67 | #endif 68 | 69 | #define RETRY_IF_INTERRUPTED(f) ({ \ 70 | ssize_t err; \ 71 | do { err = f; } while(err == -EAGAIN || err == -EINTR); \ 72 | err; \ 73 | }) 74 | 75 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,35) 76 | #define LIME_SUPPORTS_TIMING 77 | #endif 78 | 79 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) 80 | #define LIME_USE_KMAP_ATOMIC 81 | #endif 82 | 83 | #ifdef CONFIG_ZLIB_DEFLATE 84 | #define LIME_SUPPORTS_DEFLATE 85 | #endif 86 | 87 | //structures 88 | 89 | typedef struct { 90 | unsigned int magic; 91 | unsigned int version; 92 | unsigned long long s_addr; 93 | unsigned long long e_addr; 94 | unsigned char reserved[8]; 95 | } __attribute__ ((__packed__)) lime_mem_range_header; 96 | 97 | 98 | 99 | #endif //__LIME_H_ 100 | -------------------------------------------------------------------------------- /src/deflate.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LiME - Linux Memory Extractor 3 | * Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs 4 | * 5 | * 6 | * Author: 7 | * Joe Sylve - joe.sylve@gmail.com, @jtsylve 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #ifdef CONFIG_ZLIB_DEFLATE 25 | #include 26 | 27 | #include "lime.h" 28 | extern int deflate_begin_stream(void *out, size_t outlen); 29 | int deflate_end_stream(void); 30 | ssize_t deflate(const void *in, size_t inlen); 31 | 32 | /* Balance high compression level and memory footprint. */ 33 | #define DEFLATE_WBITS 11 /* 8KB */ 34 | #define DEFLATE_MEMLEVEL 5 /* 12KB */ 35 | 36 | static struct z_stream_s zstream; 37 | 38 | static void *next_out; 39 | static size_t avail_out; 40 | 41 | extern int deflate_begin_stream(void *out, size_t outlen) 42 | { 43 | int size; 44 | 45 | size = zlib_deflate_workspacesize(DEFLATE_WBITS, DEFLATE_MEMLEVEL); 46 | zstream.workspace = kzalloc(size, GFP_NOIO); 47 | if (!zstream.workspace) { 48 | return -ENOMEM; 49 | } 50 | 51 | if (zlib_deflateInit2(&zstream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, 52 | DEFLATE_WBITS, 53 | DEFLATE_MEMLEVEL, 54 | Z_DEFAULT_STRATEGY) != Z_OK) { 55 | kfree(zstream.workspace); 56 | return -EINVAL; 57 | } 58 | 59 | next_out = out; 60 | avail_out = outlen; 61 | 62 | zstream.next_out = next_out; 63 | zstream.avail_out = avail_out; 64 | 65 | return 0; 66 | } 67 | 68 | int deflate_end_stream(void) 69 | { 70 | zlib_deflateEnd(&zstream); 71 | kfree(zstream.workspace); 72 | return 0; 73 | } 74 | 75 | ssize_t deflate(const void *in, size_t inlen) 76 | { 77 | int flush, ret; 78 | 79 | if (in && inlen > 0) 80 | flush = Z_NO_FLUSH; 81 | else 82 | flush = Z_FINISH; 83 | 84 | if (zstream.avail_out != 0) { 85 | zstream.next_in = in; 86 | zstream.avail_in = inlen; 87 | } 88 | 89 | zstream.next_out = next_out; 90 | zstream.avail_out = avail_out; 91 | 92 | ret = zlib_deflate(&zstream, flush); 93 | 94 | if (ret != Z_OK && !(flush == Z_FINISH && ret == Z_STREAM_END)) { 95 | DBG("Deflate error: %d", ret); 96 | return -EIO; 97 | } 98 | 99 | return avail_out - zstream.avail_out; 100 | } 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /src/disk.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LiME - Linux Memory Extractor 3 | * Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs 4 | * 5 | * 6 | * Author: 7 | * Joe Sylve - joe.sylve@gmail.com, @jtsylve 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include "lime.h" 25 | 26 | void cleanup_disk(void); 27 | ssize_t write_vaddr_disk(void *, size_t); 28 | int setup_disk(char *path, int dio); 29 | 30 | static struct file * f = NULL; 31 | 32 | static int dio_write_test(char *path, int oflags) 33 | { 34 | int ok; 35 | 36 | f = filp_open(path, oflags | O_DIRECT | O_SYNC, 0444); 37 | if (f && !IS_ERR(f)) { 38 | ok = write_vaddr_disk("DIO", 3) == 3; 39 | filp_close(f, NULL); 40 | } else { 41 | ok = 0; 42 | } 43 | 44 | return ok; 45 | } 46 | 47 | int setup_disk(char *path, int dio) { 48 | int oflags = O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC; 49 | int err = 0; 50 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) 51 | mm_segment_t fs; 52 | 53 | fs = get_fs(); 54 | set_fs(KERNEL_DS); 55 | #endif 56 | 57 | if (dio && dio_write_test(path, oflags)) { 58 | oflags |= O_DIRECT | O_SYNC; 59 | } else { 60 | DBG("Direct IO Disabled"); 61 | } 62 | 63 | f = filp_open(path, oflags, 0444); 64 | 65 | if (!f || IS_ERR(f)) { 66 | DBG("Error opening file %ld", PTR_ERR(f)); 67 | 68 | err = (f) ? PTR_ERR(f) : -EIO; 69 | f = NULL; 70 | } 71 | 72 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) 73 | set_fs(fs); 74 | #endif 75 | 76 | return err; 77 | } 78 | 79 | void cleanup_disk(void) { 80 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) 81 | mm_segment_t fs; 82 | 83 | fs = get_fs(); 84 | set_fs(KERNEL_DS); 85 | #endif 86 | 87 | if(f) filp_close(f, NULL); 88 | 89 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) 90 | set_fs(fs); 91 | #endif 92 | } 93 | 94 | ssize_t write_vaddr_disk(void * v, size_t is) { 95 | ssize_t s; 96 | loff_t pos; 97 | 98 | pos = f->f_pos; 99 | 100 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) 101 | mm_segment_t fs; 102 | 103 | fs = get_fs(); 104 | set_fs(KERNEL_DS); 105 | s = vfs_write(f, v, is, &pos); 106 | set_fs(fs); 107 | #else 108 | s = kernel_write(f, v, is, &pos); 109 | #endif 110 | 111 | if (s == is) { 112 | f->f_pos = pos; 113 | } 114 | 115 | return s; 116 | } 117 | -------------------------------------------------------------------------------- /src/tcp.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LiME - Linux Memory Extractor 3 | * Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs 4 | * 5 | * 6 | * Author: 7 | * Joe Sylve - joe.sylve@gmail.com, @jtsylve 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #include "lime.h" 36 | 37 | ssize_t write_vaddr_tcp(void *, size_t); 38 | int setup_tcp(void); 39 | void cleanup_tcp(void); 40 | 41 | extern int port; 42 | extern int localhostonly; 43 | 44 | static struct socket *control; 45 | static struct socket *accept; 46 | 47 | int setup_tcp() { 48 | struct sockaddr_in saddr; 49 | int r; 50 | 51 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0) 52 | r = sock_create_kern(&init_net, AF_INET, SOCK_STREAM, IPPROTO_TCP, &control); 53 | #elif LINUX_VERSION_CODE > KERNEL_VERSION(2,6,5) 54 | r = sock_create_kern(AF_INET, SOCK_STREAM, IPPROTO_TCP, &control); 55 | #else 56 | r = sock_create(AF_INET, SOCK_STREAM, IPPROTO_TCP, &control); 57 | #endif 58 | 59 | if (r < 0) { 60 | DBG("Error creating control socket"); 61 | return r; 62 | } 63 | 64 | memset(&saddr, 0, sizeof(saddr)); 65 | 66 | saddr.sin_family = AF_INET; 67 | saddr.sin_port = htons(port); 68 | if (localhostonly) { 69 | saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); 70 | } else { 71 | saddr.sin_addr.s_addr = htonl(INADDR_ANY); 72 | } 73 | 74 | #if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0) 75 | int opt = 1; 76 | r = kernel_setsockopt(control, SOL_SOCKET, SO_REUSEADDR, (char *)&opt, sizeof (opt)); 77 | if (r < 0) { 78 | DBG("Error setting socket options"); 79 | 80 | return r; 81 | } 82 | #else 83 | sock_set_reuseaddr(control->sk); 84 | #endif 85 | 86 | r = kernel_bind(control,(struct sockaddr*) &saddr,sizeof(saddr)); 87 | if (r < 0) { 88 | DBG("Error binding control socket"); 89 | return r; 90 | } 91 | 92 | r = kernel_listen(control,1); 93 | if (r) { 94 | DBG("Error listening on socket"); 95 | return r; 96 | } 97 | 98 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0) 99 | r = sock_create_kern(&init_net, PF_INET, SOCK_STREAM, IPPROTO_TCP, &accept); 100 | #elif LINUX_VERSION_CODE > KERNEL_VERSION(2,6,5) 101 | r = sock_create_kern(PF_INET, SOCK_STREAM, IPPROTO_TCP, &accept); 102 | #else 103 | r = sock_create(PF_INET, SOCK_STREAM, IPPROTO_TCP, &accept); 104 | #endif 105 | 106 | if (r < 0) { 107 | DBG("Error creating accept socket"); 108 | return r; 109 | } 110 | 111 | r = kernel_accept(control, &accept, 0); 112 | 113 | if (r < 0) { 114 | DBG("Error accepting socket"); 115 | return r; 116 | } 117 | 118 | return 0; 119 | } 120 | 121 | void cleanup_tcp() { 122 | if (accept) { 123 | kernel_sock_shutdown(accept, SHUT_RDWR); 124 | sock_release(accept); 125 | accept = NULL; 126 | } 127 | 128 | if (control) { 129 | kernel_sock_shutdown(control, SHUT_RDWR); 130 | sock_release(control); 131 | control = NULL; 132 | } 133 | } 134 | 135 | ssize_t write_vaddr_tcp(void * v, size_t is) { 136 | ssize_t s; 137 | struct kvec iov; 138 | struct msghdr msg; 139 | 140 | memset(&iov, 0, sizeof(struct iovec)); 141 | memset(&msg, 0, sizeof(struct msghdr)); 142 | 143 | iov.iov_base = v; 144 | iov.iov_len = is; 145 | 146 | s = kernel_sendmsg(accept, &msg, &iov, 1, is); 147 | 148 | return s; 149 | } 150 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Project Archived 2 | 3 | This project is no longer being actively maintained. If you are interested in maintaining it, please reach out to joe.sylve@gmail.com. I would like to thank Daryl Bennett for his years of work in taking over maintenance of this project. 4 | 5 | # LiME ~ Linux Memory Extractor 6 | 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. 7 | 8 | ## Table of Contents 9 | * [Features](#features) 10 | * [Usage](#usage) 11 | * [Examples](#example) 12 | * [Presentation](#present) 13 | 14 | ## Features 15 | * Full Android memory acquisition 16 | * Acquisition over network interface 17 | * Minimal process footprint 18 | * Hash of dumped memory 19 | 20 | ## Usage 21 | Detailed documentation on LiME's usage and internals can be found in the "doc" directory of the project. 22 | 23 | LiME utilizes the insmod command to load the module, passing required arguments for its execution. 24 | ``` 25 | insmod ./lime.ko "path=> format= [digest=] [dio=<0|1>]" 26 | 27 | path (required): outfile ~ name of file to write to on local system (SD Card) 28 | tcp:port ~ network port to communicate over 29 | 30 | format (required): padded ~ pads all non-System RAM ranges with 0s 31 | lime ~ each range prepended with fixed-size header containing address space info 32 | raw ~ concatenates all System RAM ranges (warning : original position of dumped memory is likely to be lost therefore making analysis in most forensics tools impossible. This format is not recommended except for advanced users) 33 | 34 | digest (optional): Hash the RAM and provide a .digest file with the sum. 35 | Supports kernel version 2.6.11 and up. See below for 36 | available digest options. 37 | 38 | compress (optional): 1 ~ compress output with zlib 39 | 0 ~ do not compress (default) 40 | 41 | dio (optional): 1 ~ attempt to enable Direct IO 42 | 0 ~ do not attempt Direct IO (default) 43 | 44 | localhostonly (optional): 1 ~ restricts the tcp to only listen on localhost, 45 | 0 ~ binds on all interfaces (default) 46 | 47 | timeout (optional): 1000 ~ max amount of milliseconds tolerated to read a page (default). 48 | If a page exceeds the timeout all the memory region are skipped. 49 | 0 ~ disable the timeout so the slow region will be acquired. 50 | 51 | This feature is only available on kernel versions >= 2.6.35. 52 | 53 | ``` 54 | 55 | ## Examples 56 | In this example we use adb to load LiME and then start it with acquisition performed over the network 57 | ``` 58 | $ adb push lime.ko /sdcard/lime.ko 59 | $ adb forward tcp:4444 tcp:4444 60 | $ adb shell 61 | $ su 62 | # insmod /sdcard/lime.ko "path=tcp:4444 format=lime" 63 | ``` 64 | 65 | Now on the host machine, we can establish the connection and acquire memory using netcat 66 | ``` 67 | $ nc localhost 4444 > ram.lime 68 | ``` 69 | 70 | Acquiring to sdcard 71 | ``` 72 | # insmod /sdcard/lime.ko "path=/sdcard/ram.lime format=lime" 73 | ``` 74 | 75 | ## Available Digests 76 | Really LiME will support any digest algorithm that the kernel library can. 77 | Collecting a digest file when dumping over tcp will require 2 separate connections. 78 | ``` 79 | $ nc localhost 4444 > ram.lime 80 | $ nc localhost 4444 > ram.sha1 81 | ``` 82 | For a quick reference here is a list of supported digests. 83 | ### All kernel versions 84 | ``` 85 | crc32c 86 | md4, md5 87 | sha1, sha224, sha256, sha384, sha512 88 | wp512, wp384, wp256 89 | ``` 90 | ### 4.10 and up 91 | ``` 92 | sha3-224, sha3-256, sha3-384, sha3-512 93 | ``` 94 | ### 3.0 and up 95 | ``` 96 | rmd128, rmd160, rmd256, rmd320 97 | ``` 98 | 99 | ## Compression 100 | 101 | 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). 102 | 103 | 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. 104 | 105 | To decompress it you can use [pigz](https://zlib.net/pigz/) or any zlib-compatible library. 106 | 107 | ``` 108 | $ nc localhost 4444 | unpigz > ram.lime 109 | ``` 110 | 111 | Note that only the RAM file is compressed. The digest file is not compressed, and the hash value will match the uncompressed data. 112 | 113 | ## Presentation 114 | LiME was first presented at Shmoocon 2012 by Joe Sylve. 115 | Youtube~ Android Mind Reading: Memory Acquisition and Analysis with DMD and Volatility 116 | -------------------------------------------------------------------------------- /src/hash.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LiME - Linux Memory Extractor 3 | * Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs 4 | * 5 | * 6 | * Author: 7 | * Joe Sylve - joe.sylve@gmail.com, @jtsylve 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | 25 | #include "lime.h" 26 | 27 | 28 | int ldigest_init(void); 29 | int ldigest_update(void *v, size_t is); 30 | int ldigest_final(void); 31 | int ldigest_write_tcp(void); 32 | void ldigest_clean(void); 33 | 34 | // External 35 | extern ssize_t write_vaddr_tcp(void *, size_t); 36 | extern int setup_tcp(void); 37 | extern void cleanup_tcp(void); 38 | 39 | extern ssize_t write_vaddr_disk(void *, size_t); 40 | extern int setup_disk(char *, int); 41 | extern void cleanup_disk(void); 42 | int ldigest_write_disk(void); 43 | 44 | static u8 *output; 45 | static int digestsize; 46 | static char *digest_value; 47 | 48 | extern char *digest; 49 | extern char *path; 50 | 51 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) 52 | static struct crypto_ahash *tfm; 53 | static struct ahash_request *req; 54 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) 55 | static struct crypto_hash *tfm; 56 | static struct hash_desc desc; 57 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) 58 | struct crypto_tfm *tfm; 59 | #endif 60 | 61 | int ldigest_init(void) { 62 | DBG("Initializing Digest Transformation."); 63 | 64 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) 65 | tfm = crypto_alloc_ahash(digest, 0, CRYPTO_ALG_ASYNC); 66 | if (unlikely(IS_ERR(tfm))) goto init_fail; 67 | 68 | req = ahash_request_alloc(tfm, GFP_ATOMIC); 69 | if (unlikely(!req)) goto init_fail; 70 | 71 | digestsize = crypto_ahash_digestsize(tfm); 72 | 73 | ahash_request_set_callback(req, 0, NULL, NULL); 74 | crypto_ahash_init(req); 75 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) 76 | tfm = crypto_alloc_hash(digest, 0, CRYPTO_ALG_ASYNC); 77 | if (unlikely(IS_ERR(tfm))) 78 | goto init_fail; 79 | 80 | desc.tfm = tfm; 81 | desc.flags = 0; 82 | 83 | digestsize = crypto_hash_digestsize(tfm); 84 | crypto_hash_init(&desc); 85 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) 86 | tfm = crypto_alloc_tfm(digest, 0); 87 | if (unlikely(tfm == NULL)) 88 | goto init_fail; 89 | 90 | crypto_digest_init(tfm); 91 | #else 92 | DBG("Digest not supported for this kernel version."); 93 | goto init_fail; 94 | #endif 95 | 96 | output = kzalloc(sizeof(u8) * digestsize, GFP_ATOMIC); 97 | 98 | return LIME_DIGEST_COMPUTE; 99 | 100 | init_fail: 101 | DBG("Digest Initialization Failed."); 102 | return LIME_DIGEST_FAILED; 103 | } 104 | 105 | int ldigest_update(void *v, size_t is) { 106 | int ret; 107 | struct scatterlist sg; 108 | 109 | if (likely(virt_addr_valid(v))) { 110 | sg_init_one(&sg, (u8 *) v, is); 111 | } else { 112 | int nbytes = is; 113 | 114 | DBG("Invalid Virtual Address, Manually Scanning Page."); 115 | while (nbytes > 0) { 116 | int len = nbytes; 117 | int off = offset_in_page(v); 118 | if (off + len > (int)PAGE_SIZE) 119 | len = PAGE_SIZE - off; 120 | sg_init_table(&sg, 1); 121 | sg_set_page(&sg, vmalloc_to_page((u8 *) v), len, off); 122 | 123 | v += len; 124 | nbytes -= len; 125 | } 126 | } 127 | 128 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) 129 | ahash_request_set_crypt(req, &sg, output, is); 130 | ret = crypto_ahash_update(req); 131 | if (ret < 0) 132 | goto update_fail; 133 | 134 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) 135 | ret = crypto_hash_update(&desc, &sg, is); 136 | if (ret < 0) 137 | goto update_fail; 138 | 139 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) 140 | crypto_digest_update(tfm, &sg, is); 141 | #endif 142 | 143 | return LIME_DIGEST_COMPUTE; 144 | 145 | update_fail: 146 | DBG("Digest Update Failed."); 147 | return LIME_DIGEST_FAILED; 148 | } 149 | 150 | int ldigest_final(void) { 151 | int ret, i; 152 | 153 | DBG("Finalizing the digest."); 154 | digest_value = kmalloc(digestsize * 2 + 1, GFP_KERNEL); 155 | 156 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) 157 | ret = crypto_ahash_final(req); 158 | if (ret < 0) 159 | goto final_fail; 160 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) 161 | ret = crypto_hash_final(&desc, output); 162 | if (ret < 0) 163 | goto final_fail; 164 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) 165 | crypto_digest_final(tfm, output); 166 | #endif 167 | 168 | for (i = 0; i= KERNEL_VERSION(4, 6, 0) 226 | crypto_free_ahash(tfm); 227 | ahash_request_free(req); 228 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 19) 229 | crypto_free_hash(tfm); 230 | #elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 11) 231 | crypto_free_tfm(tfm); 232 | #endif 233 | } 234 | -------------------------------------------------------------------------------- /doc/external_modules.md: -------------------------------------------------------------------------------- 1 | # Building External Modules 2 | ## Contents 3 | * [Intro](#intro) 4 | + [How To](#howto) 5 | + [Required Tools](#tools) 6 | + [Downloading the kernel source](#download) 7 | + [Choosing the correct kernel release](#release) 8 | + [Using an old kernel config](#config) 9 | + [Setting the correct version](#versioncorrect) 10 | + [Prepare the source and compile](#compile) 11 | + [OS specific resources](#resources) 12 | + [CentOS](#centos) 13 | + [Fedora](#fedora) 14 | + [RHEL](#rhel) 15 | + [Ubuntu](#ubuntu) 16 | 17 | ## Introduction 18 | 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. 19 | 20 | **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. 21 | 22 | ## How to 23 | 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. 24 | 25 | ### Required tools 26 | You will need the following tools 27 | 28 | - git 29 | - build-essential package **OS specific** 30 | 31 | ### Downloading the kernel source 32 | 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). 33 | 34 | But here is the TL;DR version 35 | 36 | In order to determine the correct OS version of your target machine, you can run `cat /etc/os-release`. 37 | ``` 38 | $ cat /etc/os-release 39 | NAME="Ubuntu" 40 | VERSION="16.04.2 LTS (Xenial Xerus)" 41 | ID=ubuntu 42 | ID_LIKE=debian 43 | PRETTY_NAME="Ubuntu 16.04.2 LTS" 44 | VERSION_ID="16.04" 45 | HOME_URL="http://www.ubuntu.com/" 46 | SUPPORT_URL="http://help.ubuntu.com/" 47 | BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/" 48 | VERSION_CODENAME=xenial 49 | UBUNTU_CODENAME=xenial 50 | ``` 51 | From the output above we can see that our release is `Xenial 16.04.2 LTS`. 52 | 53 | Now we must go and clone the source using `git`. For our Ubuntu example the links are in the following format. 54 | ``` 55 | kernel.ubuntu.com/ubuntu/ubuntu-< release >.git 56 | ``` 57 | Following our Xenial example, we would clone the source by entering this 58 | ``` 59 | $git clone git://kernel.ubuntu.com/ubuntu/ubuntu-xenial.git 60 | ``` 61 | If you have firewall restrictions or other ridiculousness using the git protocol, you can clone via http. 62 | ``` 63 | $git clone http://kernel.ubuntu.com/git-repos/ubuntu/ubuntu-xenial.git 64 | ``` 65 | This will be a lot slower and you will not be able to set the history depth, therefore downloading far more data. 66 | 67 | ### Choosing the correct kernel release 68 | 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. 69 | ``` 70 | $uname -r 71 | 4.10.0-38-generic 72 | ``` 73 | 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 74 | ``` 75 | version.patchlevel.sublevel-localversion 76 | ``` 77 | 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 78 | ``` 79 | git tag -l 80 | ``` 81 | to list all the tags. Find the tag that matches you kernel version *version.patchlevel.sublevel* and checkout that the point in history. 82 | ``` 83 | git checkout < tag > 84 | ``` 85 | Following our Ubuntu guide you would run something like the following 86 | ``` 87 | git checkout Ubuntu-lts-4.10.0-9.11_16.04.2 88 | ``` 89 | 90 | ### Using an old kernel config 91 | 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-*`. 92 | 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 93 | ``` 94 | /boot/config-4.10.0-38-generic 95 | ``` 96 | Once you have renamed the config file `.config` run the following 97 | ``` 98 | $ make olddefconfig 99 | HOSTCC scripts/basic/fixdep 100 | HOSTCC scripts/kconfig/conf.o 101 | SHIPPED scripts/kconfig/zconf.tab.c 102 | SHIPPED scripts/kconfig/zconf.lex.c 103 | SHIPPED scripts/kconfig/zconf.hash.c 104 | HOSTCC scripts/kconfig/zconf.tab.o 105 | HOSTLD scripts/kconfig/conf 106 | scripts/kconfig/conf --olddefconfig Kconfig 107 | # 108 | # configuration written to .config 109 | # 110 | ``` 111 | This make function will use the old kernel config and substitute the default values for options that differ in your kernel. 112 | 113 | ### Setting the correct version 114 | 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. 115 | Once the config completes, we need to make sure that all the versions match before we continue. Run the following make function 116 | ``` 117 | $ make kernelrelease 118 | 4.10.0+ 119 | ``` 120 | Did make complete without error? Does that match the version you want? If so continue; else checkout a different tag with git. 121 | 122 | Did you notice that our kernel release is missing the `localversion` string? Well, let's fix that using your favorite text editor. 123 | Find the lines that say the following 124 | ``` 125 | # 126 | # General setup 127 | # 128 | CONFIG_INIT_ENV_ARG_LIMIT=32 129 | CONFIG_CROSS_COMPILE="" 130 | # CONFIG_COMPILE_TEST is not set 131 | CONFIG_LOCALVERSION="" 132 | # CONFIG_LOCALVERSION_AUTO is not set 133 | CONFIG_HAVE_KERNEL_GZIP=y 134 | ``` 135 | Change **both** `CONFIG_LOCALVERSION` and `# CONFIG_COMPILE_TEST is not set` to match the following example 136 | ``` 137 | CONFIG_LOCALVERSION="< localversion >" 138 | CONFIG_LOCALVERSION_AUTO=n 139 | ``` 140 | In our Ubuntu example add `-38-generic` and don't forget the hyphen. 141 | ``` 142 | CONFIG_LOCALVERSION="-38-generic" 143 | CONFIG_LOCALVERSION_AUTO=n 144 | ``` 145 | 146 | Now! run `make kernelrelease` again 147 | ``` 148 | $ make kernelrelease 149 | 4.10.0-38-generic+ 150 | ``` 151 | Is your localversion correct? If so, continue 152 | Note the `+` at the end of the localversion string. We need to remove this 153 | ``` 154 | touch .scmversion 155 | ``` 156 | to create and empty file. Now run `make kernelrelease` once more, this time the version should be an exact match. 157 | ``` 158 | $ make kernelrelease 159 | 4.10.0-38-generic 160 | ``` 161 | 162 | ### Prepare the source and compile 163 | Now run 164 | ``` 165 | $ make modules_prepare 166 | ``` 167 | 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 168 | ``` 169 | make -C < path-src-tree > KVER=< kernel-version > M=$(pwd) 170 | ``` 171 | `path-to-src-tree` is the location where you cloned your kernel source. Again, following our Ubuntu example 172 | ``` 173 | make -C /home/kd8bny/ubuntu-xenial KVER=4.10.0-38-generic M=$(pwd) 174 | ``` 175 | 176 | 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. 177 | 178 | ## OS specific resources 179 | ### CentOS 180 | 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). 181 | The source is located [here](http://vault.centos.org). Browse to the following location and download. 182 | ``` 183 | http://vault.centos.org/< cent version >/os/Source/SPackages/kernel-3.10.0-123.el7.src.rpm 184 | ``` 185 | 186 | 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`. 187 | 188 | ### Fedora 189 | Fedora keeps kernel source off the main linux git tree. Clone it here 190 | ``` 191 | git://git.kernel.org/pub/scm/linux/kernel/git/jwboyer/fedora.git 192 | ``` 193 | Follow the same process in the guide. 194 | 195 | ### RHEL 196 | 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. 197 | 198 | ### Ubuntu 199 | Follow as shown in guide. 200 | [kernel source](http://kernel.ubuntu.com/git/) 201 | -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | # LiME – Linux Memory Extractor 2 | ## Contents 3 | * [Compiling](#Compile) 4 | * [Linux](#Linux) 5 | * [External](#External) 6 | * [Debug](#Debug) 7 | * [Symbols](#Symbols) 8 | * [Android](#Android) 9 | * [Usage](#Usage) 10 | * [Parameters](#Params) 11 | * [Acquisition of Memory over TCP](#TCP) 12 | * [Acquisition of Memory to Disk (SD-Card)](#Disk) 13 | * [LiME Memory Range Header Version 1 Specification](#Spec) 14 | 15 | ## Compiling LiME 16 | ### Linux 17 | LiME is a Loadable Kernel Module (LKM). LiME ships with a default Makefile that should be suitable for compilation on most modern Linux systems. 18 | 19 | For detailed instructions on using LKM see https://www.kernel.org/doc/Documentation/kbuild/modules.txt. 20 | 21 | ### External 22 | 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. 23 | 24 | ### Debug 25 | 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. 26 | 27 | ### Symbols 28 | 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. 29 | 30 | ### Android 31 | In order to cross-compile LiME for use on an Android device, additional steps are required. 32 | 33 | #### PREREQUISITES 34 | Disclaimer: This list may be incomplete. Please let us know if we've missed anything. 35 | * Install the general android prerequisites found at http://source.android.com/source/initializing.html 36 | * Download and un(zip|tar) the android NDK found at http://developer.android.com/tools/sdk/ndk/index.html. 37 | * Download and un(zip|tar) the android SDK found at http://developer.android.com/sdk/index.html. 38 | * 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. 39 | * Root your device. In order to run custom kernel modules, you must have a rooted device. 40 | * Plug the device into computer via a USB cable. 41 | 42 | #### SETTING UP THE ENVIRONMENT 43 | In order to simplify the process, we will first set some environment variables. In a terminal, type the following commands. 44 | ``` 45 | export SDK_PATH=/path/to/android-sdk-linux/ 46 | export NDK_PATH=/path/to/android-ndk/ 47 | export KSRC_PATH=/path/to/kernel-source/ 48 | export CC_PATH=$NDK_PATH/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/ 49 | export LIME_SRC=/path/to/lime/src 50 | ``` 51 | 52 | #### PREPARING THE KERNEL SOURCE 53 | We must retrieve and copy the kernel config from our device. 54 | ``` 55 | cd $SDK_PATH/platform-tools 56 | ./adb pull /proc/config.gz 57 | gunzip ./config.gz 58 | cp config $KSRC_PATH/.config 59 | ``` 60 | 61 | Next we have to prepare our kernel source for our module. 62 | ``` 63 | $ cd $KSRC_PATH 64 | $ make ARCH=arm CROSS_COMPILE=$CC_PATH/arm-eabi- modules_prepare 65 | ``` 66 | 67 | #### PREPARING THE MODULE FOR COMPILATION 68 | 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: 69 | ``` 70 | obj-m := lime.o 71 | lime-objs := main.o tcp.o disk.o 72 | KDIR := /path/to/kernel-source 73 | PWD := $(shell pwd) 74 | CCPATH := /path/to/android-ndk/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/ 75 | default: 76 | $(MAKE) ARCH=arm CROSS_COMPILE=$(CCPATH)/arm-eabi- -C $(KDIR) M=$(PWD) modules 77 | ``` 78 | 79 | #### COMPILING THE MODULE 80 | ``` 81 | cd $LIME_SRC 82 | make 83 | ``` 84 | 85 | ## Usage 86 | 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. 87 | 88 | ### Parameters 89 | 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. 90 | 91 | 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. 92 | ``` 93 | path Either a filename to write on the local system (SD Card) or tcp: 94 | format padded: Pads all non-System RAM ranges with 0s, starting from physical address 0. 95 | lime: Each range is prepended with a fixed-sized header which contains address space information. 96 | 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) 97 | dio Optional. 1 to enable Direct IO attempt, 0 to disable (default) 98 | localhostonly Optional. 1 restricts the tcp to only listen on localhost, 0 binds on all interfaces (default) 99 | timeout Optional. If it takes longer than the specified timeout (in milliseconds) to read/write a page 100 | of memory then the range is assumed to be bad and is skipped. To disable this set timeout to 0. 101 | The default setting is 1000 (1 second). 102 | ``` 103 | 104 | ### Acquisition of Memory over TCP 105 | 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. 106 | ``` 107 | adb push lime.ko /sdcard/lime.ko 108 | adb forward tcp:4444 tcp:4444 109 | adb shell 110 | su 111 | # 112 | ``` 113 | 114 | 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. 115 | 116 | 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. 117 | The following command loads the kernel module via adb on the target Android device: 118 | ``` 119 | insmod /sdcard/lime.ko "path=tcp:4444 format=lime" 120 | ``` 121 | 122 | On the host, the following command captures the memory dump via TCP port 444 to the file “ram.lime”: 123 | ``` 124 | nc localhost 4444 > ram.lime 125 | ``` 126 | 127 | ### Acquisition of Memory to Disk (SD-Card) 128 | 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. 129 | 130 | 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. 131 | 132 | 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. 133 | 134 | 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: 135 | ``` 136 | insmod /sdcard/lime.ko "path=/sdcard/ram.lime format=lime" 137 | ``` 138 | 139 | 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. 140 | 141 | ## LiME Memory Range Header Version 1 Specification 142 | ``` 143 | typedef struct { 144 | unsigned int magic; // Always 0x4C694D45 (LiME) 145 | unsigned int version; // Header version number 146 | unsigned long long s_addr; // Starting address of physical RAM range 147 | unsigned long long e_addr; // Ending address of physical RAM range 148 | unsigned char reserved[8]; // Currently all zeros 149 | } __attribute__ ((__packed__)) lime_mem_range_header; 150 | ``` 151 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * LiME - Linux Memory Extractor 3 | * Copyright (c) 2011-2014 Joe Sylve - 504ENSICS Labs 4 | * 5 | * 6 | * Author: 7 | * Joe Sylve - joe.sylve@gmail.com, @jtsylve 8 | * 9 | * This program is free software; you can redistribute it and/or modify 10 | * it under the terms of the GNU General Public License as published by 11 | * the Free Software Foundation; either version 2 of the License, or (at 12 | * your option) any later version. 13 | * 14 | * This program is distributed in the hope that it will be useful, but 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | * General Public License for more details. 18 | * 19 | * You should have received a copy of the GNU General Public License 20 | * along with this program; if not, write to the Free Software 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 | */ 23 | 24 | #include "lime.h" 25 | 26 | // This file 27 | static ssize_t write_lime_header(struct resource *); 28 | static ssize_t write_padding(size_t); 29 | static void write_range(struct resource *); 30 | static int init(void); 31 | static ssize_t write_vaddr(void *, size_t); 32 | static ssize_t write_flush(void); 33 | static ssize_t try_write(void *, ssize_t); 34 | static int setup(void); 35 | static void cleanup(void); 36 | 37 | // External 38 | extern ssize_t write_vaddr_tcp(void *, size_t); 39 | extern int setup_tcp(void); 40 | extern void cleanup_tcp(void); 41 | 42 | extern ssize_t write_vaddr_disk(void *, size_t); 43 | extern int setup_disk(char *, int); 44 | extern void cleanup_disk(void); 45 | 46 | extern int ldigest_init(void); 47 | extern int ldigest_update(void *, size_t); 48 | extern int ldigest_final(void); 49 | extern int ldigest_write_tcp(void); 50 | extern int ldigest_write_disk(void); 51 | extern int ldigest_clean(void); 52 | 53 | #ifdef LIME_SUPPORTS_DEFLATE 54 | extern int deflate_begin_stream(void *, size_t); 55 | extern int deflate_end_stream(void); 56 | extern ssize_t deflate(const void *, size_t); 57 | #endif 58 | 59 | static char * format = 0; 60 | static int mode = 0; 61 | static int method = 0; 62 | 63 | static void * vpage; 64 | 65 | #ifdef LIME_SUPPORTS_DEFLATE 66 | static void *deflate_page_buf; 67 | #endif 68 | 69 | char * path = 0; 70 | int dio = 0; 71 | int port = 0; 72 | int localhostonly = 0; 73 | 74 | char * digest = 0; 75 | int compute_digest = 0; 76 | 77 | int no_overlap = 0; 78 | 79 | extern struct resource iomem_resource; 80 | 81 | module_param(path, charp, S_IRUGO); 82 | module_param(dio, int, S_IRUGO); 83 | module_param(format, charp, S_IRUGO); 84 | module_param(localhostonly, int, S_IRUGO); 85 | module_param(digest, charp, S_IRUGO); 86 | 87 | #ifdef LIME_SUPPORTS_TIMING 88 | long timeout = 1000; 89 | module_param(timeout, long, S_IRUGO); 90 | #endif 91 | 92 | #ifdef LIME_SUPPORTS_DEFLATE 93 | int compress = 0; 94 | module_param(compress, int, S_IRUGO); 95 | #endif 96 | 97 | static int __init lime_init_module (void) 98 | { 99 | if(!path) { 100 | DBG("No path parameter specified"); 101 | return -EINVAL; 102 | } 103 | 104 | if(!format) { 105 | DBG("No format parameter specified"); 106 | return -EINVAL; 107 | } 108 | 109 | DBG("Parameters"); 110 | DBG(" PATH: %s", path); 111 | DBG(" DIO: %u", dio); 112 | DBG(" FORMAT: %s", format); 113 | DBG(" LOCALHOSTONLY: %u", localhostonly); 114 | DBG(" DIGEST: %s", digest); 115 | 116 | #ifdef LIME_SUPPORTS_TIMING 117 | DBG(" TIMEOUT: %lu", timeout); 118 | #endif 119 | 120 | #ifdef LIME_SUPPORTS_DEFLATE 121 | DBG(" COMPRESS: %u", compress); 122 | #endif 123 | 124 | if (!strcmp(format, "raw")) mode = LIME_MODE_RAW; 125 | else if (!strcmp(format, "lime")) mode = LIME_MODE_LIME; 126 | else if (!strcmp(format, "padded")) mode = LIME_MODE_PADDED; 127 | else { 128 | DBG("Invalid format parameter specified."); 129 | return -EINVAL; 130 | } 131 | 132 | method = (sscanf(path, "tcp:%d", &port) == 1) ? LIME_METHOD_TCP : LIME_METHOD_DISK; 133 | if (digest) compute_digest = LIME_DIGEST_COMPUTE; 134 | 135 | return init(); 136 | } 137 | 138 | static int init() { 139 | struct resource *p; 140 | int err = 0; 141 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) 142 | resource_size_t p_last = -1; 143 | #else 144 | __PTRDIFF_TYPE__ p_last = -1; 145 | #endif 146 | 147 | DBG("Initializing Dump..."); 148 | 149 | if ((err = setup())) { 150 | DBG("Setup Error"); 151 | cleanup(); 152 | return err; 153 | } 154 | 155 | if (digest) { 156 | compute_digest = ldigest_init(); 157 | no_overlap = 1; 158 | } 159 | 160 | vpage = (void *) __get_free_page(GFP_NOIO); 161 | 162 | #ifdef LIME_SUPPORTS_DEFLATE 163 | if (compress) { 164 | deflate_page_buf = kmalloc(PAGE_SIZE, GFP_NOIO); 165 | err = deflate_begin_stream(deflate_page_buf, PAGE_SIZE); 166 | if (err < 0) { 167 | DBG("ZLIB begin stream failed"); 168 | return err; 169 | } 170 | no_overlap = 1; 171 | } 172 | #endif 173 | 174 | for (p = iomem_resource.child; p ; p = p->sibling) { 175 | 176 | if (!p->name || strcmp(p->name, LIME_RAMSTR)) 177 | continue; 178 | 179 | if (mode == LIME_MODE_LIME && write_lime_header(p) < 0) { 180 | DBG("Error writing header 0x%lx - 0x%lx", (long) p->start, (long) p->end); 181 | break; 182 | } else if (mode == LIME_MODE_PADDED && write_padding((size_t) ((p->start - 1) - p_last)) < 0) { 183 | DBG("Error writing padding 0x%lx - 0x%lx", (long) p_last, (long) p->start - 1); 184 | break; 185 | } 186 | 187 | write_range(p); 188 | 189 | p_last = p->end; 190 | } 191 | 192 | write_flush(); 193 | 194 | DBG("Memory Dump Complete..."); 195 | 196 | cleanup(); 197 | 198 | if (compute_digest == LIME_DIGEST_COMPUTE) { 199 | DBG("Writing Out Digest."); 200 | 201 | compute_digest = ldigest_final(); 202 | 203 | if (compute_digest == LIME_DIGEST_COMPLETE) { 204 | if (method == LIME_METHOD_TCP) 205 | err = ldigest_write_tcp(); 206 | else 207 | err = ldigest_write_disk(); 208 | 209 | DBG("Digest Write %s.", (err == 0) ? "Complete" : "Failed"); 210 | } 211 | } 212 | 213 | if (digest) 214 | ldigest_clean(); 215 | 216 | #ifdef LIME_SUPPORTS_DEFLATE 217 | if (compress) { 218 | deflate_end_stream(); 219 | kfree(deflate_page_buf); 220 | } 221 | #endif 222 | 223 | free_page((unsigned long) vpage); 224 | 225 | return 0; 226 | } 227 | 228 | static ssize_t write_lime_header(struct resource * res) { 229 | lime_mem_range_header header; 230 | 231 | memset(&header, 0, sizeof(lime_mem_range_header)); 232 | header.magic = LIME_MAGIC; 233 | header.version = 1; 234 | header.s_addr = res->start; 235 | header.e_addr = res->end; 236 | 237 | return write_vaddr(&header, sizeof(lime_mem_range_header)); 238 | } 239 | 240 | static ssize_t write_padding(size_t s) { 241 | size_t i = 0; 242 | ssize_t r; 243 | 244 | memset(vpage, 0, PAGE_SIZE); 245 | 246 | while(s -= i) { 247 | 248 | i = min((size_t) PAGE_SIZE, s); 249 | r = write_vaddr(vpage, i); 250 | 251 | if (r != i) { 252 | DBG("Error sending zero page: %zd", r); 253 | return r; 254 | } 255 | } 256 | 257 | return 0; 258 | } 259 | 260 | static void write_range(struct resource * res) { 261 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) 262 | resource_size_t i, is; 263 | #else 264 | __PTRDIFF_TYPE__ i, is; 265 | #endif 266 | struct page * p; 267 | void * v; 268 | 269 | ssize_t s; 270 | 271 | #ifdef LIME_SUPPORTS_TIMING 272 | ktime_t start,end; 273 | #endif 274 | 275 | DBG("Writing range %llx - %llx.", res->start, res->end); 276 | 277 | for (i = res->start; i <= res->end; i += is) { 278 | #ifdef LIME_SUPPORTS_TIMING 279 | start = ktime_get_real(); 280 | #endif 281 | p = pfn_to_page((i) >> PAGE_SHIFT); 282 | 283 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18) 284 | is = min((resource_size_t) PAGE_SIZE, (resource_size_t) (res->end - i + 1)); 285 | #else 286 | is = min((size_t) PAGE_SIZE, (size_t) (res->end - i + 1)); 287 | #endif 288 | 289 | if (is < PAGE_SIZE) { 290 | // We can't map partial pages and 291 | // the linux kernel doesn't use them anyway 292 | DBG("Padding partial page: vaddr %p size: %lu", (void *) i, (unsigned long) is); 293 | write_padding(is); 294 | } else { 295 | #ifdef LIME_USE_KMAP_ATOMIC 296 | v = kmap_atomic(p); 297 | #else 298 | v = kmap(p); 299 | #endif 300 | /* 301 | * If we need to compute the digest or compress the output 302 | * take a snapshot of the page. Otherwise save some cycles. 303 | */ 304 | #ifdef LIME_USE_KMAP_ATOMIC 305 | preempt_enable(); 306 | #endif 307 | if (no_overlap) { 308 | copy_page(vpage, v); 309 | s = write_vaddr(vpage, is); 310 | } else { 311 | s = write_vaddr(v, is); 312 | } 313 | #ifdef LIME_USE_KMAP_ATOMIC 314 | preempt_disable(); 315 | kunmap_atomic(v); 316 | #else 317 | kunmap(p); 318 | #endif 319 | if (s < 0) { 320 | DBG("Failed to write page: vaddr %p. Skipping Range...", v); 321 | break; 322 | } 323 | } 324 | 325 | #ifdef LIME_SUPPORTS_TIMING 326 | end = ktime_get_real(); 327 | 328 | if (timeout > 0 && ktime_to_ms(ktime_sub(end, start)) > timeout) { 329 | DBG("Reading is too slow. Skipping Range..."); 330 | write_padding(res->end - i + 1 - is); 331 | break; 332 | } 333 | #endif 334 | 335 | } 336 | } 337 | 338 | static ssize_t write_vaddr(void * v, size_t is) { 339 | ssize_t ret; 340 | 341 | if (compute_digest == LIME_DIGEST_COMPUTE) 342 | compute_digest = ldigest_update(v, is); 343 | 344 | #ifdef LIME_SUPPORTS_DEFLATE 345 | if (compress) { 346 | /* Run deflate() on input until output buffer is not full. */ 347 | do { 348 | ret = try_write(deflate_page_buf, deflate(v, is)); 349 | if (ret < 0) 350 | return ret; 351 | } while (ret == PAGE_SIZE); 352 | return is; 353 | } 354 | #endif 355 | 356 | ret = try_write(v, is); 357 | return ret; 358 | } 359 | 360 | static ssize_t write_flush(void) { 361 | #ifdef LIME_SUPPORTS_DEFLATE 362 | if (compress) { 363 | try_write(deflate_page_buf, deflate(NULL, 0)); 364 | } 365 | #endif 366 | return 0; 367 | } 368 | 369 | static ssize_t try_write(void * v, ssize_t is) { 370 | ssize_t ret; 371 | 372 | if (is <= 0) 373 | return is; 374 | 375 | ret = RETRY_IF_INTERRUPTED( 376 | (method == LIME_METHOD_TCP) ? write_vaddr_tcp(v, is) : write_vaddr_disk(v, is) 377 | ); 378 | 379 | if (ret < 0) { 380 | DBG("Write error: %zd", ret); 381 | } else if (ret != is) { 382 | DBG("Short write %zu instead of %zu.", ret, is); 383 | ret = -1; 384 | } 385 | 386 | return ret; 387 | } 388 | 389 | static int setup(void) { 390 | return (method == LIME_METHOD_TCP) ? setup_tcp() : setup_disk(path, dio); 391 | } 392 | 393 | static void cleanup(void) { 394 | return (method == LIME_METHOD_TCP) ? cleanup_tcp() : cleanup_disk(); 395 | } 396 | 397 | static void __exit lime_cleanup_module(void) { 398 | 399 | } 400 | 401 | module_init(lime_init_module); 402 | module_exit(lime_cleanup_module); 403 | 404 | MODULE_LICENSE("GPL"); 405 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | --------------------------------------------------------------------------------