19package org.sleuthkit.autopsy.modules.interestingitems;
21import java.util.ArrayList;
22import java.util.Arrays;
23import java.util.Collection;
26import java.util.concurrent.ConcurrentHashMap;
27import java.util.logging.Level;
28import org.openide.util.NbBundle;
29import org.openide.util.NbBundle.Messages;
30import org.sleuthkit.autopsy.casemodule.Case;
31import org.sleuthkit.autopsy.casemodule.NoCurrentCaseException;
32import org.sleuthkit.autopsy.coreutils.Logger;
33import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
34import org.sleuthkit.autopsy.ingest.FileIngestModule;
35import org.sleuthkit.autopsy.ingest.IngestJobContext;
36import org.sleuthkit.autopsy.ingest.IngestMessage;
37import org.sleuthkit.autopsy.ingest.IngestModuleReferenceCounter;
38import org.sleuthkit.autopsy.ingest.IngestServices;
39import org.sleuthkit.datamodel.AbstractFile;
40import org.sleuthkit.datamodel.Blackboard;
41import org.sleuthkit.datamodel.BlackboardArtifact;
42import org.sleuthkit.datamodel.BlackboardAttribute;
43import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_CATEGORY;
44import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SET_NAME;
45import org.sleuthkit.datamodel.Score;
46import org.sleuthkit.datamodel.TskCoreException;
47import org.sleuthkit.datamodel.TskData;
53@NbBundle.Messages({
"FilesIdentifierIngestModule.getFilesError=Error getting interesting files sets from file."})
56 private static final Object sharedResourcesLock =
new Object();
59 private static final Map<Long, List<FilesSet>> interestingFileSetsByJob =
new ConcurrentHashMap<>();
62 private final FilesIdentifierIngestJobSettings settings;
65 private Blackboard blackboard;
73 FilesIdentifierIngestModule(FilesIdentifierIngestJobSettings settings) {
74 this.settings = settings;
79 this.context = context;
80 synchronized (FilesIdentifierIngestModule.sharedResourcesLock) {
81 if (FilesIdentifierIngestModule.refCounter.incrementAndGet(context.getJobId()) == 1) {
87 List<FilesSet> filesSets =
new ArrayList<>();
90 if (settings.interestingFilesSetIsEnabled(
set.getName())) {
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) {
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);
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());
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());
SleuthkitCase getSleuthkitCase()
static Case getCurrentCaseThrows()
synchronized static Logger getLogger(String name)
static void error(String title, String message)
static IngestMessage createDataMessage(String source, String subject, String detailsHtml, String uniqueKey, BlackboardArtifact data)
static synchronized IngestServices getInstance()
Map< String, FilesSet > getInterestingFilesSets()
static synchronized FilesSetsManager getInstance()