Autopsy  4.5.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
FilesIdentifierIngestModule.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2014 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.modules.interestingitems;
20 
21 import java.util.ArrayList;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.concurrent.ConcurrentHashMap;
27 import java.util.logging.Level;
28 import org.openide.util.NbBundle;
29 import org.openide.util.NbBundle.Messages;
40 import org.sleuthkit.datamodel.AbstractFile;
41 import org.sleuthkit.datamodel.BlackboardArtifact;
42 import org.sleuthkit.datamodel.BlackboardAttribute;
43 import org.sleuthkit.datamodel.TskCoreException;
44 import org.sleuthkit.datamodel.TskData;
45 
50 @NbBundle.Messages({
51  "FilesIdentifierIngestModule.getFilesError=Error getting interesting files sets from file."
52 })
53 final class FilesIdentifierIngestModule implements FileIngestModule {
54 
55  private static final Object sharedResourcesLock = new Object();
56  private static final Logger logger = Logger.getLogger(FilesIdentifierIngestModule.class.getName());
57  private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
58  private static final Map<Long, List<FilesSet>> interestingFileSetsByJob = new ConcurrentHashMap<>();
59  private final FilesIdentifierIngestJobSettings settings;
60  private final IngestServices services = IngestServices.getInstance();
61  private IngestJobContext context;
62  private Blackboard blackboard;
63 
70  FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
71  this.settings = settings;
72  }
73 
77  @Override
78  public void startUp(IngestJobContext context) throws IngestModuleException {
79  this.context = context;
80  synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
81  if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
82  // Starting up the first instance of this module for this ingest
83  // job, so get the interesting file sets definitions snapshot
84  // for the job. Note that getting this snapshot atomically via a
85  // synchronized definitions manager method eliminates the need
86  // to disable the interesting files set definition UI during ingest.
87  List<FilesSet> filesSets = new ArrayList<>();
88  try {
89  for (FilesSet set : FilesSetsManager.getInstance().getInterestingFilesSets().values()) {
90  if (settings.interestingFilesSetIsEnabled(set.getName())) {
91  filesSets.add(set);
92  }
93  }
94  } catch (FilesSetsManager.FilesSetsManagerException ex) {
95  throw new IngestModuleException(Bundle.FilesIdentifierIngestModule_getFilesError(), ex);
96  }
97  FilesIdentifierIngestModule.interestingFileSetsByJob.put(context.getJobId(), filesSets);
98  }
99  }
100  }
101 
105  @Override
106  @Messages({"FilesIdentifierIngestModule.indexError.message=Failed to index interesting file hit artifact for keyword search."})
107  public ProcessResult process(AbstractFile file) {
108  blackboard = Case.getCurrentCase().getServices().getBlackboard();
109 
110  // Skip slack space files.
111  if (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
112  return ProcessResult.OK;
113  }
114 
115  // See if the file belongs to any defined interesting files set.
116  List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
117  for (FilesSet filesSet : filesSets) {
118  String ruleSatisfied = filesSet.fileIsMemberOf(file);
119  if (ruleSatisfied != null) {
120  try {
121  // Post an interesting files set hit artifact to the
122  // blackboard.
123  String moduleName = InterestingItemsIngestModuleFactory.getModuleName();
124  BlackboardArtifact artifact = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
125  Collection<BlackboardAttribute> attributes = new ArrayList<>();
126 
127  // Add a set name attribute to the artifact. This adds a
128  // fair amount of redundant data to the attributes table
129  // (i.e., rows that differ only in artifact id), but doing
130  // otherwise would requires reworking the interesting files
131  // set hit artifact.
132  BlackboardAttribute setNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, moduleName, filesSet.getName());
133  attributes.add(setNameAttribute);
134 
135  // Add a category attribute to the artifact to record the
136  // interesting files set membership rule that was satisfied.
137  BlackboardAttribute ruleNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, moduleName, ruleSatisfied);
138  attributes.add(ruleNameAttribute);
139 
140  artifact.addAttributes(attributes);
141  try {
142  // index the artifact for keyword search
143  blackboard.indexArtifact(artifact);
144  } catch (Blackboard.BlackboardException ex) {
145  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + artifact.getArtifactID(), ex); //NON-NLS
146  MessageNotifyUtil.Notify.error(Bundle.FilesIdentifierIngestModule_indexError_message(), artifact.getDisplayName());
147  }
148 
149  services.fireModuleDataEvent(new ModuleDataEvent(moduleName, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, Collections.singletonList(artifact)));
150 
151  // make an ingest inbox message
152  StringBuilder detailsSb = new StringBuilder();
153  detailsSb.append("File: " + file.getParentPath() + file.getName() + "<br/>\n");
154  detailsSb.append("Rule Set: " + filesSet.getName());
155 
156  services.postMessage(IngestMessage.createDataMessage(InterestingItemsIngestModuleFactory.getModuleName(),
157  "Interesting File Match: " + filesSet.getName() + "(" + file.getName() +")",
158  detailsSb.toString(),
159  file.getName(),
160  artifact));
161 
162  } catch (TskCoreException ex) {
163  FilesIdentifierIngestModule.logger.log(Level.SEVERE, "Error posting to the blackboard", ex); //NOI18N NON-NLS
164  }
165  }
166  }
167  return ProcessResult.OK;
168  }
169 
173  @Override
174  public void shutDown() {
175  if (context != null) {
176  if (refCounter.decrementAndGet(this.context.getJobId()) == 0) {
177  // Shutting down the last instance of this module for this ingest
178  // job, so discard the interesting file sets definitions snapshot
179  // for the job.
180  FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());
181  }
182  }
183  }
184 }

Copyright © 2012-2016 Basis Technology. Generated on: Tue Feb 20 2018
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.