/*! \page mod_ingest_page Developing Ingest Modules \section ingest_modules_getting_started Getting Started This page describes how to develop ingest modules using either Java or Python (Jython). It assumes you have already set up your development environment as described in \ref mod_dev_page or \ref mod_dev_py_page. \section ingest_module_types Ingest Module Types Ingest modules analyze data from a data source (e.g., a disk image or a folder of logical files). There are two types of ingest modules in Autopsy: - Data-source-level ingest modules - File-level ingest modules The difference between these two types of modules is what gets passed in to them: - Data source-level ingest modules get passed in a reference to a data source and it is up to the module to search for the files that it wants to analyze. - File-level ingest modules are passed in a reference to each file, one at a time, and it analyzes the file that gets passed in. Here are some guidelines for choosing the type of your ingest module: - Your module should be a data-source-level ingest module only if the following are true: - It needs to retrieve and analyze only a small number of files. - It can find the files by name or other metadata in the database. - It does not depend on results from other file-level ingest modules. - It does not need access to the contents of ZIP and other archive files. For example, our Windows registry analysis is done as a data source-level ingest module because it can query for the registry hives and process the small number of files that are found. - If your needs are not met by a data source-level ingest module, then it should be a file-level ingest module. As you will learn a little later in this guide, it is possible to make an ingest module that has both file-level and data-source level capabilities. You would do this when you need to work at both levels to get all of your analysis done. The modules in such a pair will be enabled or disabled together and will have common per ingest job and global settings. The text below will refer to example code in the org.sleuthkit.autopsy.examples package. The sample modules don't do anything particularly useful, but they can serve as templates for developing your own ingest modules. \section ingest_modules_lifecycle Ingest Module Life Cycle Before we dive into the details of creating a module, it is important to understand the life cycle of the module. Note that this life cycle is much different for Autopsy 3.1 and newer modules compared to Autopsy 3.0 modules. This section only talks about 3.1 and newer modules. You will need to implement at least two classes to make an ingest module: -# A factory class that will be created when Autopsy starts and will provide configuration panels to Autopsy and will create instances of your ingest module. -# An ingest module class that will be instantiated by the factory when the ingest modules are run. A new instance of this class will be created for each ingest thread. Here is an example sequence of events. Details will be provided below. -# User launches Autopsy and it looks for classes that implement the org.sleuthkit.autopsy.ingest.IngestModuleFactory interface. -# Autopsy finds and creates an instance of your FooIngestModuleFactory class. -# User adds a disk image. -# Autopsy presents the list of available ingest modules to the user and uses the utility methods from FooIngestModuleFactory class to get the module's name, description, and configuration panels. -# User enables your module (and others). -# Autopsy uses FooIngestModuleFactory to create two instances of FooIngestModule (Autopsy is using two threads to process the files). -# Autopsy calls FooIngestModule.startUp() on each thread and then calls FooIngestModule.process() to pass in each file. \section ingest_modules_implementing_ingestmodulefactory_basic Creating a Basic Ingest Module \subsection ingest_modules_implementing_basic_factory Basic Ingest Module Factory The first step to write an ingest module is to make its factory. There are three general types of things that a factory does: -# Provides basic information such as the module's name, version, and description. (required) -# Creates ingest modules. (required) -# Provides panels so that the user can configure the module. (optional) This section covers the required parts of a basic factory so that we can make the ingest module. A later section (\ref ingest_modules_making_options) covers how you can use the factory to provide options to the user. To make writing a simple factory easier, Autopsy provides an adapter class that implements the "optional" methods in the interface. Our basic factory will use the adapter. -# Make a factory class by either: - Copy and pasting the sample code from org.sleuthkit.autopsy.examples.SampleIngestModuleFactory (Java) or org.sleuthkit.autopsy.examples.ingestmodule.py. - Manually define a new class that extends (Java) or inherits (Jython) org.sleuthkit.autopsy.ingest.IngestModuleFactoryAdapter. If you are using Java, NetBeans will likely complain that you have not implemented the necessary methods and you can use its "hints" to automatically generate stubs for them. -# Update and create the needed methods using the org.sleuthkit.autopsy.ingest.IngestModuleFactory interface documentation. You can also use the sample code mentioned above for examples of what the methods should do if you did not already copy and paste them. -# If you are using Java, import org.openide.util.lookup.ServiceProvider and add a dependency on the NetBeans Lookup API module to the NetBeans module that contains your ingest module. Then add a NetBeans ServiceProvider annotation so that the factory is found at run time: \code @ServiceProvider(service = IngestModuleFactory.class) \endcode At this point, when you add a data source to an Autopsy case, you should see the module in the list of ingest modules. If you don't see it, double check that you either implemented org.sleuthkit.autopsy.ingest.IngestModuleFactory or extended or inherited org.sleuthkit.autopsy.ingest.IngestModuleFactoryAdapter. If using Java, make sure that you added the service provider annotation. \subsection ingest_modules_implementing_ingestmodule Common Concepts of Ingest Modules Before we cover the specific interfaces of the two different types of modules, let's talk about some common things. - They both have a startUp() method and the expectation is that if there is any error in setting up the module, then they will throw an exception from this method so that ingest can be immediately stopped before analysis begins and the user can fix the problem. - Autopsy will call a module from only a single thread. It may make several threads, but it will make an instance of the module for each thread. You do not need to worry about thread safety unless you are using static variables or other kinds of variables that would be shared among multiple instances of the module. \subsection ingest_modules_implementing_datasourceingestmodule Creating a Data Source-level Ingest Module To create a data source ingest module: -# Create the ingest module class by either: - Copy and paste the sample modules from: - Java: Core/src/org/sleuthkit/autopsy/examples/SampleDataSourceIngestModule.java - Python: pythonExamples/dataSourceIngestModule.py (https://github.com/sleuthkit/autopsy/tree/develop/pythonExamples) - Or the manual approach is to define a new class that implements (Java) or inherits (Jython) org.sleuthkit.autopsy.ingest.DataSourceIngestModule. If you are using Java, the NetBeans IDE will complain that you have not implemented one or more of the required methods. You can use its "hints" to automatically generate stubs for the missing methods. -# Configure your factory class to create instances of the new ingest module class. To do this, you will need to change the isDataSourceIngestModuleFactory() method to return true and have the createDataSourceIngestModule() method return a new instance of your ingest module. Both of these methods have default "no-op" implementations in the IngestModuleFactoryAdapter that we used. Your factory should have code similar to this Java code: \code @Override public boolean isDataSourceIngestModuleFactory() { return true; } @Override public DataSourceIngestModule createDataSourceIngestModule(IngestModuleIngestJobSettings ingestOptions) { return new FooDataSourceIngestModule(); // replace this class name with the name of your class } \endcode -# Use this page, the sample, and the documentation for the org.sleuthkit.autopsy.ingest.DataSourceIngestModule interfaces to implement the startUp() and process() methods. - org.sleuthkit.autopsy.ingest.DataSourceIngestModule.startUp() is where any initialiation occurs. If your module has a critical failure and will not be able to run, your startUp method should throw an IngestModuleException to stop ingest. - org.sleuthkit.autopsy.ingest.DataSourceIngestModule.process() is where all of the work of a data source ingest module is done. It will be called exactly once. The process() method receives a reference to an org.sleuthkit.datamodel.Content object and an org.sleuthkit.autopsy.ingest.DataSourceIngestModuleProgress object. The former is a representation of the data source. The latter should be used by the module instance to report progress as it does its potentially long-running processing. To be a good citizen within Autopsy, the module should also periodically call org.sleuthkit.autopsy.ingest.IngestJobContext.isJobCancelled() and break off processing if the ingest is canceled. Note that data source ingest modules must find the files that they want to analyze. The best way to do that is using one of the findFiles() methods of the org.sleuthkit.autopsy.casemodule.services.FileManager class. See \ref mod_dev_other_services for more details. \subsection ingest_modules_implementing_fileingestmodule Creating a File Ingest Module To create a file ingest module: To create a data source ingest module: -# Create the ingest module class by either: - Copy and paste the sample modules from: - Java: Core/src/org/sleuthkit/autopsy/examples/SampleFileIngestModule.java - Python: pythonExamples/fileIngestModule.py (https://github.com/sleuthkit/autopsy/tree/develop/pythonExamples) - Or the manual approach is to define a new class that implements (Java) or inherits (Jython) org.sleuthkit.autopsy.ingest.FileIngestModule. If you are using Java, the NetBeans IDE will complain that you have not implemented one or more of the required methods. You can use its "hints" to automatically generate stubs for the missing methods. -# Configure your factory class to create instances of the new ingest module class. To do this, you will need to change the isFileIngestModuleFactory() method to return true and have the createFileIngestModule() method return a new instance of your ingest module. Both of these methods have default "no-op" implementations in the IngestModuleFactoryAdapter that we used. Your factory should have code similar to this Java code: \code @Override public boolean isFileIngestModuleFactory() { return true; } @Override public FileIngestModule createFileIngestModule(IngestModuleIngestJobSettings ingestOptions) { return new FooFileIngestModule(); // replace this class name with the name of your class } \endcode -# Use this page, the sample, and the documentation for the org.sleuthkit.autopsy.ingest.FileIngestModule interface to implement the startUp(), and process(), and shutDown() methods. - org.sleuthkit.autopsy.ingest.FileIngestModule.startUp() should have any code that you need to initialize your module. If you have any startup errors, be sure to throw a IngestModuleException exception to stop ingest. - org.sleuthkit.autopsy.ingest.FileIngestModule.process() is where all of the work of a file ingest module is done. It will be called repeatedly between startUp() and shutDown(), once for each file Autopsy feeds into the pipeline of which the module instance is a part. The process() method receives a reference to a org.sleuthkit.datamodel.AbstractFile object. \subsection ingest_modules_implementing_next Next Steps This section gave you the outline of making the module. Now we'll cover what you can do in the module. The following sections often make use of the org.sleuthkit.autopsy.ingest.IngestServices class, which provides many convenient services to make module writing easier. Also make sure you refer to \ref mod_dev_other_services if you are looking for a feature. \section ingest_modules_making_results Doing Something With Your Results The previous section outlined how to make the basic module and how to get access to the data. The next step is to then do some fancy analysis and present the results to the user. The first question that you must answer is what type of data do you want the user to see. There are two options: -# Data that can be accessed from the tree on the left-hand side of the UI and can be displayed in a table. To do this, you will make blackboard artifacts. -# Data that is in a big text file or some other report that the user can review. To do this, you will use the Case.addReport() method to make the output available in the directory tree. \subsection ingest_modules_making_results_bb Posting Results to the Blackboard The blackboard is used to store results so that they are displayed in the results tree. See \ref platform_blackboard for details on posting results to it. You use the blackboard when you have specific items to show the user. if you want to just shown them a big report from another library or tool, see \ref mod_report_page. The blackboard defines artifacts for specific data types (such as web bookmarks). You can use one of the standard artifact types or create your own. After you make an artifact, you should call sleuthkit.Blackboard.postArtifact(), which will: