Autopsy  4.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.Collections;
23 import java.util.List;
24 import java.util.Map;
25 import java.util.concurrent.ConcurrentHashMap;
26 import java.util.logging.Level;
27 import org.openide.util.Exceptions;
28 import org.openide.util.NbBundle;
29 import org.openide.util.NbBundle.Messages;
39 import org.sleuthkit.datamodel.AbstractFile;
40 import org.sleuthkit.datamodel.BlackboardArtifact;
41 import org.sleuthkit.datamodel.BlackboardAttribute;
42 import org.sleuthkit.datamodel.TskCoreException;
43 
48 final class FilesIdentifierIngestModule implements FileIngestModule {
49  @Messages({
50  "FilesIdentifierIngestModule.getFilesError=Error getting interesting files sets from file."
51  })
52 
53  private static final Object sharedResourcesLock = new Object();
54  private static final Logger logger = Logger.getLogger(FilesIdentifierIngestModule.class.getName());
55  private static final IngestModuleReferenceCounter refCounter = new IngestModuleReferenceCounter();
56  private static final Map<Long, List<FilesSet>> interestingFileSetsByJob = new ConcurrentHashMap<>();
57  private final FilesIdentifierIngestJobSettings settings;
58  private IngestJobContext context;
59  private Blackboard blackboard;
60 
67  FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
68  this.settings = settings;
69  }
70 
74  @Override
75  public void startUp(IngestJobContext context) throws IngestModuleException {
76  this.context = context;
77  synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
78  if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
79  // Starting up the first instance of this module for this ingest
80  // job, so get the interesting file sets definitions snapshot
81  // for the job. Note that getting this snapshot atomically via a
82  // synchronized definitions manager method eliminates the need
83  // to disable the interesting files set definition UI during ingest.
84  List<FilesSet> filesSets = new ArrayList<>();
85  try {
86  for (FilesSet set : InterestingItemDefsManager.getInstance().getInterestingFilesSets().values()) {
87  if (settings.interestingFilesSetIsEnabled(set.getName())) {
88  filesSets.add(set);
89  }
90  }
91  } catch (InterestingItemDefsManager.InterestingItemDefsManagerException ex) {
92  throw new IngestModuleException(Bundle.FilesIdentifierIngestModule_getFilesError(), ex);
93  }
94  FilesIdentifierIngestModule.interestingFileSetsByJob.put(context.getJobId(), filesSets);
95  }
96  }
97  }
98 
102  @Override
103  public ProcessResult process(AbstractFile file) {
104  blackboard = Case.getCurrentCase().getServices().getBlackboard();
105 
106  // See if the file belongs to any defined interesting files set.
107  List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
108  for (FilesSet filesSet : filesSets) {
109  String ruleSatisfied = filesSet.fileIsMemberOf(file);
110  if (ruleSatisfied != null) {
111  try {
112  // Post an interesting files set hit artifact to the
113  // blackboard.
114  String moduleName = InterestingItemsIngestModuleFactory.getModuleName();
115  BlackboardArtifact artifact = file.newArtifact(BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT);
116 
117  // Add a set name attribute to the artifact. This adds a
118  // fair amount of redundant data to the attributes table
119  // (i.e., rows that differ only in artifact id), but doing
120  // otherwise would requires reworking the interesting files
121  // set hit artifact.
122  BlackboardAttribute setNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME, moduleName, filesSet.getName());
123  artifact.addAttribute(setNameAttribute);
124 
125  // Add a category attribute to the artifact to record the
126  // interesting files set membership rule that was satisfied.
127  BlackboardAttribute ruleNameAttribute = new BlackboardAttribute(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY, moduleName, ruleSatisfied);
128  artifact.addAttribute(ruleNameAttribute);
129 
130  try {
131  // index the artifact for keyword search
132  blackboard.indexArtifact(artifact);
133  } catch (Blackboard.BlackboardException ex) {
134  logger.log(Level.SEVERE, NbBundle.getMessage(Blackboard.class, "Blackboard.unableToIndexArtifact.error.msg", artifact.getDisplayName()), ex); //NON-NLS
135  MessageNotifyUtil.Notify.error(
136  NbBundle.getMessage(Blackboard.class, "Blackboard.unableToIndexArtifact.exception.msg"), artifact.getDisplayName());
137  }
138 
139  IngestServices.getInstance().fireModuleDataEvent(new ModuleDataEvent(moduleName, BlackboardArtifact.ARTIFACT_TYPE.TSK_INTERESTING_FILE_HIT, Collections.singletonList(artifact)));
140 
141  } catch (TskCoreException ex) {
142  FilesIdentifierIngestModule.logger.log(Level.SEVERE, "Error posting to the blackboard", ex); //NOI18N NON-NLS
143  }
144  }
145  }
146  return ProcessResult.OK;
147  }
148 
152  @Override
153  public void shutDown() {
154  if (context != null) {
155  if (refCounter.decrementAndGet(this.context.getJobId()) == 0) {
156  // Shutting down the last instance of this module for this ingest
157  // job, so discard the interesting file sets definitions snapshot
158  // for the job.
159  FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());
160  }
161  }
162  }
163 }

Copyright © 2012-2015 Basis Technology. Generated on: Wed Apr 6 2016
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.