SANS Digital Forensics and Incident Response Blog

Rapier: A Different Data Carver

By Keven Murphy

Rapier is a data carver written for Linux. It is a bit different than the other ones out there. First of all, the data carver treats the input file as a stream of data. For example, if the header/word is broken up between cluster/sector boundaries, Rapier doesn't see the data divided up between the clusters/sectors. Instead, it ignores these boundaries. Secondly, headers and footers (footers are not 100% implemented yet) can be up to 100 bytes/characters long. Third, there are a few built-in search patterns. Those are index.dat and registry files. Like most data carvers, it doesn't review the data it carves out to see if it is good data. That part is left to the forensics examiner.

Every byte on the drive is reviewed by Rapier. I realize that this can make it run long as compared to other data carvers. But I have good reasons for that. About a year ago I was using Foremost trying to recover some WMV files for a case I was working. Foremost was able to recover two files. I ran PhotoRec on the drive while reviewing the Foremost output. Photorec found a couple more than Foremost. After that, it got me wondering if either tool had found all of the wmv files. Then I used Sigfind,which identified a total of eight files. I ended up carving them out by hand.

Based upon that experience, I was thinking that the Boyer-Moore string search (see Foremost's engine.c file) that Foremost used was missing things. In the end, I decided it might be fun to write my own. Let me say that it was an interesting challenge and continues to be.

Author's Note: I mean no disrespect to the people who wrote and maintain Foremost and PhotoRec. I use both pieces of software every day. Both of them are great tools. Neither am I saying that Rapier is the best thing since sliced bread. It is just that, sometimes, you need to use a different tool.

How To Run Rapier

Just running Rapier without any command line arguements shows the following:

Rapier 0.2 Alpha -c {config_filename} -f {filename} -l log {filename} [-b bsize] [-t] [-v]
Note: [] optional command arguments.
-c Config file
-f Input filename
-l Log filename
-b Block size -- Default is 512
-t Put starting date & time and ending date & time in the logs
-v Verbose

Running Rapier is pretty easy. The steps below outline the general process:

  1. Rapier requires an image to review. You can either give it a dd image, device (/dev/hda1 for example), or a blkls file that consists of unallocated space or slack space.
  2. Adjust the rapier.conf file to what you are looking for.
  3. Run Rapier:
    # ./rapier -v -t -c rapier.config  -f image_file.unallocated.dd -b 4096 -l rapier.log

File Recovery

Rapier automatically recovers the files after it has completed its scan. In the directory you ran Rapier from, you will find the files Rapier recovered in the following filename format: {extension}-{starting offset}-{ending offset}.{extension}. For example a index.dat file might have the following name: dat-26215424-26248192.dat. In a future release, I plan on creating directories based upon the extension and putting those files in the respective directory.

Rapier Files and Log Output

Rapier creates three additional files besides the ones it recovers. The first is the log file given by the -l option. The second is CSV file, {log file}.csv, that contains a table of the files it finds with the starting and ending offsets. The third file is a binary file that has the name of {log file}.found.dat. This file contains binary data of the files Rapier has found with the offset information. I thought it might be handy to be able to recovery the files without re-scanning the entire drive. This option is something I am working for the next version.

An Example Log File

Rapier Log File
Version: 0.2 Alpha
Copyright by Citadel Systems, L.L.C.
Website: http://www.citadelsystems.net
License: Citadel Systems, L.L.C. grants Licensee a non-exclusive and non-transferable
license to use the Product. Licensee may not use the product for commercial purposes
beyond an initial thirty (30) day evaluation period without the purchase of a commercial
license from Citadel Systems, L.L.C. Commercial purposes include any activity engaged in
for the purpose of directly generating revenue or in support of activity that generates
revenue. This license does not entitle Licensee to receive from Citadel Systems, L.L.C.
hard-copy documentation, technical support, telephone assistance, or enhancements or
updates to the Product.

Rapier started at: Sun Jan 11 15:58:08 2009

Searching for the following
---------------------------
Total Number of headers: 2
Ext.: dat
Header Length (HEX) 10 in bytes:
Header (HEX): 43 6C 69 65 6E 74 20 55 72 6C
Length to get: 10240000

Ext.: txt
Header Length (HEX) 7 in bytes:
Header (HEX): 46 49 4E 44 5F 4D 45
Length to get: 1024

=============================================================================================================================

-----------------------------------------------------------------------------------------------------------------------------
Found txt header at Block/Sector: 79 Offset: 4092 Total Offset: 327676 Additional Bytes Before Header: 10
-----------------------------------------------------------------------------------------------------------------------------
Found dat header at Block/Sector: 6400 Offset: 1024 Total Offset: 26215424 Additional Bytes Before Header: 0
-----------------------------------------------------------------------------------------------------------------------------
Found dat header at Block/Sector: 6528 Offset: 1024 Total Offset: 26739712 Additional Bytes Before Header: 0
-----------------------------------------------------------------------------------------------------------------------------
Found dat header at Block/Sector: 6656 Offset: 1024 Total Offset: 27264000 Additional Bytes Before Header: 0
-----------------------------------------------------------------------------------------------------------------------------

Note: The number in Block/Sector field above is based upon the block size (-b) option in the command line. To figure out the offset of the file based on block/sector and offset within that block/sector it would be: (6656 * 4096 block size) + 1024 = 27264000.

Opening Rapier data file: rapier.log.found.dat

Reading Rapier data file
========================

File -- Header: txt Total Offset: 327676
Filename: txt-327676-328700.txt Startpos: 327666 Endpos: 328700 Filelength: 1024

File -- Header: dat Total Offset: 26215424
Filename: dat-26215424-26248192.dat Startpos: 26215424 Endpos: 26248192 Filelength: 32768

File -- Header: dat Total Offset: 26739712
Filename: dat-26739712-26772480.dat Startpos: 26739712 Endpos: 26772480 Filelength: 32768

File -- Header: dat Total Offset: 27264000
Filename: dat-27264000-27280384.dat Startpos: 27264000 Endpos: 27280384 Filelength: 16384

Recovery of files done

Rapier finished at: Sun Jan 11 15:58:11 2009

An Example CSV File

"Rapier CSV Log File"
"Version: 0.2 Alpha"
"Copyright by Citadel Systems, L.L.C."
"Website: http://www.citadelsystems.net"
"License: Citadel Systems, L.L.C. grants Licensee a non-exclusive and"
"non-transferable license to use the Product. Licensee may not use the"
"product for commercial purposes beyond an initial thirty (30) day "
"evaluation period without the purchase of a commercial license from "
"Citadel Systems, L.L.C. Commercial purposes include any activity engaged"
"in for the purpose of directly generating revenue or in support of "
"activity that generates revenue. This license does not entitle Licensee"
"to receive from Citadel Systems, L.L.C. hard-copy documentation, "
"technical support, telephone assistance, or enhancements or updates to "


"the Product."

"Rapier started at: Sun Jan 11 15:58:08 2009"

Filename,File Type (Extension),Starting Offset,Ending Offset,File Length

txt-327676-328700.txt,txt,327666,328700,1024
dat-26215424-26248192.dat,dat,26215424,26248192,32768
dat-26739712-26772480.dat,dat,26739712,26772480,32768
dat-27264000-27280384.dat,dat,27264000,27280384,16384

"Rapier finished at: Sun Jan 11 15:58:11 2009"

Other Suggested Uses

Word Searches

Version 0.2 does something new. It can be configured to search for a word then pull out X number of bytes before the word and after the word. This feature came in handy when I was doing my forensics review for Toad SQL logs (see my blog on Oracle Forensics: Toad from Quest Software). I was able to find my keyword and then pull out 4096 bytes before my keyword. Also, I set the total file size to be 8192 bytes, which includes the 4096 bytes before my keyword + keyword + what ever is left to make a total of 8192 bytes. For example, my keyword length is 10, Rapier would grab 4096 bytes before my keyword + 10 (keyword length) + 4082 bytes after my keyword = 8192 bytes total.

ascii_config_generator.pl For Generating Rapier Config Files From Keywords

Located under the tools directory, in the Rapier file download, is a ASCII to hex converter. If you have a list of keywords use this to create your rapier.config file. Below is from the output of ascii_config_generator.pl -man.

ascii_config_generator.pl [options]

Options:
--help Brief help message
--man Full documentation
--wordfile {file} File containing the wordlist. Note: 1 word per line.
--output {file} New Rapier config file
--beforetext {#} How many bytes to grab before keyword. Default: 1024. Optional.
--totallength {#} Total length to grab. Default: 4096. Optional.
--nocase Do not create lines with uppper and lower case. Optional.

Below is an example of it being ran at the command line:

#  ./ascii_config_generator.pl --wordfile keywords.txt \
--output new_rapier.config --beforetext 512 --totallength 4096

Sample Output From The Script

hello,\x68\x65\x6C\x6C\x6F,,512,4096
Dodge_Charger,\x44\x6F\x64\x67\x65\x5F\x43\x68\x61\x72\x67\x65\x72,,512,4096
Daytona,\x44\x61\x79\x74\x6F\x6E\x61,,512,4096
HELLO,\x48\x45\x4C\x4C\x4F,,512,4096
DODGE_CHARGER,\x44\x4F\x44\x47\x45\x5F\x43\x48\x41\x52\x47\x45\x52,,512,4096
DAYTONA,\x44\x41\x59\x54\x4F\x4E\x41,,512,4096
hello,\x68\x65\x6C\x6C\x6F,,512,4096
dodge_charger,\x64\x6F\x64\x67\x65\x5F\x63\x68\x61\x72\x67\x65\x72,,512,4096
daytona,\x64\x61\x79\x74\x6F\x6E\x61,,512,4096

The script will generate three lines for every keyword. The first set of lines, I had three keywords in my list, are converted to hex exactly how they look in the keyword file. The next set is convert into all upper case and the last set is converted into all lower case. The only thing left to do is use the new config file with Rapier.

Screenshots of Rapier

Rapier working — Click on the picture to bring up a larger view.

Rapier 0.1 Alpha Working
Rapier finished — Click on the picture to bring up a larger view.
Rapier 0.1 Alpha Working

Additional Headers

If you need headers for files try: http://www.garykessler.net/library/file_sigs.html

Download

Download it at: http://www.citadelsystems.net/index.php/forensics-tools/34-data-carver/46-rapier

Keven Murphy, GCFA Gold #24, is an IT security manager contracted to a Fortune 100 defense contractor.