Autopsy  4.11.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-2018 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;
41 import org.sleuthkit.datamodel.AbstractFile;
42 import org.sleuthkit.datamodel.BlackboardArtifact;
43 import org.sleuthkit.datamodel.BlackboardAttribute;
44 import org.sleuthkit.datamodel.TskCoreException;
45 import org.sleuthkit.datamodel.TskData;
46 
51 @NbBundle.Messages({
52  "FilesIdentifierIngestModule.getFilesError=Error getting interesting files sets from file."
53 })
54 final class FilesIdentifierIngestModule implements FileIngestModule {
55 
56  private static final Object sharedResourcesLock = new Object();
57  private static final Logger logger = Logger.getLogger(FilesIdentifierIngestModule.class.getName());
58  private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
59  private static final Map<Long, List<FilesSet>> interestingFileSetsByJob = new ConcurrentHashMap<>();
60  private final FilesIdentifierIngestJobSettings settings;
61  private final IngestServices services = IngestServices.getInstance();
62  private IngestJobContext context;
63  private Blackboard blackboard;
64 
71  FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
72  this.settings = settings;
73  }
74 
78  @Override
79  public void startUp(IngestJobContext context) throws IngestModuleException {
80  this.context = context;
81  synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
82  if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
83  // Starting up the first instance of this module for this ingest
84  // job, so get the interesting file sets definitions snapshot
85  // for the job. Note that getting this snapshot atomically via a
86  // synchronized definitions manager method eliminates the need
87  // to disable the interesting files set definition UI during ingest.
88  List<FilesSet> filesSets = new ArrayList<>();
89  try {
90  for (FilesSet set : FilesSetsManager.getInstance().getInterestingFilesSets().values()) {
91  if (settings.interestingFilesSetIsEnabled(set.getName())) {
92  filesSets.add(set);
93  }
94  }
95  } catch (FilesSetsManager.FilesSetsManagerException ex) {
96  throw new IngestModuleException(Bundle.FilesIdentifierIngestModule_getFilesError(), ex);
97  }
98  FilesIdentifierIngestModule.interestingFileSetsByJob.put(context.getJobId(), filesSets);
99  }
100  }
101  }
102 
106  @Override
107  @Messages({"FilesIdentifierIngestModule.indexError.message=Failed to index interesting file hit artifact for keyword search."})
108  public ProcessResult process(AbstractFile file) {
109  Case currentCase;
110  try {
111  currentCase = Case.getCurrentCaseThrows();
112  } catch (NoCurrentCaseException ex) {
113  logger.log(Level.SEVERE, "Exception while getting open case.", ex); //NON-NLS
114  return ProcessResult.ERROR;
115  }
116  blackboard = currentCase.getServices().getBlackboard();
117 
118  // Skip slack space files.
119  if (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
120  return ProcessResult.OK;
121  }
122 
123  // See if the file belongs to any defined interesting files set.
124  List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
125  for (FilesSet filesSet : filesSets) {
126  String ruleSatisfied = filesSet.fileIsMemberOf(file);
127  if (ruleSatisfied != null) {
128  try {
129  // Post an interesting files set hit artifact to the
130  // blackboard.
131  String moduleName = InterestingItemsIngestModuleFactory.getModuleName();
132 
133  Collection<BlackboardAttribute> attributes = new ArrayList<>();
134 
135  // Add a set name attribute to the artifact. This adds a
136  // fair amount of redundant data to the attributes table
137  // (i.e., rows that differ only in artifact id), but doing
138  // otherwise would requires reworking the interesting files
139  // set hit artifact.
140  BlackboardAttribute setNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, moduleName, filesSet.getName());
141  attributes.add(setNameAttribute);
142 
143  // Add a category attribute to the artifact to record the
144  // interesting files set membership rule that was satisfied.
145  BlackboardAttribute ruleNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, moduleName, ruleSatisfied);
146  attributes.add(ruleNameAttribute);
147 
148  org.sleuthkit.datamodel.Blackboard tskBlackboard = currentCase.getSleuthkitCase().getBlackboard();
149  // Create artifact if it doesn't already exist.
150  if (!tskBlackboard.artifactExists(file, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, attributes)) {
151  BlackboardArtifact artifact = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
152  artifact.addAttributes(attributes);
153 
154  try {
155  // index the artifact for keyword search
156  blackboard.indexArtifact(artifact);
157  } catch (Blackboard.BlackboardException ex) {
158  logger.log(Level.SEVERE, "Unable to index blackboard artifact " + artifact.getArtifactID(), ex); //NON-NLS
159  MessageNotifyUtil.Notify.error(Bundle.FilesIdentifierIngestModule_indexError_message(), artifact.getDisplayName());
160  }
161 
162  services.fireModuleDataEvent(new ModuleDataEvent(moduleName, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, Collections.singletonList(artifact)));
163 
164  // make an ingest inbox message
165  StringBuilder detailsSb = new StringBuilder();
166  detailsSb.append("File: " + file.getParentPath() + file.getName() + "<br/>\n");
167  detailsSb.append("Rule Set: " + filesSet.getName());
168 
169  services.postMessage(IngestMessage.createDataMessage(InterestingItemsIngestModuleFactory.getModuleName(),
170  "Interesting File Match: " + filesSet.getName() + "(" + file.getName() +")",
171  detailsSb.toString(),
172  file.getName(),
173  artifact));
174  }
175  } catch (TskCoreException ex) {
176  FilesIdentifierIngestModule.logger.log(Level.SEVERE, "Error posting to the blackboard", ex); //NOI18N NON-NLS
177  }
178  }
179  }
180  return ProcessResult.OK;
181  }
182 
186  @Override
187  public void shutDown() {
188  if (context != null) {
189  if (refCounter.decrementAndGet(this.context.getJobId()) == 0) {
190  // Shutting down the last instance of this module for this ingest
191  // job, so discard the interesting file sets definitions snapshot
192  // for the job.
193  FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());
194  }
195  }
196  }
197 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.