19 package org.sleuthkit.autopsy.modules.interestingitems;
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Collection;
24 import java.util.List;
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;
43 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY;
44 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
53 @NbBundle.Messages({
"FilesIdentifierIngestModule.getFilesError=Error getting interesting files sets from file."})
54 final class FilesIdentifierIngestModule implements FileIngestModule {
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 static final String MODULE_NAME = InterestingItemsIngestModuleFactory.getModuleName();
62 private final FilesIdentifierIngestJobSettings settings;
63 private final IngestServices services = IngestServices.getInstance();
64 private IngestJobContext context;
65 private Blackboard blackboard;
73 FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
74 this.settings = settings;
78 public void startUp(IngestJobContext context)
throws IngestModuleException {
79 this.context = context;
80 synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
81 if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
87 List<FilesSet> filesSets =
new ArrayList<>();
89 for (FilesSet set : FilesSetsManager.getInstance().getInterestingFilesSets().values()) {
90 if (settings.interestingFilesSetIsEnabled(set.getName())) {
94 }
catch (FilesSetsManager.FilesSetsManagerException ex) {
95 throw new IngestModuleException(Bundle.FilesIdentifierIngestModule_getFilesError(), ex);
97 FilesIdentifierIngestModule.interestingFileSetsByJob.put(context.getJobId(), filesSets);
103 @Messages({
"FilesIdentifierIngestModule.indexError.message=Failed to index interesting file hit artifact for keyword search."})
104 public ProcessResult process(AbstractFile file) {
106 blackboard = Case.getCurrentCaseThrows().getSleuthkitCase().getBlackboard();
107 }
catch (NoCurrentCaseException ex) {
108 logger.log(Level.SEVERE,
"Exception while getting open case.", ex);
109 return ProcessResult.ERROR;
113 if (file.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK)) {
114 return ProcessResult.OK;
118 List<FilesSet> filesSets = FilesIdentifierIngestModule.interestingFileSetsByJob.get(this.context.getJobId());
119 for (FilesSet filesSet : filesSets) {
120 String ruleSatisfied = filesSet.fileIsMemberOf(file);
121 if (ruleSatisfied != null) {
124 Collection<BlackboardAttribute> attributes = Arrays.asList(
131 new BlackboardAttribute(
132 TSK_SET_NAME, MODULE_NAME,
138 new BlackboardAttribute(
139 TSK_CATEGORY, MODULE_NAME,
144 if (!blackboard.artifactExists(file, BlackboardArtifact.Type.TSK_INTERESTING_ITEM, attributes)) {
145 BlackboardArtifact artifact = file.newAnalysisResult(
146 BlackboardArtifact.Type.TSK_INTERESTING_ITEM, Score.SCORE_LIKELY_NOTABLE,
147 null, filesSet.getName(), null,
149 .getAnalysisResult();
153 blackboard.postArtifact(artifact, MODULE_NAME, context.getJobId());
154 }
catch (Blackboard.BlackboardException ex) {
155 logger.log(Level.SEVERE,
"Unable to index blackboard artifact " + artifact.getArtifactID(), ex);
156 MessageNotifyUtil.Notify.error(Bundle.FilesIdentifierIngestModule_indexError_message(), artifact.getDisplayName());
160 StringBuilder detailsSb =
new StringBuilder();
161 detailsSb.append(
"File: ").append(file.getParentPath()).append(file.getName()).append(
"<br/>\n");
162 detailsSb.append(
"Rule Set: ").append(filesSet.getName());
164 services.postMessage(IngestMessage.createDataMessage(InterestingItemsIngestModuleFactory.getModuleName(),
165 "Interesting File Match: " + filesSet.getName() +
"(" + file.getName() +
")",
166 detailsSb.toString(),
170 }
catch (TskCoreException ex) {
171 FilesIdentifierIngestModule.logger.log(Level.SEVERE,
"Error posting to the blackboard", ex);
175 return ProcessResult.OK;
179 public void shutDown() {
180 if (context != null) {
181 if (refCounter.decrementAndGet(
this.context.getJobId()) == 0) {
185 FilesIdentifierIngestModule.interestingFileSetsByJob.remove(this.context.getJobId());